-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMemUtil.cpp
107 lines (85 loc) · 3.25 KB
/
MemUtil.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include "stdafx.h"
#include "MemUtil.h"
using namespace std;
#pragma region Constructors
MemUtil::MemUtil()
{
}
MemUtil::~MemUtil()
{
CloseHandle(hProcess);
}
#pragma endregion
#pragma region Get Process & ClientModule
bool MemUtil::FindProcess() {
/* Create a snapshot of all processes & declare process entry*/
HANDLE hProcSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
PROCESSENTRY32 pEntry32;
pEntry32.dwSize = sizeof(PROCESSENTRY32);
char * cTargetProc = "csgo.exe";
/* Check if snapshot is valid */
if (hProcSnap == INVALID_HANDLE_VALUE) {
cout << "ERR: MemUtils::FindProcess() => INVALID_HANDLE_VALUE" << endl;
return false;
}
/* Iterate through all processes*/
cout << "SEARCHING FOR " << cTargetProc << "..." << endl;
do
/* If the current process name matches target process name */
if (!strcmp(pEntry32.szExeFile, cTargetProc)) {
cout << "\n* PROCESS '" << cTargetProc << "' FOUND! \n" << endl;
dwPID = pEntry32.th32ProcessID; // Get the PID
CloseHandle(hProcSnap); // Close the handle
hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwPID); // Allow read access
cout << "PROCESS READ ACCESS SUCCESSFUL..." << endl;
return true;
}
while (Process32Next(hProcSnap, &pEntry32));
cout << "ERR: MemUtils::FindProcess() => PROCESS_NOT_FOUND" << endl;
return false;
}
bool MemUtil::ClientModuleBaseAddress() {
/* See comments for FindProcess(), they're basically the same*/
HANDLE hModSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, dwPID);
MODULEENTRY32 modEntry32;
modEntry32.dwSize = sizeof(MODULEENTRY32);
char * cTargetModule = "client.dll";
if (hModSnapshot == INVALID_HANDLE_VALUE) {
cout << "ERR: MemUtils::ClientModuleBaseAddress() => INVALID_HANDLE_VALUE" << endl;
return 0;
}
cout << "INFO: SEARCHING FOR " << cTargetModule << "..." << endl;
do
if (!strcmp(modEntry32.szModule, cTargetModule)) {
CloseHandle(hModSnapshot);
dwClientBase = (DWORD)modEntry32.modBaseAddr; // Save the address in dwClientBase
cout << "\n* MODULE '" << cTargetModule << "' FOUND!\n" << endl;
cout << "ClientBase: " << dwClientBase << endl;
return true;
}
while (Module32Next(hModSnapshot, &modEntry32));
cout << "ERR: MemUtils::ClientModuleBaseAddress() => MODULE_NOT_FOUND" << endl;
return false;
}
#pragma endregion
#pragma region Read Memory
/* Get Local Information */
DWORD MemUtil::GetLocalPlayer() { return MemRead<DWORD>(dwClientBase + dwLocalPlayerOffset); }
int MemUtil::GetTeam(DWORD player) { return MemRead<int>(player + dwTeamOffset); }
int MemUtil::GetCrossHair(DWORD player) { return MemRead<int>(player + dwCrossHairOffset); }
/* Get Target Information */
DWORD MemUtil::GetTarget(int xhair) {
return MemRead<DWORD>(dwClientBase +
dwEntityListOffset +
((xhair - 1) *
dwEntLoopDistanceOffset));
}
int MemUtil::GetTargetHealth(DWORD target) { return MemRead<int>(target + dwHealthOffset); }
float* MemUtil::GetPosition(DWORD player)
{
static float Position[3];
ReadProcessMemory(hProcess, (PBYTE*)(player + dwVecOrigin), &Position, sizeof(float[3]), 0);
printf("GET_POSITION: %4.2f, %4.2f, %4.2f \n\n", Position[0], Position[1], Position[2]);
return Position;
}
#pragma endregion