Advertisement
Guest User

C++

a guest
Aug 12th, 2017
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.88 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <Windows.h>
  3. #include <iostream>
  4. #include <tlhelp32.h>
  5. #include <tchar.h>
  6.  
  7. #define num0 0x60
  8. #define F6 0x75
  9.  
  10. const DWORD localHealthBase = 0x01295540;
  11. const DWORD localHealthOffset1 = 0x24;
  12. const DWORD localHealthOffset2 = 0x10;
  13. const DWORD localHealthOffset3 = 0x500;
  14. const DWORD localHealthOffset4 = 0x6A0;
  15. const DWORD localHealthOffset5 = 0x2B0;
  16.  
  17.  
  18. void godMode(HANDLE pHandle, DWORD health, int myHealth);
  19. DWORD_PTR dwGetModuleBaseAddress(DWORD dwProcID, TCHAR *szModuleName);
  20. bool godStatus = false;
  21.  
  22. int main()
  23. {
  24.     DWORD buffer = 0, localHealth = 0, moduleBase = 0, pid = 0;
  25.     int i = 0;
  26.     HWND hWnd = FindWindowA(0, ("7 Days To Die"));
  27.     GetWindowThreadProcessId(hWnd, &pid);
  28.     HANDLE pHandle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
  29.     std::cout << "Process ID: " << pid << std::endl; //returns correct PID
  30.     std::cout << "Handle: " << pHandle << std::endl; //returns 00000060 (what should it return?)
  31.     moduleBase = dwGetModuleBaseAddress(pid, _T("7DaysToDie.exe"));
  32.     std::cout << "Module Base: " << moduleBase << std::endl; //returns null
  33.     ReadProcessMemory(pHandle,(LPCVOID*)moduleBase,&localHealth,sizeof(localHealth),NULL);
  34.     std::cout << localHealth << std::endl; //returns null
  35.     /*ReadProcessMemory(pHandle, (LPCVOID*)localHealthBase + localHealthOffset1, &buffer, sizeof(buffer), NULL);
  36.     ReadProcessMemory(pHandle, (LPCVOID*)buffer + localHealthOffset2, &buffer, sizeof(buffer), 0);
  37.     ReadProcessMemory(pHandle, (LPCVOID*)buffer + localHealthOffset3, &buffer, sizeof(buffer), 0);
  38.     ReadProcessMemory(pHandle, (LPCVOID*)buffer + localHealthOffset4, &buffer, sizeof(buffer), 0);
  39.     ReadProcessMemory(pHandle, (LPCVOID*)buffer + localHealthOffset5, &localHealth, sizeof(localHealth), 0); */
  40.     int myHealth = 1117257728;
  41.     while (!GetAsyncKeyState(F6)) {
  42.         if (i == 0) {
  43.             std::cout << "While loop works." << std::endl;
  44.             i++;
  45.         }
  46.         else i++;
  47.         godMode(pHandle, localHealth, myHealth);
  48.     }
  49.     return 0;
  50. }
  51.  
  52. DWORD_PTR dwGetModuleBaseAddress(DWORD dwProcID, TCHAR *szModuleName)
  53. {
  54.     DWORD_PTR dwModuleBaseAddress = 0;
  55.     HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, dwProcID);
  56.     if (hSnapshot != INVALID_HANDLE_VALUE)
  57.     {
  58.         MODULEENTRY32 ModuleEntry32;
  59.         ModuleEntry32.dwSize = sizeof(MODULEENTRY32);
  60.         if (Module32First(hSnapshot, &ModuleEntry32))
  61.         {
  62.             do
  63.             {
  64.                 if (_tcsicmp(ModuleEntry32.szModule, szModuleName) == 0)
  65.                 {
  66.                     dwModuleBaseAddress = (DWORD_PTR)ModuleEntry32.modBaseAddr;
  67.                     break;
  68.                 }
  69.             } while (Module32Next(hSnapshot, &ModuleEntry32));
  70.         }
  71.         CloseHandle(hSnapshot);
  72.     }
  73.     return dwModuleBaseAddress;
  74. }
  75.  
  76. void godMode(HANDLE pHandle, DWORD health, int myHealth) {
  77.     if (GetAsyncKeyState(num0)) {
  78.         godStatus = !godStatus;
  79.         std::cout << "toggled" << std::endl;
  80.  
  81.     }
  82.     if (!godStatus) {
  83.         return;
  84.     }
  85.     WriteProcessMemory(pHandle, (LPVOID)health, &myHealth, sizeof(myHealth), 0);
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement