about summary refs log tree commit diff stats
path: root/WitnessRandomizer/Memory.h
diff options
context:
space:
mode:
authorjbzdarkid <jbzdarkid@gmail.com>2018-10-21 16:58:03 -0700
committerjbzdarkid <jbzdarkid@gmail.com>2018-10-21 16:58:03 -0700
commitd5d5868cc4fb6ddff6ee73d9582a629b170ced64 (patch)
tree9fc901b67a28134b4f068d46105fc8c70b551992 /WitnessRandomizer/Memory.h
parent04a162151d63e73f11033a269de4155951db9751 (diff)
downloadwitness-tutorializer-d5d5868cc4fb6ddff6ee73d9582a629b170ced64.tar.gz
witness-tutorializer-d5d5868cc4fb6ddff6ee73d9582a629b170ced64.tar.bz2
witness-tutorializer-d5d5868cc4fb6ddff6ee73d9582a629b170ced64.zip
initial version, randomizing just tutorial
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