about summary refs log tree commit diff stats
path: root/WitnessRandomizer/Memory.cpp
diff options
context:
space:
mode:
authorjbzdarkid <jbzdarkid@gmail.com>2018-10-26 21:43:17 -0700
committerjbzdarkid <jbzdarkid@gmail.com>2018-10-26 21:43:17 -0700
commit1d4763bc94c9887bc4171374202a5d12be1fc10f (patch)
tree1ea6fb996d658148e1a193f61751ea7765184037 /WitnessRandomizer/Memory.cpp
parent9503fc300e1c2d9fcddcf5b8ecc009cd4429337a (diff)
downloadwitness-tutorializer-1d4763bc94c9887bc4171374202a5d12be1fc10f.tar.gz
witness-tutorializer-1d4763bc94c9887bc4171374202a5d12be1fc10f.tar.bz2
witness-tutorializer-1d4763bc94c9887bc4171374202a5d12be1fc10f.zip
Way better caching.
Diffstat (limited to 'WitnessRandomizer/Memory.cpp')
-rw-r--r--WitnessRandomizer/Memory.cpp19
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}