From 64a2b952ba685d6e4117de55c1043918d6d4e3a3 Mon Sep 17 00:00:00 2001 From: Maschell Date: Fri, 12 Jun 2020 21:10:59 +0200 Subject: [PATCH] Add FunctionPatcherRestoreFunctions --- source/function_patcher.cpp | 37 +++++++++++++++++++++++++++++++++++++ source/function_patcher.h | 2 ++ source/main.cpp | 1 + 3 files changed, 40 insertions(+) diff --git a/source/function_patcher.cpp b/source/function_patcher.cpp index 7a22811..755341a 100644 --- a/source/function_patcher.cpp +++ b/source/function_patcher.cpp @@ -197,6 +197,43 @@ void FunctionPatcherPatchFunction(function_replacement_data_t *replacements, uin } +void FunctionPatcherRestoreFunctions(function_replacement_data_t *replacements, uint32_t size) { + DEBUG_FUNCTION_LINE("Restoring given functions!\n"); + for (uint32_t i = 0; i < size; i++) { + DEBUG_FUNCTION_LINE("Restoring %s... ", replacements[i].function_name); + if (replacements[i].restoreInstruction == 0 || replacements[i].realAddr == 0) { + DEBUG_FUNCTION_LINE("I dont have the information for the restore =( skip"); + continue; + } + + uint32_t physical = (uint32_t) OSEffectiveToPhysical(replacements[i].realAddr); + if (isDynamicFunction(physical)) { + WHBLogPrintf("Its a dynamic function. We don't need to restore it!\n", replacements[i].function_name); + } else { + if (DEBUG_LOG_DYN) { + DEBUG_FUNCTION_LINE("Restoring %08X to %08X\n", (uint32_t) replacements[i].restoreInstruction, replacements[i].realAddr); + } + uint32_t targetAddr = (uint32_t) &replacements[i].restoreInstruction; + + targetAddr = (uint32_t) OSEffectiveToPhysical(targetAddr); + + if (targetAddr == 0 && (targetAddr >= 0x00800000 || targetAddr < 0x01000000)) { + targetAddr = targetAddr + 0x30800000 - 0x00800000; + } + + KernelCopyData(physical, targetAddr, 4); + if (DEBUG_LOG_DYN) { + DEBUG_FUNCTION_LINE("ICInvalidateRange %08X\n", (void *) replacements[i].realAddr); + } + ICInvalidateRange((void *) replacements[i].realAddr, 4); + WHBLogPrintf("done\n"); + } + replacements[i].alreadyPatched = 0; // In case a + } + + DEBUG_FUNCTION_LINE("Done with restoring given functions!\n"); +} + bool isDynamicFunction(uint32_t physicalAddress) { if ((physicalAddress & 0x80000000) == 0x80000000) { return 1; diff --git a/source/function_patcher.h b/source/function_patcher.h index fc3c164..a16c8ba 100644 --- a/source/function_patcher.h +++ b/source/function_patcher.h @@ -14,6 +14,8 @@ typedef struct rpl_handling { void FunctionPatcherPatchFunction(function_replacement_data_t *replacements, uint32_t size); +void FunctionPatcherRestoreFunctions(function_replacement_data_t *replacements, uint32_t size); + void FunctionPatcherResetLibHandles(); uint32_t getAddressOfFunction(char * functionName, function_replacement_library_type_t type); diff --git a/source/main.cpp b/source/main.cpp index 7bd19b5..9ff1e4c 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -13,3 +13,4 @@ WUMS_APPLICATION_STARTS() { } WUMS_EXPORT_FUNCTION(FunctionPatcherPatchFunction); +WUMS_EXPORT_FUNCTION(FunctionPatcherRestoreFunctions);