-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasicMemoryInterface.cpp
More file actions
80 lines (65 loc) · 2.17 KB
/
BasicMemoryInterface.cpp
File metadata and controls
80 lines (65 loc) · 2.17 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
#include "BasicMemoryInterface.h"
#include <Windows.h>
#include <Psapi.h>
#include "Utils.h"
BasicMemoryInterface::~BasicMemoryInterface() {
if (this->handle) {
CloseHandle(this->handle);
}
}
bool BasicMemoryInterface::IsValid() {
return this->handle;
}
bool BasicMemoryInterface::UpdateProcessId(const wchar_t* processName) {
this->pid = GetProcessIdByName(processName);
if (this->handle) {
CloseHandle(this->handle);
this->handle = nullptr;
}
if (this->pid) {
this->handle = OpenProcess(PROCESS_ALL_ACCESS, false, this->pid);
}
return this->pid && this->handle;
}
intptr_t BasicMemoryInterface::GetBaseAddress() {
if (!this->pid || !this->handle) {
return false;
}
DWORD_PTR baseAddress = 0;
HMODULE* moduleArray = nullptr;
LPBYTE moduleArrayBytes = nullptr;
DWORD bytesRequired = 0;
if (EnumProcessModules(this->handle, NULL, 0, &bytesRequired)) {
if (bytesRequired) {
moduleArrayBytes = (LPBYTE)LocalAlloc(LPTR, bytesRequired);
if (moduleArrayBytes) {
unsigned int moduleCount = 0;
moduleCount = bytesRequired / sizeof(HMODULE);
moduleArray = (HMODULE*)moduleArrayBytes;
if (EnumProcessModules(this->handle, moduleArray, bytesRequired, &bytesRequired)) {
baseAddress = (DWORD_PTR)moduleArray[0];
}
LocalFree(moduleArrayBytes);
}
}
}
return baseAddress;
}
intptr_t BasicMemoryInterface::GetModuleBase() {
return 0x7FFDFA280000;
}
bool BasicMemoryInterface::SetTargetModule(wchar_t* moduleName) {
throw("DRIVER USE ONLY!");
}
bool BasicMemoryInterface::ReadRaw(intptr_t address, void* pBuffer, unsigned long size) {
if (!this->pid || !this->handle) {
return false;
}
return ReadProcessMemory(this->handle, (LPCVOID)address, pBuffer, size, nullptr);
}
bool BasicMemoryInterface::WriteRaw(intptr_t address, void* pBuffer, unsigned long size) {
if (!this->pid || !this->handle) {
return false;
}
return WriteProcessMemory(this->handle, (LPVOID)address, pBuffer, size, nullptr);
}