summary refs log tree commit diff stats
path: root/WitnessRandomizer/Memory.cpp
diff options
context:
space:
mode:
authorjbzdarkid <jbzdarkid@gmail.com>2018-10-27 01:27:29 -0700
committerjbzdarkid <jbzdarkid@gmail.com>2018-10-27 01:27:29 -0700
commit1f2077485e580b3b1d582298281ac6272df18d8d (patch)
tree6d1b151934137a34aa13c9bc6485581a540fc4a2 /WitnessRandomizer/Memory.cpp
parent223f7244fccfc67685fcefe889ea49414e32b715 (diff)
downloadwitness-tutorializer-1f2077485e580b3b1d582298281ac6272df18d8d.tar.gz
witness-tutorializer-1f2077485e580b3b1d582298281ac6272df18d8d.tar.bz2
witness-tutorializer-1f2077485e580b3b1d582298281ac6272df18d8d.zip
/W3 clean, add .msi installer project
Diffstat (limited to 'WitnessRandomizer/Memory.cpp')
-rw-r--r--WitnessRandomizer/Memory.cpp14
1 files changed, 6 insertions, 8 deletions
diff --git a/WitnessRandomizer/Memory.cpp b/WitnessRandomizer/Memory.cpp index 6077691..0afeded 100644 --- a/WitnessRandomizer/Memory.cpp +++ b/WitnessRandomizer/Memory.cpp
@@ -47,30 +47,28 @@ Memory::~Memory() {
47 CloseHandle(_handle); 47 CloseHandle(_handle);
48} 48}
49 49
50// Private methods:
51
52void Memory::ThrowError() { 50void Memory::ThrowError() {
53 std::string message(256, '\0'); 51 std::string message(256, '\0');
54 FormatMessageA(4096, NULL, GetLastError(), 1024, &message[0], static_cast<DWORD>(message.length()), NULL); 52 FormatMessageA(4096, nullptr, GetLastError(), 1024, &message[0], static_cast<DWORD>(message.length()), nullptr);
55 std::cout << message.c_str() << std::endl; 53 std::cout << message.c_str() << std::endl;
56 exit(EXIT_FAILURE); 54 exit(EXIT_FAILURE);
57} 55}
58 56
59uintptr_t Memory::ComputeOffset(std::vector<int> offsets) 57void* Memory::ComputeOffset(std::vector<int> offsets)
60{ 58{
61 // Leave off the last offset, since it will be either read/write, and may not be of type unitptr_t. 59 // Leave off the last offset, since it will be either read/write, and may not be of type unitptr_t.
62 int final_offset = offsets.back(); 60 int final_offset = offsets.back();
63 offsets.pop_back(); 61 offsets.pop_back();
64 62
65 uintptr_t cumulativeAddress = _baseAddress; 63 uintptr_t cumulativeAddress = _baseAddress;
66 for (int offset : offsets) { 64 for (const int offset : offsets) {
67 cumulativeAddress += offset; 65 cumulativeAddress += offset;
68 66
69 auto search = _computedAddresses.find(cumulativeAddress); 67 const auto search = _computedAddresses.find(cumulativeAddress);
70 if (search == std::end(_computedAddresses)) { 68 if (search == std::end(_computedAddresses)) {
71 // If the address is not yet computed, then compute it. 69 // If the address is not yet computed, then compute it.
72 uintptr_t computedAddress = 0; 70 uintptr_t computedAddress = 0;
73 if (!ReadProcessMemory(_handle, (LPVOID)cumulativeAddress, &computedAddress, sizeof(uintptr_t), NULL)) { 71 if (!ReadProcessMemory(_handle, reinterpret_cast<LPVOID>(cumulativeAddress), &computedAddress, sizeof(uintptr_t), NULL)) {
74 ThrowError(); 72 ThrowError();
75 } 73 }
76 _computedAddresses[cumulativeAddress] = computedAddress; 74 _computedAddresses[cumulativeAddress] = computedAddress;
@@ -78,5 +76,5 @@ uintptr_t Memory::ComputeOffset(std::vector<int> offsets)
78 76
79 cumulativeAddress = _computedAddresses[cumulativeAddress]; 77 cumulativeAddress = _computedAddresses[cumulativeAddress];
80 } 78 }
81 return cumulativeAddress + final_offset; 79 return reinterpret_cast<void*>(cumulativeAddress + final_offset);
82} 80}