diff options
author | jbzdarkid <jbzdarkid@gmail.com> | 2018-10-27 01:27:29 -0700 |
---|---|---|
committer | jbzdarkid <jbzdarkid@gmail.com> | 2018-10-27 01:27:29 -0700 |
commit | 1f2077485e580b3b1d582298281ac6272df18d8d (patch) | |
tree | 6d1b151934137a34aa13c9bc6485581a540fc4a2 /WitnessRandomizer/Memory.h | |
parent | 223f7244fccfc67685fcefe889ea49414e32b715 (diff) | |
download | witness-tutorializer-1f2077485e580b3b1d582298281ac6272df18d8d.tar.gz witness-tutorializer-1f2077485e580b3b1d582298281ac6272df18d8d.tar.bz2 witness-tutorializer-1f2077485e580b3b1d582298281ac6272df18d8d.zip |
/W3 clean, add .msi installer project
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 |