Пример #1
0
static int notice_hook(int argc, char *argv[])
{
	char *nick = grab_nick(argv[0]);
	size_t i;

	user_t *u = find_user(nick, irc_pick_server());
	assert(u != NULL);
	if (u->flags & USER_IGNORE || u->flags & USER_IGNORE_NOTICES)
		return 0;

	for (i = 0; i < strlen(argv[3]); i++)
		if (argv[3][i] == 2)
			remove_char_from_str(argv[3], i);

	if (argv[3][0] == 1)
		plugin_ctcp_in_hook(nick, argv[2], argv[3], irc_pick_server());
	else if (argv[2][0] == '#') {
		channel_t *ch = find_channel(argv[2], irc_pick_server());
		if (!ch)
			return -1;
		wio_colored_out(ch->win,
				USER_GREEN,
				"*** NOTICE from %s: %s\n", nick, argv[3]);
	} else
		io_colored_out(USER_GREEN, "*** NOTICE from %s: %s\n", nick,
			       argv[3]);
	free(nick);
	return 0;
}
Пример #2
0
int	parse_server_string	( const char *str )
{
	assert(str);

	if(bool_option("show_all_server_strings"))
		cio_out(str);

	current_server_string = str;

	size_t 	i;
	char 	**argv;
	int	argc;
	char	*buf = NULL;
	server_string_t	*si;
	server_string_list_t *sl;

	/* make a buffer */
	buf = copy_string(str);
	assert(buf != NULL);

	buf[strlen(buf) - 1] = 0;

	if(strlen(buf) == 0) {
		return -1;
	}

	make_argv(&argc, &argv, buf);
	assert(argc != 0);

	// we want a consistent format regardless of whether or not a prefix
	// was sent, so if one wasn't we fake it
	if(argv[0][0] != ':') {		// no prefix was found
		char **tmp = malloc(sizeof(char *) * (argc + 1));

		tmp[0] = malloc(strlen(irc_pick_server()) + 2);
		tmp[0][0] = ':';
		strcpy(&tmp[0][1], irc_pick_server());

		for(i = 0; i < argc; i++) {
			tmp[i + 1] = copy_string(argv[i]);
		}
		free_argv(argc, argv);
		argc++;
		argv = tmp;
	}

	// run hooks
	rcv_hook_t *rcvp = &hook_head;
	for(list_next(rcvp); rcvp != &hook_head; list_next(rcvp)) {
		rcvp->func(argc, argv);
	}

	// find a function to run
	sl = (server_string_list_t *)(head.head.next);
find_next_string_handler:
	for( ; (list_t *)sl != (list_t *)&head; list_next(sl)) {
		si = sl->strings;
		while(si->keystring != NULL) {
			if(strcmp_nc(argv[1], si->keystring) == 0) {
				goto found_string_handler;
			}
			si++;
		}
	}

	// nothing was found
	if(bool_option("verbose") || bool_option("show_unhandled_msgs")) {
		cio_out("unhandled string sent from server: %s\n", str);
	}

	free_argv(argc, argv);
	free(buf);
	return -1;

found_string_handler:
	free_argv(argc, argv);

	if(buf[0] == ':') {
		make_max_argv(&argc, &argv, buf, si->argc);
	} else {
		make_max_argv(&argc, &argv, buf, si->argc - 1);
		char **tmp = malloc(sizeof(char *) * (argc + 1));
		//tmp[0] = copy_string(irc_pick_server());
        tmp[0] = malloc(strlen(irc_pick_server()) + 2);
        tmp[0][0] = ':';
        strcpy(&tmp[0][1], irc_pick_server());
		//add_char_to_str(tmp[0], 0, ':');
		for(i = 0; i < argc; i++) {
			tmp[i + 1] = copy_string(argv[i]);
		}
		free_argv(argc, argv);
		argc++;
		argv = tmp;
	}

	if(si->strip_colon && strlen(argv[argc - 1]) != 0 && argv[argc - 1][0] == ':') {
		remove_char_from_str(argv[argc - 1], 0);
	}

	/**********************************************
	 * make sure argc is correct, so that the
	 * callbacks don't get any suprises
	 **********************************************/
	assert(!(argc > si->argc));
	if(argc < si->argc) {
		char **tmp = argv;
		argv = malloc(sizeof(char *) * si->argc);
		for(i = 0; i < argc; i++) {
			argv[i] = tmp[i];
		}
		for(i = argc; i < si->argc; i++) {
			argv[i] = malloc(1);
			argv[i][0] = 0;
		}
		argc = si->argc;
	}

	int retval = si->hook(argc, argv);

	if(retval) {
		list_next(sl);
		goto find_next_string_handler;
	}

	free_argv(argc, argv);
	current_server_string = NULL;
	return retval;
}
Пример #3
0
int linux_disk_dump_hex_data(char *device_path, long total_sectors_to_read, LP_PROGRAM_DATA PData) 
{	
	FILE *hard_disk, *tmp;
	int num_setor = 0;
	int bytes_per_sector;
	unsigned int data[512];
	int disk_id, partition_id;
	char make[64];
	char logicalSize[8];
	static unsigned long totalBytesLidos = 0;
	assert(device_path != NULL);
	assert(PData != NULL);
	int sectors_really_readed = 0;

	// essa função garante que o parametro "device path" não pode ser incorreto
	if((disk_id = convert_disk_path_to_number(device_path, &partition_id)) == -1)
		return 0x81;		

	hard_disk = fopen(device_path, "rb");
	if((hard_disk == NULL)) return 0x81;
		
	// pegar o tamanho de cada bloco
	if(PData->verbose) 
		msginfo("The hd(%d, %d) was successfully opened ...\n", disk_id, partition_id);
	
	sprintf(make, "cat /sys/block/sd%c/queue/logical_block_size > data.ztx", device_path[7]); 
	int cmd_retval = system(make);
		 
	usleep(10);
	tmp = fopen( "data.ztx", "rb");
	if((tmp != NULL))
	{
		if(PData->verbose)
			msginfo("Reading data ...\n");
		
		fgets(logicalSize, sizeof(logicalSize), tmp);
		if(strlen(logicalSize) <= 0) {
			if(PData->verbose) 
				msgerro( "Failed to read data from file ...\n");
			if(tmp) fclose(tmp);
			remove( "data.ztx" );
			return 0x84;
		}
		
		if(tmp) fclose(tmp);
		remove( "data.ztx" );
	} else 
		return 0x84;

	bytes_per_sector = strtol(logicalSize, NULL, 10);
	
	if(PData->verbose)
		msginfo("The disk has %d bytes per sector.\n", bytes_per_sector);
	
	if(bytes_per_sector > 0)
	{
		// criar o arquivo para onde os dados serão redirecionados ...
		remove_char_from_str(device_path, '/');
		sprintf(make, "%s_%d_dump.tmp", device_path, disk_id);
		tmp = fopen(make, "wb");
		
		if((tmp != NULL))
		{
			if(PData->verbose)
				msginfo( "Parsing data ...\n\n");
			while(num_setor != total_sectors_to_read)
			{						
				int bytes_readed = linux_read_disk_sector(num_setor, bytes_per_sector, data, hard_disk);
				if(bytes_readed) {
					fwrite(data, 1, sizeof(data), tmp);
					sectors_really_readed++;
				}
				else
					if(PData->verbose)
						msgaviso( "No one byte was readed from sector %d.\n", num_setor);

				totalBytesLidos += bytes_readed;
				num_setor++;
			}
			
			if(PData->verbose)
				msginfo( "%d sector(s) was readed from disk\n", sectors_really_readed);

			if(tmp) fclose(tmp);
			// converter os dados lidos para o formato hexadecimal
			if(PData->verbose) {
				msginfo( "%ld bytes readed from disk\n", totalBytesLidos);
				msginfo( "Converting data to HEX format ...\n");
			}
			 
			FILE *inputFile, *outputFile;
			struct conversion_data a1;
			struct conversion_mode a2;
			CONVERSION_DATA StructConv = &a1;
			CONVERSION_MODE StructMode = &a2;
			char output_filename[64];
			
			sprintf(output_filename, "%s_dump.hex", device_path);
			inputFile = fopen(make, "rb");
			outputFile = fopen(output_filename, "wb");
	
			assert(inputFile != NULL);
			assert(outputFile != NULL);
					
			StructConv->bytes_to_read = totalBytesLidos;
			StructMode->s_mode = DEFAULT_MODE;
			
			short res = hex_file_write_data_in_specified_mode(StructConv, StructMode, inputFile, outputFile, DEFAULT_MODE);
			
			if(PData->verbose && res == 0xFF) {
				msgerro( "Failed to make dump to HEX format (Cod: %d).\n", errno);
			}
			else if(PData->verbose && res == 0) 
				msgsucesso( "The HEX dump was finished\n");
	
			if((inputFile != NULL)) fclose(inputFile);
			if((outputFile != NULL)) fclose(outputFile);
			
			remove(make);
		} else {
			if(PData->verbose) 
				msgerro( "Failed to read %s (Code: %d).\n*** Are you root?\n", make, errno);
			return 0x85;
		}	
	} else return 0x81;
	
	return 0;
}