This repository was archived by the owner on Mar 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMemory.h
More file actions
67 lines (54 loc) · 1.37 KB
/
Memory.h
File metadata and controls
67 lines (54 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
61
62
63
64
65
66
67
#pragma once
#include <Windows.h>
#include <TlHelp32.h>
#include <comdef.h>
struct PModule
{
DWORD dwBase;
DWORD dwSize;
} pSamp;
class Memory {
public:
inline bool Attach(const char* pName, DWORD dwAccess) {
HANDLE handle = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
PROCESSENTRY32 entry;
entry.dwSize = sizeof(entry);
do
if (!strcmp(_bstr_t(entry.szExeFile), pName)) {
_pId = entry.th32ProcessID;
CloseHandle(handle);
_process = OpenProcess(dwAccess, false, _pId);
return true;
}
while (Process32Next(handle, &entry));
return false;
}
inline PModule GetModule(const char * pModule) {
HANDLE module = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, _pId);
MODULEENTRY32 entry;
entry.dwSize = sizeof(entry);
do
if (!strcmp(_bstr_t(entry.szModule), pModule)) {
CloseHandle(module);
return PModule{ reinterpret_cast<DWORD>(entry.hModule), entry.modBaseSize };
}
while (Module32Next(module, &entry));
return PModule{ 0,0 };
}
template <class T>
T ReadPointer(const DWORD dwAdress) {
T _read;
ReadProcessMemory(_process, LPVOID(dwAdress), &_read, sizeof(T), 0);
return _read;
}
template <class T>
void Write(const DWORD dwAdress, const T value) {
WriteProcessMemory(_process, LPVOID(dwAdress), &value, sizeof(T), NULL);
}
void Exit() {
CloseHandle(_process);
}
private:
HANDLE _process;
DWORD _pId;
} mem;