2018-09-24 10:43:20 +02:00
|
|
|
#include "debugger.h"
|
|
|
|
#include "exceptions.h"
|
2022-02-08 14:48:41 +01:00
|
|
|
#include "logger.h"
|
2022-07-26 19:29:41 +02:00
|
|
|
#include <coreinit/cache.h>
|
2022-02-08 14:48:41 +01:00
|
|
|
#include <coreinit/debug.h>
|
2022-07-26 19:29:41 +02:00
|
|
|
#include <coreinit/dynload.h>
|
|
|
|
#include <coreinit/memorymap.h>
|
|
|
|
#include <kernel/kernel.h>
|
2022-02-08 14:48:41 +01:00
|
|
|
#include <wups.h>
|
2018-09-24 10:43:20 +02:00
|
|
|
|
2022-02-08 14:48:41 +01:00
|
|
|
OSThread **pThreadList;
|
2018-09-24 10:43:20 +02:00
|
|
|
|
2022-02-08 14:48:41 +01:00
|
|
|
WUPS_PLUGIN_NAME("Debugger");
|
2022-07-26 19:29:41 +02:00
|
|
|
WUPS_PLUGIN_DESCRIPTION("Wii U Debugger");
|
2022-02-08 14:48:41 +01:00
|
|
|
WUPS_PLUGIN_VERSION("0.1");
|
2022-07-26 19:29:41 +02:00
|
|
|
WUPS_PLUGIN_AUTHOR("Kinnay, Maschell");
|
2022-02-08 14:48:41 +01:00
|
|
|
WUPS_PLUGIN_LICENSE("GPL");
|
2018-09-24 10:43:20 +02:00
|
|
|
|
2022-02-08 14:48:41 +01:00
|
|
|
WUPS_USE_WUT_DEVOPTAB();
|
2022-02-08 14:44:53 +01:00
|
|
|
|
2022-07-26 19:29:41 +02:00
|
|
|
/* https://github.com/QuarkTheAwesome/CafeBinPatch/blob/main/src/runtime-patcher.cpp#L58 */
|
|
|
|
bool PatchInstruction(void *instr, uint32_t original, uint32_t replacement) {
|
|
|
|
uint32_t current = *(uint32_t *) instr;
|
|
|
|
if (current != original) return current == replacement;
|
|
|
|
|
|
|
|
KernelCopyData(OSEffectiveToPhysical((uint32_t) instr), OSEffectiveToPhysical((uint32_t) &replacement), sizeof(replacement));
|
|
|
|
//Only works on AROMA! WUPS 0.1's KernelCopyData is uncached, needs DCInvalidate here instead
|
|
|
|
DCFlushRange(instr, 4);
|
|
|
|
ICInvalidateRange(instr, 4);
|
|
|
|
|
|
|
|
current = *(uint32_t *) instr;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* https://github.com/QuarkTheAwesome/CafeBinPatch/blob/main/src/runtime-patcher.cpp#L74 */
|
|
|
|
bool PatchDynLoadFunctions() {
|
|
|
|
uint32_t *patch1 = ((uint32_t *) &OSDynLoad_GetNumberOfRPLs) + 6;
|
|
|
|
uint32_t *patch2 = ((uint32_t *) &OSDynLoad_GetRPLInfo) + 22;
|
|
|
|
|
|
|
|
if (!PatchInstruction(patch1, 0x41820038 /* beq +38 */, 0x60000000 /*nop*/)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!PatchInstruction(patch2, 0x41820100 /* beq +100 */, 0x60000000 /*nop*/)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-02-08 14:48:41 +01:00
|
|
|
INITIALIZE_PLUGIN() {
|
2022-07-26 19:29:41 +02:00
|
|
|
PatchDynLoadFunctions();
|
2018-09-24 10:43:20 +02:00
|
|
|
}
|
2022-07-26 19:29:41 +02:00
|
|
|
|
2022-02-08 14:48:41 +01:00
|
|
|
ON_APPLICATION_START() {
|
|
|
|
initLogging();
|
2022-07-26 19:29:41 +02:00
|
|
|
DEBUG_FUNCTION_LINE("Hello from Debugger plugin");
|
|
|
|
pThreadList = (OSThread **) 0x100567F8; // 100567f8
|
2022-02-08 14:48:41 +01:00
|
|
|
debugger = new Debugger();
|
2022-07-26 19:29:41 +02:00
|
|
|
DCFlushRange(&debugger, 4);
|
|
|
|
DCFlushRange(debugger, sizeof(Debugger));
|
2022-02-08 14:48:41 +01:00
|
|
|
DEBUG_FUNCTION_LINE("Created Debugger");
|
2022-02-08 14:44:53 +01:00
|
|
|
debugger->start();
|
2022-02-08 14:48:41 +01:00
|
|
|
DEBUG_FUNCTION_LINE("Started Debugger thread");
|
2018-09-24 10:43:20 +02:00
|
|
|
}
|
|
|
|
|
2022-02-08 14:48:41 +01:00
|
|
|
ON_APPLICATION_REQUESTS_EXIT() {
|
|
|
|
DEBUG_FUNCTION_LINE("Deleting Debugger thread");
|
|
|
|
delete debugger;
|
|
|
|
DEBUG_FUNCTION_LINE("Deleted Debugger thread");
|
|
|
|
deinitLogging();
|
2018-09-24 10:43:20 +02:00
|
|
|
}
|
2022-07-26 19:29:41 +02:00
|
|
|
ON_APPLICATION_ENDS() {
|
|
|
|
initDebugState = false;
|
|
|
|
DCFlushRange(&initDebugState, sizeof(initDebugState));
|
|
|
|
}
|