Reset function patch state if a RPL has been unloaded.

This commit is contained in:
Maschell 2023-01-02 16:24:33 +01:00
parent d3a65723bc
commit e51e6a9509
3 changed files with 23 additions and 0 deletions

View File

@ -57,3 +57,13 @@ void FunctionAddressProvider::resetHandles() {
rplHandle.handle = nullptr;
}
}
function_replacement_library_type_t FunctionAddressProvider::getTypeForHandle(OSDynLoad_Module handle) {
for (auto &rplHandle : rpl_handles) {
if (rplHandle.handle == handle) {
return rplHandle.library;
}
}
return LIBRARY_OTHER;
}

View File

@ -16,6 +16,8 @@ public:
uint32_t getEffectiveAddressOfFunction(function_replacement_library_type_t library, const char *functionName);
void resetHandles();
function_replacement_library_type_t getTypeForHandle(OSDynLoad_Module toReset);
std::list<rpl_handling> rpl_handles = {
{LIBRARY_AVM, "avm.rpl", nullptr},
{LIBRARY_CAMERA, "camera.rpl", nullptr},

View File

@ -96,6 +96,17 @@ void notify_callback(OSDynLoad_Module module,
for (auto &cur : gPatchedFunctions) {
PatchFunction(cur);
}
} else if (reason == OS_DYNLOAD_NOTIFY_UNLOADED) {
std::lock_guard<std::mutex> lock(gPatchedFunctionsMutex);
auto library = gFunctionAddressProvider->getTypeForHandle(module);
if (library != LIBRARY_OTHER) {
for (auto &cur : gPatchedFunctions) {
if (cur->library == library) {
cur->isPatched = false;
}
}
}
CheckIfPatchedFunctionsAreStillInMemory();
}
}