Skip to content

Commit

Permalink
Format the code via clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
Maschell committed Feb 3, 2022
1 parent 6098af2 commit a3c549c
Show file tree
Hide file tree
Showing 15 changed files with 624 additions and 542 deletions.
67 changes: 67 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -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
10 changes: 9 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@ on:
- main

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
Expand Down Expand Up @@ -55,4 +63,4 @@ jobs:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: ./${{ env.REPOSITORY_NAME }}_${{ env.DATETIME }}.zip
asset_name: ${{ env.REPOSITORY_NAME }}_${{ env.DATETIME }}.zip
asset_content_type: application/unknown
asset_content_type: application/zip
8 changes: 8 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
FROM wiiuenv/devkitppc:20210414
FROM wiiuenv/devkitppc:20211229

WORKDIR project
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ docker run -it --rm -v ${PWD}:/project payloadloaderpayload-builder make
docker run -it --rm -v ${PWD}:/project payloadloaderpayload-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
Expand Down
15 changes: 9 additions & 6 deletions src/dynamic.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <coreinit/dynload.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_END()

Expand All @@ -11,20 +11,23 @@
#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);
EXPORT_VAR(uint32_t *, MEMFreeToDefaultHeap);

void InitFunctionPointers(void) {
OSDynLoad_Module handle;
addr_OSDynLoad_Acquire = (void *) 0x0102A3B4;
addr_OSDynLoad_Acquire = (void *) 0x0102A3B4;
addr_OSDynLoad_FindExport = (void *) 0x0102B828;

OSDynLoad_Acquire("coreinit.rpl", &handle);
Expand Down
43 changes: 21 additions & 22 deletions src/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/

#include <coreinit/cache.h>
#include <coreinit/memorymap.h>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <coreinit/cache.h>
#include <coreinit/memorymap.h>

#include "kernel.h"

Expand All @@ -28,7 +28,7 @@ extern "C" void Syscall_0x36(void);
extern "C" void KernelPatchesRevertHook(void);
extern "C" void KernelPatches(void);

void __attribute__ ((noinline)) kern_write(void *addr, uint32_t value);
void __attribute__((noinline)) kern_write(void *addr, uint32_t value);


void doKernelSetup() {
Expand All @@ -52,23 +52,22 @@ void revertKernelHook() {
}

/* 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");
}
10 changes: 5 additions & 5 deletions src/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
54 changes: 27 additions & 27 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,26 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/

#include <malloc.h>
#include <cstdint>

#include <coreinit/dynload.h>
#include <coreinit/screen.h>
#include <coreinit/memexpheap.h>
#include <coreinit/screen.h>
#include <cstdint>
#include <malloc.h>

#include "utils/ElfUtils.h"
#include "utils/logger.h"
#include "dynamic.h"
#include "kernel.h"
#include <whb/log_udp.h>
#include "utils/ElfUtils.h"
#include "utils/logger.h"
#include <coreinit/filesystem.h>
#include <whb/sdcard.h>
#include <sys/stat.h>
#include <string>
#include <vpad/input.h>
#include <vector>
#include <map>
#include <string>
#include <sys/stat.h>
#include <utils/StringTools.h>
#include <vector>
#include <vpad/input.h>
#include <whb/log_udp.h>
#include <whb/sdcard.h>

std::map<std::string, std::string> get_all_payloads(const char *relativefilepath);

Expand All @@ -49,7 +49,7 @@ extern "C" uint32_t start_wrapper(int argc, char **argv) {
doKernelSetup();
InitFunctionPointers();

memory_start = (uint32_t) malloc(1024);
memory_start = (uint32_t) malloc(1024);

__init_wut();

Expand Down Expand Up @@ -84,23 +84,23 @@ extern "C" uint32_t start_wrapper(int argc, char **argv) {
WHBLogUdpDeinit();

__fini_wut();

revertKernelHook();

return entryPoint;
}
extern "C" int _start(int argc, char **argv) {
uint32_t entryPoint = start_wrapper(argc, argv);

// Somewhere in this loader is a memory leak.
// This is a hacky solution to free that memory.
uint32_t head_end = (uint32_t) malloc(1024);
uint32_t head_end = (uint32_t) malloc(1024);
MEMExpHeapBlock *curUsedBlock = (MEMExpHeapBlock *) (head_end - 0x14);
while (curUsedBlock != 0) {
while (curUsedBlock != 0) {
curUsedBlock = curUsedBlock->prev;
free(&curUsedBlock[1]);
if(((uint32_t) &curUsedBlock[1]) == memory_start){

if (((uint32_t) &curUsedBlock[1]) == memory_start) {
break;
}
}
Expand Down Expand Up @@ -142,7 +142,7 @@ std::map<std::string, std::string> get_all_payloads(const char *relativefilepath
for (auto &child : files_inFolder) {
if (StringTools::EndsWith(child, "payload.elf")) {
std::vector<std::string> folders = StringTools::stringSplit(e, "/");
std::string folder_name = e;
std::string folder_name = e;
if (folders.size() > 1) {
folder_name = folders.at(folders.size() - 1);
}
Expand All @@ -154,7 +154,7 @@ std::map<std::string, std::string> get_all_payloads(const char *relativefilepath
}
}

exit:
exit:
WHBUnmountSdCard();
if (clientAdded) {
FSDelClient(&client, FS_ERROR_FLAG_ALL);
Expand Down Expand Up @@ -194,9 +194,9 @@ std::string PayloadSelectionScreen(const std::map<std::string, std::string> &pay
OSScreenInit();
uint32_t screen_buf0_size = OSScreenGetBufferSizeEx(SCREEN_TV);
uint32_t screen_buf1_size = OSScreenGetBufferSizeEx(SCREEN_DRC);
uint8_t * screenBuffer = (uint8_t*) memalign(0x100, screen_buf0_size + screen_buf1_size);
OSScreenSetBufferEx(SCREEN_TV, (void *)screenBuffer);
OSScreenSetBufferEx(SCREEN_DRC, (void *)(screenBuffer + screen_buf0_size));
uint8_t *screenBuffer = (uint8_t *) memalign(0x100, screen_buf0_size + screen_buf1_size);
OSScreenSetBufferEx(SCREEN_TV, (void *) screenBuffer);
OSScreenSetBufferEx(SCREEN_DRC, (void *) (screenBuffer + screen_buf0_size));

OSScreenEnableEx(SCREEN_TV, 1);
OSScreenEnableEx(SCREEN_DRC, 1);
Expand All @@ -210,7 +210,7 @@ std::string PayloadSelectionScreen(const std::map<std::string, std::string> &pay

VPADStatus vpad_data;
VPADReadError error;
int selected = 0;
int selected = 0;
std::string header = "Please choose your payload:";
while (true) {
// Clear screens
Expand All @@ -226,7 +226,7 @@ std::string PayloadSelectionScreen(const std::map<std::string, std::string> &pay
pos += 2;

int i = 0;
for (auto const&[key, val] : payloads) {
for (auto const &[key, val] : payloads) {
std::string text = StringTools::strfmt("%s %s", i == selected ? "> " : " ", key.c_str());
OSScreenPutFontEx(SCREEN_TV, 0, pos, text.c_str());
OSScreenPutFontEx(SCREEN_DRC, 0, pos, text.c_str());
Expand Down Expand Up @@ -257,7 +257,7 @@ std::string PayloadSelectionScreen(const std::map<std::string, std::string> &pay
OSSleepTicks(OSMillisecondsToTicks(16));
}
int i = 0;
for (auto const&[key, val] : payloads) {
for (auto const &[key, val] : payloads) {
if (i == selected) {
return val;
}
Expand Down
Loading

0 comments on commit a3c549c

Please sign in to comment.