Advertisement
cos8o

JMP Hook

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