Advertisement
Guest User

Untitled

a guest
Dec 16th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.15 KB | None | 0 0
  1. typedef void (*editVar)();
  2. editVar edVar = reinterpret_cast<editVar>(0x004010D1);
  3. BYTE* _orig = new BYTE (5);
  4.  
  5. void hEditVar()
  6. {
  7.     int _val = 0;
  8.     int __stack[2];
  9.  
  10.     __asm pop eax
  11.     __asm mov __stack, eax
  12.     __asm pop eax
  13.     __asm mov __stack+1, eax
  14.     __asm pop eax
  15.     __asm mov _val, eax
  16.     __asm push __stack
  17.     __asm push __stack+1
  18.     __asm push eax
  19.  
  20.     printf("Yeap, it is hooked, your value is: %d", _val);
  21.     while(true){}
  22. }
  23.  
  24. editVar hEdVar = &hEditVar;
  25.  
  26. int DllThread()
  27. {
  28.     printf("\nMyHookedFun = inAppTest.dll [0x%x]", (int)hEdVar);
  29.  
  30.     DWORD oldProtect;
  31.     VirtualProtect(edVar, 5, PAGE_EXECUTE_READWRITE, &oldProtect);
  32.     memcpy(_orig, edVar, 5);
  33.  
  34.     printf("\nOriginal bytes: ");
  35.     for (int i = 0; i != sizeof(_orig) + 1; i++)
  36.         printf("%x ", _orig[i]);
  37.  
  38.     int* newAddr = (int*) malloc(sizeof(int));
  39.     *newAddr = (int)hEdVar - (int)edVar - 5;
  40.     *reinterpret_cast<int*>(edVar) = 0x0E9;
  41.     memcpy((int*)((int)edVar + 1), newAddr, 4);
  42.  
  43.     printf("\nNew bytes: ");
  44.     for (int i = 0; i != sizeof(_orig) + 1; i++)
  45.         printf("%x ", reinterpret_cast<BYTE*>(edVar)[i]);
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement