From 978678675c0eaa8d024b0ef659254c071216287f Mon Sep 17 00:00:00 2001 From: Maschell Date: Mon, 28 Dec 2020 14:45:28 +0100 Subject: [PATCH] Add FunctionPatcherRestoreDynamicFunctions --- source/function_patcher.cpp | 18 ++++++++++++++++++ source/function_patcher.h | 2 ++ source/main.cpp | 1 + 3 files changed, 21 insertions(+) diff --git a/source/function_patcher.cpp b/source/function_patcher.cpp index 91b655a..c854f21 100644 --- a/source/function_patcher.cpp +++ b/source/function_patcher.cpp @@ -36,6 +36,24 @@ void writeDataAndFlushIC(CThread *thread, void *arg) { ICInvalidateRange((void *) (effective_address), 4); } +void FunctionPatcherRestoreDynamicFunctions(function_replacement_data_t *replacements, uint32_t size) { + for (uint32_t i = 0; i < size; i++) { + function_replacement_data_t *function_data = &replacements[i]; + if (function_data->VERSION != FUNCTION_REPLACEMENT_DATA_STRUCT_VERSION) { + OSFatal("Failed to patch function. struct version mismatch"); + } + + uint32_t targetAddrPhys = function_data->physicalAddr; + if (function_data->library != LIBRARY_OTHER) { + targetAddrPhys = (uint32_t) OSEffectiveToPhysical(function_data->realAddr); + } + if (isDynamicFunction(targetAddrPhys)) { + DEBUG_FUNCTION_LINE("Setting alreadyPatched to false for %s because it's a dynamic function", function_data->function_name); + function_data->alreadyPatched = 0; + } + } +} + void FunctionPatcherPatchFunction(function_replacement_data_t *replacements, uint32_t size) { for (uint32_t i = 0; i < size; i++) { function_replacement_data_t *function_data = &replacements[i]; diff --git a/source/function_patcher.h b/source/function_patcher.h index a16c8ba..93473a7 100644 --- a/source/function_patcher.h +++ b/source/function_patcher.h @@ -12,6 +12,8 @@ typedef struct rpl_handling { OSDynLoad_Module handle; } rpl_handling; +void FunctionPatcherRestoreDynamicFunctions(function_replacement_data_t *replacements, uint32_t size); + void FunctionPatcherPatchFunction(function_replacement_data_t *replacements, uint32_t size); void FunctionPatcherRestoreFunctions(function_replacement_data_t *replacements, uint32_t size); diff --git a/source/main.cpp b/source/main.cpp index 2a8ba28..776d693 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -16,3 +16,4 @@ WUMS_APPLICATION_STARTS() { WUMS_EXPORT_FUNCTION(FunctionPatcherPatchFunction); WUMS_EXPORT_FUNCTION(FunctionPatcherRestoreFunctions); +WUMS_EXPORT_FUNCTION(FunctionPatcherRestoreDynamicFunctions);