From f48a375a345addfeba97a2c371f02ab4d75137b0 Mon Sep 17 00:00:00 2001 From: Maschell Date: Fri, 1 Jan 2021 02:07:02 +0100 Subject: [PATCH] Just skip modules if imports fail instead of crashing the console on purpose --- relocator/src/entry.cpp | 23 ++++++++++++++++------- relocator/src/hooks.cpp | 4 ++++ source/module/ModuleData.h | 1 + 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/relocator/src/entry.cpp b/relocator/src/entry.cpp index ad6bafa..af34617 100644 --- a/relocator/src/entry.cpp +++ b/relocator/src/entry.cpp @@ -42,10 +42,10 @@ bool doRelocation(std::vector &relocData, relocation_trampolin_e uint32_t functionAddress = 0; for (uint32_t i = 0; i < MAXIMUM_MODULES; i++) { - if (rplName.compare(gModuleData->module_data[i].module_export_name) == 0) { + if (rplName == gModuleData->module_data[i].module_export_name) { export_data_t *exportEntries = gModuleData->module_data[i].export_entries; for (uint32_t j = 0; j < EXPORT_ENTRY_LIST_LENGTH; j++) { - if (functionName.compare(exportEntries[j].name) == 0) { + if (functionName == exportEntries[j].name) { functionAddress = (uint32_t) exportEntries[j].address; } } @@ -54,11 +54,17 @@ bool doRelocation(std::vector &relocData, relocation_trampolin_e if (functionAddress == 0) { int32_t isData = curReloc.getImportRPLInformation().isData(); - OSDynLoad_Module rplHandle = 0; + OSDynLoad_Module rplHandle = nullptr; if (moduleCache.count(rplName) == 0) { - if(OSDynLoad_IsModuleLoaded(rplName.c_str(), &rplHandle) != OS_DYNLOAD_OK) { + OSDynLoad_Error err = OSDynLoad_IsModuleLoaded(rplName.c_str(), &rplHandle); + if(err != OS_DYNLOAD_OK || rplHandle == nullptr) { + DEBUG_FUNCTION_LINE("%s is not yet loaded\n", rplName.c_str()); // only acquire if not already loaded. - OSDynLoad_Acquire(rplName.c_str(), &rplHandle); + err = OSDynLoad_Acquire(rplName.c_str(), &rplHandle); + if(err != OS_DYNLOAD_OK){ + DEBUG_FUNCTION_LINE("Failed to acquire %s\n", rplName.c_str()); + //return false; + } } moduleCache[rplName] = rplHandle; } @@ -81,17 +87,20 @@ bool doRelocation(std::vector &relocData, relocation_trampolin_e return true; } -bool ResolveRelocations(const std::vector &loadedModules) { +bool ResolveRelocations(std::vector &loadedModules) { bool wasSuccessful = true; - for (auto const &curModule : loadedModules) { + for (auto &curModule : loadedModules) { DEBUG_FUNCTION_LINE("Let's do the relocations for %s\n", curModule.getExportName().c_str()); if (wasSuccessful) { std::vector relocData = curModule.getRelocationDataList(); if (!doRelocation(relocData, gModuleData->trampolines, DYN_LINK_TRAMPOLIN_LIST_LENGTH)) { DEBUG_FUNCTION_LINE("FAIL\n"); wasSuccessful = false; + curModule.relocationsDone = false; } + curModule.relocationsDone = true; + } if (curModule.getBSSAddr() != 0) { // DEBUG_FUNCTION_LINE("memset .bss %08X (%d)\n", curModule.getBSSAddr(), curModule.getBSSSize()); diff --git a/relocator/src/hooks.cpp b/relocator/src/hooks.cpp index b10786e..686a3fb 100644 --- a/relocator/src/hooks.cpp +++ b/relocator/src/hooks.cpp @@ -19,6 +19,10 @@ void CallHook(const std::vector &modules, wums_hook_type_t type) { void CallHook(const ModuleData &module, wums_hook_type_t type) { + if(!module.relocationsDone){ + DEBUG_FUNCTION_LINE("Hook not called because the relocations failed\n"); + return; + } for (auto &curHook : module.getHookDataList()) { auto func_ptr = (uint32_t) curHook.getTarget(); if (func_ptr == 0) { diff --git a/source/module/ModuleData.h b/source/module/ModuleData.h index 77f2e0e..a1b73de 100644 --- a/source/module/ModuleData.h +++ b/source/module/ModuleData.h @@ -147,6 +147,7 @@ public: this->initBeforeRelocationDoneHook = value; } + bool relocationsDone = false; private: std::vector relocation_data_list; std::vector export_data_list;