-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMemory.cpp
More file actions
83 lines (66 loc) · 1.76 KB
/
Memory.cpp
File metadata and controls
83 lines (66 loc) · 1.76 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
#include "Memory.h"
#include <TlHelp32.h>
#include <vector>
#include "StringUtil.h"
Memory::Memory(const std::string processName) {
PROCESSENTRY32 entry;
entry.dwSize = sizeof(PROCESSENTRY32);
const auto snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
while(Process32Next(snapshot, &entry)){
if (!strcmp(processName.c_str(), convertWideToNarrow(entry.szExeFile))) {
this->id = entry.th32ProcessID;
this->process = OpenProcess(PROCESS_ALL_ACCESS, FALSE, this->id);
break;
}
}
if (snapshot) {
CloseHandle(snapshot);
}
};
Memory::~Memory() {
if (this->process) CloseHandle(this->process);
};
DWORD Memory::GetProcessId() {
return this->id;
};
HANDLE Memory::GetProcessHandle() {
return this->process;
};
uintptr_t Memory::GetModuleAddress(const std::string moduleName) {
MODULEENTRY32 entry;
entry.dwSize = sizeof(MODULEENTRY32);
const auto snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, this->id);
uintptr_t res = 0;
while (Module32Next(snapshot, &entry)) {
if (!strcmp(moduleName.c_str(), convertWideToNarrow(entry.szModule))) {
res = reinterpret_cast<uintptr_t>(entry.modBaseAddr);
break;
}
}
if (snapshot) {
CloseHandle(snapshot);
}
return res;
};
uintptr_t Memory::FindDMAAddy(uintptr_t ptr, std::vector<unsigned int> offsets)
{
uintptr_t addr = ptr;
for (unsigned int i = 0; i < offsets.size(); ++i)
{
ReadProcessMemory(this->process, (BYTE*)addr, &addr, sizeof(addr), 0);
addr += offsets[i];
}
return addr;
}
bool Memory::isValidAddress(uintptr_t address) {
if (Read<uint32_t>(address) == 3435973836) { //hex: CCCCCCCC
return false;
}
return true;
}
bool Memory::isValidEntity(uint32_t address) {
if (Read<uint32_t>(address) == 0x0054D07C) { //Vtable something?
return true;
}
return false;
}