Skip to content

Commit

Permalink
Version 1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
theawesomecoder61 committed Sep 18, 2023
1 parent 14f3962 commit 547e4cd
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 107 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand All @@ -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.

Expand Down Expand Up @@ -61,18 +61,19 @@ 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).

## 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.

Expand Down
72 changes: 3 additions & 69 deletions src/kernel.hpp
Original file line number Diff line number Diff line change
@@ -1,84 +1,18 @@
// https://github.com/wiiu-env/EnvironmentLoader
#pragma once
#include <coreinit/cache.h>
#include <coreinit/memorymap.h>
#include <whb/log.h>
#include <whb/log_udp.h>
#include <wums.h>

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 <kernel/kernel.h>

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;
// }
}
28 changes: 0 additions & 28 deletions src/kernel.s

This file was deleted.

2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down

0 comments on commit 547e4cd

Please sign in to comment.