예제 #1
0
파일: run.cpp 프로젝트: Endimmion/cuwo
uint32_t tgen_generate_debug_chunk(const char * filename,
                                   uint32_t x, uint32_t y)
{
    // restore heap
    mem.restore_heap(saved_heap);

    cpu.reset_stack();
    cpu.push_dword(y);
    cpu.push_dword(x);
    get_self() = MANAGER_ADDRESS;
    add_ret();
    generator_func();

    // save_chunk_now();
    // return 0;
    // address 405E30 is
    // void * __thiscall get_sector_chunk_data(__int64 chunk_pos)
    cpu.push_dword(y);
    cpu.push_dword(x);
    get_self() = MANAGER_ADDRESS;
    add_ret();
    sub_405E30();
    uint32_t chunk_offset = cpu.reg[EAX];
    tgen_dump_mem(filename);

    return chunk_offset;
}
예제 #2
0
파일: run.cpp 프로젝트: Endimmion/cuwo
uint32_t tgen_generate_chunk(uint32_t x, uint32_t y)
{
    // restore heap
    mem.restore_heap(saved_heap);

    cpu.reset_stack();
    cpu.push_dword(y);
    cpu.push_dword(x);
    get_self() = MANAGER_ADDRESS;
    add_ret();
    generator_func();

    // save_chunk_now();
    // return 0;
    // address 405E30 is
    // void * __thiscall get_sector_chunk_data(__int64 chunk_pos)
    cpu.push_dword(y);
    cpu.push_dword(x);
    get_self() = MANAGER_ADDRESS;
    add_ret();
    sub_405E30();

    return cpu.reg[EAX];
}
예제 #3
0
파일: runcmd.c 프로젝트: filatovvo/nagios
int runcmd_cmd2strv(const char *str, int *out_argc, char **out_argv)
{
	int arg = 0, i, a = 0;
	int state, ret = 0;
	size_t len;
	char *argz;

	set_state(STATE_NONE);
	len = strlen(str);

	argz = malloc(len + 10);
	for (i = 0; i < len; i++) {
		const char *p = &str[i];

		switch (*p) {
		case 0:
			return ret;

		case ' ': case '\t': case '\r': case '\n':
			if (is_state(STATE_INARG)) {
				set_state(STATE_NONE);
				argz[a++] = 0;
				continue;
			}
			if (!in_quotes)
				continue;

			break;

		case '\\':
			i++;
			break;

		case '\'':
			if (have_state(STATE_INDQ))
				break;
			if (have_state(STATE_INSQ)) {
				del_state(STATE_INSQ);
				continue;
			}

			/*
			 * quotes can come inside arguments or
			 * at the start of them
			 */
			if (is_state(STATE_NONE) || is_state(STATE_INARG)) {
				if (is_state(STATE_NONE)) {
					/* starting a new argument */
					out_argv[arg++] = &argz[a];
				}
				set_state(STATE_INSQ | STATE_INARG);
				continue;
			}
		case '"':
			if (have_state(STATE_INSQ))
				break;
			if (have_state(STATE_INDQ)) {
				del_state(STATE_INDQ);
				continue;
			}
			if (is_state(STATE_NONE) || is_state(STATE_INARG)) {
				if (is_state(STATE_NONE)) {
					out_argv[arg++] = &argz[a];
				}
				set_state(STATE_INDQ | STATE_INARG);
				continue;
			}
			break;

		case '|':
			if (!in_quotes) {
				add_ret(CMD_HAS_REDIR);
			}
			break;
		case '&': case ';':
			if (!in_quotes) {
				set_state(STATE_SPECIAL);
				add_ret(CMD_HAS_JOBCONTROL);
				if (i && str[i - 1] != *p) {
					argz[a++] = 0;
					out_argv[arg++] = &argz[a];
				}
			}
			break;

		case '`':
			if (!in_quotes) {
				add_ret(CMD_HAS_SUBCOMMAND);
			}
			break;

		case '(':
			if (!in_quotes) {
				add_ret(CMD_HAS_PAREN);
			}
			break;

		case '*': case '?':
			if (!in_quotes) {
				add_ret(CMD_HAS_WILDCARD);
			}

			/* fallthrough */

		default:
			break;
		}

		if (is_state(STATE_NONE)) {
			set_state(STATE_INARG);
			out_argv[arg++] = &argz[a];
		}

		/* by default we simply copy the byte */
		argz[a++] = str[i];
	}

	/* make sure we nul-terminate the last argument */
	argz[a++] = 0;

	if (have_state(STATE_INSQ))
		add_ret(CMD_HAS_UBSQ);
	if (have_state(STATE_INDQ))
		add_ret(CMD_HAS_UBDQ);

	*out_argc = arg;

	return ret;
}