From 8d46cf53030cb72199890e29ee2c9ce38f983651 Mon Sep 17 00:00:00 2001 From: Maschell Date: Sat, 30 May 2020 21:59:42 +0200 Subject: [PATCH] relocator: Save the address of the PhysicalToEffective + EffectiveToPhysical function from the memory module is present. --- relocator/src/entry.cpp | 15 +++++++++++++++ relocator/src/globals.cpp | 4 ++++ relocator/src/globals.h | 6 ++++++ 3 files changed, 25 insertions(+) create mode 100644 relocator/src/globals.cpp create mode 100644 relocator/src/globals.h diff --git a/relocator/src/entry.cpp b/relocator/src/entry.cpp index c57624a..c0ef342 100644 --- a/relocator/src/entry.cpp +++ b/relocator/src/entry.cpp @@ -20,6 +20,7 @@ #include "utils/logger.h" #include "utils/dynamic.h" +#include "globals.h" #define gModuleData ((module_information_t *) (0x00880000)) @@ -113,6 +114,20 @@ extern "C" void doStart(int argc, char **argv) { if (!gInitCalled) { gInitCalled = 1; CallInitHook(loadedModules); + for(auto& curModule : loadedModules){ + if(curModule.getExportName().compare("homebrew_memorymapping") == 0){ + for(auto& curExport : curModule.getExportDataList()){ + if(curExport.getName().compare("MemoryMappingEffectiveToPhysical") == 0){ + DEBUG_FUNCTION_LINE("Setting MemoryMappingEffectiveToPhysicalPTR to %08X\n", curExport.getAddress()); + MemoryMappingEffectiveToPhysicalPTR = (uint32_t) curExport.getAddress(); + }else if(curExport.getName().compare("MemoryMappingPhysicalToEffective") == 0){ + DEBUG_FUNCTION_LINE("Setting MemoryMappingPhysicalToEffectivePTR to %08X\n", curExport.getAddress()); + MemoryMappingPhysicalToEffectivePTR = (uint32_t) curExport.getAddress(); + } + } + break; + } + } } for (int i = 0; i < gModuleData->number_used_modules; i++) { diff --git a/relocator/src/globals.cpp b/relocator/src/globals.cpp new file mode 100644 index 0000000..c386250 --- /dev/null +++ b/relocator/src/globals.cpp @@ -0,0 +1,4 @@ +#include "globals.h" + +uint32_t MemoryMappingEffectiveToPhysicalPTR = 0; +uint32_t MemoryMappingPhysicalToEffectivePTR = 0; \ No newline at end of file diff --git a/relocator/src/globals.h b/relocator/src/globals.h new file mode 100644 index 0000000..f096fa7 --- /dev/null +++ b/relocator/src/globals.h @@ -0,0 +1,6 @@ +#pragma once + +#include + +extern uint32_t MemoryMappingEffectiveToPhysicalPTR; +extern uint32_t MemoryMappingPhysicalToEffectivePTR; \ No newline at end of file