Compare commits

...

17 Commits

Author SHA1 Message Date
Maschell
aed781e88d Fix exiting when running some payloads (like the nand dumper) 2024-05-07 19:11:21 +02:00
Maschell
88d25a79c3 Fix Makefile to be compatible with CLion 2024-04-26 10:33:05 +02:00
Maschell
a6bc48e987 Fix checking button combo 2024-04-26 10:33:05 +02:00
dependabot[bot]
3f71bb4d7f Bump softprops/action-gh-release from 1 to 2
Bumps [softprops/action-gh-release](https://github.com/softprops/action-gh-release) from 1 to 2.
- [Release notes](https://github.com/softprops/action-gh-release/releases)
- [Changelog](https://github.com/softprops/action-gh-release/blob/master/CHANGELOG.md)
- [Commits](https://github.com/softprops/action-gh-release/compare/v1...v2)

---
updated-dependencies:
- dependency-name: softprops/action-gh-release
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-04-24 17:42:22 +02:00
Maschell
1dd3adff65 Update Dockerfile to use latest devkitPPC and wut version 2024-04-24 17:42:22 +02:00
dependabot[bot]
bd90e0ef1c Bump actions/checkout from 2 to 4
Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 4.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2...v4)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-04-24 17:42:22 +02:00
Maschell
162119a289 Overwrite wuts __syscall_getreent 2024-04-24 17:42:22 +02:00
Maschell
8b6b5c3412 Update Dockerfile 2024-04-24 17:42:22 +02:00
Maschell
4c57a3d597 Create dependabot.yml 2023-07-23 10:38:20 +02:00
Maschell
f415c24015 Update Dockerfile 2023-04-17 12:24:34 +02:00
Maschell
3e2aca0583 Improve logging 2023-04-17 12:24:34 +02:00
Maschell
363ca12b14 CI: Update ci.yml to use non-deprecated actions 2023-03-17 19:11:23 +01:00
Maschell
18d4c73d45 Change docker registry to ghcr.io 2023-03-17 19:11:23 +01:00
Maschell
79db755d04 Use ubuntu-22.04 for the CI 2022-09-04 18:32:32 +02:00
Maschell
62e124e56d Update imports.h to support FSA functions 2022-09-04 18:32:32 +02:00
Maschell
d4dc996f9f Improve file reading 2022-08-08 11:52:27 +02:00
Maschell
d2f071a9ae Use wut 1.1.1 2022-08-08 11:52:27 +02:00
12 changed files with 245 additions and 71 deletions

10
.github/dependabot.yml vendored Normal file
View File

@ -0,0 +1,10 @@
version: 2
updates:
- package-ecosystem: "docker"
directory: "/"
schedule:
interval: "daily"
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"

View File

@ -7,17 +7,17 @@ on:
jobs:
clang-format:
runs-on: ubuntu-18.04
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: clang-format
run: |
docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./src
docker run --rm -v ${PWD}:/src ghcr.io/wiiu-env/clang-format:13.0.0-2 -r ./src
build-binary:
runs-on: ubuntu-18.04
runs-on: ubuntu-22.04
needs: clang-format
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: build binary
run: |
docker build . -t builder
@ -28,7 +28,7 @@ jobs:
path: "payload.elf"
deploy-binary:
needs: build-binary
runs-on: ubuntu-18.04
runs-on: ubuntu-22.04
steps:
- name: Get environment variables
id: get_repository_name
@ -42,25 +42,12 @@ jobs:
- name: zip artifact
run: zip -r ${{ env.REPOSITORY_NAME }}_${{ env.DATETIME }}.zip wiiu
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
uses: "softprops/action-gh-release@v2"
with:
tag_name: ${{ env.REPOSITORY_NAME }}-${{ env.DATETIME }}
release_name: Nightly-${{ env.REPOSITORY_NAME }}-${{ env.DATETIME }}
draft: false
prerelease: true
body: |
Not a stable release:
${{ github.event.head_commit.message }}
- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
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/zip
generate_release_notes: true
name: Nightly-${{ env.REPOSITORY_NAME }}-${{ env.DATETIME }}
files: |
./${{ env.REPOSITORY_NAME }}_${{ env.DATETIME }}.zip

View File

@ -4,17 +4,17 @@ on: [pull_request]
jobs:
clang-format:
runs-on: ubuntu-18.04
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: clang-format
run: |
docker run --rm -v ${PWD}:/src wiiuenv/clang-format:13.0.0-2 -r ./src
docker run --rm -v ${PWD}:/src ghcr.io/wiiu-env/clang-format:13.0.0-2 -r ./src
build-binary:
runs-on: ubuntu-18.04
runs-on: ubuntu-22.04
needs: clang-format
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: build binary
run: |
docker build . -t builder

View File

@ -1,3 +1,3 @@
FROM wiiuenv/devkitppc:20211229
FROM ghcr.io/wiiu-env/devkitppc:20240505
WORKDIR project

View File

@ -41,11 +41,22 @@ INCLUDES := src
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
CFLAGS := -std=c2x -g -Wall -O2 -ffunction-sections -DESPRESSO -mcpu=750 -meabi -mhard-float $(INCLUDE)
CXXFLAGS := -std=c++20 -g -Wall -O2 -ffunction-sections -DESPRESSO -mcpu=750 -meabi -mhard-float $(INCLUDE)
CFLAGS := -g -g -Wall -O2 -ffunction-sections $(MACHDEP) $(INCLUDE) -D__WIIU__
CXXFLAGS := $(CFLAGS) -std=c++20
CFLAGS += -std=c2x
ASFLAGS := -mregnames
LDFLAGS := -nostartfiles -Wl,--gc-sections,--allow-multiple-definition
ifeq ($(DEBUG),1)
CXXFLAGS += -DDEBUG -g
CFLAGS += -DDEBUG -g
endif
ifeq ($(DEBUG),VERBOSE)
CXXFLAGS += -DDEBUG -DVERBOSE_DEBUG -g
CFLAGS += -DDEBUG -DVERBOSE_DEBUG -g
endif
#---------------------------------------------------------------------------------
Q := @
MAKEFLAGS += --no-print-directory
@ -116,7 +127,7 @@ export OUTPUT := $(CURDIR)/$(TARGET)
#---------------------------------------------------------------------------------
$(BUILD):
@[ -d $@ ] || mkdir -p $@
@$(shell [ ! -d $(BUILD) ] && mkdir -p $(BUILD))
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile

View File

@ -36,7 +36,7 @@ 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`
`docker run --rm -v ${PWD}:/src ghcr.io/wiiu-env/clang-format:13.0.0-2 -r ./src -i`
## Credits
- Maschell

36
src/crt.c Normal file
View File

@ -0,0 +1,36 @@
void __init_wut_malloc();
void __init_wut_newlib();
void __init_wut_stdcpp();
void __init_wut_devoptab();
void __attribute__((weak)) __init_wut_socket();
void __fini_wut_malloc();
void __fini_wut_newlib();
void __fini_wut_stdcpp();
void __fini_wut_devoptab();
void __attribute__((weak)) __fini_wut_socket();
void __attribute__((weak))
init_wut() {
__init_wut_malloc();
__init_wut_newlib();
__init_wut_stdcpp();
__init_wut_devoptab();
if (&__init_wut_socket) __init_wut_socket();
}
void __attribute__((weak))
fini_wut() {
__fini_wut_devoptab();
__fini_wut_stdcpp();
__fini_wut_newlib();
__fini_wut_malloc();
}

View File

@ -58,6 +58,8 @@ IMPORT(OSCompareAndSwapAtomic);
IMPORT(OSGetThreadSpecific);
IMPORT(OSSetThreadSpecific);
IMPORT(OSReport);
IMPORT(OSSwapAtomic);
IMPORT(OSIsDebuggerPresent);
IMPORT(exit);
IMPORT(_Exit);
@ -92,6 +94,7 @@ IMPORT(FSChangeDir);
IMPORT(FSGetFreeSpaceSize);
IMPORT(FSGetStat);
IMPORT(FSRemove);
IMPORT(FSOpenFileEx);
IMPORT(FSOpenFile);
IMPORT(FSCloseFile);
IMPORT(FSOpenDir);
@ -113,6 +116,36 @@ IMPORT(FSChangeMode);
IMPORT(FSGetPosFile);
IMPORT(OSTicksToCalendarTime);
IMPORT(__rplwrap_exit);
IMPORT(OSMemoryBarrier);
IMPORT(OSInitMutexEx);
IMPORT(FSAMakeDir);
IMPORT(FSAInit);
IMPORT(FSAAddClient);
IMPORT(FSARewindDir);
IMPORT(FSAMount);
IMPORT(FSAGetDeviceInfo);
IMPORT(FSARename);
IMPORT(FSAChangeDir);
IMPORT(FSAUnmount);
IMPORT(FSADelClient);
IMPORT(FSAChangeMode);
IMPORT(FSAReadDir);
IMPORT(FSAOpenDir);
IMPORT(FSACloseDir);
IMPORT(FSAFlushFile);
IMPORT(FSAOpenFileEx);
IMPORT(FSACloseFile);
IMPORT(FSAGetStatFile);
IMPORT(FSAGetFreeSpaceSize);
IMPORT(FSASetPosFile);
IMPORT(FSATruncateFile);
IMPORT(FSARemove);
IMPORT(FSAReadFile);
IMPORT(FSAWriteFile);
IMPORT(FSAGetStat);
IMPORT(FSAGetStatusStr);
IMPORT(IOS_Open);
IMPORT(IOS_Close);

View File

@ -15,34 +15,31 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#include <coreinit/debug.h>
#include <coreinit/dynload.h>
#include <coreinit/memexpheap.h>
#include <coreinit/screen.h>
#include <cstdint>
#include <malloc.h>
#include "dynamic.h"
#include "kernel.h"
#include "utils/DirList.h"
#include "utils/ElfUtils.h"
#include "utils/logger.h"
#include <coreinit/debug.h>
#include <coreinit/dynload.h>
#include <coreinit/filesystem.h>
#include <coreinit/memexpheap.h>
#include <coreinit/screen.h>
#include <cstdint>
#include <malloc.h>
#include <map>
#include <string>
#include <sys/stat.h>
#include <utils/StringTools.h>
#include <vector>
#include <vpad/input.h>
#include <whb/log_cafe.h>
#include <whb/log_udp.h>
std::map<std::string, std::string> get_all_payloads(const char *relativefilepath);
std::string PayloadSelectionScreen(const std::map<std::string, std::string> &payloads);
extern "C" void __init_wut();
extern "C" void __fini_wut();
extern "C" void init_wut();
extern "C" void fini_wut();
MEMExpHeapBlock *memory_start = nullptr;
extern "C" uint32_t start_wrapper(int argc, char **argv) {
@ -54,18 +51,22 @@ extern "C" uint32_t start_wrapper(int argc, char **argv) {
auto heap = (MEMExpHeap *) mem2_heap_handle;
memory_start = heap->usedList.tail;
__init_wut();
init_wut();
WHBLogUdpInit();
WHBLogCafeInit();
initLogging();
DEBUG_FUNCTION_LINE("Hello from payload.elf multiloader");
DEBUG_FUNCTION_LINE_VERBOSE("Hello from payload.elf multiloader");
VPADReadError err;
VPADStatus vpad_data;
VPADRead(VPAD_CHAN_0, &vpad_data, 1, &err);
uint32_t btn = vpad_data.hold | vpad_data.trigger;
VPADStatus vpadStatus{};
VPADReadError vpadError = VPAD_READ_UNINITIALIZED;
int btn = 0;
do {
if (VPADRead(VPAD_CHAN_0, &vpadStatus, 1, &vpadError) > 0 && vpadError == VPAD_READ_SUCCESS) {
btn = vpadStatus.trigger | vpadStatus.hold;
} else {
OSSleepTicks(OSMillisecondsToTicks(1));
}
} while (vpadError == VPAD_READ_NO_SAMPLES);
std::map<std::string, std::string> payloads = get_all_payloads("wiiu/payloads");
@ -74,27 +75,30 @@ extern "C" uint32_t start_wrapper(int argc, char **argv) {
std::string payload_path = "wiiu/payloads/default/payload.elf";
if ((btn & VPAD_BUTTON_B) == VPAD_BUTTON_B) {
payload_path = PayloadSelectionScreen(payloads);
DEBUG_FUNCTION_LINE("Selected %s", payload_path.c_str());
DEBUG_FUNCTION_LINE_VERBOSE("Selected %s", payload_path.c_str());
}
entryPoint = load_loader_elf_from_sd(nullptr, payload_path.c_str());
if (entryPoint != 0) {
DEBUG_FUNCTION_LINE("loaded payload entrypoint at %08X", entryPoint);
DEBUG_FUNCTION_LINE("Loaded payload entrypoint at %08X", entryPoint);
} else {
DEBUG_FUNCTION_LINE("failed to load elf");
DEBUG_FUNCTION_LINE_ERR("Failed to load: %s", payload_path.c_str());
}
WHBLogUdpDeinit();
WHBLogCafeDeinit();
deinitLogging();
__fini_wut();
fini_wut();
revertKernelHook();
return entryPoint;
}
extern "C" struct _reent *__syscall_getreent(void) {
return _impure_ptr;
}
extern "C" int _start(int argc, char **argv) {
uint32_t entryPoint = start_wrapper(argc, argv);
@ -112,13 +116,14 @@ extern "C" int _start(int argc, char **argv) {
free(mem_ptr);
leak_count++;
}
OSReport("Freed %d leaked memory blocks\n", leak_count);
DEBUG_FUNCTION_LINE_INFO("Freed %d leaked memory blocks\n", leak_count);
}
int res = -1;
if (entryPoint != 0) {
res = ((int (*)(int, char **)) entryPoint)(argc, argv);
}
_Exit(0);
return res;
}

View File

@ -24,8 +24,13 @@ int32_t LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_t *size)
return -1;
}
uint32_t filesize = lseek(iFd, 0, SEEK_END);
lseek(iFd, 0, SEEK_SET);
struct stat file_stat;
int rc = fstat(iFd, &file_stat);
if (rc < 0) {
close(iFd);
return -4;
}
uint32_t filesize = file_stat.st_size;
uint8_t *buffer = (uint8_t *) memalign(0x40, (filesize + 0x3F) & ~(0x3F));
if (buffer == NULL) {
@ -33,7 +38,7 @@ int32_t LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_t *size)
return -2;
}
uint32_t blocksize = 0x20000;
uint32_t blocksize = 0x80000;
uint32_t done = 0;
int32_t readBytes = 0;
@ -42,8 +47,9 @@ int32_t LoadFileToMem(const char *filepath, uint8_t **inbuffer, uint32_t *size)
blocksize = filesize - done;
}
readBytes = read(iFd, buffer + done, blocksize);
if (readBytes <= 0)
if (readBytes <= 0) {
break;
}
done += readBytes;
}
@ -74,7 +80,7 @@ static unsigned int get_section(void *data, const char *name, unsigned int *size
uint32_t load_loader_elf_from_sd(unsigned char *baseAddress, const char *relativePath) {
char *elf_data = NULL;
uint32_t fileSize = 0;
if (LoadFileToMem(relativePath, &elf_data, &fileSize) < 0) {
if (LoadFileToMem(relativePath, (uint8_t **) &elf_data, &fileSize) < 0) {
return 0;
}

36
src/utils/logger.c Normal file
View File

@ -0,0 +1,36 @@
#ifdef DEBUG
#include <stdint.h>
#include <whb/log_cafe.h>
#include <whb/log_module.h>
#include <whb/log_udp.h>
uint32_t moduleLogInit = false;
uint32_t cafeLogInit = false;
uint32_t udpLogInit = false;
#endif // DEBUG
void initLogging() {
#ifdef DEBUG
if (!(moduleLogInit = WHBLogModuleInit())) {
cafeLogInit = WHBLogCafeInit();
udpLogInit = WHBLogUdpInit();
}
#endif // DEBUG
}
void deinitLogging() {
#ifdef DEBUG
if (moduleLogInit) {
WHBLogModuleDeinit();
moduleLogInit = false;
}
if (cafeLogInit) {
WHBLogCafeDeinit();
cafeLogInit = false;
}
if (udpLogInit) {
WHBLogUdpDeinit();
udpLogInit = false;
}
#endif // DEBUG
}

View File

@ -1,5 +1,6 @@
#pragma once
#include <coreinit/debug.h>
#include <string.h>
#include <whb/log.h>
@ -7,14 +8,63 @@
extern "C" {
#endif
#define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__)
#define LOG_APP_TYPE "PL"
#define LOG_APP_NAME "payloadloader"
#define DEBUG_FUNCTION_LINE(FMT, ARGS...) \
do { \
WHBLogPrintf("[%23s]%30s@L%04d: " FMT "", __FILENAME__, __FUNCTION__, __LINE__, ##ARGS); \
#define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__)
#define LOG(LOG_FUNC, FMT, ARGS...) LOG_EX_DEFAULT(LOG_FUNC, "", "", FMT, ##ARGS)
#define LOG_EX_DEFAULT(LOG_FUNC, LOG_LEVEL, LINE_END, FMT, ARGS...) LOG_EX(__FILENAME__, __FUNCTION__, __LINE__, LOG_FUNC, LOG_LEVEL, LINE_END, FMT, ##ARGS)
#define LOG_EX(FILENAME, FUNCTION, LINE, LOG_FUNC, LOG_LEVEL, LINE_END, FMT, ARGS...) \
do { \
LOG_FUNC("[(%s)%18s][%23s]%30s@L%04d: " LOG_LEVEL "" FMT "" LINE_END, LOG_APP_TYPE, LOG_APP_NAME, FILENAME, FUNCTION, LINE, ##ARGS); \
} while (0)
#ifdef DEBUG
#ifdef VERBOSE_DEBUG
#define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) LOG(WHBLogPrintf, FMT, ##ARGS)
#define DEBUG_FUNCTION_LINE_VERBOSE_EX(FILENAME, FUNCTION, LINE, FMT, ARGS...) LOG_EX(FILENAME, FUNCTION, LINE, WHBLogPrintf, "", "", FMT, ##ARGS);
#else
#define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while (0)
#define DEBUG_FUNCTION_LINE_VERBOSE_EX(FMT, ARGS...) while (0)
#endif
#define DEBUG_FUNCTION_LINE(FMT, ARGS...) LOG(WHBLogPrintf, FMT, ##ARGS)
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) LOG(WHBLogWritef, FMT, ##ARGS)
#define DEBUG_FUNCTION_LINE_ERR(FMT, ARGS...) LOG_EX_DEFAULT(WHBLogPrintf, "##ERROR## ", "", FMT, ##ARGS)
#define DEBUG_FUNCTION_LINE_WARN(FMT, ARGS...) LOG_EX_DEFAULT(WHBLogPrintf, "##WARN ## ", "", FMT, ##ARGS)
#define DEBUG_FUNCTION_LINE_INFO(FMT, ARGS...) LOG_EX_DEFAULT(WHBLogPrintf, "##INFO ## ", "", FMT, ##ARGS)
#define DEBUG_FUNCTION_LINE_ERR_LAMBDA(FILENAME, FUNCTION, LINE, FMT, ARGS...) LOG_EX(FILENAME, FUNCTION, LINE, WHBLogPrintf, "##ERROR## ", "", FMT, ##ARGS);
#else
#define DEBUG_FUNCTION_LINE_VERBOSE_EX(FMT, ARGS...) while (0)
#define DEBUG_FUNCTION_LINE_VERBOSE(FMT, ARGS...) while (0)
#define DEBUG_FUNCTION_LINE(FMT, ARGS...) while (0)
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...) while (0)
#define DEBUG_FUNCTION_LINE_ERR(FMT, ARGS...) LOG_EX_DEFAULT(OSReport, "##ERROR## ", "\n", FMT, ##ARGS)
#define DEBUG_FUNCTION_LINE_WARN(FMT, ARGS...) LOG_EX_DEFAULT(OSReport, "##WARN ## ", "\n", FMT, ##ARGS)
#define DEBUG_FUNCTION_LINE_INFO(FMT, ARGS...) LOG_EX_DEFAULT(OSReport, "##INFO ## ", "\n", FMT, ##ARGS)
#define DEBUG_FUNCTION_LINE_ERR_LAMBDA(FILENAME, FUNCTION, LINE, FMT, ARGS...) LOG_EX(FILENAME, FUNCTION, LINE, OSReport, "##ERROR## ", "\n", FMT, ##ARGS);
#endif
void initLogging();
void deinitLogging();
#ifdef __cplusplus
}
#endif