-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathProcess.h
92 lines (78 loc) · 2.42 KB
/
Process.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
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
#ifndef PROCESS_H_
#define PROCESS_H_
#include <iostream>
#include <vector>
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0501
#endif
#include <Windows.h>
#include <TlHelp32.h>
#include <stdexcept>
class Process
{
public:
//Process(HANDLE hProcess);
Process(DWORD processID);
Process(const Process& instance);
Process& operator=(const Process& instance);
~Process();
LPVOID allocMem(DWORD size) const;
LPVOID allocMem(DWORD size, DWORD allocationType) const;
LPVOID allocMem(DWORD size, LPVOID desiredAddress, DWORD allocationType) const;
bool freeMem(LPVOID address) const;
void writeMemory(LPVOID address, LPCVOID data, DWORD size) const;
void readMemory(LPVOID address, LPVOID buffer, DWORD size) const;
MEMORY_BASIC_INFORMATION queryMemory(LPVOID address) const;
DWORD protectMemory(LPVOID address, SIZE_T size, DWORD protect) const;
bool startThread(LPVOID address, LPVOID param);
void waitForThread();
std::vector<MODULEENTRY32> getModules() const;
uintptr_t getImageBase(HANDLE hThread) const;
uintptr_t getImageBase() const;
private:
bool duplicateHandle(HANDLE hSrc, HANDLE* hDest);
void throwSysError(const char* msg, DWORD lastError) const;
HANDLE hProcess_;
HANDLE hThread_;
DWORD processID_;
};
// handle error
class ProcessHandleException : public std::runtime_error
{
public:
ProcessHandleException(const std::string& msg) : std::runtime_error(msg) {};
};
// anything with memory
class ProcessMemoryException : public std::runtime_error
{
public:
ProcessMemoryException(const std::string& msg, LPVOID address) : std::runtime_error(msg), address_(address) {};
LPVOID getAddress() { return address_; };
private:
LPVOID address_;
};
// access memory
class MemoryAccessException : public std::runtime_error
{
public:
MemoryAccessException(const std::string& msg) : std::runtime_error(msg) {};
};
// allocate
class MemoryAllocationException : public std::runtime_error
{
public:
MemoryAllocationException(const std::string& msg) : std::runtime_error(msg) {};
};
// query memory
class MemoryQueryException : public std::runtime_error
{
public:
MemoryQueryException(const std::string& msg) : std::runtime_error(msg) {};
};
// protect memory
class MemoryProtectException : public ProcessMemoryException
{
public:
MemoryProtectException(const std::string& msg, LPVOID address) : ProcessMemoryException(msg, address) {};
};
#endif