-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathMemory.h
More file actions
61 lines (57 loc) · 1.37 KB
/
Memory.h
File metadata and controls
61 lines (57 loc) · 1.37 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
#include "Includes.h"
class RPM {
private:
DWORD Proc_ID;
LPCSTR _WindowName;
public:
HANDLE hProcess;
DWORD *base;
void attach(LPCSTR WindowName) {
HWND hWindow = FindWindowA(NULL, WindowName);
if (hWindow)
{
GetWindowThreadProcessId(hWindow, &Proc_ID);
hProcess = OpenProcess(PROCESS_VM_READ | PROCESS_VM_WRITE | PROCESS_VM_OPERATION/*PROCESS_ALL_ACCESS*/, FALSE, Proc_ID);
HANDLE hModule = INVALID_HANDLE_VALUE;
MODULEENTRY32 ePoint;
hModule = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, Proc_ID);
ePoint.dwSize = sizeof(MODULEENTRY32);
Module32First(hModule, &ePoint);
base = (DWORD*)ePoint.modBaseAddr;
CloseHandle(hModule);
}
}
template <class cData>
cData read(DWORD64(Address)) {
try {
if (Proc_ID > 0) {
cData B;
ReadProcessMemory(hProcess, (LPCVOID)Address, &B, sizeof(B), NULL);
return B;
}
else {
throw 1;
}
}
catch (int error) {
std::cout << "ERROR:\t" << error << std::endl;
}
}
template <class cData>
cData write(DWORD64(Address), cData B) {
try {
if (Proc_ID > 0) {
VirtualProtectEx(hProcess, (LPVOID)(Address), sizeof(B), PAGE_EXECUTE_READWRITE, NULL);
WriteProcessMemory(hProcess, (LPVOID)(Address), &B, sizeof(B), NULL);
return B;
}
else {
throw 1;
}
}
catch (int error) {
std::cout << "ERROR:\t" << error << std::endl;
}
// return 0;
}
};