Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.39 KB | None | 0 0
  1. #include <iostream>
  2. #include <Windows.h>
  3. #include <string>
  4. #include <ctime> // needed for our timer clock
  5.  
  6. void WriteToMemory(HANDLE hProcHandle);
  7. DWORD FindDmaAddy(int PointerLevel, HANDLE hProcHandle, DWORD Offsets[], DWORD BaseAddress);
  8.  
  9. //CREATES the string used to determine the name of our target window e.g. Calculator
  10. std::string GameName = "AssaultCube";
  11. LPCSTR LGameWindow = "AssaultCube"; //<- MAKE SURE it matches the window name
  12. std::string GameStatus;
  13. //FUNCTION PROTOTYPES
  14. bool IsGameAvail;
  15. bool UpdateOnNextRun; //used to update the display menu only when something changed
  16.  
  17. //-------AMMO VARS--------
  18. bool AmmoStatus;
  19. int AmmoValue = 500;
  20. DWORD AmmoBaseAddress = { 0x50f4f4 };
  21. DWORD AmmoOffsets[] = { 0x374, 0x14, 0x0 }; //3 LEVEL pointer
  22.  
  23. //-------HEALTH VARS--------
  24. bool HealthStatus;
  25. int HealthValue = 500;
  26. DWORD HealthBaseAddress = { 0x109B74 };
  27. DWORD HealthOffsets[] = { 0xF8 }; // 1 level pointer
  28.  
  29. int main()
  30. {
  31.    
  32.     HWND hGameWindow = NULL;
  33.     int timeSinceLastUpdate = clock(); //forces status update every x seconds
  34.     int GameAvailTMR = clock();
  35.     int OnePressTMR;//used to limit keys input to only one per x ms
  36.     DWORD dwProcId = NULL;
  37.     HANDLE hProcHandle = NULL;
  38.     UpdateOnNextRun = true;
  39.     std::string sAmmoStatus;
  40.     std::string sHealthStatus;
  41.     sAmmoStatus = "OFF";
  42.     sHealthStatus = "OFF";
  43.     OnePressTMR = clock();
  44.     while (!GetAsyncKeyState(VK_INSERT)) //Key is not = 'INSERT'
  45.     {
  46.         if (clock() - GameAvailTMR > 100)
  47.         {
  48.             GameAvailTMR = clock();
  49.             IsGameAvail = false;
  50.             hGameWindow = FindWindow(NULL, LGameWindow);
  51.             if (hGameWindow)
  52.             {
  53.                 GetWindowThreadProcessId(hGameWindow, &dwProcId);
  54.                 if (dwProcId != 0)
  55.                 {
  56.                     hProcHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcId);
  57.                     if (hProcHandle == INVALID_HANDLE_VALUE || hProcHandle == NULL)
  58.                     {
  59.                         GameStatus = "Failed to open process for valid handle";
  60.                     }
  61.                     else
  62.                     {
  63.                         GameStatus = "AssaultCube Ready to hack";
  64.                         IsGameAvail = true;
  65.                     }
  66.                 }
  67.                 else GameStatus = "Failed to obtain process id";
  68.             }
  69.             else GameStatus = "AssaultCube NOT FOUND";
  70.  
  71.             if (UpdateOnNextRun || clock() - timeSinceLastUpdate > 5000)
  72.             {
  73.                 system("cls");
  74.                 std::cout << "----------------------------------------------------" << std::endl;
  75.                 std::cout << "        AssaultCube memory hacker" << std::endl;
  76.                 std::cout << "----------------------------------------------------" << std::endl << std::endl;
  77.                 std::cout << "GAME STATUS:" << GameStatus << "   " << std::endl << std::endl;
  78.                 std::cout << "[F1] Unlimited ammo   -> " << sAmmoStatus << " <-" << std::endl << std::endl;
  79.                 std::cout << "[F2] Unlimited Health ->" << sHealthStatus << "<-" << std::endl << std::endl;
  80.                 std::cout << "[INSERT] Exit" << std::endl;
  81.                 UpdateOnNextRun = false;
  82.                 timeSinceLastUpdate = clock();
  83.             }
  84.  
  85.             if (IsGameAvail)
  86.             {
  87.                 WriteToMemory(hProcHandle);
  88.             }
  89.         }
  90.  
  91.        
  92.         if (clock() - OnePressTMR > 400)
  93.         {
  94.             if (IsGameAvail)
  95.             {
  96.                
  97.                 if (GetAsyncKeyState(VK_F1))
  98.                 {
  99.                     OnePressTMR = clock();
  100.                    
  101.                     AmmoStatus = !AmmoStatus;
  102.                     UpdateOnNextRun = true;
  103.                    
  104.                     if (AmmoStatus)sAmmoStatus = "ON";
  105.                     else sAmmoStatus = "OFF";
  106.                 }
  107.                 else if (GetAsyncKeyState(VK_F2))
  108.                 {
  109.                     OnePressTMR = clock();
  110.                     HealthStatus = !HealthStatus;
  111.                     UpdateOnNextRun = true;
  112.                
  113.                     if (HealthStatus)sHealthStatus = "ON";
  114.                     else sHealthStatus = "OFF";
  115.                 }
  116.             }
  117.         }
  118.     }
  119.     return ERROR_SUCCESS;
  120. }
  121.  
  122.  
  123. DWORD FindDmaAddy(int PointerLevel, HANDLE hProcHandle, DWORD Offsets[], DWORD BaseAddress)
  124. {
  125.     DWORD pointer = BaseAddress;          
  126.     DWORD pTemp;
  127.  
  128.     DWORD pointerAddr;
  129.     for (int c = 0; c < PointerLevel; c++)
  130.     {
  131.         if (c == 0)
  132.         {
  133.             ReadProcessMemory(hProcHandle, (LPCVOID)pointer, &pTemp, 4, NULL);
  134.         }
  135.        
  136.         pointerAddr = pTemp + Offsets[c];
  137.  
  138.         ReadProcessMemory(hProcHandle, (LPCVOID)pointerAddr, &pTemp, 4, NULL);
  139.     }
  140.     return pointerAddr;
  141. }
  142.  
  143. void WriteToMemory(HANDLE hProcHandle)
  144. {
  145.     DWORD AddressToWrite;
  146.     if (AmmoStatus)
  147.     {
  148.         AddressToWrite = FindDmaAddy(3, hProcHandle, AmmoOffsets, AmmoBaseAddress);
  149.         WriteProcessMemory(hProcHandle, (BYTE*)AddressToWrite, &AmmoValue, sizeof(AmmoValue), NULL);
  150.     }
  151.  
  152.     if (HealthStatus)
  153.     {
  154.         AddressToWrite = FindDmaAddy(1, hProcHandle, HealthOffsets, HealthBaseAddress);
  155.         WriteProcessMemory(hProcHandle, (BYTE*)AddressToWrite, &HealthValue, sizeof(HealthValue), NULL);
  156.     }
  157. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement