Advertisement
djhonga2001

Untitled

Jan 20th, 2017
409
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. if (!InitializeHooks()) Cleanup();
  2. }
  3.  
  4. // Originals
  5. extern "C"
  6. {
  7. static LPVOID(WINAPI *orig_VirtualAlloc)(LPVOID lpAddress, SIZE_T dwSize, DWORD flAllocationType, DWORD flProtect) = VirtualAlloc;
  8. }
  9.  
  10. // Detoured
  11. LPVOID WINAPI my_VirtualAlloc(LPVOID lpAddress, SIZE_T dwSize, DWORD flAllocationType, DWORD flProtect)
  12. {
  13. void *RetAddress = _ReturnAddress();
  14. Log::Msg("0x%I64X - VirtualAlloc(Region: 0x%I64X-0x%I64X, dwSize: 0x%I64X, flAllocationType: 0x%X, flProtect: 0x%X) Call: 0x%I64X",
  15. orig_VirtualAlloc, lpAddress, ((DWORD64)lpAddress + dwSize), dwSize, flAllocationType, flProtect, RetAddress);
  16. return flAllocationType == (MEM_RESERVE | MEM_WRITE_WATCH | MEM_COMMIT) ? orig_VirtualAlloc(lpAddress, dwSize, MEM_RESERVE | MEM_COMMIT, flProtect) :
  17. orig_VirtualAlloc(lpAddress, dwSize, flAllocationType, flProtect);
  18. }
  19.  
  20.  
  21. /* Hooks */
  22.  
  23. // Initialization
  24. BOOL Hooking::InitializeHooks()
  25. {
  26. // init minhook
  27. if (MH_Initialize() != MH_OK) {
  28. Log::Fatal("MinHook failed to initialize");
  29. return FALSE;
  30. }
  31.  
  32. // init VirtualAlloc Patch
  33. if (MH_CreateHook(&VirtualAlloc, &my_VirtualAlloc, reinterpret_cast<void**>(&orig_VirtualAlloc)) != MH_OK || (MH_EnableHook(&VirtualAlloc) != MH_OK)) {
  34. Log::Error("Failed to hook VirtualAlloc");
  35. return FALSE;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement