Punkbastard

Memory Reading/Writing (Game Hacking) - C++

Dec 7th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. #include<iostream>
  2. #include<Windows.h>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     int newValue = 2000;
  9.     int readTest = 0;
  10.  
  11.     HWND hwnd = FindWindowA(NULL, "Window Name");
  12.     if (hwnd == NULL)
  13.     {
  14.         cout << "Cannot find window." << endl;
  15.         Sleep(3000);
  16.         exit(-1);
  17.     }
  18.     else
  19.     {
  20.         DWORD procID;
  21.         GetWindowThreadProcessId(hwnd, &procID);
  22.         HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, procID);
  23.  
  24.         if (procID == NULL)
  25.         {
  26.             cout << "Cannot obtain process." << endl;
  27.             Sleep(3000);
  28.             exit(-1);
  29.         }
  30.         else
  31.         {
  32.             // Write Memory in infinite loop (On 'press space' Write Memory)
  33.             for (;;)
  34.             {
  35.                 if (GetAsyncKeyState(VK_SPACE))
  36.                 {
  37.                     WriteProcessMemory(handle, (LPVOID)0x00ABEA6C, &newValue, sizeof(newValue), 0);
  38.                     newValue++;
  39.                 }
  40.                 Sleep(1);
  41.             }
  42.            
  43.             // Read Memory:
  44.             ReadProcessMemory(handle, (PBYTE*)0x00ABEA6C, &readTest, sizeof(readTest), 0);
  45.             cout << readTest << endl;
  46.             Sleep(10000);
  47.         }
  48.     }
  49.     return 0;
  50. }
Add Comment
Please, Sign In to add comment