From 648fe238cab483bdcd45872ab84c37a8e5103864 Mon Sep 17 00:00:00 2001 From: FunkyFr3sh Date: Sun, 2 Jun 2024 22:17:26 +0200 Subject: [PATCH] tweak hook function --- inc/hook.h | 2 +- src/dd.c | 2 +- src/dllmain.c | 2 +- src/hook.c | 10 +++++----- src/winapi_hooks.c | 12 ++++++------ 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/inc/hook.h b/inc/hook.h index e2a5b87..893238f 100644 --- a/inc/hook.h +++ b/inc/hook.h @@ -125,7 +125,7 @@ extern SETUNHANDLEDEXCEPTIONFILTERPROC real_SetUnhandledExceptionFilter; extern BOOL g_hook_active; extern HOOKLIST g_hook_hooklist[]; -void hook_init(BOOL initial_hook); +void hook_init(); void hook_exit(); void hook_patch_iat(HMODULE hmod, BOOL unhook, char* module_name, char* function_name, PROC new_function); void hook_patch_iat_list(HMODULE hmod, BOOL unhook, HOOKLIST* hooks, BOOL is_local); diff --git a/src/dd.c b/src/dd.c index ea370aa..cc2d248 100644 --- a/src/dd.c +++ b/src/dd.c @@ -1202,7 +1202,7 @@ HRESULT dd_SetCooperativeLevel(HWND hwnd, DWORD dwFlags) if (!g_ddraw.wndproc) { - hook_init(FALSE); + hook_init(); g_ddraw.wndproc = (WNDPROC)real_SetWindowLongA(g_ddraw.hwnd, GWL_WNDPROC, (LONG)fake_WndProc); g_ddraw.gui_thread_id = GetWindowThreadProcessId(g_ddraw.hwnd, NULL); diff --git a/src/dllmain.c b/src/dllmain.c index 0f9e5c4..c131c54 100644 --- a/src/dllmain.c +++ b/src/dllmain.c @@ -121,7 +121,7 @@ BOOL WINAPI DllMain(HANDLE hDll, DWORD dwReason, LPVOID lpReserved) } timeBeginPeriod(1); - hook_init(TRUE); + hook_init(); break; } case DLL_PROCESS_DETACH: diff --git a/src/hook.c b/src/hook.c index f26ca90..9d9b54c 100644 --- a/src/hook.c +++ b/src/hook.c @@ -632,9 +632,9 @@ void hook_revert(HOOKLIST* hooks) } } -void hook_init(BOOL initial_hook) +void hook_init() { - if (initial_hook) + if (!g_hook_active) { if (g_config.hook == 4 && hook_got_ddraw_import(GetModuleHandleA(NULL), TRUE)) { @@ -646,7 +646,7 @@ void hook_init(BOOL initial_hook) if (!g_hook_active || g_config.hook == 3 || g_config.hook == 4) { #if defined(_DEBUG) && defined(_MSC_VER) - if (initial_hook) + if (!g_hook_active) { DetourTransactionBegin(); DetourUpdateThread(GetCurrentThread()); @@ -655,12 +655,12 @@ void hook_init(BOOL initial_hook) } #endif - if (initial_hook) + if (!g_hook_active) { hook_patch_iat(GetModuleHandle("AcGenral"), FALSE, "user32.dll", "SetWindowsHookExA", (PROC)fake_SetWindowsHookExA); } - hook_create((HOOKLIST*)&g_hook_hooklist, initial_hook); + hook_create((HOOKLIST*)&g_hook_hooklist, !g_hook_active); g_hook_active = TRUE; } diff --git a/src/winapi_hooks.c b/src/winapi_hooks.c index 09a8a9e..560a8b8 100644 --- a/src/winapi_hooks.c +++ b/src/winapi_hooks.c @@ -1195,7 +1195,7 @@ HMODULE WINAPI fake_LoadLibraryA(LPCSTR lpLibFileName) if (hmod && hmod != hmod_old) { - hook_init(FALSE); + hook_init(); } return hmod; @@ -1223,7 +1223,7 @@ HMODULE WINAPI fake_LoadLibraryW(LPCWSTR lpLibFileName) if (hmod && hmod != hmod_old) { - hook_init(FALSE); + hook_init(); } return hmod; @@ -1251,7 +1251,7 @@ HMODULE WINAPI fake_LoadLibraryExA(LPCSTR lpLibFileName, HANDLE hFile, DWORD dwF if (hmod && hmod != hmod_old) { - hook_init(FALSE); + hook_init(); } return hmod; @@ -1279,7 +1279,7 @@ HMODULE WINAPI fake_LoadLibraryExW(LPCWSTR lpLibFileName, HANDLE hFile, DWORD dw if (hmod && hmod != hmod_old) { - hook_init(FALSE); + hook_init(); } return hmod; @@ -1650,7 +1650,7 @@ HRESULT WINAPI fake_CoCreateInstance(REFCLSID rclsid, LPUNKNOWN pUnkOuter, DWORD if ((!quartz_dll && GetModuleHandleA("quartz")) || (!msvfw32_dll && GetModuleHandleA("msvfw32"))) { - hook_init(FALSE); + hook_init(); } return result; @@ -1667,7 +1667,7 @@ MCIERROR WINAPI fake_mciSendCommandA(MCIDEVICEID IDDevice, UINT uMsg, DWORD_PTR if ((!quartz_dll && GetModuleHandleA("quartz")) || (!msvfw32_dll && GetModuleHandleA("msvfw32"))) { - hook_init(FALSE); + hook_init(); } return result;