-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemory.h
More file actions
100 lines (89 loc) · 2.58 KB
/
Copy pathmemory.h
File metadata and controls
100 lines (89 loc) · 2.58 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/**
* memory.h - Memory Manager Header
*
* Provides functionality for reading and writing process memory.
* Used to interact with the game's memory space.
*
* @version 1.0
* @date 2026-08-21
*/
#pragma once
#include <Windows.h>
#include <vector>
#include <cstdint>
/**
* MemoryManager Class
*
* Handles process attachment, memory reading/writing,
* and signature scanning functionality.
*/
class MemoryManager {
public:
MemoryManager();
~MemoryManager();
/**
* Attach to a process by name.
*
* @param processName The name of the process (e.g., "Pax Autocratica.exe")
* @return true if attachment was successful, false otherwise
*/
bool AttachToProcess(const wchar_t* processName);
/**
* Detach from the current process.
*/
void Detach();
/**
* Read a value from memory.
*
* @tparam T The type of value to read (e.g., int, float)
* @param address The memory address to read from
* @return The value read from memory
*/
template<typename T>
T Read(uintptr_t address) {
T buffer;
ReadProcessMemory(m_hProcess, (LPCVOID)address, &buffer, sizeof(T), nullptr);
return buffer;
}
/**
* Write a value to memory.
*
* @tparam T The type of value to write (e.g., int, float)
* @param address The memory address to write to
* @param value The value to write
*/
template<typename T>
void Write(uintptr_t address, T value) {
WriteProcessMemory(m_hProcess, (LPVOID)address, &value, sizeof(T), nullptr);
}
/**
* Find a byte pattern (signature) in memory.
*
* @param pattern The byte pattern to search for
* @param mask The mask for the pattern (e.g., "xx?x")
* @return The address where the pattern was found, or 0 if not found
*/
uintptr_t FindSignature(const std::vector<uint8_t>& pattern, const std::vector<uint8_t>& mask);
/**
* Get the base address of the main module.
*
* @return The base address of the game's main executable
*/
uintptr_t GetBaseAddress() const { return m_baseAddress; }
/**
* Get the process handle.
*
* @return The handle to the game process
*/
HANDLE GetProcessHandle() const { return m_hProcess; }
/**
* Get the process ID.
*
* @return The process ID of the game
*/
DWORD GetProcessId() const { return m_pid; }
private:
HANDLE m_hProcess; // Handle to the game process
DWORD m_pid; // Process ID
uintptr_t m_baseAddress; // Base address of the main module
};