diff options
author | jbzdarkid <jbzdarkid@gmail.com> | 2019-11-16 10:27:06 -0800 |
---|---|---|
committer | jbzdarkid <jbzdarkid@gmail.com> | 2019-11-16 10:27:06 -0800 |
commit | 0baa521ba34d2cd4e0f732f83d23b807605786a2 (patch) | |
tree | dfb01163d291ee846c7a5840ffc08e089a7fb8e6 /Source/Memory.h | |
parent | 0d0abe2ee56382c5751dd12fbca75af87773879f (diff) | |
download | witness-tutorializer-0baa521ba34d2cd4e0f732f83d23b807605786a2.tar.gz witness-tutorializer-0baa521ba34d2cd4e0f732f83d23b807605786a2.tar.bz2 witness-tutorializer-0baa521ba34d2cd4e0f732f83d23b807605786a2.zip |
More and more progress.
Split out functions in serializer Figured out how to allocate memory (for sequences)
Diffstat (limited to 'Source/Memory.h')
-rw-r--r-- | Source/Memory.h | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/Source/Memory.h b/Source/Memory.h index 6b8403f..af4f0ae 100644 --- a/Source/Memory.h +++ b/Source/Memory.h | |||
@@ -35,7 +35,14 @@ public: | |||
35 | 35 | ||
36 | template <class T> | 36 | template <class T> |
37 | void WriteArray(int panel, int offset, const std::vector<T>& data) { | 37 | void WriteArray(int panel, int offset, const std::vector<T>& data) { |
38 | WriteData<T>({GLOBALS, 0x18, panel*8, offset, 0}, data); | 38 | WriteData({GLOBALS, 0x18, panel*8, offset, 0}, data); |
39 | } | ||
40 | |||
41 | template <class T> | ||
42 | void WriteNewArray(int panel, int offset, const std::vector<T>& data) { | ||
43 | std::vector<uintptr_t> newAddr = {Allocate(data.size() * sizeof(T))}; | ||
44 | WritePanelData(panel, offset, newAddr); | ||
45 | WriteArray(panel, offset, data); | ||
39 | } | 46 | } |
40 | 47 | ||
41 | template <class T> | 48 | template <class T> |
@@ -45,7 +52,7 @@ public: | |||
45 | 52 | ||
46 | template <class T> | 53 | template <class T> |
47 | void WritePanelData(int panel, int offset, const std::vector<T>& data) { | 54 | void WritePanelData(int panel, int offset, const std::vector<T>& data) { |
48 | WriteData<T>({GLOBALS, 0x18, panel*8, offset}, data); | 55 | WriteData({GLOBALS, 0x18, panel*8, offset}, data); |
49 | } | 56 | } |
50 | 57 | ||
51 | void AddSigScan(const std::vector<byte>& scanBytes, const std::function<void(int index)>& scanFunc); | 58 | void AddSigScan(const std::vector<byte>& scanBytes, const std::function<void(int index)>& scanFunc); |
@@ -57,9 +64,12 @@ private: | |||
57 | if (numItems == 0) return {}; | 64 | if (numItems == 0) return {}; |
58 | std::vector<T> data; | 65 | std::vector<T> data; |
59 | data.resize(numItems); | 66 | data.resize(numItems); |
67 | void* computedOffset = ComputeOffset(offsets); | ||
60 | for (int i=0; i<5; i++) { | 68 | for (int i=0; i<5; i++) { |
61 | if (ReadProcessMemory(_handle, ComputeOffset(offsets), &data[0], sizeof(T) * numItems, nullptr)) | 69 | if (ReadProcessMemory(_handle, computedOffset, &data[0], sizeof(T) * numItems, nullptr)) { |
62 | { | 70 | if (i != 0) { |
71 | int k = 0; | ||
72 | } | ||
63 | return data; | 73 | return data; |
64 | } | 74 | } |
65 | } | 75 | } |
@@ -70,8 +80,12 @@ private: | |||
70 | template <class T> | 80 | template <class T> |
71 | void WriteData(const std::vector<int>& offsets, const std::vector<T>& data) { | 81 | void WriteData(const std::vector<int>& offsets, const std::vector<T>& data) { |
72 | if (data.empty()) return; | 82 | if (data.empty()) return; |
83 | void* computedOffset = ComputeOffset(offsets); | ||
73 | for (int i=0; i<5; i++) { | 84 | for (int i=0; i<5; i++) { |
74 | if (WriteProcessMemory(_handle, ComputeOffset(offsets), &data[0], sizeof(T) * data.size(), nullptr)) { | 85 | if (WriteProcessMemory(_handle, computedOffset, &data[0], sizeof(T) * data.size(), nullptr)) { |
86 | if (i != 0) { | ||
87 | int k = 0; | ||
88 | } | ||
75 | return; | 89 | return; |
76 | } | 90 | } |
77 | } | 91 | } |
@@ -82,6 +96,7 @@ private: | |||
82 | bool Initialize(); | 96 | bool Initialize(); |
83 | void ThrowError(); | 97 | void ThrowError(); |
84 | void* ComputeOffset(std::vector<int> offsets); | 98 | void* ComputeOffset(std::vector<int> offsets); |
99 | uintptr_t Allocate(size_t bytes); | ||
85 | 100 | ||
86 | int _previousFrame = 0; | 101 | int _previousFrame = 0; |
87 | bool _threadActive = false; | 102 | bool _threadActive = false; |
@@ -90,6 +105,8 @@ private: | |||
90 | std::map<uintptr_t, uintptr_t> _computedAddresses; | 105 | std::map<uintptr_t, uintptr_t> _computedAddresses; |
91 | uintptr_t _baseAddress = 0; | 106 | uintptr_t _baseAddress = 0; |
92 | HANDLE _handle = nullptr; | 107 | HANDLE _handle = nullptr; |
108 | uintptr_t _freeMem = 0; | ||
109 | uintptr_t _freeMemEnd = 0; | ||
93 | struct SigScan { | 110 | struct SigScan { |
94 | std::function<void(int)> scanFunc; | 111 | std::function<void(int)> scanFunc; |
95 | bool found; | 112 | bool found; |