Advertisement
csmit195

Untitled

Apr 8th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.49 KB | None | 0 0
  1. #undef UNICODE
  2. #define PSAPI_VERSION 1
  3. #include<iostream>
  4. #include<Windows.h>
  5. #include<TlHelp32.h>
  6. #include <stdio.h>
  7. #include <tchar.h>
  8. #include <psapi.h>
  9.  
  10.  
  11. DWORD FindDmaAddy(int PointerLevel, HANDLE hProcHandle, DWORD Offsets[], DWORD BaseAddress);
  12.  
  13. using namespace std;
  14.  
  15. DWORD FindDmaAddy(int PointerLevel, HANDLE hProcHandle, DWORD Offsets[], DWORD BaseAddress)
  16. {
  17.     //DECLARE BASE ADDRESS
  18.     DWORD pointer = BaseAddress;             // Declare a pointer of DWORD
  19.                                              //USED TO output the contents in the pointer
  20.     DWORD pTemp;
  21.  
  22.     DWORD pointerAddr;
  23.     for (int i = 0; i < PointerLevel; i++)
  24.     {
  25.         if (i == 0)
  26.         {
  27.             ReadProcessMemory(hProcHandle, (LPCVOID)pointer, &pTemp, 4, NULL);
  28.         }
  29.         //add first offset to that address
  30.         pointerAddr = pTemp + Offsets[i];   // Set p1 to content of p + offset
  31.  
  32.                                             //Read memory one more time and exit the loop
  33.         ReadProcessMemory(hProcHandle, (LPCVOID)pointerAddr, &pTemp, 4, NULL);
  34.     }
  35.     return pointerAddr;
  36. }
  37.  
  38. DWORD dwGetModuleBaseAddress(DWORD dwProcessIdentifier, CHAR *lpszModuleName)
  39. {
  40.     HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, dwProcessIdentifier);
  41.     DWORD dwModuleBaseAddress = 0;
  42.     if (hSnapshot != INVALID_HANDLE_VALUE)
  43.     {
  44.         MODULEENTRY32 ModuleEntry32 = { 0 };
  45.         ModuleEntry32.dwSize = sizeof(MODULEENTRY32);
  46.         if (Module32First(hSnapshot, &ModuleEntry32))
  47.         {
  48.             do
  49.             {
  50.                 if (_tcscmp(ModuleEntry32.szModule, lpszModuleName) == 0)
  51.                 {
  52.                     dwModuleBaseAddress = (DWORD)ModuleEntry32.modBaseAddr;
  53.                     break;
  54.                 }
  55.             } while (Module32Next(hSnapshot, &ModuleEntry32));
  56.         }
  57.         CloseHandle(hSnapshot);
  58.     }
  59.     return dwModuleBaseAddress;
  60. }
  61.  
  62. DWORD hackBaseAddress = {0x006A1E98};
  63. DWORD woodOffsets[] = {0x30, 0x3D0, 0x480 };
  64. int main()
  65. {
  66.     HWND hwnd = FindWindowA(NULL, "Harvest Seasons");
  67.     if (hwnd == NULL)
  68.     {
  69.         cout << "Cannot find window" << endl;
  70.         Sleep(3000);
  71.         exit(-1);
  72.     }
  73.     else
  74.     {
  75.         DWORD procID;
  76.         GetWindowThreadProcessId(hwnd, &procID);
  77.         HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, procID);
  78.         DWORD baseAddr = dwGetModuleBaseAddress(procID, (char*)TEXT("Harvest Seasons.exe"));
  79.  
  80.         if (hProc == NULL)
  81.         {
  82.             std::cout << "Cannot open process...";
  83.             Sleep(3000);
  84.             exit(-1);
  85.         }
  86.         else
  87.         {
  88.            
  89.             DWORD WoodValue = 1000;
  90.             DWORD WoodAddressToWrite = FindDmaAddy(3, hProc, woodOffsets, baseAddr);
  91.             printf("%x", WoodAddressToWrite);
  92.             Sleep(10000);
  93.             WriteProcessMemory(hProc, (BYTE*)WoodAddressToWrite, &WoodValue, sizeof(WoodValue), NULL);
  94.         }
  95.     }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement