Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <Windows.h>
  3. #include <string>
  4. #include <ctime>
  5.  
  6. void WriteToMemory(HANDLE hProcHandle);
  7. DWORD FindDmaAddy(int PointerLevel, HANDLE hProcHandle, DWORD Offsets[], DWORD BaseAddress);
  8.  
  9. std::string GameName = "Counter-Strike Source";
  10. LPCSTR LGameWindow = "Counter-Strike Source";
  11. std::string GameStatus;
  12.  
  13. bool IsGameAvail;
  14. bool UpdateOnNextRun;
  15.  
  16. bool HealthStatus;
  17. int HealthValue = 1337;
  18. DWORD HealthBaseAddress = { 0x22562d7c };
  19. DWORD HealthOffsets[] = { 0x88 };
  20.  
  21.  
  22.  
  23. int main()
  24. {
  25.     //Declare our handles as NULL to avoid crashes when closing if they were unused e.g. player starts trainer and closes it before doing any cheats
  26.     HWND hGameWindow = NULL;
  27.     int timeSinceLastUpdate = clock(); //forces status update every x seconds
  28.     int GameAvailTMR = clock();
  29.     int OnePressTMR;//used to limit keys input to only one per x ms
  30.     DWORD dwProcId = NULL;
  31.     HANDLE hProcHandle = NULL;
  32.     UpdateOnNextRun = true;
  33.     std::string sAmmoStatus;
  34.     std::string sHealthStatus;
  35.     sAmmoStatus = "OFF";
  36.     sHealthStatus = "OFF";
  37.     OnePressTMR = clock();
  38.     while (!GetAsyncKeyState(VK_INSERT))
  39.     {
  40.  
  41.  
  42.         if (clock() - GameAvailTMR > 100)
  43.         {
  44.             GameAvailTMR = clock();
  45.             IsGameAvail = false;
  46.             hGameWindow = FindWindow(NULL, LGameWindow);
  47.             if (hGameWindow)
  48.             {
  49.                 GetWindowThreadProcessId(hGameWindow, &dwProcId);
  50.                 if (dwProcId != 0)
  51.                 {
  52.                     hProcHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcId);
  53.                     if (hProcHandle == INVALID_HANDLE_VALUE || hProcHandle == NULL)
  54.                     {
  55.                         GameStatus = "Failed to open process for valid handle";
  56.                     }
  57.                     else
  58.                     {
  59.                         GameStatus = "Counter-Strike Source Ready to hack";
  60.                         IsGameAvail = true;
  61.                     }
  62.                 }
  63.                 else GameStatus = "Failed to obtain process id";
  64.             }
  65.             else GameStatus = "Counter-Strike Source NOT FOUND";
  66.             if (UpdateOnNextRun || clock() - timeSinceLastUpdate > 5000)
  67.             {
  68.                 system("cls");
  69.                 std::cout << "----------------------------------------------------" << std::endl;
  70.                 std::cout << "        Counter-Strike Source memory hacker" << std::endl;
  71.                 std::cout << "----------------------------------------------------" << std::endl << std::endl;
  72.                 std::cout << "GAME STATUS:" << GameStatus << "   " << std::endl << std::endl;
  73.                 std::cout << "[F1] Unlimited Health ->" << sHealthStatus << "<-" << std::endl << std::endl;
  74.                 std::cout << "[INSERT] Exit" << std::endl;
  75.                 UpdateOnNextRun = false;
  76.                 timeSinceLastUpdate = clock();
  77.             }
  78.  
  79.             if (IsGameAvail)
  80.             {
  81.                 WriteToMemory(hProcHandle);
  82.             }
  83.         }
  84.         if (clock() - OnePressTMR > 400)
  85.         {
  86.             if (IsGameAvail)
  87.             {
  88.                 if (GetAsyncKeyState(VK_F1))
  89.                 {
  90.                     OnePressTMR = clock();
  91.                     HealthStatus = !HealthStatus;
  92.                     UpdateOnNextRun = true;
  93.                     if (HealthStatus)sHealthStatus = "ON";
  94.                     else sHealthStatus = "OFF";
  95.                 }
  96.             }
  97.         }
  98.     }
  99.     CloseHandle(hProcHandle);
  100.     return ERROR_SUCCESS;
  101. }
  102.  
  103. DWORD FindDmaAddy(int PointerLevel, HANDLE hProcHandle, DWORD Offsets[], DWORD BaseAddress)
  104. {
  105.     DWORD pointer = BaseAddress;
  106.     DWORD pTemp;
  107.     DWORD pointerAddr;
  108.     for (int i = 0; i < PointerLevel; i++)
  109.     {
  110.         if (i == 0)
  111.         {
  112.             ReadProcessMemory(hProcHandle, (LPCVOID)pointer, &pTemp, 4, NULL);
  113.         }
  114.         pointerAddr = pTemp + Offsets[i];
  115.         ReadProcessMemory(hProcHandle, (LPCVOID)pointerAddr, &pTemp, 4, NULL);
  116.     }
  117.     return pointerAddr;
  118. }
  119.  
  120. void WriteToMemory(HANDLE hProcHandle)
  121. {
  122.     if (HealthStatus)
  123.     {
  124.         DWORD HealthAddressToWrite = FindDmaAddy(1, hProcHandle, HealthOffsets, HealthBaseAddress);
  125.         WriteProcessMemory(hProcHandle, (BYTE*)HealthAddressToWrite, &HealthValue, sizeof(HealthValue), NULL);
  126.     }
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement