about summary refs log tree commit diff stats
path: root/WitnessRandomizer/Memory.h
diff options
context:
space:
mode:
authorjbzdarkid <jbzdarkid@gmail.com>2018-10-27 23:28:42 -0700
committerjbzdarkid <jbzdarkid@gmail.com>2018-10-27 23:28:42 -0700
commit2c9afc07fe5cc53fefb90540d5db2ca424c71a51 (patch)
tree55ba19ae0e3f52f732d9382b6deccf6d879035c7 /WitnessRandomizer/Memory.h
parentecc14a3463c0c1c52b5de17d2aeb719ce2942a4a (diff)
downloadwitness-tutorializer-2c9afc07fe5cc53fefb90540d5db2ca424c71a51.tar.gz
witness-tutorializer-2c9afc07fe5cc53fefb90540d5db2ca424c71a51.tar.bz2
witness-tutorializer-2c9afc07fe5cc53fefb90540d5db2ca424c71a51.zip
Major restructuring -- also set up for UI work tomorrow
Diffstat (limited to 'WitnessRandomizer/Memory.h')
-rw-r--r--WitnessRandomizer/Memory.h51
1 files changed, 0 insertions, 51 deletions
diff --git a/WitnessRandomizer/Memory.h b/WitnessRandomizer/Memory.h deleted file mode 100644 index 8e8bbc3..0000000 --- a/WitnessRandomizer/Memory.h +++ /dev/null
@@ -1,51 +0,0 @@
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 Memory(const Memory& memory) = delete;
17 Memory& operator=(const Memory& other) = delete;
18
19 template<class T>
20 std::vector<T> ReadData(const std::vector<int>& offsets, size_t numItems) {
21 std::vector<T> data;
22 data.resize(numItems);
23 for (int i=0; i<5; i++) {
24 if (ReadProcessMemory(_handle, ComputeOffset(offsets), &data[0], sizeof(T) * numItems, nullptr))
25 {
26 return data;
27 }
28 }
29 ThrowError();
30 return {};
31 }
32
33 template <class T>
34 void WriteData(const std::vector<int>& offsets, const std::vector<T>& data) {
35 for (int i=0; i<5; i++) {
36 if (WriteProcessMemory(_handle, ComputeOffset(offsets), &data[0], sizeof(T) * data.size(), nullptr)) {
37 return;
38 }
39 }
40 ThrowError();
41 }
42
43private:
44 void ThrowError();
45
46 void* ComputeOffset(std::vector<int> offsets);
47
48 std::map<uintptr_t, uintptr_t> _computedAddresses;
49 uintptr_t _baseAddress = 0;
50 HANDLE _handle = nullptr;
51}; \ No newline at end of file