From 242c40a19763590871853ef2d5a699b1ad8c7ccf Mon Sep 17 00:00:00 2001 From: FunkyFr3sh Date: Sun, 6 Jun 2021 19:03:38 +0200 Subject: [PATCH] hook SetWindowsHookExA --- inc/hook.h | 2 ++ inc/winapi_hooks.h | 1 + src/hook.c | 3 +++ src/winapi_hooks.c | 10 ++++++++++ 4 files changed, 16 insertions(+) diff --git a/inc/hook.h b/inc/hook.h index b561d93..1426e38 100644 --- a/inc/hook.h +++ b/inc/hook.h @@ -30,6 +30,7 @@ typedef BOOL (WINAPI* ENABLEWINDOWPROC)(HWND, BOOL); typedef HWND (WINAPI* CREATEWINDOWEXAPROC)(DWORD, LPCSTR, LPCSTR, DWORD, int, int, int, int, HWND, HMENU, HINSTANCE, LPVOID); typedef BOOL (WINAPI* DESTROYWINDOWPROC)(HWND); typedef int (WINAPI* MAPWINDOWPOINTSPROC)(HWND, HWND, LPPOINT, UINT); +typedef HHOOK (WINAPI* SETWINDOWSHOOKEXAPROC)(int, HOOKPROC, HINSTANCE, DWORD); typedef int (WINAPI* GETDEVICECAPSPROC)(HDC, int); typedef HMODULE (WINAPI* LOADLIBRARYAPROC)(LPCSTR); typedef HMODULE (WINAPI* LOADLIBRARYWPROC)(LPCWSTR); @@ -58,6 +59,7 @@ extern ENABLEWINDOWPROC real_EnableWindow; extern CREATEWINDOWEXAPROC real_CreateWindowExA; extern DESTROYWINDOWPROC real_DestroyWindow; extern MAPWINDOWPOINTSPROC real_MapWindowPoints; +extern SETWINDOWSHOOKEXAPROC real_SetWindowsHookExA; extern GETDEVICECAPSPROC real_GetDeviceCaps; extern LOADLIBRARYAPROC real_LoadLibraryA; extern LOADLIBRARYWPROC real_LoadLibraryW; diff --git a/inc/winapi_hooks.h b/inc/winapi_hooks.h index 7139b42..b8b1434 100644 --- a/inc/winapi_hooks.h +++ b/inc/winapi_hooks.h @@ -26,6 +26,7 @@ LONG WINAPI fake_GetWindowLongA(HWND hWnd, int nIndex); BOOL WINAPI fake_EnableWindow(HWND hWnd, BOOL bEnable); BOOL WINAPI fake_DestroyWindow(HWND hWnd); int WINAPI fake_MapWindowPoints(HWND hWndFrom, HWND hWndTo, LPPOINT lpPoints, UINT cPoints); +HHOOK WINAPI fake_SetWindowsHookExA(int idHook, HOOKPROC lpfn, HINSTANCE hmod, DWORD dwThreadId); int WINAPI fake_GetDeviceCaps(HDC hdc, int index); HMODULE WINAPI fake_LoadLibraryA(LPCSTR lpLibFileName); HMODULE WINAPI fake_LoadLibraryW(LPCWSTR lpLibFileName); diff --git a/src/hook.c b/src/hook.c index 8a29f08..fdd8c41 100644 --- a/src/hook.c +++ b/src/hook.c @@ -38,6 +38,7 @@ ENABLEWINDOWPROC real_EnableWindow = EnableWindow; CREATEWINDOWEXAPROC real_CreateWindowExA = CreateWindowExA; DESTROYWINDOWPROC real_DestroyWindow = DestroyWindow; MAPWINDOWPOINTSPROC real_MapWindowPoints = MapWindowPoints; +SETWINDOWSHOOKEXAPROC real_SetWindowsHookExA = SetWindowsHookExA; GETDEVICECAPSPROC real_GetDeviceCaps = GetDeviceCaps; LOADLIBRARYAPROC real_LoadLibraryA = LoadLibraryA; LOADLIBRARYWPROC real_LoadLibraryW = LoadLibraryW; @@ -439,6 +440,7 @@ void hook_early_init() hook_patch_iat(GetModuleHandle(NULL), FALSE, "dinput.dll", "DirectInputCreateW", (PROC)fake_DirectInputCreateW); hook_patch_iat(GetModuleHandle(NULL), FALSE, "dinput.dll", "DirectInputCreateEx", (PROC)fake_DirectInputCreateEx); hook_patch_iat(GetModuleHandle(NULL), FALSE, "dinput8.dll", "DirectInput8Create", (PROC)fake_DirectInput8Create); + hook_patch_iat(GetModuleHandle("AcGenral"), FALSE, "user32.dll", "SetWindowsHookExA", (PROC)fake_SetWindowsHookExA); } void hook_exit() @@ -491,4 +493,5 @@ void hook_exit() hook_patch_iat(GetModuleHandle(NULL), TRUE, "dinput.dll", "DirectInputCreateW", (PROC)fake_DirectInputCreateW); hook_patch_iat(GetModuleHandle(NULL), TRUE, "dinput.dll", "DirectInputCreateEx", (PROC)fake_DirectInputCreateEx); hook_patch_iat(GetModuleHandle(NULL), TRUE, "dinput8.dll", "DirectInput8Create", (PROC)fake_DirectInput8Create); + hook_patch_iat(GetModuleHandle("AcGenral"), TRUE, "user32.dll", "SetWindowsHookExA", (PROC)fake_SetWindowsHookExA); } diff --git a/src/winapi_hooks.c b/src/winapi_hooks.c index 3681a5e..19adea2 100644 --- a/src/winapi_hooks.c +++ b/src/winapi_hooks.c @@ -364,6 +364,16 @@ int WINAPI fake_MapWindowPoints(HWND hWndFrom, HWND hWndTo, LPPOINT lpPoints, UI return real_MapWindowPoints(hWndFrom, hWndTo, lpPoints, cPoints); } +HHOOK WINAPI fake_SetWindowsHookExA(int idHook, HOOKPROC lpfn, HINSTANCE hmod, DWORD dwThreadId) +{ + if (idHook == WH_KEYBOARD_LL && hmod && GetModuleHandle("AcGenral") == hmod) + { + return NULL; + } + + return real_SetWindowsHookExA(idHook, lpfn, hmod, dwThreadId); +} + int WINAPI fake_GetDeviceCaps(HDC hdc, int index) { if (g_ddraw &&