示例#1
0
文件: inject.c 项目: GovanifY/thcrap
BOOL thcrap_inject_into_new(const char *exe_fn, char *args, const char *run_cfg_fn)
{
	int ret = 0;
	json_t *run_cfg = json_load_file_report(run_cfg_fn);
	if(!run_cfg) {
		return 1;
	};
	json_object_set_new(run_cfg, "run_cfg_fn", json_string(run_cfg_fn));
	runconfig_set(run_cfg);
	{
		STRLEN_DEC(exe_fn);
		VLA(char, exe_dir_local, exe_fn_len);
		VLA(char, exe_fn_local, exe_fn_len);
		STARTUPINFOA si = {0};
		PROCESS_INFORMATION pi = {0};
		char *exe_dir = NULL;

		strcpy(exe_fn_local, exe_fn);
		str_slash_normalize_win(exe_fn_local);

		strcpy(exe_dir_local, exe_fn);
		if(PathRemoveFileSpec(exe_dir_local)) {
			exe_dir = exe_dir_local;
		}

		/**
		  * Sure, the alternative would be to set up the entire engine
		  * with all plug-ins and modules to correctly run any additional
		  * detours. While it would indeed be nice to allow those to control
		  * initial startup, it really shouldn't be necessary for now - and
		  * it really does run way too much unnecessary code for my taste.
		  */
		ret = W32_ERR_WRAP(inject_CreateProcessU(
			exe_fn_local, args, NULL, NULL, TRUE, 0, NULL, exe_dir, &si, &pi
		));
		if(ret) {
			char *msg_str = "";

			FormatMessage(
				FORMAT_MESSAGE_FROM_SYSTEM |
				FORMAT_MESSAGE_ALLOCATE_BUFFER |
				FORMAT_MESSAGE_IGNORE_INSERTS,
				NULL, ret, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
				(LPSTR)&msg_str, 0, NULL
			);

			log_mboxf(NULL, MB_OK | MB_ICONEXCLAMATION,
				"Failed to start %s: %s",
				exe_fn, msg_str
			);
			LocalFree(msg_str);
		}
		VLA_FREE(exe_fn_local);
		VLA_FREE(exe_dir_local);
	}
	return ret;
}
示例#2
0
文件: zip.cpp 项目: thpatch/thcrap
static int zip_file_extra_read(zip_file_info_t *file, zip_t *zip, int extra_len)
{
	assert(file);
	assert(zip);

	VLA(char, extra_buf, extra_len);
	DWORD byte_ret;
	int ret = W32_ERR_WRAP(ReadFile(
		zip->hArc, extra_buf, extra_len, &byte_ret, NULL
	));
	if(!ret) {
		zip_file_extra_parse(file, extra_buf, byte_ret);
	}
	VLA_FREE(extra_buf);
	return 0;
}