From e5ead1af44a187083229d9261636cab0646c7003 Mon Sep 17 00:00:00 2001 From: Maschell Date: Wed, 2 Feb 2022 19:42:35 +0100 Subject: [PATCH] Format the code via clang-format (#1) --- .clang-format | 66 ++++++++++++++++++++++++++++ .github/workflows/ci.yml | 8 ++++ .github/workflows/pr.yml | 8 ++++ README.md | 5 +++ src/ElfUtils.cpp | 24 +++++----- src/ElfUtils.h | 5 ++- src/common/dynamic_linking_defines.h | 4 +- src/common/module_defines.h | 4 +- src/common/relocation_defines.h | 6 ++- src/dynamic.c | 13 +++--- src/elfio/elf_types.hpp | 1 + src/elfio/elfio.hpp | 1 + src/elfio/elfio_dump.hpp | 1 + src/elfio/elfio_dynamic.hpp | 1 + src/elfio/elfio_header.hpp | 1 + src/elfio/elfio_note.hpp | 1 + src/elfio/elfio_relocation.hpp | 1 + src/elfio/elfio_section.hpp | 1 + src/elfio/elfio_segment.hpp | 1 + src/elfio/elfio_strings.hpp | 1 + src/elfio/elfio_symbols.hpp | 1 + src/elfio/elfio_utils.hpp | 1 + src/kernel.cpp | 44 +++++++++---------- src/kernel.h | 10 ++--- src/main.cpp | 29 ++++++------ src/module/ImportRPLInformation.h | 4 +- src/module/ModuleData.cpp | 2 +- src/module/ModuleData.h | 2 +- src/module/ModuleDataFactory.cpp | 12 ++--- src/module/ModuleDataFactory.h | 8 ++-- src/module/RelocationData.h | 2 +- src/utils/StringTools.cpp | 19 ++++---- src/utils/StringTools.h | 2 +- src/utils/logger.c | 8 ++-- src/utils/logger.h | 13 +++--- 35 files changed, 210 insertions(+), 100 deletions(-) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..92399ef --- /dev/null +++ b/.clang-format @@ -0,0 +1,66 @@ +# Generated from CLion C/C++ Code Style settings +BasedOnStyle: LLVM +AccessModifierOffset: -4 +AlignAfterOpenBracket: Align +AlignConsecutiveAssignments: None +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: 0 +SpacesInAngles: false +SpacesInCStyleCastParentheses: false +SpacesInContainerLiterals: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +TabWidth: 4 +UseTab: Never diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 79638db..edd117e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 ./src build-binary: runs-on: ubuntu-18.04 + needs: clang-format steps: - uses: actions/checkout@v2 - name: build binary diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index e652ab1..31191bf 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -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 ./src build-binary: runs-on: ubuntu-18.04 + needs: clang-format steps: - uses: actions/checkout@v2 - name: build binary diff --git a/README.md b/README.md index 6aa4a5d..2d841d0 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ +[![CI-Release](https://github.com/wiiu-env/CustomRPXLoader/actions/workflows/ci.yml/badge.svg)](https://github.com/wiiu-env/CustomRPXLoader/actions/workflows/ci.yml) # CustomRPXLoader This custom loader for `.rpx` files which can be used with any `payload.elf` loader. (For example [PayloadFromRPX](https://github.com/wiiu-env/PayloadFromRPX) or [JsTypeHax](https://github.com/wiiu-env/JsTypeHax)) @@ -23,6 +24,10 @@ docker run -it --rm -v ${PWD}:/project customrpxloader-builder make docker run -it --rm -v ${PWD}:/project customrpxloader-builder make clean ``` +## Format the code via docker + +`docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./src -i` + ## Credits - Maschell - orboditilt diff --git a/src/ElfUtils.cpp b/src/ElfUtils.cpp index df99d17..6a47172 100644 --- a/src/ElfUtils.cpp +++ b/src/ElfUtils.cpp @@ -15,11 +15,11 @@ * along with this program. If not, see . ****************************************************************************/ -#include -#include -#include -#include "utils/logger.h" #include "ElfUtils.h" +#include "utils/logger.h" +#include +#include +#include // See https://github.com/decaf-emu/decaf-emu/blob/43366a34e7b55ab9d19b2444aeb0ccd46ac77dea/src/libdecaf/src/cafe/loader/cafe_loader_reloc.cpp#L144 bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t destination, uint32_t symbol_addr, relocation_trampolin_entry_t *trampolin_data, uint32_t trampolin_data_length, @@ -113,19 +113,19 @@ bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t des } if (freeSlot == nullptr) { DEBUG_FUNCTION_LINE("***24-bit relative branch cannot hit target. Trampolin data list is full"); - DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X", value, target, target - (uint32_t) &(freeSlot->trampolin[0])); + DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X", value, target, target - (uint32_t) & (freeSlot->trampolin[0])); return false; } - if (target - (uint32_t) &(freeSlot->trampolin[0]) > 0x1FFFFFC) { + if (target - (uint32_t) & (freeSlot->trampolin[0]) > 0x1FFFFFC) { DEBUG_FUNCTION_LINE("**Cannot link 24-bit jump (too far to tramp buffer)."); - DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X", value, target, (target - (uint32_t) &(freeSlot->trampolin[0]))); + DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X", value, target, (target - (uint32_t) & (freeSlot->trampolin[0]))); return false; } - freeSlot->trampolin[0] = 0x3D600000 | ((((uint32_t) value) >> 16) & 0x0000FFFF); // lis r11, real_addr@h - freeSlot->trampolin[1] = 0x616B0000 | (((uint32_t) value) & 0x0000ffff); // ori r11, r11, real_addr@l - freeSlot->trampolin[2] = 0x7D6903A6; // mtctr r11 - freeSlot->trampolin[3] = 0x4E800420; // bctr + freeSlot->trampolin[0] = 0x3D600000 | ((((uint32_t) value) >> 16) & 0x0000FFFF);// lis r11, real_addr@h + freeSlot->trampolin[1] = 0x616B0000 | (((uint32_t) value) & 0x0000ffff); // ori r11, r11, real_addr@l + freeSlot->trampolin[2] = 0x7D6903A6; // mtctr r11 + freeSlot->trampolin[3] = 0x4E800420; // bctr DCFlushRange((void *) freeSlot->trampolin, sizeof(freeSlot->trampolin)); ICInvalidateRange((unsigned char *) freeSlot->trampolin, sizeof(freeSlot->trampolin)); @@ -135,7 +135,7 @@ bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t des // Relocations for the imports may be overridden freeSlot->status = RELOC_TRAMP_IMPORT_DONE; } - auto symbolValue = (uint32_t) &(freeSlot->trampolin[0]); + auto symbolValue = (uint32_t) & (freeSlot->trampolin[0]); value = symbolValue + addend; distance = static_cast(value) - static_cast(target); } diff --git a/src/ElfUtils.h b/src/ElfUtils.h index 15e150f..df189ec 100644 --- a/src/ElfUtils.h +++ b/src/ElfUtils.h @@ -17,13 +17,15 @@ #pragma once -#include #include "common/relocation_defines.h" +#include +#include #ifdef __cplusplus extern "C" { #endif +// clang-format off #define R_PPC_NONE 0 #define R_PPC_ADDR32 1 #define R_PPC_ADDR16_LO 4 @@ -51,6 +53,7 @@ extern "C" { #define PPC_LOW24 0x03FFFFFC #define PPC_LOW14 0x0020FFFC #define PPC_HALF16 0xFFFF +// clang-format on #ifdef __cplusplus } diff --git a/src/common/dynamic_linking_defines.h b/src/common/dynamic_linking_defines.h index 7f5102e..9ef300f 100644 --- a/src/common/dynamic_linking_defines.h +++ b/src/common/dynamic_linking_defines.h @@ -17,13 +17,14 @@ #pragma once -#include #include +#include #ifdef __cplusplus extern "C" { #endif +// clang-format off #define DYN_LINK_FUNCTION_NAME_LENGTH 351 #define DYN_LINK_IMPORT_NAME_LENGTH 50 @@ -31,6 +32,7 @@ extern "C" { #define DYN_LINK_IMPORT_LIST_LENGTH 50 #define DYN_LINK_TRAMPOLIN_LIST_LENGTH DYN_LINK_FUNCTION_LIST_LENGTH +// clang-format on typedef struct _dyn_linking_function_t { char functionName[DYN_LINK_FUNCTION_NAME_LENGTH + 1]; diff --git a/src/common/module_defines.h b/src/common/module_defines.h index 2795c91..e7b684e 100644 --- a/src/common/module_defines.h +++ b/src/common/module_defines.h @@ -17,10 +17,10 @@ #pragma once -#include -#include #include "dynamic_linking_defines.h" #include "relocation_defines.h" +#include +#include #ifdef __cplusplus extern "C" { diff --git a/src/common/relocation_defines.h b/src/common/relocation_defines.h index 73c1256..c1e023e 100644 --- a/src/common/relocation_defines.h +++ b/src/common/relocation_defines.h @@ -19,17 +19,19 @@ #include -typedef enum RelocationTrampolinStatus{ +// clang-format off +typedef enum RelocationTrampolinStatus { RELOC_TRAMP_FREE = 0, RELOC_TRAMP_FIXED = 1, RELOC_TRAMP_IMPORT_IN_PROGRESS = 2, RELOC_TRAMP_IMPORT_DONE = 3, } RelocationTrampolinStatus; -typedef enum RelocationType{ +typedef enum RelocationType { RELOC_TYPE_FIXED = 0, RELOC_TYPE_IMPORT = 1 } RelocationType; +// clang-format on typedef struct relocation_trampolin_entry_t { uint32_t trampolin[4]; diff --git a/src/dynamic.c b/src/dynamic.c index 901352e..f06396f 100644 --- a/src/dynamic.c +++ b/src/dynamic.c @@ -1,7 +1,7 @@ -#include #include +#include -#define IMPORT(name) void* addr_##name +#define IMPORT(name) void *addr_##name #define IMPORT_BEGIN(lib) #define IMPORT_END() @@ -11,12 +11,15 @@ #undef IMPORT_BEGIN #undef IMPORT_END -#define IMPORT(name) do{if(OSDynLoad_FindExport(handle, 0, #name, &addr_##name) < 0)OSFatal("Function " # name " is NULL");} while(0) -#define IMPORT_BEGIN(lib) OSDynLoad_Acquire(#lib ".rpl", &handle) +#define IMPORT(name) \ + do { \ + if (OSDynLoad_FindExport(handle, 0, #name, &addr_##name) < 0) OSFatal("Function " #name " is NULL"); \ + } while (0) +#define IMPORT_BEGIN(lib) OSDynLoad_Acquire(#lib ".rpl", &handle) /* #define IMPORT_END() OSDynLoad_Release(handle) */ #define IMPORT_END() -#define EXPORT_VAR(type, var) type var __attribute__((section(".data"))); +#define EXPORT_VAR(type, var) type var __attribute__((section(".data"))); EXPORT_VAR(uint32_t *, MEMAllocFromDefaultHeap); EXPORT_VAR(uint32_t *, MEMAllocFromDefaultHeapEx); diff --git a/src/elfio/elf_types.hpp b/src/elfio/elf_types.hpp index 63d025a..9a20040 100644 --- a/src/elfio/elf_types.hpp +++ b/src/elfio/elf_types.hpp @@ -1,3 +1,4 @@ +// clang-format off /* Copyright (C) 2001-2015 by Serge Lamikhov-Center diff --git a/src/elfio/elfio.hpp b/src/elfio/elfio.hpp index f997b5d..5381935 100644 --- a/src/elfio/elfio.hpp +++ b/src/elfio/elfio.hpp @@ -1,3 +1,4 @@ +// clang-format off /* Copyright (C) 2001-2015 by Serge Lamikhov-Center diff --git a/src/elfio/elfio_dump.hpp b/src/elfio/elfio_dump.hpp index 4ace665..015cff2 100644 --- a/src/elfio/elfio_dump.hpp +++ b/src/elfio/elfio_dump.hpp @@ -1,3 +1,4 @@ +// clang-format off /* Copyright (C) 2001-2015 by Serge Lamikhov-Center diff --git a/src/elfio/elfio_dynamic.hpp b/src/elfio/elfio_dynamic.hpp index 42f2680..36de384 100644 --- a/src/elfio/elfio_dynamic.hpp +++ b/src/elfio/elfio_dynamic.hpp @@ -1,3 +1,4 @@ +// clang-format off /* Copyright (C) 2001-2015 by Serge Lamikhov-Center diff --git a/src/elfio/elfio_header.hpp b/src/elfio/elfio_header.hpp index 6f8da02..e7b9a24 100644 --- a/src/elfio/elfio_header.hpp +++ b/src/elfio/elfio_header.hpp @@ -1,3 +1,4 @@ +// clang-format off /* Copyright (C) 2001-2015 by Serge Lamikhov-Center diff --git a/src/elfio/elfio_note.hpp b/src/elfio/elfio_note.hpp index 8619c73..fbfc51c 100644 --- a/src/elfio/elfio_note.hpp +++ b/src/elfio/elfio_note.hpp @@ -1,3 +1,4 @@ +// clang-format off /* Copyright (C) 2001-2015 by Serge Lamikhov-Center diff --git a/src/elfio/elfio_relocation.hpp b/src/elfio/elfio_relocation.hpp index 4a3fab0..641031a 100644 --- a/src/elfio/elfio_relocation.hpp +++ b/src/elfio/elfio_relocation.hpp @@ -1,3 +1,4 @@ +// clang-format off /* Copyright (C) 2001-2015 by Serge Lamikhov-Center diff --git a/src/elfio/elfio_section.hpp b/src/elfio/elfio_section.hpp index ceb15be..6e6b136 100644 --- a/src/elfio/elfio_section.hpp +++ b/src/elfio/elfio_section.hpp @@ -1,3 +1,4 @@ +// clang-format off /* Copyright (C) 2001-2015 by Serge Lamikhov-Center diff --git a/src/elfio/elfio_segment.hpp b/src/elfio/elfio_segment.hpp index 638da11..eb7cf21 100644 --- a/src/elfio/elfio_segment.hpp +++ b/src/elfio/elfio_segment.hpp @@ -1,3 +1,4 @@ +// clang-format off /* Copyright (C) 2001-2015 by Serge Lamikhov-Center diff --git a/src/elfio/elfio_strings.hpp b/src/elfio/elfio_strings.hpp index 552f000..5fc9bb1 100644 --- a/src/elfio/elfio_strings.hpp +++ b/src/elfio/elfio_strings.hpp @@ -1,3 +1,4 @@ +// clang-format off /* Copyright (C) 2001-2015 by Serge Lamikhov-Center diff --git a/src/elfio/elfio_symbols.hpp b/src/elfio/elfio_symbols.hpp index d18756a..6205bd2 100644 --- a/src/elfio/elfio_symbols.hpp +++ b/src/elfio/elfio_symbols.hpp @@ -1,3 +1,4 @@ +// clang-format off /* Copyright (C) 2001-2015 by Serge Lamikhov-Center diff --git a/src/elfio/elfio_utils.hpp b/src/elfio/elfio_utils.hpp index 2baf5a7..e567d41 100644 --- a/src/elfio/elfio_utils.hpp +++ b/src/elfio/elfio_utils.hpp @@ -1,3 +1,4 @@ +// clang-format off /* Copyright (C) 2001-2015 by Serge Lamikhov-Center diff --git a/src/kernel.cpp b/src/kernel.cpp index abce1eb..d047e6f 100644 --- a/src/kernel.cpp +++ b/src/kernel.cpp @@ -15,11 +15,11 @@ * along with this program. If not, see . ****************************************************************************/ +#include +#include #include #include #include -#include -#include #include "kernel.h" @@ -29,7 +29,7 @@ extern "C" void KernelPatches(void); extern "C" void KernelPatchesFinal(void); extern "C" void SaveAndResetDataBATs_And_SRs_hook(void); -void __attribute__ ((noinline)) kern_write(void *addr, uint32_t value); +void __attribute__((noinline)) kern_write(void *addr, uint32_t value); extern "C" void SC_0x25_KernelCopyData(unsigned int addr, unsigned int src, unsigned int len); @@ -80,27 +80,25 @@ void doKernelSetup2() { kern_write((void *) (KERN_SYSCALL_TBL_3 + (0x25 * 4)), (unsigned int) SCKernelCopyData); kern_write((void *) (KERN_SYSCALL_TBL_4 + (0x25 * 4)), (unsigned int) SCKernelCopyData); kern_write((void *) (KERN_SYSCALL_TBL_5 + (0x25 * 4)), (unsigned int) SCKernelCopyData); - } /* Write a 32-bit word with kernel permissions */ -void __attribute__ ((noinline)) kern_write(void *addr, uint32_t value) { - asm volatile ( - "li 3,1\n" - "li 4,0\n" - "mr 5,%1\n" - "li 6,0\n" - "li 7,0\n" - "lis 8,1\n" - "mr 9,%0\n" - "mr %1,1\n" - "li 0,0x3500\n" - "sc\n" - "nop\n" - "mr 1,%1\n" - : - : "r"(addr), "r"(value) - : "memory", "ctr", "lr", "0", "3", "4", "5", "6", "7", "8", "9", "10", - "11", "12" - ); +void __attribute__((noinline)) kern_write(void *addr, uint32_t value) { + asm volatile( + "li 3,1\n" + "li 4,0\n" + "mr 5,%1\n" + "li 6,0\n" + "li 7,0\n" + "lis 8,1\n" + "mr 9,%0\n" + "mr %1,1\n" + "li 0,0x3500\n" + "sc\n" + "nop\n" + "mr 1,%1\n" + : + : "r"(addr), "r"(value) + : "memory", "ctr", "lr", "0", "3", "4", "5", "6", "7", "8", "9", "10", + "11", "12"); } diff --git a/src/kernel.h b/src/kernel.h index 000baeb..4a16725 100644 --- a/src/kernel.h +++ b/src/kernel.h @@ -17,11 +17,11 @@ #pragma once -#define KERN_SYSCALL_TBL_1 0xFFE84C70 // unknown -#define KERN_SYSCALL_TBL_2 0xFFE85070 // works with games -#define KERN_SYSCALL_TBL_3 0xFFE85470 // works with loader -#define KERN_SYSCALL_TBL_4 0xFFEAAA60 // works with home menu -#define KERN_SYSCALL_TBL_5 0xFFEAAE60 // works with browser (previously KERN_SYSCALL_TBL) +#define KERN_SYSCALL_TBL_1 0xFFE84C70// unknown +#define KERN_SYSCALL_TBL_2 0xFFE85070// works with games +#define KERN_SYSCALL_TBL_3 0xFFE85470// works with loader +#define KERN_SYSCALL_TBL_4 0xFFEAAA60// works with home menu +#define KERN_SYSCALL_TBL_5 0xFFEAAE60// works with browser (previously KERN_SYSCALL_TBL) #ifdef __cplusplus extern "C" { diff --git a/src/main.cpp b/src/main.cpp index 793d6e7..7cd1735 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -15,29 +15,29 @@ * along with this program. If not, see . ****************************************************************************/ -#include #include #include -#include -#include -#include #include #include +#include +#include #include +#include +#include #include "ElfUtils.h" +#include "common/module_defines.h" #include "module/ModuleData.h" #include "module/ModuleDataFactory.h" -#include "common/module_defines.h" #include -#include "kernel.h" #include "dynamic.h" +#include "kernel.h" #include "utils/logger.h" -#include -#include #include +#include +#include bool doRelocation(const std::vector &relocData, relocation_trampolin_entry_t *tramp_data, uint32_t tramp_length); @@ -67,7 +67,7 @@ bool CheckRunning() { extern "C" void __init_wut(); extern "C" void __fini_wut(); -extern "C" int _start(int argc, char **argv) __attribute__ ((section (".start_code"))); +extern "C" int _start(int argc, char **argv) __attribute__((section(".start_code"))); extern "C" int _start(int argc, char **argv) { doKernelSetup(); InitFunctionPointers(); @@ -95,7 +95,7 @@ extern "C" int _start(int argc, char **argv) { if (memory_end == memory_start) { break; } - auto mem_ptr = &memory_end[1]; // &memory_end + sizeof(MEMExpHeapBlock); + auto mem_ptr = &memory_end[1];// &memory_end + sizeof(MEMExpHeapBlock); free(mem_ptr); leak_count++; } @@ -105,7 +105,9 @@ extern "C" int _start(int argc, char **argv) { __fini_wut(); if (entrypoint > 0) { - return ((int (*)(int, char **)) entrypoint)(argc, argv); + // clang-format off + return ((int(*)(int, char **)) entrypoint)(argc, argv); + // clang-format on } return -1; @@ -121,7 +123,8 @@ uint32_t do_start(int argc, char **argv) { uint32_t ApplicationMemoryEnd; - asm volatile("lis %0, __CODE_END@h; ori %0, %0, __CODE_END@l" : "=r" (ApplicationMemoryEnd)); + asm volatile("lis %0, __CODE_END@h; ori %0, %0, __CODE_END@l" + : "=r"(ApplicationMemoryEnd)); ApplicationMemoryEnd = (ApplicationMemoryEnd + 0x100) & 0xFFFFFF00; @@ -185,7 +188,7 @@ uint32_t do_start(int argc, char **argv) { } bool doRelocation(const std::vector &relocData, relocation_trampolin_entry_t *tramp_data, uint32_t tramp_length) { - for (auto const &curReloc: relocData) { + for (auto const &curReloc : relocData) { const RelocationData &cur = curReloc; std::string functionName = cur.getName(); std::string rplName = cur.getImportRPLInformation().getName(); diff --git a/src/module/ImportRPLInformation.h b/src/module/ImportRPLInformation.h index bb3926f..98113da 100644 --- a/src/module/ImportRPLInformation.h +++ b/src/module/ImportRPLInformation.h @@ -17,9 +17,9 @@ #pragma once -#include -#include #include "utils/logger.h" +#include +#include class ImportRPLInformation { diff --git a/src/module/ModuleData.cpp b/src/module/ModuleData.cpp index 2888eb6..78bba7a 100644 --- a/src/module/ModuleData.cpp +++ b/src/module/ModuleData.cpp @@ -20,7 +20,7 @@ std::string ModuleData::toString() const { std::string res = StringTools::strfmt("Entrypoint %08X, bss: %08X (%d), bss: %08X (%d)\n", getEntrypoint(), getBSSAddr(), getBSSSize(), getSBSSAddr(), getSBSSSize()); - for (auto const &reloc: relocation_data_list) { + for (auto const &reloc : relocation_data_list) { res += reloc.toString(); } return res; diff --git a/src/module/ModuleData.h b/src/module/ModuleData.h index 002b01f..3aed9e8 100644 --- a/src/module/ModuleData.h +++ b/src/module/ModuleData.h @@ -17,9 +17,9 @@ #pragma once +#include "RelocationData.h" #include #include -#include "RelocationData.h" class ModuleData { public: diff --git a/src/module/ModuleDataFactory.cpp b/src/module/ModuleDataFactory.cpp index 4bca77b..7f3d79e 100644 --- a/src/module/ModuleDataFactory.cpp +++ b/src/module/ModuleDataFactory.cpp @@ -15,13 +15,13 @@ * along with this program. If not, see . ****************************************************************************/ +#include "ModuleDataFactory.h" +#include "../ElfUtils.h" +#include "elfio/elfio.hpp" +#include +#include #include #include -#include -#include -#include "ModuleDataFactory.h" -#include "elfio/elfio.hpp" -#include "../ElfUtils.h" using namespace ELFIO; @@ -136,7 +136,7 @@ ModuleDataFactory::load(const std::string &path, uint32_t destination_address, u } std::vector relocationData = getImportRelocationData(reader, destinations); - for (auto const &reloc: relocationData) { + for (auto const &reloc : relocationData) { moduleData.addRelocationData(reloc); } diff --git a/src/module/ModuleDataFactory.h b/src/module/ModuleDataFactory.h index ec74202..e18dcb5 100644 --- a/src/module/ModuleDataFactory.h +++ b/src/module/ModuleDataFactory.h @@ -17,12 +17,12 @@ #pragma once +#include "ModuleData.h" +#include "common/relocation_defines.h" +#include "elfio/elfio.hpp" +#include #include #include -#include -#include "common/relocation_defines.h" -#include "ModuleData.h" -#include "elfio/elfio.hpp" class ModuleDataFactory { public: diff --git a/src/module/RelocationData.h b/src/module/RelocationData.h index e8f2012..37ea010 100644 --- a/src/module/RelocationData.h +++ b/src/module/RelocationData.h @@ -17,8 +17,8 @@ #pragma once -#include #include "ImportRPLInformation.h" +#include class RelocationData { diff --git a/src/utils/StringTools.cpp b/src/utils/StringTools.cpp index c60227e..faaa523 100644 --- a/src/utils/StringTools.cpp +++ b/src/utils/StringTools.cpp @@ -23,17 +23,16 @@ * * for WiiXplorer 2010 ***************************************************************************/ -#include -#include -#include #include +#include #include -#include -#include +#include +#include #include -#include -#include #include +#include +#include +#include BOOL StringTools::EndsWith(const std::string &a, const std::string &b) { @@ -259,7 +258,7 @@ char *StringTools::str_replace(char *orig, char *rep, char *with) { char *tmp; // varies int len_rep; // length of rep (the string to remove) int len_with; // length of with (the string to replace rep with) - int len_front; // distance between rep and end of last rep + int len_front;// distance between rep and end of last rep int count; // number of replacements // sanity checks and initialization @@ -269,7 +268,7 @@ char *StringTools::str_replace(char *orig, char *rep, char *with) { len_rep = strlen(rep); if (len_rep == 0) { return NULL; - } // empty rep causes infinite loop during count + }// empty rep causes infinite loop during count if (!with) { with = (char *) ""; } @@ -297,7 +296,7 @@ char *StringTools::str_replace(char *orig, char *rep, char *with) { len_front = ins - orig; tmp = strncpy(tmp, orig, len_front) + len_front; tmp = strcpy(tmp, with) + len_with; - orig += len_front + len_rep; // move to next "end of rep" + orig += len_front + len_rep;// move to next "end of rep" } strcpy(tmp, orig); return result; diff --git a/src/utils/StringTools.h b/src/utils/StringTools.h index 6c53f0d..9285f8e 100644 --- a/src/utils/StringTools.h +++ b/src/utils/StringTools.h @@ -25,8 +25,8 @@ ***************************************************************************/ #pragma once -#include #include +#include #include class StringTools { diff --git a/src/utils/logger.c b/src/utils/logger.c index 0411db7..0ed05e6 100644 --- a/src/utils/logger.c +++ b/src/utils/logger.c @@ -1,13 +1,13 @@ #ifdef DEBUG #include -#include #include #include +#include uint32_t moduleLogInit = false; uint32_t cafeLogInit = false; uint32_t udpLogInit = false; -#endif // DEBUG +#endif// DEBUG void initLogging() { #ifdef DEBUG @@ -15,7 +15,7 @@ void initLogging() { cafeLogInit = WHBLogCafeInit(); udpLogInit = WHBLogUdpInit(); } -#endif // DEBUG +#endif// DEBUG } void deinitLogging() { @@ -32,5 +32,5 @@ void deinitLogging() { WHBLogUdpDeinit(); udpLogInit = false; } -#endif // DEBUG +#endif// DEBUG } \ No newline at end of file diff --git a/src/utils/logger.h b/src/utils/logger.h index 6ff5ae2..2321b2b 100644 --- a/src/utils/logger.h +++ b/src/utils/logger.h @@ -1,7 +1,7 @@ #pragma once -#include #include +#include #ifdef __cplusplus extern "C" { @@ -14,12 +14,14 @@ extern "C" { #define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while (0) -#define DEBUG_FUNCTION_LINE(FMT, ARGS...)do { \ - WHBLogPrintf("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \ +#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 { \ - WHBLogWritef("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \ +#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) \ + do { \ + WHBLogWritef("[%23s]%30s@L%04d: " FMT "", __FILENAME__, __FUNCTION__, __LINE__, ##ARGS); \ } while (0) #else @@ -39,4 +41,3 @@ void deinitLogging(); #ifdef __cplusplus } #endif -