-
Notifications
You must be signed in to change notification settings - Fork 1
/
Memory.cpp
63 lines (52 loc) · 1.39 KB
/
Memory.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
#include "Memory.h"
DWORD GetPID(const wchar_t* procName)
{
DWORD PID = NULL;
HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
if (hSnap != INVALID_HANDLE_VALUE)
{
PROCESSENTRY32 procEntry;
procEntry.dwSize = sizeof(procEntry);
if (Process32First(hSnap, &procEntry) == 1)
{
do {
if (!_wcsicmp(procEntry.szExeFile, procName)) {
PID = procEntry.th32ProcessID;
break;
}
} while (Process32Next(hSnap, &procEntry) == 1);
}
}
CloseHandle(hSnap);
return PID;
}
uintptr_t GetModule(DWORD PID, const wchar_t* modName)
{
uintptr_t baseAddress = NULL;
HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, PID);
if (hSnap != INVALID_HANDLE_VALUE)
{
MODULEENTRY32 modEntry;
modEntry.dwSize = sizeof(modEntry);
if (Module32First(hSnap, &modEntry) == 1)
{
do {
if (!_wcsicmp (modEntry.szModule, modName))
{
baseAddress = (uintptr_t)modEntry.modBaseAddr;
break;
}
} while (Module32Next(hSnap, &modEntry) == 1);
}
}
CloseHandle(hSnap);
return baseAddress;
}
uintptr_t FindAddress(HANDLE hProc, std::vector<int> offsets, uintptr_t baseAddress)
{
for (int i = 0; i < offsets.size(); i++) {
ReadProcessMemory(hProc, (LPCVOID)baseAddress, &baseAddress, sizeof(baseAddress), NULL);
baseAddress += offsets[i];
}
return baseAddress;
}