From 6e352b0085370049d5bb1c164793e66eb38d7691 Mon Sep 17 00:00:00 2001 From: Maschell Date: Sat, 26 Dec 2020 13:22:12 +0100 Subject: [PATCH] Only use OSDynload_Acquire if really needed --- relocator/src/entry.cpp | 5 ++++- source/main.cpp | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/relocator/src/entry.cpp b/relocator/src/entry.cpp index 2f109d1..f8002b1 100644 --- a/relocator/src/entry.cpp +++ b/relocator/src/entry.cpp @@ -59,7 +59,10 @@ bool doRelocation(std::vector &relocData, relocation_trampolin_e int32_t isData = curReloc.getImportRPLInformation().isData(); OSDynLoad_Module rplHandle = 0; if (moduleCache.count(rplName) == 0) { - OSDynLoad_Acquire(rplName.c_str(), &rplHandle); + if(OSDynLoad_IsModuleLoaded(rplName.c_str(), &rplHandle) != OS_DYNLOAD_OK) { + // only acquire if not already loaded. + OSDynLoad_Acquire(rplName.c_str(), &rplHandle); + } moduleCache[rplName] = rplHandle; } rplHandle = moduleCache.at(rplName); diff --git a/source/main.cpp b/source/main.cpp index 5c5fd26..9c93cf9 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -46,7 +46,11 @@ bool doRelocation(std::vector &relocData, relocation_trampolin_e std::string rplName = curReloc.getImportRPLInformation().getName(); int32_t isData = curReloc.getImportRPLInformation().isData(); OSDynLoad_Module rplHandle = nullptr; - OSDynLoad_Acquire(rplName.c_str(), &rplHandle); + + if(OSDynLoad_IsModuleLoaded(rplName.c_str(), &rplHandle) != OS_DYNLOAD_OK) { + // only acquire if not already loaded. + OSDynLoad_Acquire(rplName.c_str(), &rplHandle); + } uint32_t functionAddress = 0; OSDynLoad_FindExport(rplHandle, isData, functionName.c_str(), (void **) &functionAddress);