From ab773f6469eec19ce8da1f8d62a24ce7b6893e55 Mon Sep 17 00:00:00 2001 From: FunkyFr3sh Date: Tue, 18 Oct 2022 22:21:42 +0200 Subject: [PATCH] hook GetTopWindow --- inc/hook.h | 4 +++- inc/winapi_hooks.h | 1 + src/hook.c | 2 ++ src/winapi_hooks.c | 10 ++++++++++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/inc/hook.h b/inc/hook.h index 725ad40..f7718b2 100644 --- a/inc/hook.h +++ b/inc/hook.h @@ -9,7 +9,7 @@ #define SKIP_HOOK3 0x00000002l typedef struct HOOKLISTDATA { char function_name[32]; PROC new_function; PROC* function; DWORD flags; } HOOKLISTDATA; -typedef struct HOOKLIST { char module_name[32]; HOOKLISTDATA data[24]; } HOOKLIST; +typedef struct HOOKLIST { char module_name[32]; HOOKLISTDATA data[25]; } HOOKLIST; typedef BOOL(WINAPI* GETCURSORPOSPROC)(LPPOINT); typedef BOOL(WINAPI* CLIPCURSORPROC)(const RECT*); @@ -34,6 +34,7 @@ typedef HWND(WINAPI* CREATEWINDOWEXAPROC)(DWORD, LPCSTR, LPCSTR, DWORD, int, int typedef BOOL(WINAPI* DESTROYWINDOWPROC)(HWND); typedef int (WINAPI* MAPWINDOWPOINTSPROC)(HWND, HWND, LPPOINT, UINT); typedef BOOL (WINAPI* SHOWWINDOWPROC)(HWND, int); +typedef HWND(WINAPI* GETTOPWINDOWPROC)(HWND); typedef BOOL(WINAPI* STRETCHBLTPROC)(HDC, int, int, int, int, HDC, int, int, int, int, DWORD); typedef int (WINAPI* SETDIBITSTODEVICEPROC)( @@ -74,6 +75,7 @@ extern CREATEWINDOWEXAPROC real_CreateWindowExA; extern DESTROYWINDOWPROC real_DestroyWindow; extern MAPWINDOWPOINTSPROC real_MapWindowPoints; extern SHOWWINDOWPROC real_ShowWindow; +extern GETTOPWINDOWPROC real_GetTopWindow; extern STRETCHBLTPROC real_StretchBlt; extern SETDIBITSTODEVICEPROC real_SetDIBitsToDevice; extern STRETCHDIBITSPROC real_StretchDIBits; diff --git a/inc/winapi_hooks.h b/inc/winapi_hooks.h index 4dc1f93..074b521 100644 --- a/inc/winapi_hooks.h +++ b/inc/winapi_hooks.h @@ -27,6 +27,7 @@ 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); BOOL WINAPI fake_ShowWindow(HWND hWnd, int nCmdShow); +HWND WINAPI fake_GetTopWindow(HWND hWnd); HHOOK WINAPI fake_SetWindowsHookExA(int idHook, HOOKPROC lpfn, HINSTANCE hmod, DWORD dwThreadId); int WINAPI fake_GetDeviceCaps(HDC hdc, int index); diff --git a/src/hook.c b/src/hook.c index a958b42..e29af3a 100644 --- a/src/hook.c +++ b/src/hook.c @@ -40,6 +40,7 @@ CREATEWINDOWEXAPROC real_CreateWindowExA = CreateWindowExA; DESTROYWINDOWPROC real_DestroyWindow = DestroyWindow; MAPWINDOWPOINTSPROC real_MapWindowPoints = MapWindowPoints; SHOWWINDOWPROC real_ShowWindow = ShowWindow; +GETTOPWINDOWPROC real_GetTopWindow = GetTopWindow; STRETCHBLTPROC real_StretchBlt = StretchBlt; SETDIBITSTODEVICEPROC real_SetDIBitsToDevice = SetDIBitsToDevice; STRETCHDIBITSPROC real_StretchDIBits = StretchDIBits; @@ -80,6 +81,7 @@ static HOOKLIST g_hooks[] = { "DestroyWindow", (PROC)fake_DestroyWindow, (PROC*)&real_DestroyWindow, 0 }, { "MapWindowPoints", (PROC)fake_MapWindowPoints, (PROC*)&real_MapWindowPoints, 0 }, { "ShowWindow", (PROC)fake_ShowWindow, (PROC*)&real_ShowWindow, 0 }, + { "GetTopWindow", (PROC)fake_GetTopWindow, (PROC*)&real_GetTopWindow, 0 }, { "", NULL, NULL, 0 } } }, diff --git a/src/winapi_hooks.c b/src/winapi_hooks.c index fcd8143..efe1f3f 100644 --- a/src/winapi_hooks.c +++ b/src/winapi_hooks.c @@ -517,6 +517,16 @@ BOOL WINAPI fake_ShowWindow(HWND hWnd, int nCmdShow) return real_ShowWindow(hWnd, nCmdShow); } +HWND WINAPI fake_GetTopWindow(HWND hWnd) +{ + if (g_ddraw && g_ddraw->windowed && g_ddraw->hwnd && !hWnd) + { + return g_ddraw->hwnd; + } + + return real_GetTopWindow(hWnd); +} + HHOOK WINAPI fake_SetWindowsHookExA(int idHook, HOOKPROC lpfn, HINSTANCE hmod, DWORD dwThreadId) { if (idHook == WH_KEYBOARD_LL && hmod && GetModuleHandle("AcGenral") == hmod)