Format the code via clang-format

This commit is contained in:
Maschell 2022-02-03 20:53:38 +01:00
parent 2e5e3d1d2f
commit a8b4f7188b
10 changed files with 236 additions and 129 deletions

67
.clang-format Normal file
View 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

View File

@ -6,8 +6,16 @@ on:
- master
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:
runs-on: ubuntu-18.04
needs: clang-format
steps:
- uses: actions/checkout@v2
- name: build binary

View File

@ -3,8 +3,16 @@ name: CI-PR
on: [pull_request]
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:
runs-on: ubuntu-18.04
needs: clang-format
steps:
- uses: actions/checkout@v2
- name: build binary

View File

@ -18,3 +18,7 @@ docker run -it --rm -v ${PWD}:/project functionpatchermodule-builder make
# 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`

View File

@ -16,10 +16,10 @@
****************************************************************************/
#pragma once
#include <coreinit/thread.h>
#include <cstdint>
#include <malloc.h>
#include <unistd.h>
#include <cstdint>
#include <coreinit/thread.h>
class CThread {
public:
@ -36,7 +36,9 @@ public:
pThreadStack = (uint8_t *) memalign(0x20, iStackSize);
//! create the thread
if (pThread && pThreadStack) {
// clang-format off
OSCreateThread(pThread, (int(*)(int, const char **)) & CThread::threadCallback, 1, (char *) this, (void *) (pThreadStack + iStackSize), iStackSize, iPriority, iAttributes);
// clang-format on
}
}
@ -138,6 +140,7 @@ public:
eAttributeDetach = 0x08,
eAttributePinnedAff = 0x10
};
private:
static int32_t threadCallback(int32_t argc, void *arg) {
//! After call to start() continue with the internal function

View File

@ -1,11 +1,11 @@
#include <coreinit/dynload.h>
#include "function_patcher.h"
#include "CThread.h"
#include "logger.h"
#include <coreinit/cache.h>
#include <coreinit/debug.h>
#include <coreinit/dynload.h>
#include <coreinit/memorymap.h>
#include <kernel/kernel.h>
#include "function_patcher.h"
#include "logger.h"
#include "CThread.h"
void writeDataAndFlushIC(CThread *thread, void *arg) {
auto *data = (uint32_t *) arg;
@ -123,10 +123,14 @@ void FunctionPatcherPatchFunction(function_replacement_data_t *replacements, uin
00808d08 4e800420 bctr
*/
*space = 0x3d600000 | (((real_addr + 4) >> 16) & 0x0000FFFF); space++; // lis r11 ,0x1234
*space = 0x616b0000 | ((real_addr + 4) & 0x0000ffff); space++; // ori r11 ,r11 ,0x5678
*space = 0x7d6903a6; space++; // mtspr CTR ,r11
*space = 0x4e800420; space++; // bctr
*space = 0x3d600000 | (((real_addr + 4) >> 16) & 0x0000FFFF);
space++; // lis r11 ,0x1234
*space = 0x616b0000 | ((real_addr + 4) & 0x0000ffff);
space++; // ori r11 ,r11 ,0x5678
*space = 0x7d6903a6;
space++; // mtspr CTR ,r11
*space = 0x4e800420;
space++; // bctr
//setting jump back
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;
if (function_data->targetProcess != FP_TARGET_PROCESS_ALL) {
// Only use patched function if OSGetUPID matches function_data->targetProcess
*space = 0x3d600000 | (((uint32_t*) OSGetUPID)[0] & 0x0000FFFF); space++; // lis r11 ,0x0
*space = 0x816b0000 | (((uint32_t*) OSGetUPID)[1] & 0x0000FFFF); space++; // lwz r11 ,0x0(r11)
*space = 0x3d600000 | (((uint32_t *) OSGetUPID)[0] & 0x0000FFFF);
space++; // lis r11 ,0x0
*space = 0x816b0000 | (((uint32_t *) OSGetUPID)[1] & 0x0000FFFF);
space++; // lwz r11 ,0x0(r11)
if (function_data->targetProcess == FP_TARGET_PROCESS_GAME_AND_MENU) {
*space = 0x2c0b0000 | FP_TARGET_PROCESS_WII_U_MENU; 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
*space = 0x2c0b0000 | FP_TARGET_PROCESS_WII_U_MENU;
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 {
*space = 0x2c0b0000 | function_data->targetProcess; space++; // cmpwi r11 ,function_data->targetProcess
*space = 0x41820000 | 0x00000018; space++; // beq myfunc
*space = 0x2c0b0000 | function_data->targetProcess;
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 = 0x616b0000 | ((real_addr + 4) & 0x0000ffff); space++; // ori r11 ,(real_addr + 4)@lo
*space = 0x7d6903a6; space++; // mtspr CTR ,r11
*space = function_data->restoreInstruction; space++; //
*space = 0x4e800420; space++; // bctr
*space = 0x3d600000 | (((real_addr + 4) >> 16) & 0x0000FFFF);
space++; // lis r11 ,(real_addr + 4)@hi
*space = 0x616b0000 | ((real_addr + 4) & 0x0000ffff);
space++; // ori r11 ,(real_addr + 4)@lo
*space = 0x7d6903a6;
space++; // mtspr CTR ,r11
*space = function_data->restoreInstruction;
space++; //
*space = 0x4e800420;
space++; // bctr
}
// myfunc:
*space = 0x3d600000 | (((repl_addr) >> 16) & 0x0000FFFF); space++; // lis r11 ,repl_addr@hi
*space = 0x616b0000 | ((repl_addr) & 0x0000ffff); space++; // ori r11 ,r11 ,repl_addr@lo
*space = 0x7d6903a6; space++; // mtspr CTR ,r11
*space = 0x4e800420; space++; // bctr
*space = 0x3d600000 | (((repl_addr) >> 16) & 0x0000FFFF);
space++; // lis r11 ,repl_addr@hi
*space = 0x616b0000 | ((repl_addr) &0x0000ffff);
space++; // ori r11 ,r11 ,repl_addr@lo
*space = 0x7d6903a6;
space++; // mtspr CTR ,r11
*space = 0x4e800420;
space++; // bctr
// Make sure the trampoline itself is usable.
if ((repl_addr_test & 0x03FFFFFC) != repl_addr_test) {
@ -177,16 +198,13 @@ void FunctionPatcherPatchFunction(function_replacement_data_t *replacements, uin
uint32_t data[] = {
replace_instr,
physical,
real_addr
};
real_addr};
CThread::runOnAllCores(writeDataAndFlushIC, data);
function_data->alreadyPatched = 1;
DEBUG_FUNCTION_LINE_VERBOSE("done with patching %s!", function_data->function_name);
}
DEBUG_FUNCTION_LINE_VERBOSE("Done with patching given functions!");
}
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.
replacements[i].targetProcess != FP_TARGET_PROCESS_GAME_AND_MENU &&
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);
replacements[i].alreadyPatched = false;
} else {
@ -310,8 +327,7 @@ rpl_handling rpl_handles[] __attribute__((section(".data"))) = {
{LIBRARY_UVD, "uvd.rpl", nullptr},
{LIBRARY_VPAD, "vpad.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 real_addr = 0;

View File

@ -1,7 +1,7 @@
#pragma once
#include <function_patcher/fpatching_defines.h>
#include <coreinit/dynload.h>
#include <function_patcher/fpatching_defines.h>
#ifdef __cplusplus
extern "C" {

View File

@ -1,8 +1,8 @@
#ifdef DEBUG
#include <stdint.h>
#include <whb/log_udp.h>
#include <whb/log_cafe.h>
#include <whb/log_module.h>
#include <whb/log_udp.h>
uint32_t moduleLogInit = false;
uint32_t cafeLogInit = false;

View File

@ -1,7 +1,7 @@
#pragma once
#include <whb/log.h>
#include <string.h>
#include <whb/log.h>
#ifdef __cplusplus
extern "C" {
@ -14,11 +14,13 @@ extern "C" {
#define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while (0)
#define DEBUG_FUNCTION_LINE(FMT, ARGS...)do { \
#define DEBUG_FUNCTION_LINE(FMT, ARGS...) \
do { \
WHBLogPrintf("[%23s]%30s@L%04d: " FMT "", __FILENAME__, __FUNCTION__, __LINE__, ##ARGS); \
} while (0)
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...)do { \
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) \
do { \
WHBLogWritef("[%23s]%30s@L%04d: " FMT "", __FILENAME__, __FUNCTION__, __LINE__, ##ARGS); \
} while (0)
@ -39,4 +41,3 @@ void deinitLogging();
#ifdef __cplusplus
}
#endif

View File

@ -1,5 +1,5 @@
#include <wums.h>
#include "logger.h"
#include <wums.h>
#include "function_patcher.h"