From fa68c980af287029197a2fbf63a46572a3ff63d9 Mon Sep 17 00:00:00 2001 From: Maschell Date: Thu, 28 May 2020 21:45:44 +0200 Subject: [PATCH] Fix support for loading multiple modules --- relocator/src/entry.cpp | 2 +- source/main.cpp | 7 ++++--- source/module/ModuleDataFactory.cpp | 14 ++++++++------ source/module/ModuleDataFactory.h | 2 +- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/relocator/src/entry.cpp b/relocator/src/entry.cpp index cac3696..7383f60 100644 --- a/relocator/src/entry.cpp +++ b/relocator/src/entry.cpp @@ -51,7 +51,7 @@ bool doRelocation(std::vector &relocData, relocation_trampolin_e } rplHandle = moduleCache.at(rplName); uint32_t functionAddress = 0; - + OSDynLoad_FindExport(rplHandle, isData, functionName.c_str(), (void **) &functionAddress); if (functionAddress == 0) { OSFatal_printf("Failed to find export %s of %s", functionName.c_str(), rplName.c_str()); diff --git a/source/main.cpp b/source/main.cpp index 373e932..4bf97a9 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -87,7 +87,8 @@ int main(int argc, char **argv) { for (int i = 0; i < setupModules.GetFilecount(); i++) { memset((void *) gModuleData, 0, sizeof(module_information_t)); DEBUG_FUNCTION_LINE("Trying to run %s", setupModules.GetFilepath(i)); - std::optional moduleData = ModuleDataFactory::load(setupModules.GetFilepath(i), 0x00900000, 0x01000000 - textSectionStart, gModuleData->trampolines, DYN_LINK_TRAMPOLIN_LIST_LENGTH); + uint32_t destination_address = 0x00900000; + std::optional moduleData = ModuleDataFactory::load(setupModules.GetFilepath(i), &destination_address, 0x01000000 - textSectionStart, gModuleData->trampolines, DYN_LINK_TRAMPOLIN_LIST_LENGTH); if (!moduleData) { DEBUG_FUNCTION_LINE("Failed to load %s", setupModules.GetFilepath(i)); continue; @@ -116,11 +117,11 @@ int main(int argc, char **argv) { DirList modules("fs:/vol/external01/wiiu/modules", ".wms", DirList::Files, 1); modules.SortList(); - + uint32_t destination_address = 0x00900000; for (int i = 0; i < modules.GetFilecount(); i++) { DEBUG_FUNCTION_LINE("Loading module %s", modules.GetFilepath(i)); - std::optional moduleData = ModuleDataFactory::load(modules.GetFilepath(i), 0x00900000, 0x01000000 - textSectionStart, gModuleData->trampolines, DYN_LINK_TRAMPOLIN_LIST_LENGTH); + std::optional moduleData = ModuleDataFactory::load(modules.GetFilepath(i), &destination_address, 0x01000000 - textSectionStart, gModuleData->trampolines, DYN_LINK_TRAMPOLIN_LIST_LENGTH); if (moduleData) { DEBUG_FUNCTION_LINE("Successfully loaded %s", modules.GetFilepath(i)); diff --git a/source/module/ModuleDataFactory.cpp b/source/module/ModuleDataFactory.cpp index 48df690..6c74bdb 100644 --- a/source/module/ModuleDataFactory.cpp +++ b/source/module/ModuleDataFactory.cpp @@ -29,7 +29,7 @@ using namespace ELFIO; -std::optional ModuleDataFactory::load(std::string path, uint32_t destination_address, uint32_t maximum_size, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length) { +std::optional ModuleDataFactory::load(std::string path, uint32_t* destination_address_ptr, uint32_t maximum_size, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length) { elfio reader; ModuleData moduleData; @@ -43,7 +43,7 @@ std::optional ModuleDataFactory::load(std::string path, uint32_t des uint8_t **destinations = (uint8_t **) malloc(sizeof(uint8_t *) * sec_num); - uint32_t baseOffset = destination_address; + uint32_t baseOffset = *destination_address_ptr; uint32_t offset_text = baseOffset; uint32_t offset_data = offset_text; @@ -181,18 +181,20 @@ std::optional ModuleDataFactory::load(std::string path, uint32_t des } } - DCFlushRange((void*)destination_address, totalSize); - ICInvalidateRange((void*)destination_address, totalSize); + DCFlushRange((void*)*destination_address_ptr, totalSize); + ICInvalidateRange((void*)*destination_address_ptr, totalSize); free(destinations); moduleData.setEntrypoint(entrypoint); - moduleData.setStartAddress(destination_address); + moduleData.setStartAddress(*destination_address_ptr); moduleData.setEndAddress(endAddress); DEBUG_FUNCTION_LINE("Saved entrypoint as %08X", entrypoint); - DEBUG_FUNCTION_LINE("Saved startAddress as %08X", destination_address); + DEBUG_FUNCTION_LINE("Saved startAddress as %08X", *destination_address_ptr); DEBUG_FUNCTION_LINE("Saved endAddress as %08X", endAddress); + *destination_address_ptr = (*destination_address_ptr + totalSize + 0x100) & 0xFFFFFF00; + return moduleData; } diff --git a/source/module/ModuleDataFactory.h b/source/module/ModuleDataFactory.h index 21633c9..685cfef 100644 --- a/source/module/ModuleDataFactory.h +++ b/source/module/ModuleDataFactory.h @@ -26,7 +26,7 @@ class ModuleDataFactory { public: - static std::optional load(std::string path, uint32_t destination_address, uint32_t maximum_size, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length); + static std::optional load(std::string path, uint32_t* destination_address_ptr, uint32_t maximum_size, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length); static bool linkSection(ELFIO::elfio &reader, uint32_t section_index, uint32_t destination, uint32_t base_text, uint32_t base_data, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length);