From 1f2077485e580b3b1d582298281ac6272df18d8d Mon Sep 17 00:00:00 2001 From: jbzdarkid Date: Sat, 27 Oct 2018 01:27:29 -0700 Subject: /W3 clean, add .msi installer project --- WitnessRandomizer/Memory.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'WitnessRandomizer/Memory.cpp') 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() { CloseHandle(_handle); } -// Private methods: - void Memory::ThrowError() { std::string message(256, '\0'); - FormatMessageA(4096, NULL, GetLastError(), 1024, &message[0], static_cast(message.length()), NULL); + FormatMessageA(4096, nullptr, GetLastError(), 1024, &message[0], static_cast(message.length()), nullptr); std::cout << message.c_str() << std::endl; exit(EXIT_FAILURE); } -uintptr_t Memory::ComputeOffset(std::vector offsets) +void* Memory::ComputeOffset(std::vector offsets) { // Leave off the last offset, since it will be either read/write, and may not be of type unitptr_t. int final_offset = offsets.back(); offsets.pop_back(); uintptr_t cumulativeAddress = _baseAddress; - for (int offset : offsets) { + for (const int offset : offsets) { cumulativeAddress += offset; - auto search = _computedAddresses.find(cumulativeAddress); + const auto search = _computedAddresses.find(cumulativeAddress); if (search == std::end(_computedAddresses)) { // If the address is not yet computed, then compute it. uintptr_t computedAddress = 0; - if (!ReadProcessMemory(_handle, (LPVOID)cumulativeAddress, &computedAddress, sizeof(uintptr_t), NULL)) { + if (!ReadProcessMemory(_handle, reinterpret_cast(cumulativeAddress), &computedAddress, sizeof(uintptr_t), NULL)) { ThrowError(); } _computedAddresses[cumulativeAddress] = computedAddress; @@ -78,5 +76,5 @@ uintptr_t Memory::ComputeOffset(std::vector offsets) cumulativeAddress = _computedAddresses[cumulativeAddress]; } - return cumulativeAddress + final_offset; + return reinterpret_cast(cumulativeAddress + final_offset); } -- cgit 1.4.1