summary refs log tree commit diff stats
path: root/WitnessRandomizer/Memory.h
diff options
context:
space:
mode:
Diffstat (limited to 'WitnessRandomizer/Memory.h')
-rw-r--r--WitnessRandomizer/Memory.h39
1 files changed, 39 insertions, 0 deletions
diff --git a/WitnessRandomizer/Memory.h b/WitnessRandomizer/Memory.h new file mode 100644 index 0000000..2453cf0 --- /dev/null +++ b/WitnessRandomizer/Memory.h
@@ -0,0 +1,39 @@
1#pragma once
2#include <vector>
3#include <map>
4#include <windows.h>
5
6// https://github.com/erayarslan/WriteProcessMemory-Example
7// http://stackoverflow.com/q/32798185
8// http://stackoverflow.com/q/36018838
9// http://stackoverflow.com/q/1387064
10class Memory
11{
12public:
13 Memory(const std::string& processName);
14 ~Memory();
15
16 template<class T>
17 std::vector<T> ReadData(const std::vector<int>& offsets, int numItems) {
18 std::vector<T> data;
19 data.resize(numItems);
20 if (!ReadProcessMemory(_handle, (LPVOID)ComputeOffset(offsets), &data[0], sizeof(T) * numItems, NULL)) {
21 ThrowError();
22 }
23 return data;
24 }
25
26 template <class T>
27 void WriteData(const std::vector<int>& offsets, const std::vector<T>& data) {
28 if (!WriteProcessMemory(_handle, (LPVOID)ComputeOffset(offsets), &data[0], sizeof(T) * data.size(), NULL)) {
29 ThrowError();
30 }
31 }
32
33private:
34 void ThrowError();
35
36 uintptr_t ComputeOffset(std::vector<int> offsets);
37 uintptr_t _baseAddress;
38 HANDLE _handle;
39}; \ No newline at end of file