-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelper.cpp
More file actions
82 lines (67 loc) · 2.05 KB
/
helper.cpp
File metadata and controls
82 lines (67 loc) · 2.05 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
#include "helper.h"
Helper::Helper(HANDLE hprocess, uint32_t pid) :m_hprocess(hprocess), m_pid(pid)
{
;
}
Helper::~Helper()
{
CloseHandle(m_hprocess);
}
Helper* Helper::Make()
{
static Helper* helper = nullptr;
if (helper != nullptr) {
return helper;
}
uint32_t pid = 0;
HANDLE hprocess = INVALID_HANDLE_VALUE;
PROCESSENTRY32 process_entry = { .dwSize = sizeof(PROCESSENTRY32) };
HANDLE snapshot_handle = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (snapshot_handle == INVALID_HANDLE_VALUE || snapshot_handle == nullptr) {
return nullptr;
}
boolean success = Process32First(snapshot_handle, &process_entry);
while (success) {
if (_stricmp(process_entry.szExeFile, "csgo.exe") == 0) {
hprocess = OpenProcess(PROCESS_ALL_ACCESS, false, process_entry.th32ProcessID);
pid = process_entry.th32ProcessID;
break;
}
success = Process32Next(snapshot_handle, &process_entry);
}
CloseHandle(snapshot_handle);
if (hprocess != INVALID_HANDLE_VALUE && hprocess != nullptr) {
helper = new Helper(hprocess, pid);
return helper;
}
return nullptr;
}
boolean Helper::ReadMemory(uint_ptr address, void* buffer, size_t size)
{
return ReadProcessMemory(m_hprocess, reinterpret_cast<void*>(address), buffer, size, nullptr);
}
boolean Helper::WriteMemory(uint_ptr address, void* buffer, size_t size)
{
return WriteProcessMemory(m_hprocess, reinterpret_cast<void*>(address), buffer, size, nullptr);
}
uint_ptr Helper::GetModuleAddress(std::string module_name)
{
HANDLE handle = nullptr;
HMODULE hmodule = nullptr;
handle = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, m_pid); //ËùÓнø³ÌµÄ¾ä±ú
MODULEENTRY32 module_entry{ .dwSize = sizeof(MODULEENTRY32) };
if (handle == nullptr || handle == INVALID_HANDLE_VALUE) {
return 0;
}
boolean success = Module32First(handle, &module_entry);
if (success) {
do {
if (_stricmp(module_entry.szModule, module_name.c_str()) == 0) {
hmodule = module_entry.hModule;
break;
}
} while (Module32Next(handle, &module_entry));
}
CloseHandle(handle);
return reinterpret_cast<uint_ptr>(hmodule);
}