mirror of
https://github.com/FunkyFr3sh/cnc-ddraw.git
synced 2025-03-25 01:57:47 +01:00
improve IAT hook performance
This commit is contained in:
parent
bae707f865
commit
df52dd869a
10
inc/hook.h
10
inc/hook.h
@ -8,7 +8,15 @@
|
|||||||
#define HOOK_SKIP_2 0x00000001l
|
#define HOOK_SKIP_2 0x00000001l
|
||||||
#define HOOK_LOCAL_ONLY 0x00000002l
|
#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 struct HOOKLIST { char module_name[32]; HOOKLISTDATA data[30]; } HOOKLIST;
|
||||||
|
|
||||||
typedef BOOL(WINAPI* GETCURSORPOSPROC)(LPPOINT);
|
typedef BOOL(WINAPI* GETCURSORPOSPROC)(LPPOINT);
|
||||||
|
17
src/hook.c
17
src/hook.c
@ -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++)
|
for (int x = 0; hooks[i].data[x].function_name[0]; x++)
|
||||||
{
|
{
|
||||||
DWORD org_function =
|
/* GetProcAddress is slow, save the pointer and reuse it for better performance */
|
||||||
(DWORD)real_GetProcAddress(
|
DWORD org_function = (DWORD)InterlockedExchangeAdd((LONG*)&hooks[i].data[x].org_function, 0);
|
||||||
cur_mod,
|
|
||||||
hooks[i].data[x].function_name);
|
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)
|
if (!hooks[i].data[x].new_function || !org_function)
|
||||||
continue;
|
continue;
|
||||||
@ -357,7 +364,7 @@ void hook_patch_iat_list(HMODULE hmod, BOOL unhook, HOOKLIST* hooks, BOOL is_loc
|
|||||||
{
|
{
|
||||||
DWORD org =
|
DWORD org =
|
||||||
(DWORD)real_GetProcAddress(
|
(DWORD)real_GetProcAddress(
|
||||||
GetModuleHandle(hooks[i].module_name),
|
GetModuleHandleA(hooks[i].module_name),
|
||||||
hooks[i].data[x].function_name);
|
hooks[i].data[x].function_name);
|
||||||
|
|
||||||
if (org && first_thunk->u1.Function != org)
|
if (org && first_thunk->u1.Function != org)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user