diff options
-rw-r--r-- | WitnessRandomizer/Memory.cpp | 10 | ||||
-rw-r--r-- | WitnessRandomizer/Memory.h | 2 |
2 files changed, 10 insertions, 2 deletions
diff --git a/WitnessRandomizer/Memory.cpp b/WitnessRandomizer/Memory.cpp index c5852ac..f2bd8f1 100644 --- a/WitnessRandomizer/Memory.cpp +++ b/WitnessRandomizer/Memory.cpp | |||
@@ -58,16 +58,22 @@ void Memory::ThrowError() { | |||
58 | 58 | ||
59 | uintptr_t Memory::ComputeOffset(std::vector<int> offsets) | 59 | uintptr_t Memory::ComputeOffset(std::vector<int> offsets) |
60 | { | 60 | { |
61 | uintptr_t cumulativeAddress = _baseAddress; | ||
62 | |||
63 | // Leave off the last offset, since it will be either read/write, and may not be of type unitptr_t. | 61 | // Leave off the last offset, since it will be either read/write, and may not be of type unitptr_t. |
64 | int final_offset = offsets.back(); | 62 | int final_offset = offsets.back(); |
65 | offsets.pop_back(); | 63 | offsets.pop_back(); |
64 | |||
65 | auto search = _computedOffsets.find(offsets); | ||
66 | if (search != std::end(_computedOffsets)) { | ||
67 | return search->second + final_offset; | ||
68 | } | ||
69 | |||
70 | uintptr_t cumulativeAddress = _baseAddress; | ||
66 | for (int offset : offsets) { | 71 | for (int offset : offsets) { |
67 | cumulativeAddress += offset; | 72 | cumulativeAddress += offset; |
68 | if (!ReadProcessMemory(_handle, (LPVOID)cumulativeAddress, &cumulativeAddress, sizeof(uintptr_t), NULL)) { | 73 | if (!ReadProcessMemory(_handle, (LPVOID)cumulativeAddress, &cumulativeAddress, sizeof(uintptr_t), NULL)) { |
69 | ThrowError(); | 74 | ThrowError(); |
70 | } | 75 | } |
71 | } | 76 | } |
77 | _computedOffsets[offsets] = cumulativeAddress; | ||
72 | return cumulativeAddress + final_offset; | 78 | return cumulativeAddress + final_offset; |
73 | } | 79 | } |
diff --git a/WitnessRandomizer/Memory.h b/WitnessRandomizer/Memory.h index 6882c9c..dc92349 100644 --- a/WitnessRandomizer/Memory.h +++ b/WitnessRandomizer/Memory.h | |||
@@ -40,6 +40,8 @@ private: | |||
40 | void ThrowError(); | 40 | void ThrowError(); |
41 | 41 | ||
42 | uintptr_t ComputeOffset(std::vector<int> offsets); | 42 | uintptr_t ComputeOffset(std::vector<int> offsets); |
43 | |||
44 | std::map<std::vector<int>, uintptr_t> _computedOffsets; | ||
43 | uintptr_t _baseAddress; | 45 | uintptr_t _baseAddress; |
44 | HANDLE _handle; | 46 | HANDLE _handle; |
45 | }; \ No newline at end of file | 47 | }; \ No newline at end of file |