diff options
Diffstat (limited to 'WitnessRandomizer/Memory.h')
-rw-r--r-- | WitnessRandomizer/Memory.h | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/WitnessRandomizer/Memory.h b/WitnessRandomizer/Memory.h index 6f5b8b7..8e8bbc3 100644 --- a/WitnessRandomizer/Memory.h +++ b/WitnessRandomizer/Memory.h | |||
@@ -2,9 +2,6 @@ | |||
2 | #include <vector> | 2 | #include <vector> |
3 | #include <map> | 3 | #include <map> |
4 | #include <windows.h> | 4 | #include <windows.h> |
5 | #include <thread> | ||
6 | #include <chrono> | ||
7 | using namespace std::chrono_literals; | ||
8 | 5 | ||
9 | // https://github.com/erayarslan/WriteProcessMemory-Example | 6 | // https://github.com/erayarslan/WriteProcessMemory-Example |
10 | // http://stackoverflow.com/q/32798185 | 7 | // http://stackoverflow.com/q/32798185 |
@@ -16,16 +13,18 @@ public: | |||
16 | Memory(const std::string& processName); | 13 | Memory(const std::string& processName); |
17 | ~Memory(); | 14 | ~Memory(); |
18 | 15 | ||
16 | Memory(const Memory& memory) = delete; | ||
17 | Memory& operator=(const Memory& other) = delete; | ||
18 | |||
19 | template<class T> | 19 | template<class T> |
20 | std::vector<T> ReadData(const std::vector<int>& offsets, int numItems) { | 20 | std::vector<T> ReadData(const std::vector<int>& offsets, size_t numItems) { |
21 | std::vector<T> data; | 21 | std::vector<T> data; |
22 | data.resize(numItems); | 22 | data.resize(numItems); |
23 | for (int i=0; i<5; i++) { | 23 | for (int i=0; i<5; i++) { |
24 | if (ReadProcessMemory(_handle, (LPVOID)ComputeOffset(offsets), &data[0], sizeof(T) * numItems, NULL)) | 24 | if (ReadProcessMemory(_handle, ComputeOffset(offsets), &data[0], sizeof(T) * numItems, nullptr)) |
25 | { | 25 | { |
26 | return data; | 26 | return data; |
27 | } | 27 | } |
28 | // std::this_thread::sleep_for(10ms); | ||
29 | } | 28 | } |
30 | ThrowError(); | 29 | ThrowError(); |
31 | return {}; | 30 | return {}; |
@@ -34,10 +33,9 @@ public: | |||
34 | template <class T> | 33 | template <class T> |
35 | void WriteData(const std::vector<int>& offsets, const std::vector<T>& data) { | 34 | void WriteData(const std::vector<int>& offsets, const std::vector<T>& data) { |
36 | for (int i=0; i<5; i++) { | 35 | for (int i=0; i<5; i++) { |
37 | if (WriteProcessMemory(_handle, (LPVOID)ComputeOffset(offsets), &data[0], sizeof(T) * data.size(), NULL)) { | 36 | if (WriteProcessMemory(_handle, ComputeOffset(offsets), &data[0], sizeof(T) * data.size(), nullptr)) { |
38 | return; | 37 | return; |
39 | } | 38 | } |
40 | // std::this_thread::sleep_for(10ms); | ||
41 | } | 39 | } |
42 | ThrowError(); | 40 | ThrowError(); |
43 | } | 41 | } |
@@ -45,9 +43,9 @@ public: | |||
45 | private: | 43 | private: |
46 | void ThrowError(); | 44 | void ThrowError(); |
47 | 45 | ||
48 | uintptr_t ComputeOffset(std::vector<int> offsets); | 46 | void* ComputeOffset(std::vector<int> offsets); |
49 | 47 | ||
50 | std::map<uintptr_t, uintptr_t> _computedAddresses; | 48 | std::map<uintptr_t, uintptr_t> _computedAddresses; |
51 | uintptr_t _baseAddress; | 49 | uintptr_t _baseAddress = 0; |
52 | HANDLE _handle; | 50 | HANDLE _handle = nullptr; |
53 | }; \ No newline at end of file | 51 | }; \ No newline at end of file |