summary refs log tree commit diff stats
path: root/WitnessRandomizer/Memory.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'WitnessRandomizer/Memory.cpp')
-rw-r--r--WitnessRandomizer/Memory.cpp10
1 files changed, 8 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
59uintptr_t Memory::ComputeOffset(std::vector<int> offsets) 59uintptr_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}