From 6350c309c9129f1acf22293671926ff997a18f4f Mon Sep 17 00:00:00 2001 From: mkwcat Date: Thu, 22 Feb 2024 10:40:50 -0500 Subject: [PATCH] Payload: Add WritePointer patch type --- include/wwfcCommon.h | 8 +++++++- payload/wwfcPatch.cpp | 11 +++++++++++ payload/wwfcPatch.hpp | 10 ++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/include/wwfcCommon.h b/include/wwfcCommon.h index c886460..8e2f132 100644 --- a/include/wwfcCommon.h +++ b/include/wwfcCommon.h @@ -121,13 +121,19 @@ typedef enum { * @param arg1 Temporary register to use for call. */ WWFC_PATCH_TYPE_BRANCH_CTR_LINK = 5, + + /** + * Write a pointer specified in `arg0` to the destination `address`. + * @param arg0 Pointer destination address. + * @param arg1 Not used. + */ + WWFC_PATCH_TYPE_WRITE_POINTER = 6, } wwfc_patch_type; /** * Flags for different patch levels. */ typedef enum { - /** * Critical, used for security patches and other things required to connect * to the server. This has no value and is always automatically applied. diff --git a/payload/wwfcPatch.cpp b/payload/wwfcPatch.cpp index d61f883..79c0d47 100644 --- a/payload/wwfcPatch.cpp +++ b/payload/wwfcPatch.cpp @@ -1,6 +1,7 @@ #include "wwfcPatch.hpp" #include #include +#include namespace wwfc::Patch { @@ -111,6 +112,16 @@ void ApplyPatch(u32 base, wwfc_patch& patch) address[3] = 0x4E800421; flushSize = sizeof(u32) * 4; break; + + /** + * Write a pointer specified in `arg0` to the destination `address`. + * @param arg0 Pointer destination address. + * @param arg1 Not used. + */ + case WWFC_PATCH_TYPE_WRITE_POINTER: + *address = baseArg0; + flushSize = sizeof(u32); + break; } RVL::DCFlushRange(address, flushSize); diff --git a/payload/wwfcPatch.hpp b/payload/wwfcPatch.hpp index e20de05..65c6929 100644 --- a/payload/wwfcPatch.hpp +++ b/payload/wwfcPatch.hpp @@ -37,6 +37,16 @@ constexpr wwfc_patch WriteString(u8 level, u32 address, const char (&string)[N]) }; } +constexpr wwfc_patch WritePointer(u8 level, u32 address, auto pointer) +{ + return wwfc_patch{ + .level = level, + .type = WWFC_PATCH_TYPE_WRITE_POINTER, + .address = address, + .arg0 = u32(+pointer), + }; +} + constexpr wwfc_patch WriteASM(u8 level, u32 address, u32 instructionCount, auto function) {