mirror of
https://github.com/wiiu-env/CustomRPXLoader.git
synced 2024-11-22 01:49:16 +01:00
Format the code via clang-format (#1)
This commit is contained in:
parent
4e29e33931
commit
e5ead1af44
66
.clang-format
Normal file
66
.clang-format
Normal file
@ -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
|
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 ./src
|
||||||
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 ./src
|
||||||
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
|
||||||
|
@ -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
|
# 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))
|
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
|
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
|
## Credits
|
||||||
- Maschell
|
- Maschell
|
||||||
- orboditilt
|
- orboditilt
|
||||||
|
@ -15,11 +15,11 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <cstring>
|
|
||||||
#include <coreinit/cache.h>
|
|
||||||
#include <whb/log.h>
|
|
||||||
#include "utils/logger.h"
|
|
||||||
#include "ElfUtils.h"
|
#include "ElfUtils.h"
|
||||||
|
#include "utils/logger.h"
|
||||||
|
#include <coreinit/cache.h>
|
||||||
|
#include <cstring>
|
||||||
|
#include <whb/log.h>
|
||||||
|
|
||||||
// See https://github.com/decaf-emu/decaf-emu/blob/43366a34e7b55ab9d19b2444aeb0ccd46ac77dea/src/libdecaf/src/cafe/loader/cafe_loader_reloc.cpp#L144
|
// 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,
|
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) {
|
if (freeSlot == nullptr) {
|
||||||
DEBUG_FUNCTION_LINE("***24-bit relative branch cannot hit target. Trampolin data list is full");
|
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;
|
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("**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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
freeSlot->trampolin[0] = 0x3D600000 | ((((uint32_t) value) >> 16) & 0x0000FFFF); // lis r11, real_addr@h
|
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[1] = 0x616B0000 | (((uint32_t) value) & 0x0000ffff); // ori r11, r11, real_addr@l
|
||||||
freeSlot->trampolin[2] = 0x7D6903A6; // mtctr r11
|
freeSlot->trampolin[2] = 0x7D6903A6; // mtctr r11
|
||||||
freeSlot->trampolin[3] = 0x4E800420; // bctr
|
freeSlot->trampolin[3] = 0x4E800420; // bctr
|
||||||
DCFlushRange((void *) freeSlot->trampolin, sizeof(freeSlot->trampolin));
|
DCFlushRange((void *) freeSlot->trampolin, sizeof(freeSlot->trampolin));
|
||||||
ICInvalidateRange((unsigned char *) 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
|
// Relocations for the imports may be overridden
|
||||||
freeSlot->status = RELOC_TRAMP_IMPORT_DONE;
|
freeSlot->status = RELOC_TRAMP_IMPORT_DONE;
|
||||||
}
|
}
|
||||||
auto symbolValue = (uint32_t) &(freeSlot->trampolin[0]);
|
auto symbolValue = (uint32_t) & (freeSlot->trampolin[0]);
|
||||||
value = symbolValue + addend;
|
value = symbolValue + addend;
|
||||||
distance = static_cast<int32_t>(value) - static_cast<int32_t>(target);
|
distance = static_cast<int32_t>(value) - static_cast<int32_t>(target);
|
||||||
}
|
}
|
||||||
|
@ -17,13 +17,15 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
#include "common/relocation_defines.h"
|
#include "common/relocation_defines.h"
|
||||||
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
#define R_PPC_NONE 0
|
#define R_PPC_NONE 0
|
||||||
#define R_PPC_ADDR32 1
|
#define R_PPC_ADDR32 1
|
||||||
#define R_PPC_ADDR16_LO 4
|
#define R_PPC_ADDR16_LO 4
|
||||||
@ -51,6 +53,7 @@ extern "C" {
|
|||||||
#define PPC_LOW24 0x03FFFFFC
|
#define PPC_LOW24 0x03FFFFFC
|
||||||
#define PPC_LOW14 0x0020FFFC
|
#define PPC_LOW14 0x0020FFFC
|
||||||
#define PPC_HALF16 0xFFFF
|
#define PPC_HALF16 0xFFFF
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -17,13 +17,14 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
#define DYN_LINK_FUNCTION_NAME_LENGTH 351
|
#define DYN_LINK_FUNCTION_NAME_LENGTH 351
|
||||||
#define DYN_LINK_IMPORT_NAME_LENGTH 50
|
#define DYN_LINK_IMPORT_NAME_LENGTH 50
|
||||||
|
|
||||||
@ -31,6 +32,7 @@ extern "C" {
|
|||||||
#define DYN_LINK_IMPORT_LIST_LENGTH 50
|
#define DYN_LINK_IMPORT_LIST_LENGTH 50
|
||||||
|
|
||||||
#define DYN_LINK_TRAMPOLIN_LIST_LENGTH DYN_LINK_FUNCTION_LIST_LENGTH
|
#define DYN_LINK_TRAMPOLIN_LIST_LENGTH DYN_LINK_FUNCTION_LIST_LENGTH
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
typedef struct _dyn_linking_function_t {
|
typedef struct _dyn_linking_function_t {
|
||||||
char functionName[DYN_LINK_FUNCTION_NAME_LENGTH + 1];
|
char functionName[DYN_LINK_FUNCTION_NAME_LENGTH + 1];
|
||||||
|
@ -17,10 +17,10 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
#include <cstddef>
|
|
||||||
#include "dynamic_linking_defines.h"
|
#include "dynamic_linking_defines.h"
|
||||||
#include "relocation_defines.h"
|
#include "relocation_defines.h"
|
||||||
|
#include <cstddef>
|
||||||
|
#include <cstdint>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -19,17 +19,19 @@
|
|||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
typedef enum RelocationTrampolinStatus{
|
// clang-format off
|
||||||
|
typedef enum RelocationTrampolinStatus {
|
||||||
RELOC_TRAMP_FREE = 0,
|
RELOC_TRAMP_FREE = 0,
|
||||||
RELOC_TRAMP_FIXED = 1,
|
RELOC_TRAMP_FIXED = 1,
|
||||||
RELOC_TRAMP_IMPORT_IN_PROGRESS = 2,
|
RELOC_TRAMP_IMPORT_IN_PROGRESS = 2,
|
||||||
RELOC_TRAMP_IMPORT_DONE = 3,
|
RELOC_TRAMP_IMPORT_DONE = 3,
|
||||||
} RelocationTrampolinStatus;
|
} RelocationTrampolinStatus;
|
||||||
|
|
||||||
typedef enum RelocationType{
|
typedef enum RelocationType {
|
||||||
RELOC_TYPE_FIXED = 0,
|
RELOC_TYPE_FIXED = 0,
|
||||||
RELOC_TYPE_IMPORT = 1
|
RELOC_TYPE_IMPORT = 1
|
||||||
} RelocationType;
|
} RelocationType;
|
||||||
|
// clang-format on
|
||||||
|
|
||||||
typedef struct relocation_trampolin_entry_t {
|
typedef struct relocation_trampolin_entry_t {
|
||||||
uint32_t trampolin[4];
|
uint32_t trampolin[4];
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#include <coreinit/dynload.h>
|
|
||||||
#include <coreinit/debug.h>
|
#include <coreinit/debug.h>
|
||||||
|
#include <coreinit/dynload.h>
|
||||||
|
|
||||||
#define IMPORT(name) void* addr_##name
|
#define IMPORT(name) void *addr_##name
|
||||||
#define IMPORT_BEGIN(lib)
|
#define IMPORT_BEGIN(lib)
|
||||||
#define IMPORT_END()
|
#define IMPORT_END()
|
||||||
|
|
||||||
@ -11,12 +11,15 @@
|
|||||||
#undef IMPORT_BEGIN
|
#undef IMPORT_BEGIN
|
||||||
#undef IMPORT_END
|
#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(name) \
|
||||||
#define IMPORT_BEGIN(lib) OSDynLoad_Acquire(#lib ".rpl", &handle)
|
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() OSDynLoad_Release(handle) */
|
||||||
#define IMPORT_END()
|
#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 *, MEMAllocFromDefaultHeap);
|
||||||
EXPORT_VAR(uint32_t *, MEMAllocFromDefaultHeapEx);
|
EXPORT_VAR(uint32_t *, MEMAllocFromDefaultHeapEx);
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
// clang-format off
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2001-2015 by Serge Lamikhov-Center
|
Copyright (C) 2001-2015 by Serge Lamikhov-Center
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
// clang-format off
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2001-2015 by Serge Lamikhov-Center
|
Copyright (C) 2001-2015 by Serge Lamikhov-Center
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
// clang-format off
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2001-2015 by Serge Lamikhov-Center
|
Copyright (C) 2001-2015 by Serge Lamikhov-Center
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
// clang-format off
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2001-2015 by Serge Lamikhov-Center
|
Copyright (C) 2001-2015 by Serge Lamikhov-Center
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
// clang-format off
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2001-2015 by Serge Lamikhov-Center
|
Copyright (C) 2001-2015 by Serge Lamikhov-Center
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
// clang-format off
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2001-2015 by Serge Lamikhov-Center
|
Copyright (C) 2001-2015 by Serge Lamikhov-Center
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
// clang-format off
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2001-2015 by Serge Lamikhov-Center
|
Copyright (C) 2001-2015 by Serge Lamikhov-Center
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
// clang-format off
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2001-2015 by Serge Lamikhov-Center
|
Copyright (C) 2001-2015 by Serge Lamikhov-Center
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
// clang-format off
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2001-2015 by Serge Lamikhov-Center
|
Copyright (C) 2001-2015 by Serge Lamikhov-Center
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
// clang-format off
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2001-2015 by Serge Lamikhov-Center
|
Copyright (C) 2001-2015 by Serge Lamikhov-Center
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
// clang-format off
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2001-2015 by Serge Lamikhov-Center
|
Copyright (C) 2001-2015 by Serge Lamikhov-Center
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
// clang-format off
|
||||||
/*
|
/*
|
||||||
Copyright (C) 2001-2015 by Serge Lamikhov-Center
|
Copyright (C) 2001-2015 by Serge Lamikhov-Center
|
||||||
|
|
||||||
|
@ -15,11 +15,11 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <coreinit/cache.h>
|
||||||
|
#include <coreinit/memorymap.h>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <coreinit/cache.h>
|
|
||||||
#include <coreinit/memorymap.h>
|
|
||||||
|
|
||||||
#include "kernel.h"
|
#include "kernel.h"
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ extern "C" void KernelPatches(void);
|
|||||||
extern "C" void KernelPatchesFinal(void);
|
extern "C" void KernelPatchesFinal(void);
|
||||||
extern "C" void SaveAndResetDataBATs_And_SRs_hook(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);
|
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_3 + (0x25 * 4)), (unsigned int) SCKernelCopyData);
|
||||||
kern_write((void *) (KERN_SYSCALL_TBL_4 + (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);
|
kern_write((void *) (KERN_SYSCALL_TBL_5 + (0x25 * 4)), (unsigned int) SCKernelCopyData);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Write a 32-bit word with kernel permissions */
|
/* Write a 32-bit word with kernel permissions */
|
||||||
void __attribute__ ((noinline)) kern_write(void *addr, uint32_t value) {
|
void __attribute__((noinline)) kern_write(void *addr, uint32_t value) {
|
||||||
asm volatile (
|
asm volatile(
|
||||||
"li 3,1\n"
|
"li 3,1\n"
|
||||||
"li 4,0\n"
|
"li 4,0\n"
|
||||||
"mr 5,%1\n"
|
"mr 5,%1\n"
|
||||||
"li 6,0\n"
|
"li 6,0\n"
|
||||||
"li 7,0\n"
|
"li 7,0\n"
|
||||||
"lis 8,1\n"
|
"lis 8,1\n"
|
||||||
"mr 9,%0\n"
|
"mr 9,%0\n"
|
||||||
"mr %1,1\n"
|
"mr %1,1\n"
|
||||||
"li 0,0x3500\n"
|
"li 0,0x3500\n"
|
||||||
"sc\n"
|
"sc\n"
|
||||||
"nop\n"
|
"nop\n"
|
||||||
"mr 1,%1\n"
|
"mr 1,%1\n"
|
||||||
:
|
:
|
||||||
: "r"(addr), "r"(value)
|
: "r"(addr), "r"(value)
|
||||||
: "memory", "ctr", "lr", "0", "3", "4", "5", "6", "7", "8", "9", "10",
|
: "memory", "ctr", "lr", "0", "3", "4", "5", "6", "7", "8", "9", "10",
|
||||||
"11", "12"
|
"11", "12");
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
10
src/kernel.h
10
src/kernel.h
@ -17,11 +17,11 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define KERN_SYSCALL_TBL_1 0xFFE84C70 // unknown
|
#define KERN_SYSCALL_TBL_1 0xFFE84C70// unknown
|
||||||
#define KERN_SYSCALL_TBL_2 0xFFE85070 // works with games
|
#define KERN_SYSCALL_TBL_2 0xFFE85070// works with games
|
||||||
#define KERN_SYSCALL_TBL_3 0xFFE85470 // works with loader
|
#define KERN_SYSCALL_TBL_3 0xFFE85470// works with loader
|
||||||
#define KERN_SYSCALL_TBL_4 0xFFEAAA60 // works with home menu
|
#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_5 0xFFEAAE60// works with browser (previously KERN_SYSCALL_TBL)
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
29
src/main.cpp
29
src/main.cpp
@ -15,29 +15,29 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
#include <coreinit/cache.h>
|
#include <coreinit/cache.h>
|
||||||
#include <coreinit/dynload.h>
|
#include <coreinit/dynload.h>
|
||||||
#include <coreinit/title.h>
|
|
||||||
#include <sysapp/launch.h>
|
|
||||||
#include <proc_ui/procui.h>
|
|
||||||
#include <coreinit/foreground.h>
|
#include <coreinit/foreground.h>
|
||||||
#include <coreinit/screen.h>
|
#include <coreinit/screen.h>
|
||||||
|
#include <coreinit/title.h>
|
||||||
|
#include <cstdint>
|
||||||
#include <nn/act/client_cpp.h>
|
#include <nn/act/client_cpp.h>
|
||||||
|
#include <proc_ui/procui.h>
|
||||||
|
#include <sysapp/launch.h>
|
||||||
|
|
||||||
#include "ElfUtils.h"
|
#include "ElfUtils.h"
|
||||||
|
#include "common/module_defines.h"
|
||||||
#include "module/ModuleData.h"
|
#include "module/ModuleData.h"
|
||||||
#include "module/ModuleDataFactory.h"
|
#include "module/ModuleDataFactory.h"
|
||||||
#include "common/module_defines.h"
|
|
||||||
|
|
||||||
#include <utils/StringTools.h>
|
#include <utils/StringTools.h>
|
||||||
|
|
||||||
#include "kernel.h"
|
|
||||||
#include "dynamic.h"
|
#include "dynamic.h"
|
||||||
|
#include "kernel.h"
|
||||||
#include "utils/logger.h"
|
#include "utils/logger.h"
|
||||||
#include <malloc.h>
|
|
||||||
#include <coreinit/memexpheap.h>
|
|
||||||
#include <coreinit/debug.h>
|
#include <coreinit/debug.h>
|
||||||
|
#include <coreinit/memexpheap.h>
|
||||||
|
#include <malloc.h>
|
||||||
|
|
||||||
bool doRelocation(const std::vector<RelocationData> &relocData, relocation_trampolin_entry_t *tramp_data, uint32_t tramp_length);
|
bool doRelocation(const std::vector<RelocationData> &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 __init_wut();
|
||||||
extern "C" void __fini_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) {
|
extern "C" int _start(int argc, char **argv) {
|
||||||
doKernelSetup();
|
doKernelSetup();
|
||||||
InitFunctionPointers();
|
InitFunctionPointers();
|
||||||
@ -95,7 +95,7 @@ extern "C" int _start(int argc, char **argv) {
|
|||||||
if (memory_end == memory_start) {
|
if (memory_end == memory_start) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
auto mem_ptr = &memory_end[1]; // &memory_end + sizeof(MEMExpHeapBlock);
|
auto mem_ptr = &memory_end[1];// &memory_end + sizeof(MEMExpHeapBlock);
|
||||||
free(mem_ptr);
|
free(mem_ptr);
|
||||||
leak_count++;
|
leak_count++;
|
||||||
}
|
}
|
||||||
@ -105,7 +105,9 @@ extern "C" int _start(int argc, char **argv) {
|
|||||||
__fini_wut();
|
__fini_wut();
|
||||||
|
|
||||||
if (entrypoint > 0) {
|
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;
|
return -1;
|
||||||
@ -121,7 +123,8 @@ uint32_t do_start(int argc, char **argv) {
|
|||||||
|
|
||||||
uint32_t ApplicationMemoryEnd;
|
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;
|
ApplicationMemoryEnd = (ApplicationMemoryEnd + 0x100) & 0xFFFFFF00;
|
||||||
|
|
||||||
@ -185,7 +188,7 @@ uint32_t do_start(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool doRelocation(const std::vector<RelocationData> &relocData, relocation_trampolin_entry_t *tramp_data, uint32_t tramp_length) {
|
bool doRelocation(const std::vector<RelocationData> &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;
|
const RelocationData &cur = curReloc;
|
||||||
std::string functionName = cur.getName();
|
std::string functionName = cur.getName();
|
||||||
std::string rplName = cur.getImportRPLInformation().getName();
|
std::string rplName = cur.getImportRPLInformation().getName();
|
||||||
|
@ -17,9 +17,9 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <optional>
|
|
||||||
#include "utils/logger.h"
|
#include "utils/logger.h"
|
||||||
|
#include <optional>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
class ImportRPLInformation {
|
class ImportRPLInformation {
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
std::string ModuleData::toString() const {
|
std::string ModuleData::toString() const {
|
||||||
std::string res = StringTools::strfmt("Entrypoint %08X, bss: %08X (%d), bss: %08X (%d)\n", getEntrypoint(), getBSSAddr(), getBSSSize(), getSBSSAddr(), getSBSSSize());
|
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();
|
res += reloc.toString();
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
|
@ -17,9 +17,9 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "RelocationData.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "RelocationData.h"
|
|
||||||
|
|
||||||
class ModuleData {
|
class ModuleData {
|
||||||
public:
|
public:
|
||||||
|
@ -15,13 +15,13 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include "ModuleDataFactory.h"
|
||||||
|
#include "../ElfUtils.h"
|
||||||
|
#include "elfio/elfio.hpp"
|
||||||
|
#include <coreinit/cache.h>
|
||||||
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
|
||||||
#include <coreinit/cache.h>
|
|
||||||
#include "ModuleDataFactory.h"
|
|
||||||
#include "elfio/elfio.hpp"
|
|
||||||
#include "../ElfUtils.h"
|
|
||||||
|
|
||||||
using namespace ELFIO;
|
using namespace ELFIO;
|
||||||
|
|
||||||
@ -136,7 +136,7 @@ ModuleDataFactory::load(const std::string &path, uint32_t destination_address, u
|
|||||||
}
|
}
|
||||||
std::vector<RelocationData> relocationData = getImportRelocationData(reader, destinations);
|
std::vector<RelocationData> relocationData = getImportRelocationData(reader, destinations);
|
||||||
|
|
||||||
for (auto const &reloc: relocationData) {
|
for (auto const &reloc : relocationData) {
|
||||||
moduleData.addRelocationData(reloc);
|
moduleData.addRelocationData(reloc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,12 +17,12 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "ModuleData.h"
|
||||||
|
#include "common/relocation_defines.h"
|
||||||
|
#include "elfio/elfio.hpp"
|
||||||
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
|
||||||
#include "common/relocation_defines.h"
|
|
||||||
#include "ModuleData.h"
|
|
||||||
#include "elfio/elfio.hpp"
|
|
||||||
|
|
||||||
class ModuleDataFactory {
|
class ModuleDataFactory {
|
||||||
public:
|
public:
|
||||||
|
@ -17,8 +17,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include "ImportRPLInformation.h"
|
#include "ImportRPLInformation.h"
|
||||||
|
#include <string>
|
||||||
|
|
||||||
class RelocationData {
|
class RelocationData {
|
||||||
|
|
||||||
|
@ -23,17 +23,16 @@
|
|||||||
*
|
*
|
||||||
* for WiiXplorer 2010
|
* for WiiXplorer 2010
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <string.h>
|
||||||
#include <wchar.h>
|
#include <string>
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
#include <wut_types.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <utils/StringTools.h>
|
#include <utils/StringTools.h>
|
||||||
|
#include <vector>
|
||||||
|
#include <wchar.h>
|
||||||
|
#include <wut_types.h>
|
||||||
|
|
||||||
|
|
||||||
BOOL StringTools::EndsWith(const std::string &a, const std::string &b) {
|
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
|
char *tmp; // varies
|
||||||
int len_rep; // length of rep (the string to remove)
|
int len_rep; // length of rep (the string to remove)
|
||||||
int len_with; // length of with (the string to replace rep with)
|
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
|
int count; // number of replacements
|
||||||
|
|
||||||
// sanity checks and initialization
|
// sanity checks and initialization
|
||||||
@ -269,7 +268,7 @@ char *StringTools::str_replace(char *orig, char *rep, char *with) {
|
|||||||
len_rep = strlen(rep);
|
len_rep = strlen(rep);
|
||||||
if (len_rep == 0) {
|
if (len_rep == 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
} // empty rep causes infinite loop during count
|
}// empty rep causes infinite loop during count
|
||||||
if (!with) {
|
if (!with) {
|
||||||
with = (char *) "";
|
with = (char *) "";
|
||||||
}
|
}
|
||||||
@ -297,7 +296,7 @@ char *StringTools::str_replace(char *orig, char *rep, char *with) {
|
|||||||
len_front = ins - orig;
|
len_front = ins - orig;
|
||||||
tmp = strncpy(tmp, orig, len_front) + len_front;
|
tmp = strncpy(tmp, orig, len_front) + len_front;
|
||||||
tmp = strcpy(tmp, with) + len_with;
|
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);
|
strcpy(tmp, orig);
|
||||||
return result;
|
return result;
|
||||||
|
@ -25,8 +25,8 @@
|
|||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
#include <wut_types.h>
|
#include <wut_types.h>
|
||||||
|
|
||||||
class StringTools {
|
class StringTools {
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
#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
|
||||||
@ -15,7 +15,7 @@ void initLogging() {
|
|||||||
cafeLogInit = WHBLogCafeInit();
|
cafeLogInit = WHBLogCafeInit();
|
||||||
udpLogInit = WHBLogUdpInit();
|
udpLogInit = WHBLogUdpInit();
|
||||||
}
|
}
|
||||||
#endif // DEBUG
|
#endif// DEBUG
|
||||||
}
|
}
|
||||||
|
|
||||||
void deinitLogging() {
|
void deinitLogging() {
|
||||||
@ -32,5 +32,5 @@ void deinitLogging() {
|
|||||||
WHBLogUdpDeinit();
|
WHBLogUdpDeinit();
|
||||||
udpLogInit = false;
|
udpLogInit = false;
|
||||||
}
|
}
|
||||||
#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" {
|
||||||
@ -14,12 +14,14 @@ extern "C" {
|
|||||||
|
|
||||||
#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
|
||||||
@ -39,4 +41,3 @@ void deinitLogging();
|
|||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user