Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (!InitializeHooks()) Cleanup();
- }
- // Originals
- extern "C"
- {
- static LPVOID(WINAPI *orig_VirtualAlloc)(LPVOID lpAddress, SIZE_T dwSize, DWORD flAllocationType, DWORD flProtect) = VirtualAlloc;
- }
- // Detoured
- LPVOID WINAPI my_VirtualAlloc(LPVOID lpAddress, SIZE_T dwSize, DWORD flAllocationType, DWORD flProtect)
- {
- void *RetAddress = _ReturnAddress();
- Log::Msg("0x%I64X - VirtualAlloc(Region: 0x%I64X-0x%I64X, dwSize: 0x%I64X, flAllocationType: 0x%X, flProtect: 0x%X) Call: 0x%I64X",
- orig_VirtualAlloc, lpAddress, ((DWORD64)lpAddress + dwSize), dwSize, flAllocationType, flProtect, RetAddress);
- return flAllocationType == (MEM_RESERVE | MEM_WRITE_WATCH | MEM_COMMIT) ? orig_VirtualAlloc(lpAddress, dwSize, MEM_RESERVE | MEM_COMMIT, flProtect) :
- orig_VirtualAlloc(lpAddress, dwSize, flAllocationType, flProtect);
- }
- /* Hooks */
- // Initialization
- BOOL Hooking::InitializeHooks()
- {
- // init minhook
- if (MH_Initialize() != MH_OK) {
- Log::Fatal("MinHook failed to initialize");
- return FALSE;
- }
- // init VirtualAlloc Patch
- if (MH_CreateHook(&VirtualAlloc, &my_VirtualAlloc, reinterpret_cast<void**>(&orig_VirtualAlloc)) != MH_OK || (MH_EnableHook(&VirtualAlloc) != MH_OK)) {
- Log::Error("Failed to hook VirtualAlloc");
- return FALSE;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement