-
Notifications
You must be signed in to change notification settings - Fork 4
/
process.cpp
68 lines (58 loc) · 1.92 KB
/
process.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
//........HEXRAZE | From GitHub:https://github.com/Barracuda1900/HexrazeMemoryMacro_Rust
#include "process.h"
processManager process_Manager;
uintptr_t processManager::GetModuleBaseAddress(const char* modName)
{
uintptr_t modBaseAddr = 0;
HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, processPID);
if (hSnap != INVALID_HANDLE_VALUE)
{
MODULEENTRY32 modEntry;
modEntry.dwSize = sizeof(modEntry);
if (Module32First(hSnap, &modEntry))
{
do
{
if (!strcmp(modEntry.szModule, modName))
{
modBaseAddr = (uintptr_t)modEntry.modBaseAddr;
break;
}
} while (Module32Next(hSnap, &modEntry));
}
}
CloseHandle(hSnap);
return modBaseAddr;
}
bool processManager::attach(const char* process_name) {
PROCESSENTRY32 process_entry{};
process_entry.dwSize = sizeof(PROCESSENTRY32);
auto snapshot{ CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL) };
if (snapshot == INVALID_HANDLE_VALUE)
return false;
if (Process32First(snapshot, &process_entry)) {
do {
if (!strcmp(process_name, process_entry.szExeFile)) {
processPID = process_entry.th32ProcessID;
processNAME = process_name;
processHANDLE = OpenProcess(PROCESS_ALL_ACCESS, FALSE, process_entry.th32ProcessID);
CloseHandle(snapshot);
return 1;
}
} while (Process32Next(snapshot, &process_entry));
}
CloseHandle(snapshot);
return 0;
}
size_t processManager::read_memory(LPCVOID src_addr, LPVOID dst_addr, size_t size)
{
size_t bytes_read = 0;
ReadProcessMemory(processHANDLE, src_addr, dst_addr, size, &bytes_read);
return bytes_read;
}
size_t processManager::write_memory(LPVOID dst_addr, LPCVOID src_addr, size_t size)
{
size_t bytes_write = 0;
return WriteProcessMemory(processHANDLE, dst_addr, src_addr, size, &bytes_write);
return bytes_write;
}