Format the code via clang-format

This commit is contained in:
Maschell 2022-02-04 14:23:22 +01:00
parent 77c31bd0fe
commit 8015a18f24
37 changed files with 877 additions and 783 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
@ -54,4 +62,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

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

@ -1,5 +1,7 @@
[![CI-Release](https://github.com/wiiu-env/MochaPayload/actions/workflows/ci.yml/badge.svg)](https://github.com/wiiu-env/MochaPayload/actions/workflows/ci.yml)
# MochaPayload - a simple custom firmware
This a lite version of the [original mocha](https://github.com/dimok789/mocha) to be used with the [EnvironmentLoader](https://github.com/wiiu-env/EnvironmentLoader).
This a version of the [original mocha](https://github.com/dimok789/mocha) to be used with the [EnvironmentLoader](https://github.com/wiiu-env/EnvironmentLoader).
## Usage
Place the `00_mocha.rpx` in the `[ENVIRONMENT]/modules/setup` folder and run the [EnvironmentLoader](https://github.com/wiiu-env/EnvironmentLoader).
@ -15,7 +17,6 @@ Place the `00_mocha.rpx` in the `[ENVIRONMENT]/modules/setup` folder and run the
For building you just need [wut](https://github.com/devkitPro/wut/) installed, then use the `make` command.
## Building using the Dockerfile
It's possible to use a docker image for building. This way you don't need anything installed on your host system.
@ -31,6 +32,10 @@ docker run -it --rm -v ${PWD}:/project mochapayload-builder make
docker run -it --rm -v ${PWD}:/project mochapayload-builder make clean
```
## Format the code via docker
`docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./source -i`
## Credits
dimok
Maschell

View File

@ -2,6 +2,7 @@
#include <assert.h>
#include <stddef.h>
#include <stdint.h>
#define CHECK_SIZE(Type, Size) \
static_assert(sizeof(Type) == Size, \

View File

@ -1,9 +1,9 @@
#include <string.h>
#include <coreinit/cache.h>
#include <coreinit/thread.h>
#include <coreinit/ios.h>
#include <stdint.h>
#include "ios_exploit.h"
#include <coreinit/cache.h>
#include <coreinit/ios.h>
#include <coreinit/thread.h>
#include <stdint.h>
#include <string.h>
#define ALIGN4(x) (((x) + 3) & ~3)
@ -34,8 +34,8 @@ typedef struct __attribute__((packed)) {
/* YOUR ARM CODE HERE (starts at ARM_CODE_BASE) */
#include "ios_kernel/ios_kernel.bin.h"
#include "ios_usb/ios_usb.bin.h"
#include "ios_mcp/ios_mcp.bin.h"
#include "ios_usb/ios_usb.bin.h"
/* ROP CHAIN STARTS HERE (0x1015BD78) */
static const int final_chain[] = {

View File

@ -1,3 +1,4 @@
// clang-format off
/*
* Copyright (c) 1995, 1996, 2001, 2002
* Erik Theisen. All rights reserved.

View File

@ -21,16 +21,14 @@
* 3. This notice may not be removed or altered from any source
* distribution.
***************************************************************************/
#include "types.h"
#include "elf_abi.h"
#include "types.h"
#include "utils.h"
static Elf32_Phdr *get_section(u32 data, u32 vaddr) {
Elf32_Ehdr *ehdr = (Elf32_Ehdr *) data;
if (!IS_ELF (*ehdr)
|| (ehdr->e_type != ET_EXEC)
|| (ehdr->e_machine != EM_ARM)) {
if (!IS_ELF(*ehdr) || (ehdr->e_type != ET_EXEC) || (ehdr->e_machine != EM_ARM)) {
return 0;
}

View File

@ -218,4 +218,3 @@ int FSA_SDWriteRawSectors(const void *buffer, u32 sector, u32 num_sectors) {
return res;
}

View File

@ -21,12 +21,12 @@
* 3. This notice may not be removed or altered from any source
* distribution.
***************************************************************************/
#include "utils.h"
#include "types.h"
#include "elf_patcher.h"
#include "kernel_patches.h"
#include "ios_mcp_patches.h"
#include "../../ios_mcp/ios_mcp_syms.h"
#include "elf_patcher.h"
#include "ios_mcp_patches.h"
#include "kernel_patches.h"
#include "types.h"
#include "utils.h"
typedef struct {
u32 paddr;

View File

@ -21,11 +21,11 @@
* 3. This notice may not be removed or altered from any source
* distribution.
***************************************************************************/
#include "types.h"
#include "elf_patcher.h"
#include "ios_mcp_patches.h"
#include "../../ios_mcp/ios_mcp.bin.h"
#include "../../ios_mcp/ios_mcp_syms.h"
#include "elf_patcher.h"
#include "types.h"
#define MCP_CODE_BASE_PHYS_ADDR (-0x05100000 + 0x13D80000)

View File

@ -24,6 +24,8 @@
#ifndef _MCP_PATCHES_H_
#define _MCP_PATCHES_H_
#include "types.h"
#define MCP_LAUNCH_IMG_PHYS_ADDR (0x27000000)
u32 mcp_get_phys_code_base(void);

View File

@ -21,14 +21,14 @@
* 3. This notice may not be removed or altered from any source
* distribution.
***************************************************************************/
#include "types.h"
#include "kernel_patches.h"
#include "../../common/kernel_commands.h"
#include "elf_patcher.h"
#include "ios_mcp_patches.h"
#include "kernel_patches.h"
#include "fsa.h"
#include "utils.h"
#include "ios_mcp_patches.h"
#include "thread.h"
#include "types.h"
#include "utils.h"
extern void __KERNEL_CODE_START(void);
@ -154,4 +154,3 @@ void kernel_run_patches(u32 ios_elf_start) {
u32 patch_count = (u32) (((u8 *) kernel_patches_table_end) - ((u8 *) kernel_patches_table)) / sizeof(patch_table_t);
patch_table_entries(ios_elf_start, kernel_patches_table, patch_count);
}

View File

@ -24,6 +24,8 @@
#ifndef _KERNEL_PATCHES_H
#define _KERNEL_PATCHES_H
#include "types.h"
int kernel_init_otp_buffer(u32 sd_sector, int tagValid);
int kernel_syscall_0x81(u32 command, u32 arg1, u32 arg2, u32 arg3);

View File

@ -21,10 +21,10 @@
* 3. This notice may not be removed or altered from any source
* distribution.
***************************************************************************/
#include "instant_patches.h"
#include "ios_mcp_patches.h"
#include "types.h"
#include "utils.h"
#include "ios_mcp_patches.h"
#include "instant_patches.h"
#define USB_PHYS_CODE_BASE 0x101312D0
@ -33,6 +33,7 @@ typedef struct {
u8 data[0];
} payload_info_t;
// clang-format off
static const char repairData_set_fault_behavior[] = {
0xE1, 0x2F, 0xFF, 0x1E, 0xE9, 0x2D, 0x40, 0x30, 0xE5, 0x93, 0x20, 0x00, 0xE1, 0xA0, 0x40, 0x00,
0xE5, 0x92, 0x30, 0x54, 0xE1, 0xA0, 0x50, 0x01, 0xE3, 0x53, 0x00, 0x01, 0x0A, 0x00, 0x00, 0x02,
@ -56,6 +57,7 @@ static const char repairData_usb_root_thread[] = {
0xE2, 0x4D, 0xDE, 0x17, 0xEB, 0x00, 0xB9, 0x92, 0xE3, 0xA0, 0x10, 0x00, 0xE3, 0xA0, 0x20, 0x03,
0xE5, 0x9F, 0x0E, 0x68, 0xEB, 0x00, 0xB3, 0x20,
};
// clang-format on
int _main() {
void (*invalidate_icache)() = (void (*)()) 0x0812DCF0;

View File

@ -1,7 +1,7 @@
#pragma once
#include <stdint.h>
#include <assert.h>
#include <stdint.h>
typedef struct ThreadContext {
uint32_t cspr;

View File

@ -37,17 +37,24 @@ void reverse_memcpy(void *dest, const void *src, unsigned int size);
static inline unsigned int disable_mmu(void) {
unsigned int control_register = 0;
asm volatile("MRC p15, 0, %0, c1, c0, 0" : "=r" (control_register));
asm volatile("MCR p15, 0, %0, c1, c0, 0" : : "r" (control_register & 0xFFFFEFFA));
asm volatile("MRC p15, 0, %0, c1, c0, 0"
: "=r"(control_register));
asm volatile("MCR p15, 0, %0, c1, c0, 0"
:
: "r"(control_register & 0xFFFFEFFA));
return control_register;
}
static inline void restore_mmu(unsigned int control_register) {
asm volatile("MCR p15, 0, %0, c1, c0, 0" : : "r" (control_register));
asm volatile("MCR p15, 0, %0, c1, c0, 0"
:
: "r"(control_register));
}
static inline void set_domain_register(unsigned int domain_register) {
asm volatile("MCR p15, 0, %0, c3, c0, 0" : : "r" (domain_register));
asm volatile("MCR p15, 0, %0, c3, c0, 0"
:
: "r"(domain_register));
}
#endif

View File

@ -1,9 +1,9 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "svc.h"
#include "imports.h"
#include "fsa.h"
#include "imports.h"
#include "svc.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static void *allocIobuf() {
void *ptr = svcAlloc(0xCAFF, 0x828);
@ -193,7 +193,8 @@ int _FSA_ReadWriteFile(int fd, void *data, u32 size, u32 cnt, int fileHandle, u3
int ret;
if (read) ret = svcIoctlv(fd, 0x0F, 1, 2, iovec);
else ret = svcIoctlv(fd, 0x10, 2, 1, iovec);
else
ret = svcIoctlv(fd, 0x10, 2, 1, iovec);
freeIobuf(iobuf);
return ret;

View File

@ -1,6 +1,8 @@
#ifndef FSA_H
#define FSA_H
#include "types.h"
typedef struct {
u32 flag;
u32 permission;

View File

@ -1,9 +1,9 @@
#ifndef IMPORTS_H
#define IMPORTS_H
#include <stdlib.h>
#include <stdarg.h>
#include "types.h"
#include <stdarg.h>
#include <stdlib.h>
#define MCP_SVC_BASE ((void *) 0x050567EC)

View File

@ -21,16 +21,15 @@
* 3. This notice may not be removed or altered from any source
* distribution.
***************************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "imports.h"
#include "fsa.h"
#include "svc.h"
#include "logger.h"
#include "fsa.h"
#include "wupserver.h"
#include "../../common/kernel_commands.h"
#include "fsa.h"
#include "imports.h"
#include "logger.h"
#include "svc.h"
#include "wupserver.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define IOS_ERROR_UNKNOWN_VALUE 0xFFFFFFD6
#define IOS_ERROR_INVALID_ARG 0xFFFFFFE3
@ -451,5 +450,4 @@ void ipc_deinit(void) {
svcIoctl(fd, IOCTL_KILL_SERVER, &dummy, sizeof(dummy), &dummy, sizeof(dummy));
svcClose(fd);
}
}

View File

@ -1,9 +1,9 @@
#include <stdarg.h>
#include <string.h>
#include "types.h"
#include "logger.h"
#include "imports.h"
#include "socket.h"
#include "logger.h"
#include "types.h"
#include <stdarg.h>
#include <string.h>
#ifdef LOG_IP
static int log_socket = 0;
@ -20,8 +20,7 @@ int log_init(unsigned int ipAddress){
connect_addr.sin_port = 4405;
connect_addr.sin_addr.s_addr = ipAddress;
if(connect(log_socket, (struct sockaddr*)&connect_addr, sizeof(connect_addr)) < 0)
{
if (connect(log_socket, (struct sockaddr *) &connect_addr, sizeof(connect_addr)) < 0) {
closesocket(log_socket);
log_socket = -1;
}
@ -29,17 +28,14 @@ int log_init(unsigned int ipAddress){
return log_socket;
}
void log_deinit()
{
if(log_socket >= 0)
{
void log_deinit() {
if (log_socket >= 0) {
closesocket(log_socket);
log_socket = -1;
}
}
static void log_print(const char *str, int len)
{
static void log_print(const char *str, int len) {
if (log_socket < 0) {
return;
}
@ -55,8 +51,7 @@ static void log_print(const char *str, int len)
}
}
void log_printf(const char *format, ...)
{
void log_printf(const char *format, ...) {
if (log_socket < 0) {
return;
}

View File

@ -15,7 +15,8 @@ void log_printf(const char *format, ...);
#define log_printf(x, ...)
#endif
#define DEBUG_FUNCTION_LINE(FMT, ARGS...)do { \
#define DEBUG_FUNCTION_LINE(FMT, ARGS...) \
do { \
log_printf("[%23s]%30s@L%04d: " FMT "", __FILE__, __FUNCTION__, __LINE__, ##ARGS); \
} while (0)

View File

@ -1,5 +1,5 @@
#include "wupserver.h"
#include "ipc.h"
#include "wupserver.h"
static int threadsStarted = 0;

View File

@ -16,10 +16,10 @@
* - each request routes here where we can do whatever
*/
#include "logger.h"
#include "ipc_types.h"
#include "../../common/ipc_defs.h"
#include "fsa.h"
#include "ipc_types.h"
#include "logger.h"
#include "svc.h"
#include <string.h>

View File

@ -1,8 +1,8 @@
#include <stdlib.h>
#include <string.h>
#include "net_ifmgr_ncl.h"
#include "imports.h"
#include "svc.h"
#include <stdlib.h>
#include <string.h>
static int ifmgrncl_handle = 0;

View File

@ -1,9 +1,9 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "socket.h"
#include "svc.h"
#include "imports.h"
#include "svc.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static int socket_handle = 0;

View File

@ -1,8 +1,8 @@
#ifndef TYPES_H
#define TYPES_H
#include <stdint.h>
#include <stdbool.h>
#include <stdint.h>
#define U64_MAX UINT64_MAX

View File

@ -1,13 +1,13 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "fsa.h"
#include "imports.h"
#include "ipc.h"
#include "logger.h"
#include "net_ifmgr_ncl.h"
#include "socket.h"
#include "fsa.h"
#include "svc.h"
#include "logger.h"
#include "ipc.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static int serverKilled;
static int serverSocket;

View File

@ -19,6 +19,4 @@ void _main() {
"newlr: .word 0x1012EACC\n"
"newr0: .word 0x10146080\n"
"newpc: .word 0x10111164\n");
}

View File

@ -1,7 +1,7 @@
#include <cstring>
#include <cstdio>
#include <coreinit/cache.h>
#include <coreinit/ios.h>
#include <cstdio>
#include <cstring>
#include <sysapp/title.h>
#include <whb/log.h>