diff options
Diffstat (limited to 'WitnessRandomizer/Memory.cpp')
-rw-r--r-- | WitnessRandomizer/Memory.cpp | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/WitnessRandomizer/Memory.cpp b/WitnessRandomizer/Memory.cpp index 92a5136..6077691 100644 --- a/WitnessRandomizer/Memory.cpp +++ b/WitnessRandomizer/Memory.cpp | |||
@@ -62,18 +62,21 @@ uintptr_t Memory::ComputeOffset(std::vector<int> offsets) | |||
62 | int final_offset = offsets.back(); | 62 | int final_offset = offsets.back(); |
63 | offsets.pop_back(); | 63 | offsets.pop_back(); |
64 | 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; | 65 | uintptr_t cumulativeAddress = _baseAddress; |
71 | for (int offset : offsets) { | 66 | for (int offset : offsets) { |
72 | cumulativeAddress += offset; | 67 | cumulativeAddress += offset; |
73 | if (!ReadProcessMemory(_handle, (LPVOID)cumulativeAddress, &cumulativeAddress, sizeof(uintptr_t), NULL)) { | 68 | |
74 | ThrowError(); | 69 | auto search = _computedAddresses.find(cumulativeAddress); |
70 | if (search == std::end(_computedAddresses)) { | ||
71 | // If the address is not yet computed, then compute it. | ||
72 | uintptr_t computedAddress = 0; | ||
73 | if (!ReadProcessMemory(_handle, (LPVOID)cumulativeAddress, &computedAddress, sizeof(uintptr_t), NULL)) { | ||
74 | ThrowError(); | ||
75 | } | ||
76 | _computedAddresses[cumulativeAddress] = computedAddress; | ||
75 | } | 77 | } |
78 | |||
79 | cumulativeAddress = _computedAddresses[cumulativeAddress]; | ||
76 | } | 80 | } |
77 | _computedOffsets[offsets] = cumulativeAddress; | ||
78 | return cumulativeAddress + final_offset; | 81 | return cumulativeAddress + final_offset; |
79 | } | 82 | } |