From 547e4cd61f5346daf4e95626ce46da8a1b9c713c Mon Sep 17 00:00:00 2001 From: theawesomecoder61 Date: Mon, 18 Sep 2023 15:17:07 -0400 Subject: [PATCH] Version 1.1 --- Makefile | 4 +-- README.md | 15 ++++++----- src/kernel.hpp | 72 +++----------------------------------------------- src/kernel.s | 28 -------------------- src/main.cpp | 2 +- 5 files changed, 14 insertions(+), 107 deletions(-) delete mode 100644 src/kernel.s diff --git a/Makefile b/Makefile index c68d2f1..5a33bfe 100644 --- a/Makefile +++ b/Makefile @@ -37,9 +37,9 @@ CFLAGS += $(INCLUDE) -D__WIIU__ -D__WUT__ -D__WUPS__ CXXFLAGS := $(CFLAGS) ASFLAGS := -g $(ARCH) -LDFLAGS = -g $(ARCH) $(RPXSPECS) -Wl,-Map,$(notdir $*.map) $(WUPSSPECS) +LDFLAGS = -g $(ARCH) $(RPXSPECS) -Wl,-Map,$(notdir $*.map) -T$(WUMS_ROOT)/share/libkernel.ld $(WUPSSPECS) -LIBS := -lwups -lwut -lwums -lnotifications +LIBS := -lwups -lwut -lwums -lnotifications -lkernel #------------------------------------------------------------------------------- # list of directories containing libraries, this must be the top level diff --git a/README.md b/README.md index 0fb4942..0c06527 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Code Patch will load all `.hax` files in a folder and apply all patches found th --- ## Installation -Be sure you fully installed and configured Tiramisu and Aroma on your Wii U. +Be sure you fully installed and configured Tiramisu and Aroma on your Wii U. You should have NotificationModule and KernelModule in `/fs/vol/external01/wiiu/environments/aroma/modules`. 1. Copy `CodePatchPlugin.wps` into `/fs/vol/external01/wiiu/environments/aroma/plugins`. 2. Create a folder in `/fs/vol/external01/wiiu/` called `codepatches`. @@ -26,10 +26,10 @@ Patching can be enabled/disabled globally via the WUPS config menu (press L, DPA When loading and applying patches, the plugin will display messages in the top left. These too can be enabled/disabled in the WUPS config menu. -I tested on a 32 GB US model running 5.5.5. This plugin will work on all 5.5.X versions that Tiramisu supports. +I tested the plugin on a 32 GB US model running 5.5.5. This plugin will work on all 5.5.X versions that Tiramisu supports. ## hax files -A `.hax` file is a format that contains individual code replacements with corresponding addresses. Since the Wii U's CPU is big-endian, `.hax` files must also be. I did not invent this format; I use it since CafeLoader used it. +A `.hax` file is a format that contains individual code replacements with corresponding addresses. Such files are big-endian. I did not invent this format; I use it since CafeLoader used it. For reference, here is a breakdown of the format. @@ -61,6 +61,7 @@ To build, you need: - [Wii U Plugin System](https://github.com/Maschell/WiiUPluginSystem) - [Wii U Module System](https://github.com/wiiu-env/WiiUModuleSystem) - [NotificationModule](https://github.com/wiiu-env/NotificationModule) +- [libkernel](https://github.com/wiiu-env/libkernel) - [wut](https://github.com/devkitpro/wut) Install them with their dependencies in this order according to their READMEs. After, compile the plugin using `make` (with no logging) or `make DEBUG=1` (with logging). @@ -68,11 +69,11 @@ Install them with their dependencies in this order according to their READMEs. A ## Buildflags ### Logging -Building via `make` only logs errors (via OSReport). To enable logging via the [LoggingModule](https://github.com/wiiu-env/LoggingModule) set `DEBUG` to `1` or `VERBOSE`. +You can build the plugin in one of three ways: -`make` Logs errors only (via OSReport). -`make DEBUG=1` Enables information and error logging via [LoggingModule](https://github.com/wiiu-env/LoggingModule). -`make DEBUG=VERBOSE` Enables verbose information and error logging via [LoggingModule](https://github.com/wiiu-env/LoggingModule). +- `make` Logs errors only (via OSReport). +- `make DEBUG=1` Enables information and error logging via [LoggingModule](https://github.com/wiiu-env/LoggingModule). +- `make DEBUG=VERBOSE` Enables verbose information and error logging via [LoggingModule](https://github.com/wiiu-env/LoggingModule). If the [LoggingModule](https://github.com/wiiu-env/LoggingModule) is not present, it will fallback to UDP (port 4405) and [CafeOS](https://github.com/wiiu-env/USBSerialLoggingModule) logging. You can use `udplogserver` (/opt/devkitpro/tools/bin/udplogserver) to view logs. diff --git a/src/kernel.hpp b/src/kernel.hpp index 22bb9ee..239deac 100644 --- a/src/kernel.hpp +++ b/src/kernel.hpp @@ -1,84 +1,18 @@ -// https://github.com/wiiu-env/EnvironmentLoader #pragma once #include #include -#include -#include #include - -extern "C" void SCKernelCopyData(uint32_t dst, uint32_t src, uint32_t len); -extern "C" void SC_KernelCopyData(uint32_t addr, uint32_t src, uint32_t len); - -#define KERN_SYSCALL_TBL_1 0xFFE84C70 //Unknown -#define KERN_SYSCALL_TBL_2 0xFFE85070 //Games -#define KERN_SYSCALL_TBL_3 0xFFE85470 //Loader -#define KERN_SYSCALL_TBL_4 0xFFEAAA60 //Home menu -#define KERN_SYSCALL_TBL_5 0xFFEAAE60 //Browser - -/* 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"); -} - -// https://github.com/wiiu-env/payload_loader -/* Read a 32-bit word with kernel permissions */ -uint32_t __attribute__ ((noinline)) kern_read(const void *addr) { - uint32_t result; - asm volatile ( - "li 3,1\n" - "li 4,0\n" - "li 5,0\n" - "li 6,0\n" - "li 7,0\n" - "lis 8,1\n" - "mr 9,%1\n" - "li 0,0x3400\n" - "mr %0,1\n" - "sc\n" - "nop\n" - "mr 1,%0\n" - "mr %0,3\n" - : "=r"(result) - : "b"(addr) - : "memory", "ctr", "lr", "0", "3", "4", "5", "6", "7", "8", "9", "10", - "11", "12" - ); - - return result; -} +#include void KernelWriteU32(uint32_t addr, uint32_t value) { - kern_write((void *) (KERN_SYSCALL_TBL_2 + (0x25 * 4)), (unsigned int) SCKernelCopyData); - ICInvalidateRange(&value, 4); DCFlushRange(&value, 4); auto dst = (uint32_t) OSEffectiveToPhysical(addr); auto src = (uint32_t) OSEffectiveToPhysical((uint32_t) &value); - SC_KernelCopyData(dst, src, 4); + KernelCopyData(dst, src, 4); DCFlushRange((void *) addr, 4); ICInvalidateRange((void *) addr, 4); -} - -// uint32_t KernelReadU32(uint32_t addr) { -// uint32_t value = kern_read((void *) OSEffectiveToPhysical(addr)); -// return value; -// } \ No newline at end of file +} \ No newline at end of file diff --git a/src/kernel.s b/src/kernel.s deleted file mode 100644 index eb7281e..0000000 --- a/src/kernel.s +++ /dev/null @@ -1,28 +0,0 @@ -// https://github.com/wiiu-env/EnvironmentLoader -.global SCKernelCopyData -SCKernelCopyData: - // Disable data address translation - mfmsr %r6 - li %r7, 0x10 - andc %r6, %r6, %r7 - mtmsr %r6 - - // Copy data - addi %r3, %r3, -1 - addi %r4, %r4, -1 - mtctr %r5 -SCKernelCopyData_loop: - lbzu %r5, 1(%r4) - stbu %r5, 1(%r3) - bdnz SCKernelCopyData_loop - - // Enable data address translation - ori %r6, %r6, 0x10 - mtmsr %r6 - blr - -.global SC_KernelCopyData -SC_KernelCopyData: - li %r0, 0x2500 - sc - blr \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 0bce407..dfa2bbe 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,7 +18,7 @@ WUPS_PLUGIN_NAME("Code Patch Plugin"); WUPS_PLUGIN_DESCRIPTION("This plugin dynamically patches executables with user-specified patches."); -WUPS_PLUGIN_VERSION("v1.0"); +WUPS_PLUGIN_VERSION("v1.1"); WUPS_PLUGIN_AUTHOR("pineapples721"); WUPS_PLUGIN_LICENSE("GPL");