-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathOEPHook.cpp
More file actions
31 lines (26 loc) · 844 Bytes
/
OEPHook.cpp
File metadata and controls
31 lines (26 loc) · 844 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <windows.h>
#include "Detours\detours.h"
typedef int (CALLBACK *fnWinMain)(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow);
void HookOEP(void)
{
HMODULE hGameModule = GetModuleHandle(NULL);
PBYTE PEHead = (PBYTE)hGameModule;
PIMAGE_DOS_HEADER pDosHeader = (PIMAGE_DOS_HEADER)hGameModule;
PIMAGE_NT_HEADERS pNTHeader = (PIMAGE_NT_HEADERS)&PEHead[pDosHeader->e_lfanew];
fnWinMain pWinMain = (fnWinMain)&PEHead[pNTHeader->OptionalHeader.AddressOfEntryPoint];
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach((void**)&pWinMain, WinMain);
DetourTransactionCommit();
}
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
{
HookOEP();
}
}
return TRUE;
}