From a3d44e37b59d204780d39a5eb6af726f72ebd04f Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Tue, 5 Mar 2019 11:56:17 -0800 Subject: [PATCH] dmnt-cheat: *properly* update frozen address values on write --- stratosphere/dmnt/source/dmnt_cheat_manager.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/stratosphere/dmnt/source/dmnt_cheat_manager.cpp b/stratosphere/dmnt/source/dmnt_cheat_manager.cpp index 287af8a39..9ea7edc50 100644 --- a/stratosphere/dmnt/source/dmnt_cheat_manager.cpp +++ b/stratosphere/dmnt/source/dmnt_cheat_manager.cpp @@ -108,9 +108,18 @@ Result DmntCheatManager::WriteCheatProcessMemoryForVm(u64 proc_addr, const void /* We might have a frozen address. Update it if we do! */ if (R_SUCCEEDED(rc)) { - auto it = g_frozen_addresses_map.find(proc_addr); - if (it != g_frozen_addresses_map.end()) { - memcpy(&it->second.value, data, size < sizeof(it->second.value) ? size : sizeof(it->second.value)); + for (auto & [address, value] : g_frozen_addresses_map) { + /* Map is in order, so break here. */ + if (address >= proc_addr + size) { + break; + } + + /* Check if we need to write. */ + if (proc_addr <= address) { + const size_t offset = (address - proc_addr); + const size_t size_to_copy = size - offset; + memcpy(&value.value, (void *)((uintptr_t)data + offset), size_to_copy < sizeof(value.value) ? size_to_copy : sizeof(value.value)); + } } }