diff --git a/relocator/src/hooks_patcher_static.cpp b/relocator/src/hooks_patcher_static.cpp index 1d8449d..9bf9475 100644 --- a/relocator/src/hooks_patcher_static.cpp +++ b/relocator/src/hooks_patcher_static.cpp @@ -1,6 +1,7 @@ #include "utils/logger.h" #include "utils/function_patcher.h" #include "../../source/common/module_defines.h" +#include "globals.h" #include #include @@ -52,9 +53,54 @@ DECL(OSDynLoad_Error, OSDynLoad_FindExport, OSDynLoad_Module module, BOOL isData return result; } +DECL(int32_t, KiEffectiveToPhysical, uint32_t addressSpace, uint32_t virtualAddress) { + int32_t result = real_KiEffectiveToPhysical(addressSpace, virtualAddress); + if (result == 0) { + if(MemoryMappingEffectiveToPhysicalPTR != 0){ + return ((uint32_t (*)(uint32_t)) ((uint32_t *) MemoryMappingEffectiveToPhysicalPTR))(virtualAddress); + } + } + return result; +} + +DECL(int32_t, KiPhysicalToEffectiveCached, uint32_t addressSpace, uint32_t virtualAddress) { + int32_t result = real_KiPhysicalToEffectiveCached(addressSpace, virtualAddress); + if (result == 0) { + if(MemoryMappingPhysicalToEffectivePTR != 0){ + return ((uint32_t (*)(uint32_t)) ((uint32_t *) MemoryMappingPhysicalToEffectivePTR))(virtualAddress); + } + } + return result; +} + +DECL(int32_t, KiPhysicalToEffectiveUncached, uint32_t addressSpace, uint32_t virtualAddress) { + int32_t result = real_KiPhysicalToEffectiveUncached(addressSpace, virtualAddress); + if (result == 0) { + if(MemoryMappingPhysicalToEffectivePTR != 0){ + return ((uint32_t (*)(uint32_t)) ((uint32_t *) MemoryMappingPhysicalToEffectivePTR))(virtualAddress); + } + } + return result; +} + +DECL(int32_t, IPCKDriver_ValidatePhysicalAddress, uint32_t u1, uint32_t physStart, uint32_t physEnd) { + int32_t result = real_IPCKDriver_ValidatePhysicalAddress(u1, physStart, physEnd); + if (result == 0) { + if(MemoryMappingPhysicalToEffectivePTR != 0){ + return ((uint32_t (*)(uint32_t)) ((uint32_t *) MemoryMappingPhysicalToEffectivePTR))(physStart) > 0; + } + return 1; + } + return result; +} + hooks_magic_t method_hooks_hooks_static[] __attribute__((section(".data"))) = { - MAKE_MAGIC(OSDynLoad_Acquire, LIB_CORE_INIT, STATIC_FUNCTION), - MAKE_MAGIC(OSDynLoad_FindExport, LIB_CORE_INIT, STATIC_FUNCTION) + MAKE_MAGIC(KiEffectiveToPhysical, LIB_CORE_INIT, STATIC_FUNCTION), + MAKE_MAGIC(KiPhysicalToEffectiveCached, LIB_CORE_INIT, STATIC_FUNCTION), + MAKE_MAGIC(KiPhysicalToEffectiveUncached, LIB_CORE_INIT, STATIC_FUNCTION), + MAKE_MAGIC(IPCKDriver_ValidatePhysicalAddress, LIB_CORE_INIT, STATIC_FUNCTION), + MAKE_MAGIC(OSDynLoad_Acquire, LIB_CORE_INIT, STATIC_FUNCTION), + MAKE_MAGIC(OSDynLoad_FindExport, LIB_CORE_INIT, STATIC_FUNCTION) }; uint32_t method_hooks_size_hooks_static __attribute__((section(".data"))) = sizeof(method_hooks_hooks_static) / sizeof(hooks_magic_t); diff --git a/relocator/src/utils/function_patcher.cpp b/relocator/src/utils/function_patcher.cpp index 5d3a9d9..03b00a7 100644 --- a/relocator/src/utils/function_patcher.cpp +++ b/relocator/src/utils/function_patcher.cpp @@ -247,6 +247,14 @@ int32_t isDynamicFunction(uint32_t physicalAddress) { uint32_t GetAddressOfFunction(const char *functionName, uint32_t library) { uint32_t real_addr = 0; + if(strcmp(functionName, "KiEffectiveToPhysical") == 0){ + return 0xffee0aac; + }else if(strcmp(functionName, "KiPhysicalToEffectiveCached") == 0){ + return 0xffee0a3c; + }else if(strcmp(functionName, "IPCKDriver_ValidatePhysicalAddress") == 0){ + return 0xfff0cb5c; + } + OSDynLoad_Module rpl_handle = 0; if (library == LIB_CORE_INIT) { if (DEBUG_LOG_DYN) {