-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcMemory.h
54 lines (42 loc) · 1.12 KB
/
cMemory.h
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
#pragma once
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <Windows.h>
#include <TlHelp32.h>
#include "cLogger.h"
class cMemory
{
static std::shared_ptr<cMemory> _instance;
public:
static std::shared_ptr<cMemory> Get();
cMemory();
~cMemory();
void DumpAllProcesses();
void DumpModulesFromProcess(const DWORD& processID);
std::string GetCurrentProcessName() const;
DWORD GetCurrentProcessID() const;
HANDLE GetCurrentProcessHandle() const;
bool IsProcessAttatched() const;
bool AttatchProcess(const std::string& processName);
BYTE* GetModuleAddress(const std::string& moduleName);
template <typename T>
void WriteMemory(void* address, const T& value)
{
WriteProcessMemory(_processHandle, address, &value, sizeof(T), NULL);
}
template <typename T>
T ReadMemory(void* address)
{
T value;
ReadProcessMemory(_processHandle, address, &value, sizeof(T), NULL);
return value;
}
private:
std::string _processName = "";
HANDLE _processHandle = nullptr;
DWORD _processID = NULL;
bool _attatched = false;
cLogger_t _logger = nullptr;
};
typedef std::shared_ptr<cMemory> cMemory_t;