Advertisement
cos8o

PUSH Hook

Aug 23rd, 2017
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. bool pushHook(void *toBeHooked, void *hooker) {
  2.     DWORD oldProtect, newProtect;
  3.     if (!(VirtualProtect((LPVOID)toBeHooked, 6, PAGE_EXECUTE_READWRITE, &oldProtect) &&
  4.         WriteProcessMemory((HANDLE)-1, (LPVOID)toBeHooked, new byte{ 0x68 }, 1, NULL) &&
  5.         WriteProcessMemory((HANDLE)-1, (LPVOID)((DWORD)toBeHooked + 1), (byte*)&hooker, 4, NULL) &&
  6.         WriteProcessMemory((HANDLE)-1, (LPVOID)((DWORD)toBeHooked + 5), new byte{ 0xc3 }, 1, NULL) &&
  7.         VirtualProtect((LPVOID)toBeHooked, 6, oldProtect, &newProtect))) {
  8.         return false;
  9.     }
  10.     return true;
  11. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement