mirror of
https://github.com/wiiu-env/FunctionPatcherModule.git
synced 2026-08-28 19:55:49 -05:00
Fix restoring "dynamic" functions. Instead of predicting an unload of a RPL we now check if the replaced instruction has been changed.
This commit is contained in:
@@ -38,6 +38,7 @@ extern "C" {
|
||||
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) LOG(WHBLogWritef, FMT, ##ARGS)
|
||||
|
||||
#define DEBUG_FUNCTION_LINE_ERR(FMT, ARGS...) LOG_EX_DEFAULT(WHBLogPrintf, "##ERROR## ", "", FMT, ##ARGS)
|
||||
#define DEBUG_FUNCTION_LINE_WARN(FMT, ARGS...) LOG_EX_DEFAULT(WHBLogPrintf, "## WARN## ", "", FMT, ##ARGS)
|
||||
|
||||
#define DEBUG_FUNCTION_LINE_ERR_LAMBDA(FILENAME, FUNCTION, LINE, FMT, ARGS...) LOG_EX(FILENAME, FUNCTION, LINE, WHBLogPrintf, "##ERROR## ", "", FMT, ##ARGS);
|
||||
|
||||
@@ -52,6 +53,7 @@ extern "C" {
|
||||
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) while (0)
|
||||
|
||||
#define DEBUG_FUNCTION_LINE_ERR(FMT, ARGS...) LOG_EX_DEFAULT(OSReport, "##ERROR## ", "\n", FMT, ##ARGS)
|
||||
#define DEBUG_FUNCTION_LINE_WARN(FMT, ARGS...) LOG_EX_DEFAULT(OSReport, "## WARN## ", "\n", FMT, ##ARGS)
|
||||
|
||||
#define DEBUG_FUNCTION_LINE_ERR_LAMBDA(FILENAME, FUNCTION, LINE, FMT, ARGS...) LOG_EX(FILENAME, FUNCTION, LINE, OSReport, "##ERROR## ", "\n", FMT, ##ARGS);
|
||||
|
||||
|
||||
28
source/utils/utils.cpp
Normal file
28
source/utils/utils.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#include <coreinit/cache.h>
|
||||
#include <coreinit/memorymap.h>
|
||||
#include <kernel/kernel.h>
|
||||
|
||||
bool ReadFromPhysicalAddress(uint32_t srcPhys, uint32_t *out) {
|
||||
if (!out) {
|
||||
return false;
|
||||
}
|
||||
// Check if patched instruction is still loaded.
|
||||
volatile uint32_t currentInstruction;
|
||||
|
||||
auto currentInstructionAddress = (uint32_t) ¤tInstruction;
|
||||
uint32_t currentInstructionAddressPhys;
|
||||
if (currentInstructionAddress < 0x00800000 || currentInstructionAddress >= 0x01000000) {
|
||||
currentInstructionAddressPhys = (uint32_t) OSEffectiveToPhysical(currentInstructionAddress);
|
||||
} else {
|
||||
currentInstructionAddressPhys = currentInstructionAddress + 0x30800000 - 0x00800000;
|
||||
}
|
||||
|
||||
if (currentInstructionAddressPhys == 0) {
|
||||
return false;
|
||||
}
|
||||
// Save the instruction we will replace.
|
||||
KernelCopyData(currentInstructionAddressPhys, srcPhys, 4);
|
||||
DCFlushRange((void *) ¤tInstruction, 4);
|
||||
*out = currentInstruction;
|
||||
return true;
|
||||
}
|
||||
@@ -10,3 +10,5 @@ template<class T, class... Args>
|
||||
std::shared_ptr<T> make_shared_nothrow(Args &&...args) noexcept(noexcept(T(std::forward<Args>(args)...))) {
|
||||
return std::shared_ptr<T>(new (std::nothrow) T(std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
bool ReadFromPhysicalAddress(uint32_t srcPhys, uint32_t *out);
|
||||
|
||||
Reference in New Issue
Block a user