mirror of
https://github.com/wiiu-env/FunctionPatcherModule.git
synced 2025-01-06 23:28:14 +01:00
Format the code via clang-format
This commit is contained in:
parent
2e5e3d1d2f
commit
a8b4f7188b
67
.clang-format
Normal file
67
.clang-format
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
# Generated from CLion C/C++ Code Style settings
|
||||||
|
BasedOnStyle: LLVM
|
||||||
|
AccessModifierOffset: -4
|
||||||
|
AlignAfterOpenBracket: Align
|
||||||
|
AlignConsecutiveAssignments: Consecutive
|
||||||
|
AlignConsecutiveMacros: AcrossEmptyLinesAndComments
|
||||||
|
AlignOperands: Align
|
||||||
|
AllowAllArgumentsOnNextLine: false
|
||||||
|
AllowAllConstructorInitializersOnNextLine: false
|
||||||
|
AllowAllParametersOfDeclarationOnNextLine: false
|
||||||
|
AllowShortBlocksOnASingleLine: Always
|
||||||
|
AllowShortCaseLabelsOnASingleLine: false
|
||||||
|
AllowShortFunctionsOnASingleLine: All
|
||||||
|
AllowShortIfStatementsOnASingleLine: Always
|
||||||
|
AllowShortLambdasOnASingleLine: All
|
||||||
|
AllowShortLoopsOnASingleLine: true
|
||||||
|
AlwaysBreakAfterReturnType: None
|
||||||
|
AlwaysBreakTemplateDeclarations: Yes
|
||||||
|
BreakBeforeBraces: Custom
|
||||||
|
BraceWrapping:
|
||||||
|
AfterCaseLabel: false
|
||||||
|
AfterClass: false
|
||||||
|
AfterControlStatement: Never
|
||||||
|
AfterEnum: false
|
||||||
|
AfterFunction: false
|
||||||
|
AfterNamespace: false
|
||||||
|
AfterUnion: false
|
||||||
|
BeforeCatch: false
|
||||||
|
BeforeElse: false
|
||||||
|
IndentBraces: false
|
||||||
|
SplitEmptyFunction: false
|
||||||
|
SplitEmptyRecord: true
|
||||||
|
BreakBeforeBinaryOperators: None
|
||||||
|
BreakBeforeTernaryOperators: true
|
||||||
|
BreakConstructorInitializers: BeforeColon
|
||||||
|
BreakInheritanceList: BeforeColon
|
||||||
|
ColumnLimit: 0
|
||||||
|
CompactNamespaces: false
|
||||||
|
ContinuationIndentWidth: 8
|
||||||
|
IndentCaseLabels: true
|
||||||
|
IndentPPDirectives: None
|
||||||
|
IndentWidth: 4
|
||||||
|
KeepEmptyLinesAtTheStartOfBlocks: true
|
||||||
|
MaxEmptyLinesToKeep: 2
|
||||||
|
NamespaceIndentation: All
|
||||||
|
ObjCSpaceAfterProperty: false
|
||||||
|
ObjCSpaceBeforeProtocolList: true
|
||||||
|
PointerAlignment: Right
|
||||||
|
ReflowComments: false
|
||||||
|
SpaceAfterCStyleCast: true
|
||||||
|
SpaceAfterLogicalNot: false
|
||||||
|
SpaceAfterTemplateKeyword: false
|
||||||
|
SpaceBeforeAssignmentOperators: true
|
||||||
|
SpaceBeforeCpp11BracedList: false
|
||||||
|
SpaceBeforeCtorInitializerColon: true
|
||||||
|
SpaceBeforeInheritanceColon: true
|
||||||
|
SpaceBeforeParens: ControlStatements
|
||||||
|
SpaceBeforeRangeBasedForLoopColon: true
|
||||||
|
SpaceInEmptyParentheses: false
|
||||||
|
SpacesBeforeTrailingComments: 1
|
||||||
|
SpacesInAngles: false
|
||||||
|
SpacesInCStyleCastParentheses: false
|
||||||
|
SpacesInContainerLiterals: false
|
||||||
|
SpacesInParentheses: false
|
||||||
|
SpacesInSquareBrackets: false
|
||||||
|
TabWidth: 4
|
||||||
|
UseTab: Never
|
8
.github/workflows/ci.yml
vendored
8
.github/workflows/ci.yml
vendored
@ -6,8 +6,16 @@ on:
|
|||||||
- master
|
- master
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
clang-format:
|
||||||
|
runs-on: ubuntu-18.04
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: clang-format
|
||||||
|
run: |
|
||||||
|
docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./source
|
||||||
build-binary:
|
build-binary:
|
||||||
runs-on: ubuntu-18.04
|
runs-on: ubuntu-18.04
|
||||||
|
needs: clang-format
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: build binary
|
- name: build binary
|
||||||
|
8
.github/workflows/pr.yml
vendored
8
.github/workflows/pr.yml
vendored
@ -3,8 +3,16 @@ name: CI-PR
|
|||||||
on: [pull_request]
|
on: [pull_request]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
clang-format:
|
||||||
|
runs-on: ubuntu-18.04
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: clang-format
|
||||||
|
run: |
|
||||||
|
docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./source
|
||||||
build-binary:
|
build-binary:
|
||||||
runs-on: ubuntu-18.04
|
runs-on: ubuntu-18.04
|
||||||
|
needs: clang-format
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: build binary
|
- name: build binary
|
||||||
|
@ -18,3 +18,7 @@ docker run -it --rm -v ${PWD}:/project functionpatchermodule-builder make
|
|||||||
# make clean
|
# make clean
|
||||||
docker run -it --rm -v ${PWD}:/project functionpatchermodule-builder make clean
|
docker run -it --rm -v ${PWD}:/project functionpatchermodule-builder make clean
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Format the code via docker
|
||||||
|
|
||||||
|
`docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./source -i`
|
@ -16,10 +16,10 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <coreinit/thread.h>
|
||||||
|
#include <cstdint>
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <cstdint>
|
|
||||||
#include <coreinit/thread.h>
|
|
||||||
|
|
||||||
class CThread {
|
class CThread {
|
||||||
public:
|
public:
|
||||||
@ -27,7 +27,7 @@ public:
|
|||||||
|
|
||||||
//! constructor
|
//! constructor
|
||||||
explicit CThread(int32_t iAttr, int32_t iPriority = 16, int32_t iStackSize = 0x8000, CThread::Callback callback = NULL, void *callbackArg = NULL)
|
explicit CThread(int32_t iAttr, int32_t iPriority = 16, int32_t iStackSize = 0x8000, CThread::Callback callback = NULL, void *callbackArg = NULL)
|
||||||
: pThread(nullptr), pThreadStack(nullptr), pCallback(callback), pCallbackArg(callbackArg) {
|
: pThread(nullptr), pThreadStack(nullptr), pCallback(callback), pCallbackArg(callbackArg) {
|
||||||
//! save attribute assignment
|
//! save attribute assignment
|
||||||
iAttributes = iAttr;
|
iAttributes = iAttr;
|
||||||
//! allocate the thread
|
//! allocate the thread
|
||||||
@ -36,7 +36,9 @@ public:
|
|||||||
pThreadStack = (uint8_t *) memalign(0x20, iStackSize);
|
pThreadStack = (uint8_t *) memalign(0x20, iStackSize);
|
||||||
//! create the thread
|
//! create the thread
|
||||||
if (pThread && pThreadStack) {
|
if (pThread && pThreadStack) {
|
||||||
OSCreateThread(pThread, (int (*)(int, const char **)) &CThread::threadCallback, 1, (char *) this, (void *) (pThreadStack + iStackSize), iStackSize, iPriority, iAttributes);
|
// clang-format off
|
||||||
|
OSCreateThread(pThread, (int(*)(int, const char **)) & CThread::threadCallback, 1, (char *) this, (void *) (pThreadStack + iStackSize), iStackSize, iPriority, iAttributes);
|
||||||
|
// clang-format on
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,7 +54,7 @@ public:
|
|||||||
static void runOnAllCores(CThread::Callback callback, void *callbackArg, int32_t iAttr = 0, int32_t iPriority = 16, int32_t iStackSize = 0x8000) {
|
static void runOnAllCores(CThread::Callback callback, void *callbackArg, int32_t iAttr = 0, int32_t iPriority = 16, int32_t iStackSize = 0x8000) {
|
||||||
int32_t aff[] = {CThread::eAttributeAffCore2, CThread::eAttributeAffCore1, CThread::eAttributeAffCore0};
|
int32_t aff[] = {CThread::eAttributeAffCore2, CThread::eAttributeAffCore1, CThread::eAttributeAffCore0};
|
||||||
|
|
||||||
for (int i: aff) {
|
for (int i : aff) {
|
||||||
CThread thread(iAttr | i, iPriority, iStackSize, callback, callbackArg);
|
CThread thread(iAttr | i, iPriority, iStackSize, callback, callbackArg);
|
||||||
thread.resumeThread();
|
thread.resumeThread();
|
||||||
}
|
}
|
||||||
@ -125,19 +127,20 @@ public:
|
|||||||
if (pThread) {
|
if (pThread) {
|
||||||
free(pThread);
|
free(pThread);
|
||||||
}
|
}
|
||||||
pThread = nullptr;
|
pThread = nullptr;
|
||||||
pThreadStack = nullptr;
|
pThreadStack = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Thread attributes
|
//! Thread attributes
|
||||||
enum eCThreadAttributes {
|
enum eCThreadAttributes {
|
||||||
eAttributeNone = 0x07,
|
eAttributeNone = 0x07,
|
||||||
eAttributeAffCore0 = 0x01,
|
eAttributeAffCore0 = 0x01,
|
||||||
eAttributeAffCore1 = 0x02,
|
eAttributeAffCore1 = 0x02,
|
||||||
eAttributeAffCore2 = 0x04,
|
eAttributeAffCore2 = 0x04,
|
||||||
eAttributeDetach = 0x08,
|
eAttributeDetach = 0x08,
|
||||||
eAttributePinnedAff = 0x10
|
eAttributePinnedAff = 0x10
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static int32_t threadCallback(int32_t argc, void *arg) {
|
static int32_t threadCallback(int32_t argc, void *arg) {
|
||||||
//! After call to start() continue with the internal function
|
//! After call to start() continue with the internal function
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
#include <coreinit/dynload.h>
|
#include "function_patcher.h"
|
||||||
|
#include "CThread.h"
|
||||||
|
#include "logger.h"
|
||||||
#include <coreinit/cache.h>
|
#include <coreinit/cache.h>
|
||||||
#include <coreinit/debug.h>
|
#include <coreinit/debug.h>
|
||||||
|
#include <coreinit/dynload.h>
|
||||||
#include <coreinit/memorymap.h>
|
#include <coreinit/memorymap.h>
|
||||||
#include <kernel/kernel.h>
|
#include <kernel/kernel.h>
|
||||||
#include "function_patcher.h"
|
|
||||||
#include "logger.h"
|
|
||||||
#include "CThread.h"
|
|
||||||
|
|
||||||
void writeDataAndFlushIC(CThread *thread, void *arg) {
|
void writeDataAndFlushIC(CThread *thread, void *arg) {
|
||||||
auto *data = (uint32_t *) arg;
|
auto *data = (uint32_t *) arg;
|
||||||
@ -13,14 +13,14 @@ void writeDataAndFlushIC(CThread *thread, void *arg) {
|
|||||||
DCFlushRange(data, sizeof(uint32_t) * 3);
|
DCFlushRange(data, sizeof(uint32_t) * 3);
|
||||||
|
|
||||||
uint32_t replace_instruction = data[0];
|
uint32_t replace_instruction = data[0];
|
||||||
uint32_t physical_address = data[1];
|
uint32_t physical_address = data[1];
|
||||||
uint32_t effective_address = data[2];
|
uint32_t effective_address = data[2];
|
||||||
DCFlushRange(&replace_instruction, 4);
|
DCFlushRange(&replace_instruction, 4);
|
||||||
DCFlushRange(&physical_address, 4);
|
DCFlushRange(&physical_address, 4);
|
||||||
|
|
||||||
DEBUG_FUNCTION_LINE_VERBOSE("Write instruction %08X to %08X [%08X] on core %d", replace_instruction, effective_address, physical_address, OSGetThreadAffinity(OSGetCurrentThread()) / 2);
|
DEBUG_FUNCTION_LINE_VERBOSE("Write instruction %08X to %08X [%08X] on core %d", replace_instruction, effective_address, physical_address, OSGetThreadAffinity(OSGetCurrentThread()) / 2);
|
||||||
|
|
||||||
auto replace_instruction_physical = (uint32_t) & replace_instruction;
|
auto replace_instruction_physical = (uint32_t) &replace_instruction;
|
||||||
|
|
||||||
if (replace_instruction_physical < 0x00800000 || replace_instruction_physical >= 0x01000000) {
|
if (replace_instruction_physical < 0x00800000 || replace_instruction_physical >= 0x01000000) {
|
||||||
replace_instruction_physical = OSEffectiveToPhysical(replace_instruction_physical);
|
replace_instruction_physical = OSEffectiveToPhysical(replace_instruction_physical);
|
||||||
@ -67,8 +67,8 @@ void FunctionPatcherPatchFunction(function_replacement_data_t *replacements, uin
|
|||||||
DEBUG_FUNCTION_LINE_VERBOSE("Patching %s ...", function_data->function_name);
|
DEBUG_FUNCTION_LINE_VERBOSE("Patching %s ...", function_data->function_name);
|
||||||
|
|
||||||
uint32_t physical = function_data->physicalAddr;
|
uint32_t physical = function_data->physicalAddr;
|
||||||
auto repl_addr = (uint32_t) function_data->replaceAddr;
|
auto repl_addr = (uint32_t) function_data->replaceAddr;
|
||||||
auto call_addr = (uint32_t) function_data->replaceCall;
|
auto call_addr = (uint32_t) function_data->replaceCall;
|
||||||
|
|
||||||
uint32_t real_addr = function_data->virtualAddr;
|
uint32_t real_addr = function_data->virtualAddr;
|
||||||
if (function_data->library != LIBRARY_OTHER) {
|
if (function_data->library != LIBRARY_OTHER) {
|
||||||
@ -93,7 +93,7 @@ void FunctionPatcherPatchFunction(function_replacement_data_t *replacements, uin
|
|||||||
|
|
||||||
DEBUG_FUNCTION_LINE_VERBOSE("%s physical is located at %08X!", function_data->function_name, physical);
|
DEBUG_FUNCTION_LINE_VERBOSE("%s physical is located at %08X!", function_data->function_name, physical);
|
||||||
|
|
||||||
*(volatile uint32_t *) (call_addr) = (uint32_t)(space);
|
*(volatile uint32_t *) (call_addr) = (uint32_t) (space);
|
||||||
|
|
||||||
auto targetAddr = (uint32_t) space;
|
auto targetAddr = (uint32_t) space;
|
||||||
if (targetAddr < 0x00800000 || targetAddr >= 0x01000000) {
|
if (targetAddr < 0x00800000 || targetAddr >= 0x01000000) {
|
||||||
@ -110,7 +110,7 @@ void FunctionPatcherPatchFunction(function_replacement_data_t *replacements, uin
|
|||||||
space++;
|
space++;
|
||||||
|
|
||||||
// fill the restore instruction section
|
// fill the restore instruction section
|
||||||
function_data->realAddr = real_addr;
|
function_data->realAddr = real_addr;
|
||||||
function_data->restoreInstruction = space[-1];
|
function_data->restoreInstruction = space[-1];
|
||||||
|
|
||||||
DEBUG_FUNCTION_LINE_VERBOSE("function_data->realAddr = %08X!", function_data->realAddr);
|
DEBUG_FUNCTION_LINE_VERBOSE("function_data->realAddr = %08X!", function_data->realAddr);
|
||||||
@ -123,10 +123,14 @@ void FunctionPatcherPatchFunction(function_replacement_data_t *replacements, uin
|
|||||||
00808d08 4e800420 bctr
|
00808d08 4e800420 bctr
|
||||||
*/
|
*/
|
||||||
|
|
||||||
*space = 0x3d600000 | (((real_addr + 4) >> 16) & 0x0000FFFF); space++; // lis r11 ,0x1234
|
*space = 0x3d600000 | (((real_addr + 4) >> 16) & 0x0000FFFF);
|
||||||
*space = 0x616b0000 | ((real_addr + 4) & 0x0000ffff); space++; // ori r11 ,r11 ,0x5678
|
space++; // lis r11 ,0x1234
|
||||||
*space = 0x7d6903a6; space++; // mtspr CTR ,r11
|
*space = 0x616b0000 | ((real_addr + 4) & 0x0000ffff);
|
||||||
*space = 0x4e800420; space++; // bctr
|
space++; // ori r11 ,r11 ,0x5678
|
||||||
|
*space = 0x7d6903a6;
|
||||||
|
space++; // mtspr CTR ,r11
|
||||||
|
*space = 0x4e800420;
|
||||||
|
space++; // bctr
|
||||||
|
|
||||||
//setting jump back
|
//setting jump back
|
||||||
uint32_t replace_instr = 0x48000002 | (repl_addr & 0x03FFFFFC);
|
uint32_t replace_instr = 0x48000002 | (repl_addr & 0x03FFFFFC);
|
||||||
@ -136,28 +140,45 @@ void FunctionPatcherPatchFunction(function_replacement_data_t *replacements, uin
|
|||||||
auto repl_addr_test = (uint32_t) space;
|
auto repl_addr_test = (uint32_t) space;
|
||||||
if (function_data->targetProcess != FP_TARGET_PROCESS_ALL) {
|
if (function_data->targetProcess != FP_TARGET_PROCESS_ALL) {
|
||||||
// Only use patched function if OSGetUPID matches function_data->targetProcess
|
// Only use patched function if OSGetUPID matches function_data->targetProcess
|
||||||
*space = 0x3d600000 | (((uint32_t*) OSGetUPID)[0] & 0x0000FFFF); space++; // lis r11 ,0x0
|
*space = 0x3d600000 | (((uint32_t *) OSGetUPID)[0] & 0x0000FFFF);
|
||||||
*space = 0x816b0000 | (((uint32_t*) OSGetUPID)[1] & 0x0000FFFF); space++; // lwz r11 ,0x0(r11)
|
space++; // lis r11 ,0x0
|
||||||
if(function_data->targetProcess == FP_TARGET_PROCESS_GAME_AND_MENU){
|
*space = 0x816b0000 | (((uint32_t *) OSGetUPID)[1] & 0x0000FFFF);
|
||||||
*space = 0x2c0b0000 | FP_TARGET_PROCESS_WII_U_MENU; space++; // cmpwi r11 ,FP_TARGET_PROCESS_WII_U_MENU
|
space++; // lwz r11 ,0x0(r11)
|
||||||
*space = 0x41820000 | 0x00000020; space++; // beq myfunc
|
if (function_data->targetProcess == FP_TARGET_PROCESS_GAME_AND_MENU) {
|
||||||
*space = 0x2c0b0000 | FP_TARGET_PROCESS_GAME; space++; // cmpwi r11 ,FP_TARGET_PROCESS_GAME
|
*space = 0x2c0b0000 | FP_TARGET_PROCESS_WII_U_MENU;
|
||||||
*space = 0x41820000 | 0x00000018; space++; // beq myfunc
|
space++; // cmpwi r11 ,FP_TARGET_PROCESS_WII_U_MENU
|
||||||
|
*space = 0x41820000 | 0x00000020;
|
||||||
|
space++; // beq myfunc
|
||||||
|
*space = 0x2c0b0000 | FP_TARGET_PROCESS_GAME;
|
||||||
|
space++; // cmpwi r11 ,FP_TARGET_PROCESS_GAME
|
||||||
|
*space = 0x41820000 | 0x00000018;
|
||||||
|
space++; // beq myfunc
|
||||||
} else {
|
} else {
|
||||||
*space = 0x2c0b0000 | function_data->targetProcess; space++; // cmpwi r11 ,function_data->targetProcess
|
*space = 0x2c0b0000 | function_data->targetProcess;
|
||||||
*space = 0x41820000 | 0x00000018; space++; // beq myfunc
|
space++; // cmpwi r11 ,function_data->targetProcess
|
||||||
|
*space = 0x41820000 | 0x00000018;
|
||||||
|
space++; // beq myfunc
|
||||||
}
|
}
|
||||||
*space = 0x3d600000 | (((real_addr + 4) >> 16) & 0x0000FFFF); space++; // lis r11 ,(real_addr + 4)@hi
|
*space = 0x3d600000 | (((real_addr + 4) >> 16) & 0x0000FFFF);
|
||||||
*space = 0x616b0000 | ((real_addr + 4) & 0x0000ffff); space++; // ori r11 ,(real_addr + 4)@lo
|
space++; // lis r11 ,(real_addr + 4)@hi
|
||||||
*space = 0x7d6903a6; space++; // mtspr CTR ,r11
|
*space = 0x616b0000 | ((real_addr + 4) & 0x0000ffff);
|
||||||
*space = function_data->restoreInstruction; space++; //
|
space++; // ori r11 ,(real_addr + 4)@lo
|
||||||
*space = 0x4e800420; space++; // bctr
|
*space = 0x7d6903a6;
|
||||||
|
space++; // mtspr CTR ,r11
|
||||||
|
*space = function_data->restoreInstruction;
|
||||||
|
space++; //
|
||||||
|
*space = 0x4e800420;
|
||||||
|
space++; // bctr
|
||||||
}
|
}
|
||||||
// myfunc:
|
// myfunc:
|
||||||
*space = 0x3d600000 | (((repl_addr) >> 16) & 0x0000FFFF); space++; // lis r11 ,repl_addr@hi
|
*space = 0x3d600000 | (((repl_addr) >> 16) & 0x0000FFFF);
|
||||||
*space = 0x616b0000 | ((repl_addr) & 0x0000ffff); space++; // ori r11 ,r11 ,repl_addr@lo
|
space++; // lis r11 ,repl_addr@hi
|
||||||
*space = 0x7d6903a6; space++; // mtspr CTR ,r11
|
*space = 0x616b0000 | ((repl_addr) &0x0000ffff);
|
||||||
*space = 0x4e800420; space++; // bctr
|
space++; // ori r11 ,r11 ,repl_addr@lo
|
||||||
|
*space = 0x7d6903a6;
|
||||||
|
space++; // mtspr CTR ,r11
|
||||||
|
*space = 0x4e800420;
|
||||||
|
space++; // bctr
|
||||||
|
|
||||||
// Make sure the trampoline itself is usable.
|
// Make sure the trampoline itself is usable.
|
||||||
if ((repl_addr_test & 0x03FFFFFC) != repl_addr_test) {
|
if ((repl_addr_test & 0x03FFFFFC) != repl_addr_test) {
|
||||||
@ -177,16 +198,13 @@ void FunctionPatcherPatchFunction(function_replacement_data_t *replacements, uin
|
|||||||
uint32_t data[] = {
|
uint32_t data[] = {
|
||||||
replace_instr,
|
replace_instr,
|
||||||
physical,
|
physical,
|
||||||
real_addr
|
real_addr};
|
||||||
};
|
|
||||||
CThread::runOnAllCores(writeDataAndFlushIC, data);
|
CThread::runOnAllCores(writeDataAndFlushIC, data);
|
||||||
|
|
||||||
function_data->alreadyPatched = 1;
|
function_data->alreadyPatched = 1;
|
||||||
DEBUG_FUNCTION_LINE_VERBOSE("done with patching %s!", function_data->function_name);
|
DEBUG_FUNCTION_LINE_VERBOSE("done with patching %s!", function_data->function_name);
|
||||||
|
|
||||||
}
|
}
|
||||||
DEBUG_FUNCTION_LINE_VERBOSE("Done with patching given functions!");
|
DEBUG_FUNCTION_LINE_VERBOSE("Done with patching given functions!");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FunctionPatcherRestoreFunctions(function_replacement_data_t *replacements, uint32_t size) {
|
void FunctionPatcherRestoreFunctions(function_replacement_data_t *replacements, uint32_t size) {
|
||||||
@ -208,8 +226,7 @@ void FunctionPatcherRestoreFunctions(function_replacement_data_t *replacements,
|
|||||||
// Other processes than the wii u menu and game one seem to keep their rpl's loaded.
|
// Other processes than the wii u menu and game one seem to keep their rpl's loaded.
|
||||||
replacements[i].targetProcess != FP_TARGET_PROCESS_GAME_AND_MENU &&
|
replacements[i].targetProcess != FP_TARGET_PROCESS_GAME_AND_MENU &&
|
||||||
replacements[i].targetProcess != FP_TARGET_PROCESS_GAME &&
|
replacements[i].targetProcess != FP_TARGET_PROCESS_GAME &&
|
||||||
replacements[i].targetProcess != FP_TARGET_PROCESS_WII_U_MENU
|
replacements[i].targetProcess != FP_TARGET_PROCESS_WII_U_MENU) {
|
||||||
) {
|
|
||||||
DEBUG_FUNCTION_LINE_VERBOSE("Its a dynamic function. We don't need to restore it!", replacements[i].function_name);
|
DEBUG_FUNCTION_LINE_VERBOSE("Its a dynamic function. We don't need to restore it!", replacements[i].function_name);
|
||||||
replacements[i].alreadyPatched = false;
|
replacements[i].alreadyPatched = false;
|
||||||
} else {
|
} else {
|
||||||
@ -223,7 +240,7 @@ void FunctionPatcherRestoreFunctions(function_replacement_data_t *replacements,
|
|||||||
sourceAddrPhys = sourceAddr + (0x30800000 - 0x00800000);
|
sourceAddrPhys = sourceAddr + (0x30800000 - 0x00800000);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(sourceAddrPhys == 0){
|
if (sourceAddrPhys == 0) {
|
||||||
OSFatal("Failed to get physical address");
|
OSFatal("Failed to get physical address");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -245,73 +262,72 @@ bool isDynamicFunction(uint32_t physicalAddress) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
rpl_handling rpl_handles[] __attribute__((section(".data"))) = {
|
rpl_handling rpl_handles[] __attribute__((section(".data"))) = {
|
||||||
{LIBRARY_AVM, "avm.rpl", nullptr},
|
{LIBRARY_AVM, "avm.rpl", nullptr},
|
||||||
{LIBRARY_CAMERA, "camera.rpl", nullptr},
|
{LIBRARY_CAMERA, "camera.rpl", nullptr},
|
||||||
{LIBRARY_COREINIT, "coreinit.rpl", nullptr},
|
{LIBRARY_COREINIT, "coreinit.rpl", nullptr},
|
||||||
{LIBRARY_DC, "dc.rpl", nullptr},
|
{LIBRARY_DC, "dc.rpl", nullptr},
|
||||||
{LIBRARY_DMAE, "dmae.rpl", nullptr},
|
{LIBRARY_DMAE, "dmae.rpl", nullptr},
|
||||||
{LIBRARY_DRMAPP, "drmapp.rpl", nullptr},
|
{LIBRARY_DRMAPP, "drmapp.rpl", nullptr},
|
||||||
{LIBRARY_ERREULA, "erreula.rpl", nullptr},
|
{LIBRARY_ERREULA, "erreula.rpl", nullptr},
|
||||||
{LIBRARY_GX2, "gx2.rpl", nullptr},
|
{LIBRARY_GX2, "gx2.rpl", nullptr},
|
||||||
{LIBRARY_H264, "h264.rpl", nullptr},
|
{LIBRARY_H264, "h264.rpl", nullptr},
|
||||||
{LIBRARY_LZMA920, "lzma920.rpl", nullptr},
|
{LIBRARY_LZMA920, "lzma920.rpl", nullptr},
|
||||||
{LIBRARY_MIC, "mic.rpl", nullptr},
|
{LIBRARY_MIC, "mic.rpl", nullptr},
|
||||||
{LIBRARY_NFC, "nfc.rpl", nullptr},
|
{LIBRARY_NFC, "nfc.rpl", nullptr},
|
||||||
{LIBRARY_NIO_PROF, "nio_prof.rpl", nullptr},
|
{LIBRARY_NIO_PROF, "nio_prof.rpl", nullptr},
|
||||||
{LIBRARY_NLIBCURL, "nlibcurl.rpl", nullptr},
|
{LIBRARY_NLIBCURL, "nlibcurl.rpl", nullptr},
|
||||||
{LIBRARY_NLIBNSS, "nlibnss.rpl", nullptr},
|
{LIBRARY_NLIBNSS, "nlibnss.rpl", nullptr},
|
||||||
{LIBRARY_NLIBNSS2, "nlibnss2.rpl", nullptr},
|
{LIBRARY_NLIBNSS2, "nlibnss2.rpl", nullptr},
|
||||||
{LIBRARY_NN_AC, "nn_ac.rpl", nullptr},
|
{LIBRARY_NN_AC, "nn_ac.rpl", nullptr},
|
||||||
{LIBRARY_NN_ACP, "nn_acp.rpl", nullptr},
|
{LIBRARY_NN_ACP, "nn_acp.rpl", nullptr},
|
||||||
{LIBRARY_NN_ACT, "nn_act.rpl", nullptr},
|
{LIBRARY_NN_ACT, "nn_act.rpl", nullptr},
|
||||||
{LIBRARY_NN_AOC, "nn_aoc.rpl", nullptr},
|
{LIBRARY_NN_AOC, "nn_aoc.rpl", nullptr},
|
||||||
{LIBRARY_NN_BOSS, "nn_boss.rpl", nullptr},
|
{LIBRARY_NN_BOSS, "nn_boss.rpl", nullptr},
|
||||||
{LIBRARY_NN_CCR, "nn_ccr.rpl", nullptr},
|
{LIBRARY_NN_CCR, "nn_ccr.rpl", nullptr},
|
||||||
{LIBRARY_NN_CMPT, "nn_cmpt.rpl", nullptr},
|
{LIBRARY_NN_CMPT, "nn_cmpt.rpl", nullptr},
|
||||||
{LIBRARY_NN_DLP, "nn_dlp.rpl", nullptr},
|
{LIBRARY_NN_DLP, "nn_dlp.rpl", nullptr},
|
||||||
{LIBRARY_NN_EC, "nn_ec.rpl", nullptr},
|
{LIBRARY_NN_EC, "nn_ec.rpl", nullptr},
|
||||||
{LIBRARY_NN_FP, "nn_fp.rpl", nullptr},
|
{LIBRARY_NN_FP, "nn_fp.rpl", nullptr},
|
||||||
{LIBRARY_NN_HAI, "nn_hai.rpl", nullptr},
|
{LIBRARY_NN_HAI, "nn_hai.rpl", nullptr},
|
||||||
{LIBRARY_NN_HPAD, "nn_hpad.rpl", nullptr},
|
{LIBRARY_NN_HPAD, "nn_hpad.rpl", nullptr},
|
||||||
{LIBRARY_NN_IDBE, "nn_idbe.rpl", nullptr},
|
{LIBRARY_NN_IDBE, "nn_idbe.rpl", nullptr},
|
||||||
{LIBRARY_NN_NDM, "nn_ndm.rpl", nullptr},
|
{LIBRARY_NN_NDM, "nn_ndm.rpl", nullptr},
|
||||||
{LIBRARY_NN_NETS2, "nn_nets2.rpl", nullptr},
|
{LIBRARY_NN_NETS2, "nn_nets2.rpl", nullptr},
|
||||||
{LIBRARY_NN_NFP, "nn_nfp.rpl", nullptr},
|
{LIBRARY_NN_NFP, "nn_nfp.rpl", nullptr},
|
||||||
{LIBRARY_NN_NIM, "nn_nim.rpl", nullptr},
|
{LIBRARY_NN_NIM, "nn_nim.rpl", nullptr},
|
||||||
{LIBRARY_NN_OLV, "nn_olv.rpl", nullptr},
|
{LIBRARY_NN_OLV, "nn_olv.rpl", nullptr},
|
||||||
{LIBRARY_NN_PDM, "nn_pdm.rpl", nullptr},
|
{LIBRARY_NN_PDM, "nn_pdm.rpl", nullptr},
|
||||||
{LIBRARY_NN_SAVE, "nn_save.rpl", nullptr},
|
{LIBRARY_NN_SAVE, "nn_save.rpl", nullptr},
|
||||||
{LIBRARY_NN_SL, "nn_sl.rpl", nullptr},
|
{LIBRARY_NN_SL, "nn_sl.rpl", nullptr},
|
||||||
{LIBRARY_NN_SPM, "nn_spm.rpl", nullptr},
|
{LIBRARY_NN_SPM, "nn_spm.rpl", nullptr},
|
||||||
{LIBRARY_NN_TEMP, "nn_temp.rpl", nullptr},
|
{LIBRARY_NN_TEMP, "nn_temp.rpl", nullptr},
|
||||||
{LIBRARY_NN_UDS, "nn_uds.rpl", nullptr},
|
{LIBRARY_NN_UDS, "nn_uds.rpl", nullptr},
|
||||||
{LIBRARY_NN_VCTL, "nn_vctl.rpl", nullptr},
|
{LIBRARY_NN_VCTL, "nn_vctl.rpl", nullptr},
|
||||||
{LIBRARY_NSYSCCR, "nsysccr.rpl", nullptr},
|
{LIBRARY_NSYSCCR, "nsysccr.rpl", nullptr},
|
||||||
{LIBRARY_NSYSHID, "nsyshid.rpl", nullptr},
|
{LIBRARY_NSYSHID, "nsyshid.rpl", nullptr},
|
||||||
{LIBRARY_NSYSKBD, "nsyskbd.rpl", nullptr},
|
{LIBRARY_NSYSKBD, "nsyskbd.rpl", nullptr},
|
||||||
{LIBRARY_NSYSNET, "nsysnet.rpl", nullptr},
|
{LIBRARY_NSYSNET, "nsysnet.rpl", nullptr},
|
||||||
{LIBRARY_NSYSUHS, "nsysuhs.rpl", nullptr},
|
{LIBRARY_NSYSUHS, "nsysuhs.rpl", nullptr},
|
||||||
{LIBRARY_NSYSUVD, "nsysuvd.rpl", nullptr},
|
{LIBRARY_NSYSUVD, "nsysuvd.rpl", nullptr},
|
||||||
{LIBRARY_NTAG, "ntag.rpl", nullptr},
|
{LIBRARY_NTAG, "ntag.rpl", nullptr},
|
||||||
{LIBRARY_PADSCORE, "padscore.rpl", nullptr},
|
{LIBRARY_PADSCORE, "padscore.rpl", nullptr},
|
||||||
{LIBRARY_PROC_UI, "proc_ui.rpl", nullptr},
|
{LIBRARY_PROC_UI, "proc_ui.rpl", nullptr},
|
||||||
{LIBRARY_SNDCORE2, "sndcore2.rpl", nullptr},
|
{LIBRARY_SNDCORE2, "sndcore2.rpl", nullptr},
|
||||||
{LIBRARY_SNDUSER2, "snduser2.rpl", nullptr},
|
{LIBRARY_SNDUSER2, "snduser2.rpl", nullptr},
|
||||||
{LIBRARY_SND_CORE, "snd_core.rpl", nullptr},
|
{LIBRARY_SND_CORE, "snd_core.rpl", nullptr},
|
||||||
{LIBRARY_SND_USER, "snd_user.rpl", nullptr},
|
{LIBRARY_SND_USER, "snd_user.rpl", nullptr},
|
||||||
{LIBRARY_SWKBD, "swkbd.rpl", nullptr},
|
{LIBRARY_SWKBD, "swkbd.rpl", nullptr},
|
||||||
{LIBRARY_SYSAPP, "sysapp.rpl", nullptr},
|
{LIBRARY_SYSAPP, "sysapp.rpl", nullptr},
|
||||||
{LIBRARY_TCL, "tcl.rpl", nullptr},
|
{LIBRARY_TCL, "tcl.rpl", nullptr},
|
||||||
{LIBRARY_TVE, "tve.rpl", nullptr},
|
{LIBRARY_TVE, "tve.rpl", nullptr},
|
||||||
{LIBRARY_UAC, "uac.rpl", nullptr},
|
{LIBRARY_UAC, "uac.rpl", nullptr},
|
||||||
{LIBRARY_UAC_RPL, "uac_rpl.rpl", nullptr},
|
{LIBRARY_UAC_RPL, "uac_rpl.rpl", nullptr},
|
||||||
{LIBRARY_USB_MIC, "usb_mic.rpl", nullptr},
|
{LIBRARY_USB_MIC, "usb_mic.rpl", nullptr},
|
||||||
{LIBRARY_UVC, "uvc.rpl", nullptr},
|
{LIBRARY_UVC, "uvc.rpl", nullptr},
|
||||||
{LIBRARY_UVD, "uvd.rpl", nullptr},
|
{LIBRARY_UVD, "uvd.rpl", nullptr},
|
||||||
{LIBRARY_VPAD, "vpad.rpl", nullptr},
|
{LIBRARY_VPAD, "vpad.rpl", nullptr},
|
||||||
{LIBRARY_VPADBASE, "vpadbase.rpl", nullptr},
|
{LIBRARY_VPADBASE, "vpadbase.rpl", nullptr},
|
||||||
{LIBRARY_ZLIB125, "zlib125.rpl", nullptr}
|
{LIBRARY_ZLIB125, "zlib125.rpl", nullptr}};
|
||||||
};
|
|
||||||
|
|
||||||
uint32_t getAddressOfFunction(char *functionName, function_replacement_library_type_t library) {
|
uint32_t getAddressOfFunction(char *functionName, function_replacement_library_type_t library) {
|
||||||
uint32_t real_addr = 0;
|
uint32_t real_addr = 0;
|
||||||
@ -349,13 +365,13 @@ uint32_t getAddressOfFunction(char *functionName, function_replacement_library_t
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((library == LIBRARY_NN_ACP) && (uint32_t)(*(volatile uint32_t *) (real_addr) & 0x48000002) == 0x48000000) {
|
if ((library == LIBRARY_NN_ACP) && (uint32_t) (*(volatile uint32_t *) (real_addr) &0x48000002) == 0x48000000) {
|
||||||
auto address_diff = (uint32_t)(*(volatile uint32_t *) (real_addr) & 0x03FFFFFC);
|
auto address_diff = (uint32_t) (*(volatile uint32_t *) (real_addr) &0x03FFFFFC);
|
||||||
if ((address_diff & 0x03000000) == 0x03000000) {
|
if ((address_diff & 0x03000000) == 0x03000000) {
|
||||||
address_diff |= 0xFC000000;
|
address_diff |= 0xFC000000;
|
||||||
}
|
}
|
||||||
real_addr += (int32_t) address_diff;
|
real_addr += (int32_t) address_diff;
|
||||||
if ((uint32_t)(*(volatile uint32_t *) (real_addr) & 0x48000002) == 0x48000000) {
|
if ((uint32_t) (*(volatile uint32_t *) (real_addr) &0x48000002) == 0x48000000) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <function_patcher/fpatching_defines.h>
|
|
||||||
#include <coreinit/dynload.h>
|
#include <coreinit/dynload.h>
|
||||||
|
#include <function_patcher/fpatching_defines.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <whb/log_udp.h>
|
|
||||||
#include <whb/log_cafe.h>
|
#include <whb/log_cafe.h>
|
||||||
#include <whb/log_module.h>
|
#include <whb/log_module.h>
|
||||||
|
#include <whb/log_udp.h>
|
||||||
|
|
||||||
uint32_t moduleLogInit = false;
|
uint32_t moduleLogInit = false;
|
||||||
uint32_t cafeLogInit = false;
|
uint32_t cafeLogInit = false;
|
||||||
uint32_t udpLogInit = false;
|
uint32_t udpLogInit = false;
|
||||||
#endif // DEBUG
|
#endif // DEBUG
|
||||||
|
|
||||||
void initLogging() {
|
void initLogging() {
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
if (!(moduleLogInit = WHBLogModuleInit())) {
|
if (!(moduleLogInit = WHBLogModuleInit())) {
|
||||||
cafeLogInit = WHBLogCafeInit();
|
cafeLogInit = WHBLogCafeInit();
|
||||||
udpLogInit = WHBLogUdpInit();
|
udpLogInit = WHBLogUdpInit();
|
||||||
}
|
}
|
||||||
#endif // DEBUG
|
#endif // DEBUG
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <whb/log.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <whb/log.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@ -9,26 +9,28 @@ extern "C" {
|
|||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
|
||||||
#define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
|
#define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
|
||||||
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__)
|
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__)
|
||||||
|
|
||||||
#define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while (0)
|
#define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while (0)
|
||||||
|
|
||||||
#define DEBUG_FUNCTION_LINE(FMT, ARGS...)do { \
|
#define DEBUG_FUNCTION_LINE(FMT, ARGS...) \
|
||||||
WHBLogPrintf("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
|
do { \
|
||||||
|
WHBLogPrintf("[%23s]%30s@L%04d: " FMT "", __FILENAME__, __FUNCTION__, __LINE__, ##ARGS); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...)do { \
|
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) \
|
||||||
WHBLogWritef("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
|
do { \
|
||||||
|
WHBLogWritef("[%23s]%30s@L%04d: " FMT "", __FILENAME__, __FUNCTION__, __LINE__, ##ARGS); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while (0)
|
#define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while (0)
|
||||||
|
|
||||||
#define DEBUG_FUNCTION_LINE(FMT, ARGS...) while (0)
|
#define DEBUG_FUNCTION_LINE(FMT, ARGS...) while (0)
|
||||||
|
|
||||||
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) while (0)
|
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) while (0)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -39,4 +41,3 @@ void deinitLogging();
|
|||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#include <wums.h>
|
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
#include <wums.h>
|
||||||
|
|
||||||
#include "function_patcher.h"
|
#include "function_patcher.h"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user