1
0
mirror of https://github.com/FunkyFr3sh/cnc-ddraw.git synced 2025-03-15 06:04:49 +01:00

improve IAT hook performance

This commit is contained in:
FunkyFr3sh 2023-10-23 12:16:44 +02:00
parent bae707f865
commit df52dd869a
2 changed files with 21 additions and 6 deletions

View File

@ -8,7 +8,15 @@
#define HOOK_SKIP_2 0x00000001l
#define HOOK_LOCAL_ONLY 0x00000002l
typedef struct HOOKLISTDATA { char function_name[32]; PROC new_function; PROC* function; DWORD flags; } HOOKLISTDATA;
typedef struct HOOKLISTDATA {
char function_name[32];
PROC new_function;
PROC* function;
DWORD flags;
PROC org_function;
HMODULE mod;
} HOOKLISTDATA;
typedef struct HOOKLIST { char module_name[32]; HOOKLISTDATA data[30]; } HOOKLIST;
typedef BOOL(WINAPI* GETCURSORPOSPROC)(LPPOINT);

View File

@ -209,10 +209,17 @@ void hook_patch_obfuscated_iat_list(HMODULE hmod, BOOL unhook, HOOKLIST* hooks,
{
for (int x = 0; hooks[i].data[x].function_name[0]; x++)
{
DWORD org_function =
(DWORD)real_GetProcAddress(
cur_mod,
hooks[i].data[x].function_name);
/* GetProcAddress is slow, save the pointer and reuse it for better performance */
DWORD org_function = (DWORD)InterlockedExchangeAdd((LONG*)&hooks[i].data[x].org_function, 0);
if (!org_function || cur_mod != hooks[i].data[x].mod)
{
hooks[i].data[x].mod = cur_mod;
org_function = (DWORD)real_GetProcAddress(cur_mod, hooks[i].data[x].function_name);
InterlockedExchange((LONG*)&hooks[i].data[x].org_function, (LONG)org_function);
}
if (!hooks[i].data[x].new_function || !org_function)
continue;
@ -357,7 +364,7 @@ void hook_patch_iat_list(HMODULE hmod, BOOL unhook, HOOKLIST* hooks, BOOL is_loc
{
DWORD org =
(DWORD)real_GetProcAddress(
GetModuleHandle(hooks[i].module_name),
GetModuleHandleA(hooks[i].module_name),
hooks[i].data[x].function_name);
if (org && first_thunk->u1.Function != org)