From 03cedf68e3ccbdd4378b58048c3f19f875a60627 Mon Sep 17 00:00:00 2001 From: mkwcat Date: Wed, 22 Nov 2023 23:12:27 -0500 Subject: [PATCH] Add wiimmfi.de domain to be replaced --- payload/wwfcSupport.cpp | 81 +++++++++++++++++++++++------------------ 1 file changed, 45 insertions(+), 36 deletions(-) diff --git a/payload/wwfcSupport.cpp b/payload/wwfcSupport.cpp index 16c396d..0a94b37 100644 --- a/payload/wwfcSupport.cpp +++ b/payload/wwfcSupport.cpp @@ -14,46 +14,55 @@ WWFC_DEFINE_PATCH = {Patch::Write( (u32[]){AUTH_HANDLERESP_UNPATCH} )}; -static void FixHostname(char* name) +static const char* FixHostname(const char* name, char* out) { + if (std::strlen(name) > 256 - sizeof(WWFC_DOMAIN)) { + // Hostname is too big to replace + return name; + } + for (u32 i = 0; name[i] != '\0'; i++) { - if (std::strncmp( - name + i, "nintendowifi.net", sizeof("nintendowifi.net") - 1 - ) == 0) { - OSReport("[WWFC] Hostname: %s", name); - - // Replace nintendowifi.net with the custom domain - std::memcpy(name + i, WWFC_DOMAIN, sizeof(WWFC_DOMAIN) - 1); - if (sizeof(WWFC_DOMAIN) < sizeof("nintendowifi.net")) { - std::strcpy( - name + i + sizeof(WWFC_DOMAIN) - 1, - name + i + sizeof("nintendowifi.net") - 1 - ); + auto replaceDomain = [&](const char* check, u32 checkSize, + const char* replace, u32 replaceSize) { + if (std::strncmp(name + i, check, checkSize) != 0) { + return false; } - OSReport(" -> %s\n", name); - break; + // Replace with the custom hostname + std::memcpy(out, name, i); + std::memcpy(out + i, replace, replaceSize); + std::strcpy(out + i + replaceSize, name + i + checkSize); + OSReport("[WWFC] Hostname: %s -> %s\n", name, out); + return true; + }; + + // Replace nintendowifi.net with the custom name + if (replaceDomain( + "nintendowifi.net", sizeof("nintendowifi.net") - 1, WWFC_DOMAIN, + sizeof(WWFC_DOMAIN) - 1 + )) { + return out; } - if (std::strncmp(name + i, "gamespy.com", sizeof("gamespy.com") - 1) == - 0) { - OSReport("[WWFC] Hostname: %s", name); - - // Replace gamespy.com with the custom domain - std::memcpy( - name + i, "gs." WWFC_DOMAIN, sizeof("gs." WWFC_DOMAIN) - 1 - ); - if (sizeof("gs." WWFC_DOMAIN) < sizeof("gamespy.com")) { - std::strcpy( - name + i + sizeof("gs." WWFC_DOMAIN) - 1, - name + i + sizeof("gamespy.com") - 1 - ); - } + // Redirect gamespy.com to the "gs" subdomain, required for some games + if (replaceDomain( + "gamespy.com", sizeof("gamespy.com"), "gs." WWFC_DOMAIN, + sizeof("gs." WWFC_DOMAIN) - 1 + )) { + return out; + } - OSReport(" -> %s\n", name); - break; + // WWFC patch over an already Wiimmfi patched game + if (replaceDomain( + "wiimmfi.de", sizeof("wiimmfi.de") - 1, WWFC_DOMAIN, + sizeof(WWFC_DOMAIN) - 1 + )) { + return out; } } + + // No custom hostname + return name; } WWFC_DEFINE_CTR_STUB( // @@ -72,8 +81,8 @@ WWFC_DEFINE_PATCH = {Patch::BranchWithCTR( WWFC_PATCH_LEVEL_SUPPORT, // ADDRESS_gethostbyname, // [](char* name) -> void* { - FixHostname(name); - return gethostbyname(name); + char fixedName[256]; + return gethostbyname(FixHostname(name, fixedName)); } )}; @@ -92,9 +101,9 @@ WWFC_DEFINE_CTR_STUB( // WWFC_DEFINE_PATCH = {Patch::BranchWithCTR( WWFC_PATCH_LEVEL_SUPPORT, // ADDRESS_SOInetAtoN, // - [](char* name, u8* param_2) -> u32 { - FixHostname(name); - return SOInetAtoN(name, param_2); + [](const char* name, u8* param_2) -> u32 { + char fixedName[256]; + return SOInetAtoN(FixHostname(name, fixedName), param_2); } )};