-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSource.cpp
More file actions
106 lines (91 loc) · 4.57 KB
/
Copy pathSource.cpp
File metadata and controls
106 lines (91 loc) · 4.57 KB
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
#include <iostream>
#include <Windows.h>
#include <TlHelp32.h>
HANDLE process_handle;
#define m_iDefaultFOV 0x332C
template<typename T> T RPM(SIZE_T address) {
T buffer;
ReadProcessMemory(process_handle, (LPCVOID)address, &buffer, sizeof(T), NULL);
return buffer;
}
template<typename T> void WPM(SIZE_T address, T buffer) {
WriteProcessMemory(process_handle, (LPVOID)address, &buffer, sizeof(buffer), NULL);
}
MODULEENTRY32 get_module(const char* modName, DWORD proc_id) {
HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, proc_id);
if (hSnap != INVALID_HANDLE_VALUE) {
MODULEENTRY32 modEntry;
modEntry.dwSize = sizeof(modEntry);
if (Module32First(hSnap, &modEntry)) {
do {
if (!strcmp(modEntry.szModule, modName)) {
CloseHandle(hSnap);
return modEntry;
}
} while (Module32Next(hSnap, &modEntry));
}
}
MODULEENTRY32 module = { -1 };
return module;
}
uintptr_t find_pattern(MODULEENTRY32 module, uint8_t* arr, const char* pattern, int offset, int extra) {
uintptr_t scan = 0x0;
const char* pat = pattern;
uintptr_t firstMatch = 0;
for (uintptr_t pCur = (uintptr_t)arr; pCur < (uintptr_t)arr + module.modBaseSize; ++pCur) {
if (!*pat) { scan = firstMatch; break; }
if (*(uint8_t*)pat == '\?' || *(uint8_t*)pCur == ((((pat[0] & (~0x20)) >= 'A' && (pat[0] & (~0x20)) <= 'F') ? ((pat[0] & (~0x20)) - 'A' + 0xa) : ((pat[0] >= '0' && pat[0] <= '9') ? pat[0] - '0' : 0)) << 4 | (((pat[1] & (~0x20)) >= 'A' && (pat[1] & (~0x20)) <= 'F') ? ((pat[1] & (~0x20)) - 'A' + 0xa) : ((pat[1] >= '0' && pat[1] <= '9') ? pat[1] - '0' : 0)))) {
if (!firstMatch) firstMatch = pCur;
if (!pat[2]) { scan = firstMatch; break; }
if (*(WORD*)pat == 16191 /*??*/ || *(uint8_t*)pat != '\?') pat += 3;
else pat += 2;
}
else { pat = pattern; firstMatch = 0; }
}
if (!scan) return 0x0;
uint32_t read;
ReadProcessMemory(process_handle, (void*)(scan - (uintptr_t)arr + (uintptr_t)module.modBaseAddr + offset), &read, sizeof(read), NULL);
return read + extra;
}
int main() {
//opening a handle to CSGO
HWND hwnd = FindWindowA(NULL, "Counter-Strike: Global Offensive");
DWORD proc_id; GetWindowThreadProcessId(hwnd, &proc_id);
process_handle = OpenProcess(PROCESS_VM_READ | PROCESS_VM_OPERATION | PROCESS_VM_WRITE, false, proc_id);
//sig-scan
MODULEENTRY32 client = get_module("client.dll", proc_id);
auto bytes = new uint8_t[client.modBaseSize]; //making a variable size of the module
DWORD bytes_read;
ReadProcessMemory(process_handle, client.modBaseAddr, bytes, client.modBaseSize, &bytes_read); //reading the module and storing as bytes_read
if (bytes_read != client.modBaseSize) throw; //checking that the size of bytes read is = to size of bytes in the module
//example of scanning for LocalPlayer and EntityList
uintptr_t LocalPlayer = find_pattern(client, bytes, "8D 34 85 ? ? ? ? 89 15 ? ? ? ? 8B 41 08 8B 48 04 83 F9 FF", 0x3, 0x4); //0x3 is the offset, 0x4 is the extra
uintptr_t EntityList = find_pattern(client, bytes, "BB ? ? ? ? 83 FF 01 0F 8C ? ? ? ? 3B F8", 0x1, 0x0); //0x1 is the offset, there is no extra
delete[] bytes;
printf("[+] Found dwLocalPlayer @ 0x%X\n", LocalPlayer - (uintptr_t)client.modBaseAddr);
printf("[+] Found dwEntityList @ 0x%X\n", EntityList - (uintptr_t)client.modBaseAddr);
system("pause");
//optional example
uintptr_t dwLocalPlayer = LocalPlayer - (uintptr_t)client.modBaseAddr; //getting rid of the base is optional, you will just have to add it back when you RPM
uintptr_t dwEntityList = EntityList - (uintptr_t)client.modBaseAddr;
//fov changer example
int fov = 90;
LocalPlayer = RPM<uintptr_t>(LocalPlayer);
while (true)
{
if (GetAsyncKeyState(0x76 /*F7*/) & 1) { //minus
fov -= 1; WPM<int>(LocalPlayer + m_iDefaultFOV, fov);
std::cout << "FOV: " << RPM<int>(LocalPlayer + m_iDefaultFOV) << std::endl;
}
if (GetAsyncKeyState(0x77 /*F8*/) & 1) { //add
fov += +1; WPM<int>(LocalPlayer + m_iDefaultFOV, fov);
std::cout << "FOV: " << RPM<int>(LocalPlayer + m_iDefaultFOV) << std::endl;
}
if (GetAsyncKeyState(0x78 /*F9*/) & 1) { //resets
fov = 90; WPM<int>(LocalPlayer + m_iDefaultFOV, fov);
std::cout << "FOV: " << RPM<int>(LocalPlayer + m_iDefaultFOV) << std::endl;
}
}
system("pause");
return 0;
}