From 9f7912cb60bbb53378bcc458662bdaa59bfabc95 Mon Sep 17 00:00:00 2001 From: Maschell Date: Sun, 23 Jan 2022 22:07:38 +0100 Subject: [PATCH] Support for WUMS 0.3.1 --- Dockerfile | 2 +- relocator/src/ModuleDataMinimal.h | 9 +++++++++ relocator/src/ModuleDataPersistence.cpp | 1 + relocator/src/entry.cpp | 14 +++++--------- relocator/src/hooks.cpp | 7 ++++++- source/module/ModuleData.h | 18 +++++++++--------- source/module/ModuleDataFactory.cpp | 8 ++++---- source/module/ModuleDataPersistence.cpp | 4 ++-- 8 files changed, 37 insertions(+), 26 deletions(-) diff --git a/Dockerfile b/Dockerfile index a60f1b0..a32d9e5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ FROM wiiuenv/devkitppc:20211229 -COPY --from=wiiuenv/wiiumodulesystem:20211207 /artifacts $DEVKITPRO +COPY --from=wiiuenv/wiiumodulesystem:20220123 /artifacts $DEVKITPRO WORKDIR project \ No newline at end of file diff --git a/relocator/src/ModuleDataMinimal.h b/relocator/src/ModuleDataMinimal.h index 96f160e..6e04205 100644 --- a/relocator/src/ModuleDataMinimal.h +++ b/relocator/src/ModuleDataMinimal.h @@ -66,6 +66,14 @@ public: this->initBeforeRelocationDoneHook = value; } + [[nodiscard]] bool isSkipInitFini() const { + return this->skipInitFini; + } + + void setSkipInitFini(bool value) { + this->skipInitFini = value; + } + bool relocationsDone = false; private: std::vector> relocation_data_list; @@ -73,4 +81,5 @@ private: std::string export_name; uint32_t entrypoint = 0; bool initBeforeRelocationDoneHook = false; + bool skipInitFini = false; }; diff --git a/relocator/src/ModuleDataPersistence.cpp b/relocator/src/ModuleDataPersistence.cpp index 6d4eecc..2c570b5 100644 --- a/relocator/src/ModuleDataPersistence.cpp +++ b/relocator/src/ModuleDataPersistence.cpp @@ -26,6 +26,7 @@ std::vector> ModuleDataPersistence::loadModul moduleData->setEntrypoint(module_data->entrypoint); moduleData->setInitBeforeRelocationDoneHook(module_data->initBeforeRelocationDoneHook); + moduleData->setSkipInitFini(module_data->skipInitFini); moduleData->setExportName(module_data->module_export_name); for (auto &hook_entry: module_data->hook_entries) { diff --git a/relocator/src/entry.cpp b/relocator/src/entry.cpp index f5800f8..d1d8457 100644 --- a/relocator/src/entry.cpp +++ b/relocator/src/entry.cpp @@ -184,14 +184,6 @@ extern "C" void doStart(int argc, char **argv) { DEBUG_FUNCTION_LINE_VERBOSE("Relocations done\n"); CallHook(loadedModules, WUMS_HOOK_RELOCATIONS_DONE); - for (int i = 0; i < gModuleData->number_used_modules; i++) { - if (!gModuleData->module_data[i].skipEntrypoint) { - DEBUG_FUNCTION_LINE_VERBOSE("About to call %08X\n", gModuleData->module_data[i].entrypoint); - int ret = ((int (*)(int, char **)) (gModuleData->module_data[i].entrypoint))(argc, argv); - DEBUG_FUNCTION_LINE_VERBOSE("return code was %d\n", ret); - } - } - for (auto &curModule: loadedModules) { if (!curModule->isInitBeforeRelocationDoneHook()) { CallInitHooksForModule(curModule); @@ -208,8 +200,10 @@ extern "C" void doStart(int argc, char **argv) { CallHook(loadedModules, WUMS_HOOK_INIT_WUT_STDCPP); CallHook(loadedModules, WUMS_HOOK_INIT_WUT_DEVOPTAB); CallHook(loadedModules, WUMS_HOOK_INIT_WUT_SOCKETS); + for (auto &curModule: loadedModules) { + CallHook(curModule, WUMS_HOOK_INIT_WRAPPER, !curModule->isSkipInitFini()); + } CallHook(loadedModules, WUMS_HOOK_APPLICATION_STARTS); - //CallHook(loadedModules, WUMS_HOOK_FINI_WUT); } void CallInitHooksForModule(const std::shared_ptr &curModule) { @@ -218,7 +212,9 @@ void CallInitHooksForModule(const std::shared_ptr &curModule) CallHook(curModule, WUMS_HOOK_INIT_WUT_STDCPP); CallHook(curModule, WUMS_HOOK_INIT_WUT_DEVOPTAB); CallHook(curModule, WUMS_HOOK_INIT_WUT_SOCKETS); + CallHook(curModule, WUMS_HOOK_INIT_WRAPPER, !curModule->isSkipInitFini()); CallHook(curModule, WUMS_HOOK_INIT); + CallHook(curModule, WUMS_HOOK_FINI_WRAPPER, !curModule->isSkipInitFini()); CallHook(curModule, WUMS_HOOK_FINI_WUT_SOCKETS); CallHook(curModule, WUMS_HOOK_FINI_WUT_DEVOPTAB); CallHook(curModule, WUMS_HOOK_FINI_WUT_STDCPP); diff --git a/relocator/src/hooks.cpp b/relocator/src/hooks.cpp index 0fc673d..d600396 100644 --- a/relocator/src/hooks.cpp +++ b/relocator/src/hooks.cpp @@ -14,6 +14,9 @@ static const char **hook_names = (const char *[]) { "WUMS_HOOK_INIT_WUT_SOCKETS", "WUMS_HOOK_FINI_WUT_SOCKETS", + "WUMS_HOOK_INIT_WRAPPER", + "WUMS_HOOK_FINI_WRAPPER", + "WUMS_HOOK_INIT", "WUMS_HOOK_APPLICATION_STARTS", "WUMS_HOOK_APPLICATION_ENDS", @@ -65,7 +68,9 @@ void CallHook(const std::shared_ptr &module, wums_hook_type_t type == WUMS_HOOK_INIT_WUT_DEVOPTAB || type == WUMS_HOOK_FINI_WUT_DEVOPTAB || type == WUMS_HOOK_INIT_WUT_SOCKETS || - type == WUMS_HOOK_FINI_WUT_SOCKETS + type == WUMS_HOOK_FINI_WUT_SOCKETS || + type == WUMS_HOOK_INIT_WRAPPER || + type == WUMS_HOOK_FINI_WRAPPER )) { DEBUG_FUNCTION_LINE_VERBOSE("Calling hook of type %s [%d] %d for %s: %08X\n", hook_names[type], type, curHook->getType(), module->getExportName().c_str(), curHook->getTarget()); ((void (*)()) ((uint32_t *) func_ptr))(); diff --git a/source/module/ModuleData.h b/source/module/ModuleData.h index af3f941..803f617 100644 --- a/source/module/ModuleData.h +++ b/source/module/ModuleData.h @@ -148,22 +148,22 @@ public: return this->export_name; } - [[nodiscard]] bool isSkipEntrypoint() const { - return this->skipEntrypoint; - } - [[nodiscard]] bool isInitBeforeRelocationDoneHook() const { return this->initBeforeRelocationDoneHook; } - void setSkipEntrypoint(bool value) { - this->skipEntrypoint = value; - } - void setInitBeforeRelocationDoneHook(bool value) { this->initBeforeRelocationDoneHook = value; } + [[nodiscard]] bool isSkipInitFini() const { + return this->skipInitFini; + } + + void setSkipInitFini(bool value) { + this->skipInitFini = value; + } + bool relocationsDone = false; private: std::vector> relocation_data_list; @@ -181,6 +181,6 @@ private: uint32_t startAddress = 0; uint32_t endAddress = 0; uint32_t entrypoint = 0; - bool skipEntrypoint = false; bool initBeforeRelocationDoneHook = false; + bool skipInitFini = false; }; diff --git a/source/module/ModuleDataFactory.cpp b/source/module/ModuleDataFactory.cpp index a1c8285..964c6c7 100644 --- a/source/module/ModuleDataFactory.cpp +++ b/source/module/ModuleDataFactory.cpp @@ -186,12 +186,12 @@ ModuleDataFactory::load(const std::string &path, uint32_t *destination_address_p if (key == "export_name") { DEBUG_FUNCTION_LINE("export_name = %s", value.c_str()); moduleData->setExportName(value); - } else if (key == "skipEntrypoint") { + } else if (key == "skipInitFini") { if (value == "true") { - DEBUG_FUNCTION_LINE("skipEntrypoint = %s", value.c_str()); - moduleData->setSkipEntrypoint(true); + DEBUG_FUNCTION_LINE("skipInitFini = %s", value.c_str()); + moduleData->setSkipInitFini(true); } else { - moduleData->setSkipEntrypoint(false); + moduleData->setSkipInitFini(false); } } else if (key == "initBeforeRelocationDoneHook") { if (value == "true") { diff --git a/source/module/ModuleDataPersistence.cpp b/source/module/ModuleDataPersistence.cpp index d4ec391..667e49f 100644 --- a/source/module/ModuleDataPersistence.cpp +++ b/source/module/ModuleDataPersistence.cpp @@ -92,7 +92,7 @@ bool ModuleDataPersistence::saveModuleData(module_information_t *moduleInformati module_data->startAddress = module->getStartAddress(); module_data->endAddress = module->getEndAddress(); module_data->entrypoint = module->getEntrypoint(); - module_data->skipEntrypoint = module->isSkipEntrypoint(); + module_data->skipInitFini = module->isSkipInitFini(); module_data->initBeforeRelocationDoneHook = module->isInitBeforeRelocationDoneHook(); moduleInformation->number_used_modules++; @@ -127,7 +127,7 @@ std::vector> ModuleDataPersistence::loadModuleData(m moduleData->setStartAddress(module_data->startAddress); moduleData->setEndAddress(module_data->endAddress); moduleData->setExportName(module_data->module_export_name); - moduleData->setSkipEntrypoint(module_data->skipEntrypoint); + moduleData->setSkipInitFini(module_data->skipInitFini); moduleData->setInitBeforeRelocationDoneHook(module_data->initBeforeRelocationDoneHook); for (auto &export_entrie: module_data->export_entries) {