mirror of
https://github.com/FunkyFr3sh/cnc-ddraw.git
synced 2025-03-24 17:49:52 +01:00
fix GCC build
This commit is contained in:
parent
62d1451885
commit
5c919177d9
90
src/hook.c
90
src/hook.c
@ -42,58 +42,68 @@ void Hook_PatchIAT(HMODULE hMod, char *moduleName, char *functionName, PROC newF
|
|||||||
if (!hMod || hMod == INVALID_HANDLE_VALUE || !newFunction)
|
if (!hMod || hMod == INVALID_HANDLE_VALUE || !newFunction)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
PIMAGE_DOS_HEADER pDosHeader = (PIMAGE_DOS_HEADER)hMod;
|
#ifdef _MSC_VER
|
||||||
if (pDosHeader->e_magic != IMAGE_DOS_SIGNATURE)
|
__try
|
||||||
return;
|
|
||||||
|
|
||||||
PIMAGE_NT_HEADERS pNTHeaders = (PIMAGE_NT_HEADERS)((DWORD)pDosHeader + (DWORD)pDosHeader->e_lfanew);
|
|
||||||
if (pNTHeaders->Signature != IMAGE_NT_SIGNATURE)
|
|
||||||
return;
|
|
||||||
|
|
||||||
PIMAGE_IMPORT_DESCRIPTOR pImportDescriptor = (PIMAGE_IMPORT_DESCRIPTOR)((DWORD)pDosHeader +
|
|
||||||
(DWORD)(pNTHeaders->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress));
|
|
||||||
|
|
||||||
if (pImportDescriptor == (PIMAGE_IMPORT_DESCRIPTOR)pNTHeaders)
|
|
||||||
return;
|
|
||||||
|
|
||||||
while (pImportDescriptor->FirstThunk)
|
|
||||||
{
|
{
|
||||||
char *impModuleName = (char *)((DWORD)pDosHeader + (DWORD)(pImportDescriptor->Name));
|
#endif
|
||||||
|
PIMAGE_DOS_HEADER pDosHeader = (PIMAGE_DOS_HEADER)hMod;
|
||||||
|
if (pDosHeader->e_magic != IMAGE_DOS_SIGNATURE)
|
||||||
|
return;
|
||||||
|
|
||||||
if (_stricmp(impModuleName, moduleName) == 0)
|
PIMAGE_NT_HEADERS pNTHeaders = (PIMAGE_NT_HEADERS)((DWORD)pDosHeader + (DWORD)pDosHeader->e_lfanew);
|
||||||
|
if (pNTHeaders->Signature != IMAGE_NT_SIGNATURE)
|
||||||
|
return;
|
||||||
|
|
||||||
|
PIMAGE_IMPORT_DESCRIPTOR pImportDescriptor = (PIMAGE_IMPORT_DESCRIPTOR)((DWORD)pDosHeader +
|
||||||
|
(DWORD)(pNTHeaders->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress));
|
||||||
|
|
||||||
|
if (pImportDescriptor == (PIMAGE_IMPORT_DESCRIPTOR)pNTHeaders)
|
||||||
|
return;
|
||||||
|
|
||||||
|
while (pImportDescriptor->FirstThunk)
|
||||||
{
|
{
|
||||||
PIMAGE_THUNK_DATA pFirstThunk =
|
char* impModuleName = (char*)((DWORD)pDosHeader + (DWORD)(pImportDescriptor->Name));
|
||||||
(PIMAGE_THUNK_DATA)((DWORD)pDosHeader + (DWORD)pImportDescriptor->FirstThunk);
|
|
||||||
|
|
||||||
PIMAGE_THUNK_DATA pOrigFirstThunk =
|
if (_stricmp(impModuleName, moduleName) == 0)
|
||||||
(PIMAGE_THUNK_DATA)((DWORD)pDosHeader + (DWORD)pImportDescriptor->OriginalFirstThunk);
|
|
||||||
|
|
||||||
while (pFirstThunk->u1.Function && pOrigFirstThunk->u1.AddressOfData)
|
|
||||||
{
|
{
|
||||||
PIMAGE_IMPORT_BY_NAME pImport =
|
PIMAGE_THUNK_DATA pFirstThunk =
|
||||||
(PIMAGE_IMPORT_BY_NAME)((DWORD)pDosHeader + pOrigFirstThunk->u1.AddressOfData);
|
(PIMAGE_THUNK_DATA)((DWORD)pDosHeader + (DWORD)pImportDescriptor->FirstThunk);
|
||||||
|
|
||||||
if ((pOrigFirstThunk->u1.Ordinal & IMAGE_ORDINAL_FLAG) == 0 &&
|
PIMAGE_THUNK_DATA pOrigFirstThunk =
|
||||||
_stricmp((const char *)pImport->Name, functionName) == 0)
|
(PIMAGE_THUNK_DATA)((DWORD)pDosHeader + (DWORD)pImportDescriptor->OriginalFirstThunk);
|
||||||
|
|
||||||
|
while (pFirstThunk->u1.Function && pOrigFirstThunk->u1.AddressOfData)
|
||||||
{
|
{
|
||||||
DWORD oldProtect;
|
PIMAGE_IMPORT_BY_NAME pImport =
|
||||||
|
(PIMAGE_IMPORT_BY_NAME)((DWORD)pDosHeader + pOrigFirstThunk->u1.AddressOfData);
|
||||||
|
|
||||||
if (VirtualProtect(&pFirstThunk->u1.Function, sizeof(DWORD), PAGE_READWRITE, &oldProtect))
|
if ((pOrigFirstThunk->u1.Ordinal & IMAGE_ORDINAL_FLAG) == 0 &&
|
||||||
|
_stricmp((const char*)pImport->Name, functionName) == 0)
|
||||||
{
|
{
|
||||||
pFirstThunk->u1.Function = (DWORD)newFunction;
|
DWORD oldProtect;
|
||||||
VirtualProtect(&pFirstThunk->u1.Function, sizeof(DWORD), oldProtect, &oldProtect);
|
|
||||||
|
if (VirtualProtect(&pFirstThunk->u1.Function, sizeof(DWORD), PAGE_READWRITE, &oldProtect))
|
||||||
|
{
|
||||||
|
pFirstThunk->u1.Function = (DWORD)newFunction;
|
||||||
|
VirtualProtect(&pFirstThunk->u1.Function, sizeof(DWORD), oldProtect, &oldProtect);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
pFirstThunk++;
|
||||||
|
pOrigFirstThunk++;
|
||||||
}
|
}
|
||||||
|
|
||||||
pFirstThunk++;
|
|
||||||
pOrigFirstThunk++;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
pImportDescriptor++;
|
pImportDescriptor++;
|
||||||
|
}
|
||||||
|
#ifdef _MSC_VER
|
||||||
}
|
}
|
||||||
|
__except (EXCEPTION_EXECUTE_HANDLER)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void Hook_Create(char *moduleName, char *functionName, PROC newFunction, PROC *function)
|
void Hook_Create(char *moduleName, char *functionName, PROC newFunction, PROC *function)
|
||||||
@ -213,18 +223,20 @@ void Hook_Init()
|
|||||||
{
|
{
|
||||||
if (!Hook_Active || HookingMethod == 3 || HookingMethod == 4)
|
if (!Hook_Active || HookingMethod == 3 || HookingMethod == 4)
|
||||||
{
|
{
|
||||||
|
#ifdef _MSC_VER
|
||||||
if (!Hook_Active && HookingMethod == 3)
|
if (!Hook_Active && HookingMethod == 3)
|
||||||
{
|
{
|
||||||
FARPROC proc = GetProcAddress(GetModuleHandle("kernelbase.dll"), "LoadLibraryExW");
|
FARPROC proc = GetProcAddress(GetModuleHandle("kernelbase.dll"), "LoadLibraryExW");
|
||||||
|
|
||||||
if (proc)
|
if (proc)
|
||||||
real_LoadLibraryExW = proc;
|
real_LoadLibraryExW = (LOADLIBRARYEXWPROC)proc;
|
||||||
|
|
||||||
DetourTransactionBegin();
|
DetourTransactionBegin();
|
||||||
DetourUpdateThread(GetCurrentThread());
|
DetourUpdateThread(GetCurrentThread());
|
||||||
DetourAttach((PVOID*)&real_LoadLibraryExW, (PVOID)fake_LoadLibraryExW);
|
DetourAttach((PVOID*)&real_LoadLibraryExW, (PVOID)fake_LoadLibraryExW);
|
||||||
DetourTransactionCommit();
|
DetourTransactionCommit();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
Hook_Active = TRUE;
|
Hook_Active = TRUE;
|
||||||
|
|
||||||
@ -266,6 +278,7 @@ void Hook_Exit()
|
|||||||
{
|
{
|
||||||
Hook_Active = FALSE;
|
Hook_Active = FALSE;
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
if (HookingMethod == 3)
|
if (HookingMethod == 3)
|
||||||
{
|
{
|
||||||
DetourTransactionBegin();
|
DetourTransactionBegin();
|
||||||
@ -273,6 +286,7 @@ void Hook_Exit()
|
|||||||
DetourDetach((PVOID*)&real_LoadLibraryExW, (PVOID)fake_LoadLibraryExW);
|
DetourDetach((PVOID*)&real_LoadLibraryExW, (PVOID)fake_LoadLibraryExW);
|
||||||
DetourTransactionCommit();
|
DetourTransactionCommit();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
Hook_Revert("user32.dll", "GetCursorPos", (PROC)fake_GetCursorPos, (PROC *)&real_GetCursorPos);
|
Hook_Revert("user32.dll", "GetCursorPos", (PROC)fake_GetCursorPos, (PROC *)&real_GetCursorPos);
|
||||||
Hook_Revert("user32.dll", "ClipCursor", (PROC)fake_ClipCursor, (PROC *)&real_ClipCursor);
|
Hook_Revert("user32.dll", "ClipCursor", (PROC)fake_ClipCursor, (PROC *)&real_ClipCursor);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user