Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.65 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <windows.h>
  3. #include <iostream>
  4. #include <TlHelp32.h>
  5. #include <tchar.h>
  6. #include <vector>
  7. #include <fstream>
  8. #include <string.h>
  9. #include <codecvt>
  10. #include <locale.h>
  11.  
  12.  
  13. using namespace std;
  14.  
  15. // addresses we read
  16. BYTE* healthAdress = NULL;
  17.  
  18. // Program information
  19. DWORD pid; // Process ID of program
  20. HWND hwnd; // Handle of window
  21.  
  22. double health;
  23.  
  24. //window
  25. hwnd = FindWindow(NULL, L"AssaultCube");
  26. if (!hwnd) {
  27.    
  28.     cout << "window not foundn";
  29.     cin.get();
  30.    
  31. }
  32.  
  33.  
  34.  
  35. GetWindowThreadProcessId(hwnd, &pid);
  36.  
  37. HANDLE phandle = OpenProcess(PROCESS_VM_OPERATION, 0, pid);
  38. if (!phandle) {
  39.    
  40.     cout << "could not get handlen";
  41.     cin.get();
  42.    
  43. }
  44.  
  45.  
  46.  
  47. // According to microsoft documentation you can grab a snapshot of modules of a program like this, code is pretty patched together since I was testing things here.
  48.  
  49. HANDLE snapshot_test = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, pid);
  50. // Check if the handle is valid
  51. if (snapshot_test != INVALID_HANDLE_VALUE) {
  52.    
  53.     MODULEENTRY32 mod_entry;
  54.     mod_entry.dwSize = sizeof(mod_entry);
  55.    
  56.     int num = 0;
  57.    
  58.     if (Module32First(snapshot_test, &mod_entry)) {
  59.        
  60.         //ofstream myfile;
  61.         //myfile.open("D:/Users/Jack/Documents/visual studio 2015/Projects/Digging_Bot/Debug/test.txt", std::ios::binary);
  62.        
  63.         do {
  64.            
  65.             if (num == 2) {
  66.                
  67.                 cout << "module base address - ";
  68.                 wcout << mod_entry.modBaseAddr << endl;
  69.                 healthAdress = mod_entry.modBaseAddr + 0x46F68;
  70.                
  71.             }
  72.            
  73.            
  74.             num += 1;
  75.            
  76.             //DWORD test = (DWORD)(mod_entry.modBaseAddr + 0x46F68 + 10);
  77.             //cout << ReadProcessMemory(phandle, (void*)(test), &health, sizeof(health), 0);
  78.            
  79.         }
  80.        
  81.         while (Module32Next(snapshot_test, &mod_entry));
  82.         //myfile.close();
  83.        
  84.     }
  85.    
  86.    
  87.     else (cout << "module32first error");
  88.    
  89. }
  90.  
  91.  
  92. else (cout << "snapshot error");
  93.  
  94. while (1) {
  95.    
  96.     cout << "healthadress - ";
  97.     wcout << healthAdress << endl;
  98.    
  99.    
  100.     // Address that the pointer points to
  101.     uintptr_t pointedTo;
  102.     cout << "void test - ";
  103.     wcout << (void*)(healthAdress) << endl;
  104.     ReadProcessMemory(phandle, (void*)(healthAdress), &pointedTo, sizeof(pointedTo), 0);
  105.    
  106.     cout << "pointed to adress - ";
  107.     wcout << pointedTo;
  108.    
  109.     ReadProcessMemory(phandle, (void*)pointedTo, &health, sizeof(health), 0);
  110.     wcout << health;
  111.     Sleep(1000)
  112.    
  113. }
  114.  
  115.  
  116. return (0);
  117.  
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement