mirror of
https://github.com/FunkyFr3sh/cnc-ddraw.git
synced 2025-03-25 01:57:47 +01:00
add new hook flag for local hooks
This commit is contained in:
parent
b85ee1674f
commit
e7867e1cd3
@ -5,7 +5,8 @@
|
|||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
|
|
||||||
#define SKIP_HOOK2 0x00000001l
|
#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; } HOOKLISTDATA;
|
||||||
typedef struct HOOKLIST { char module_name[32]; HOOKLISTDATA data[30]; } HOOKLIST;
|
typedef struct HOOKLIST { char module_name[32]; HOOKLISTDATA data[30]; } HOOKLIST;
|
||||||
@ -109,7 +110,7 @@ extern HOOKLIST g_hook_hooklist[];
|
|||||||
void hook_init(BOOL initial_hook);
|
void hook_init(BOOL initial_hook);
|
||||||
void hook_exit();
|
void hook_exit();
|
||||||
void hook_patch_iat(HMODULE hmod, BOOL unhook, char* module_name, char* function_name, PROC new_function);
|
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);
|
void hook_patch_iat_list(HMODULE hmod, BOOL unhook, HOOKLIST* hooks, BOOL is_local);
|
||||||
void hook_create(HOOKLIST* hooks, BOOL initial_hook);
|
void hook_create(HOOKLIST* hooks, BOOL initial_hook);
|
||||||
void hook_revert(HOOKLIST* hooks);
|
void hook_revert(HOOKLIST* hooks);
|
||||||
|
|
||||||
|
64
src/hook.c
64
src/hook.c
@ -98,33 +98,33 @@ HOOKLIST g_hook_hooklist[] =
|
|||||||
{
|
{
|
||||||
"ole32.dll",
|
"ole32.dll",
|
||||||
{
|
{
|
||||||
{ "CoCreateInstance", (PROC)fake_CoCreateInstance, (PROC*)&real_CoCreateInstance, SKIP_HOOK2 },
|
{ "CoCreateInstance", (PROC)fake_CoCreateInstance, (PROC*)&real_CoCreateInstance, HOOK_SKIP_2 },
|
||||||
{ "", NULL, NULL, 0 }
|
{ "", NULL, NULL, 0 }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"dinput.dll",
|
"dinput.dll",
|
||||||
{
|
{
|
||||||
{ "DirectInputCreateA", (PROC)fake_DirectInputCreateA, (PROC*)&real_DirectInputCreateA, SKIP_HOOK2 },
|
{ "DirectInputCreateA", (PROC)fake_DirectInputCreateA, (PROC*)&real_DirectInputCreateA, HOOK_SKIP_2 },
|
||||||
//{ "DirectInputCreateW", (PROC)fake_DirectInputCreateW, (PROC*)&real_DirectInputCreateW, SKIP_HOOK2 },
|
//{ "DirectInputCreateW", (PROC)fake_DirectInputCreateW, (PROC*)&real_DirectInputCreateW, HOOK_SKIP_2 },
|
||||||
{ "DirectInputCreateEx", (PROC)fake_DirectInputCreateEx, (PROC*)&real_DirectInputCreateEx, SKIP_HOOK2 },
|
{ "DirectInputCreateEx", (PROC)fake_DirectInputCreateEx, (PROC*)&real_DirectInputCreateEx, HOOK_SKIP_2 },
|
||||||
{ "", NULL, NULL, 0 }
|
{ "", NULL, NULL, 0 }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"dinput8.dll",
|
"dinput8.dll",
|
||||||
{
|
{
|
||||||
{ "DirectInput8Create", (PROC)fake_DirectInput8Create, (PROC*)&real_DirectInput8Create, SKIP_HOOK2 },
|
{ "DirectInput8Create", (PROC)fake_DirectInput8Create, (PROC*)&real_DirectInput8Create, HOOK_SKIP_2 },
|
||||||
{ "", NULL, NULL, 0 }
|
{ "", NULL, NULL, 0 }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"gdi32.dll",
|
"gdi32.dll",
|
||||||
{
|
{
|
||||||
{ "StretchBlt", (PROC)fake_StretchBlt, (PROC*)&real_StretchBlt, SKIP_HOOK2 },
|
{ "StretchBlt", (PROC)fake_StretchBlt, (PROC*)&real_StretchBlt, HOOK_SKIP_2 },
|
||||||
{ "SetDIBitsToDevice", (PROC)fake_SetDIBitsToDevice, (PROC*)&real_SetDIBitsToDevice, SKIP_HOOK2 },
|
{ "SetDIBitsToDevice", (PROC)fake_SetDIBitsToDevice, (PROC*)&real_SetDIBitsToDevice, HOOK_SKIP_2 },
|
||||||
{ "StretchDIBits", (PROC)fake_StretchDIBits, (PROC*)&real_StretchDIBits, SKIP_HOOK2 },
|
{ "StretchDIBits", (PROC)fake_StretchDIBits, (PROC*)&real_StretchDIBits, HOOK_SKIP_2 },
|
||||||
{ "GetDeviceCaps", (PROC)fake_GetDeviceCaps, (PROC*)&real_GetDeviceCaps, 0 },
|
{ "GetDeviceCaps", (PROC)fake_GetDeviceCaps, (PROC*)&real_GetDeviceCaps, HOOK_LOCAL_ONLY },
|
||||||
{ "CreateFontA", (PROC)fake_CreateFontA, (PROC*)&real_CreateFontA, 0 },
|
{ "CreateFontA", (PROC)fake_CreateFontA, (PROC*)&real_CreateFontA, 0 },
|
||||||
{ "CreateFontIndirectA", (PROC)fake_CreateFontIndirectA, (PROC*)&real_CreateFontIndirectA, 0 },
|
{ "CreateFontIndirectA", (PROC)fake_CreateFontIndirectA, (PROC*)&real_CreateFontIndirectA, 0 },
|
||||||
{ "", NULL, NULL, 0 }
|
{ "", NULL, NULL, 0 }
|
||||||
@ -133,12 +133,12 @@ HOOKLIST g_hook_hooklist[] =
|
|||||||
{
|
{
|
||||||
"kernel32.dll",
|
"kernel32.dll",
|
||||||
{
|
{
|
||||||
{ "LoadLibraryA", (PROC)fake_LoadLibraryA, (PROC*)&real_LoadLibraryA, SKIP_HOOK2 },
|
{ "LoadLibraryA", (PROC)fake_LoadLibraryA, (PROC*)&real_LoadLibraryA, HOOK_SKIP_2 },
|
||||||
{ "LoadLibraryW", (PROC)fake_LoadLibraryW, (PROC*)&real_LoadLibraryW, SKIP_HOOK2 },
|
{ "LoadLibraryW", (PROC)fake_LoadLibraryW, (PROC*)&real_LoadLibraryW, HOOK_SKIP_2 },
|
||||||
{ "LoadLibraryExA", (PROC)fake_LoadLibraryExA, (PROC*)&real_LoadLibraryExA, SKIP_HOOK2 },
|
{ "LoadLibraryExA", (PROC)fake_LoadLibraryExA, (PROC*)&real_LoadLibraryExA, HOOK_SKIP_2 },
|
||||||
{ "LoadLibraryExW", (PROC)fake_LoadLibraryExW, (PROC*)&real_LoadLibraryExW, SKIP_HOOK2 },
|
{ "LoadLibraryExW", (PROC)fake_LoadLibraryExW, (PROC*)&real_LoadLibraryExW, HOOK_SKIP_2 },
|
||||||
{ "GetProcAddress", (PROC)fake_GetProcAddress, (PROC*)&real_GetProcAddress, SKIP_HOOK2 },
|
{ "GetProcAddress", (PROC)fake_GetProcAddress, (PROC*)&real_GetProcAddress, HOOK_SKIP_2 },
|
||||||
{ "GetDiskFreeSpaceA", (PROC)fake_GetDiskFreeSpaceA, (PROC*)&real_GetDiskFreeSpaceA, SKIP_HOOK2 },
|
{ "GetDiskFreeSpaceA", (PROC)fake_GetDiskFreeSpaceA, (PROC*)&real_GetDiskFreeSpaceA, HOOK_SKIP_2 },
|
||||||
{ "", NULL, NULL, 0 }
|
{ "", NULL, NULL, 0 }
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -160,10 +160,10 @@ void hook_patch_iat(HMODULE hmod, BOOL unhook, char* module_name, char* function
|
|||||||
strncpy(hooks[0].module_name, module_name, sizeof(hooks[0].module_name) - 1);
|
strncpy(hooks[0].module_name, module_name, sizeof(hooks[0].module_name) - 1);
|
||||||
strncpy(hooks[0].data[0].function_name, function_name, sizeof(hooks[0].data[0].function_name) - 1);
|
strncpy(hooks[0].data[0].function_name, function_name, sizeof(hooks[0].data[0].function_name) - 1);
|
||||||
|
|
||||||
hook_patch_iat_list(hmod, unhook, (HOOKLIST*)&hooks);
|
hook_patch_iat_list(hmod, unhook, (HOOKLIST*)&hooks, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void hook_patch_obfuscated_iat_list(HMODULE hmod, BOOL unhook, HOOKLIST* hooks)
|
void hook_patch_obfuscated_iat_list(HMODULE hmod, BOOL unhook, HOOKLIST* hooks, BOOL is_local)
|
||||||
{
|
{
|
||||||
if (!hmod || hmod == INVALID_HANDLE_VALUE || !hooks)
|
if (!hmod || hmod == INVALID_HANDLE_VALUE || !hooks)
|
||||||
return;
|
return;
|
||||||
@ -212,6 +212,9 @@ void hook_patch_obfuscated_iat_list(HMODULE hmod, BOOL unhook, HOOKLIST* hooks)
|
|||||||
if (!hooks[i].data[x].new_function || !org_function)
|
if (!hooks[i].data[x].new_function || !org_function)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
if (!is_local && (hooks[i].data[x].flags & HOOK_LOCAL_ONLY))
|
||||||
|
continue;
|
||||||
|
|
||||||
if (unhook)
|
if (unhook)
|
||||||
{
|
{
|
||||||
if (first_thunk->u1.Function == (DWORD)hooks[i].data[x].new_function)
|
if (first_thunk->u1.Function == (DWORD)hooks[i].data[x].new_function)
|
||||||
@ -268,9 +271,9 @@ void hook_patch_obfuscated_iat_list(HMODULE hmod, BOOL unhook, HOOKLIST* hooks)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void hook_patch_iat_list(HMODULE hmod, BOOL unhook, HOOKLIST* hooks)
|
void hook_patch_iat_list(HMODULE hmod, BOOL unhook, HOOKLIST* hooks, BOOL is_local)
|
||||||
{
|
{
|
||||||
hook_patch_obfuscated_iat_list(hmod, unhook, hooks);
|
hook_patch_obfuscated_iat_list(hmod, unhook, hooks, is_local);
|
||||||
|
|
||||||
if (!hmod || hmod == INVALID_HANDLE_VALUE || !hooks)
|
if (!hmod || hmod == INVALID_HANDLE_VALUE || !hooks)
|
||||||
return;
|
return;
|
||||||
@ -317,6 +320,9 @@ void hook_patch_iat_list(HMODULE hmod, BOOL unhook, HOOKLIST* hooks)
|
|||||||
if (!unhook && !hooks[i].data[x].new_function)
|
if (!unhook && !hooks[i].data[x].new_function)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
if (!is_local && (hooks[i].data[x].flags & HOOK_LOCAL_ONLY))
|
||||||
|
continue;
|
||||||
|
|
||||||
if (_stricmp((const char*)import->Name, hooks[i].data[x].function_name) == 0)
|
if (_stricmp((const char*)import->Name, hooks[i].data[x].function_name) == 0)
|
||||||
{
|
{
|
||||||
DWORD op;
|
DWORD op;
|
||||||
@ -415,7 +421,7 @@ void hook_create(HOOKLIST* hooks, BOOL initial_hook)
|
|||||||
{
|
{
|
||||||
for (int x = 0; hooks[i].data[x].function_name[0]; x++)
|
for (int x = 0; hooks[i].data[x].function_name[0]; x++)
|
||||||
{
|
{
|
||||||
if ((hooks[i].data[x].flags & SKIP_HOOK2))
|
if ((hooks[i].data[x].flags & HOOK_SKIP_2))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
DetourTransactionBegin();
|
DetourTransactionBegin();
|
||||||
@ -470,12 +476,14 @@ void hook_create(HOOKLIST* hooks, BOOL initial_hook)
|
|||||||
_strcmpi(mod_filename, "Shw32") == 0)
|
_strcmpi(mod_filename, "Shw32") == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (_strnicmp(game_dir, mod_dir, strlen(game_dir)) == 0 ||
|
BOOL is_local = _strnicmp(game_dir, mod_dir, strlen(game_dir)) == 0;
|
||||||
|
|
||||||
|
if (is_local ||
|
||||||
_strcmpi(mod_filename, "MSVFW32") == 0 ||
|
_strcmpi(mod_filename, "MSVFW32") == 0 ||
|
||||||
_strcmpi(mod_filename, "quartz") == 0 ||
|
_strcmpi(mod_filename, "quartz") == 0 ||
|
||||||
_strcmpi(mod_filename, "winmm") == 0)
|
_strcmpi(mod_filename, "winmm") == 0)
|
||||||
{
|
{
|
||||||
hook_patch_iat_list(hmod, FALSE, hooks);
|
hook_patch_iat_list(hmod, FALSE, hooks, is_local);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -487,7 +495,7 @@ void hook_create(HOOKLIST* hooks, BOOL initial_hook)
|
|||||||
|
|
||||||
if (g_config.hook == 1)
|
if (g_config.hook == 1)
|
||||||
{
|
{
|
||||||
hook_patch_iat_list(GetModuleHandle(NULL), FALSE, hooks);
|
hook_patch_iat_list(GetModuleHandle(NULL), FALSE, hooks, TRUE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -500,7 +508,7 @@ void hook_revert(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++)
|
||||||
{
|
{
|
||||||
if ((hooks[i].data[x].flags & SKIP_HOOK2))
|
if ((hooks[i].data[x].flags & HOOK_SKIP_2))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
DetourTransactionBegin();
|
DetourTransactionBegin();
|
||||||
@ -544,12 +552,14 @@ void hook_revert(HOOKLIST* hooks)
|
|||||||
{
|
{
|
||||||
_splitpath(mod_path, NULL, mod_dir, mod_filename, NULL);
|
_splitpath(mod_path, NULL, mod_dir, mod_filename, NULL);
|
||||||
|
|
||||||
if (_strnicmp(game_dir, mod_dir, strlen(game_dir)) == 0 ||
|
BOOL is_local = _strnicmp(game_dir, mod_dir, strlen(game_dir)) == 0;
|
||||||
|
|
||||||
|
if (is_local ||
|
||||||
_strcmpi(mod_filename, "MSVFW32") == 0 ||
|
_strcmpi(mod_filename, "MSVFW32") == 0 ||
|
||||||
_strcmpi(mod_filename, "quartz") == 0 ||
|
_strcmpi(mod_filename, "quartz") == 0 ||
|
||||||
_strcmpi(mod_filename, "winmm") == 0)
|
_strcmpi(mod_filename, "winmm") == 0)
|
||||||
{
|
{
|
||||||
hook_patch_iat_list(hmod, TRUE, hooks);
|
hook_patch_iat_list(hmod, TRUE, hooks, is_local);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -561,7 +571,7 @@ void hook_revert(HOOKLIST* hooks)
|
|||||||
|
|
||||||
if (g_config.hook == 1)
|
if (g_config.hook == 1)
|
||||||
{
|
{
|
||||||
hook_patch_iat_list(GetModuleHandle(NULL), TRUE, hooks);
|
hook_patch_iat_list(GetModuleHandle(NULL), TRUE, hooks, TRUE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user