From bcfac02dd330b3271e92b1aa6f8a8bc26214805c Mon Sep 17 00:00:00 2001 From: wiidev Date: Sun, 1 Aug 2021 18:00:15 +0100 Subject: [PATCH] Return to the loader when exiting homebrew --- data/binary/stub.bin | Bin 3528 -> 4704 bytes source/homebrewboot/BootHomebrew.cpp | 11 +-- source/lstub.cpp | 104 ++++++++++++++++----------- source/lstub.h | 6 +- 4 files changed, 68 insertions(+), 53 deletions(-) diff --git a/data/binary/stub.bin b/data/binary/stub.bin index 63a37a0bd277b8a19ba8bb4fbe170f1dba5e9a91..ecb26b3789217d30aeace4ddd537d085f8759092 100644 GIT binary patch literal 4704 zcmcInZ)_9i8Gp_`%n?jxI)mKCfKwth37L{=Omk+ZIXi|qe^%0A3YDhrG6#)nAc1Jt z3tZxJoJmdTha^tRpN1r8;FTzg&^GPMR%SF*^$XI}u?-4@WN3q_tAsQ*0!g_2o;y1U zDI4s=PWt8bz3=ny{k_lg+?yzoYin#oXCl(0@UkZbv=PA}@@i)EH3VyAAO z^~a4F?X*49pCU0##!RV$DAY-=ffNZFKQaut)0kp;ZSVbz5*N)}G2clXwdUlxxl)m+ zDGA#<9R_Sj{x0$X>tbD(JG5?lMx&xpf1G^qW7>SYyk|~6LS$pV|BKF($*-I9ps>FWz+nAP$8{Q$NdS8qfwD0NQ~Lz|2XTc^;bjXXZoK z)EgPt_ku%r3N}(~qnJE%epsg!d+V|Kpvk4#6R8!hs76Me_;jjnShKsjY)v!HZ>qh% z`6bQbz=^!B;Pv1HQG2~T(^BRn|IL+Ks_RK;FYu2YUB>fURpj_>?h$?jgT70R#%#US zGa!#SyuZf2@$(_ByVs)+$V8RhsKY^WS2w`!`sOiymj{hI?R8sKK5Nb^jtRX*=KQLi z(1n08q9fS#1(PSp4=Q2KA+kQ}2m@&#&XATe3a@8amTGRH4l%1G!n-yNg* z`F&;dEc`tSf4AG4!hdbA0Lr7y8@ksYl8+mA{(~J`-VXb$k!6DIs@{6bH}+}f^};g; z9|GI*$4B&F_5wJ)K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T8&^uLZyawzjFf$kYI^QfOkHQkHm)oU99K9p*AhFIqWLPugJS!dpb(wWP&_t~Uy zR@2;w|LG!mGqUX-#^y1@F>*)HoP8LP+_O^u(pDm0=TUsz&*N(FjU-oAs@r8fc!v9X zxu==6=KT_p>|{6VSo!V?@70<{s%I5ai;s!^gR_b;9df6ssSNLNgdJ3Fk^8sr`P3OiKAD;96o{{bO0B`FVC8|*pa>5 z^ChvxSVCe)d}KS(8u$?V-wpbzE3m0CK+Z1&d%35!hBhKx7ZDrWD>m25;ERkW3A|5HU*pYE#M$2z`4oyfQ6uKOI#)_?uu6F=;qc%lA$??9s;MC4yD*14Ae diff --git a/source/homebrewboot/BootHomebrew.cpp b/source/homebrewboot/BootHomebrew.cpp index c8447995..c34a7738 100644 --- a/source/homebrewboot/BootHomebrew.cpp +++ b/source/homebrewboot/BootHomebrew.cpp @@ -142,16 +142,7 @@ static int RunAppbooter() u64 currentStub = getStubDest(); loadStub(); - - if (Set_Stub_Split(0x00010001, "UNEO") < 0) - { - if (Set_Stub_Split(0x00010001, "ULNR") < 0) - { - if (!currentStub) currentStub = 0x100000002ULL; - - Set_Stub(currentStub); - } - } + Set_Stub(returnTo(currentStub)); gprintf("Exiting USBLoaderGX...\n\n"); diff --git a/source/lstub.cpp b/source/lstub.cpp index 459975ba..5e72886e 100644 --- a/source/lstub.cpp +++ b/source/lstub.cpp @@ -1,4 +1,5 @@ //functions for manipulating the HBC stub by giantpune +//updated by blackb0x August 2021 #include #include @@ -7,78 +8,70 @@ #include "lstub.h" #include "gecko.h" - #include "wad/nandtitle.h" extern const u8 stub_bin[]; extern const u32 stub_bin_size; -static char* determineStubTIDLocation() +static char *determineStubTIDLocation() { - u32 *stubID = (u32*) 0x80001818; + u32 *stubID = (u32 *)0x80001818; - //HBC stub 1.0.6 and lower, and stub.bin - if (stubID[0] == 0x480004c1 && stubID[1] == 0x480004f5) - return (char *) 0x800024C6; + // HBC stub 1.1.4 + if (stubID[0] == 0x548406B0 && stubID[1] == 0x7C800124) + return (char *)0x80002662; + // HBC stub changed @ version 1.0.7. this file was last updated for HBC 1.0.8 + else if (stubID[0] == 0x48000859 && stubID[1] == 0x4800088d) + return (char *)0x8000286A; + // HBC stub 1.0.6 and lower, and stub.bin + else if (stubID[0] == 0x480004c1 && stubID[1] == 0x480004f5) + return (char *)0x800024C6; - //HBC stub changed @ version 1.0.7. this file was last updated for HBC 1.0.8 - else if (stubID[0] == 0x48000859 && stubID[1] == 0x4800088d) return (char *) 0x8000286A; - - //hexdump( stubID, 0x20 ); return NULL; - } s32 Set_Stub(u64 reqID) { - if (NandTitles.IndexOf(reqID) < 0) return WII_EINSTALL; + if (!hbcStubAvailable()) + return 0; + if (NandTitles.IndexOf(reqID) < 0) + return WII_EINSTALL; char *stub = determineStubTIDLocation(); - if (!stub) return -68; + if (!stub) + return 0; - stub[0] = TITLE_7( reqID ); - stub[1] = TITLE_6( reqID ); - stub[8] = TITLE_5( reqID ); - stub[9] = TITLE_4( reqID ); - stub[4] = TITLE_3( reqID ); - stub[5] = TITLE_2( reqID ); - stub[12] = TITLE_1( reqID ); - stub[13] = ((u8) (reqID)); + stub[0] = TITLE_7(reqID); + stub[1] = TITLE_6(reqID); + stub[8] = TITLE_5(reqID); + stub[9] = TITLE_4(reqID); + stub[4] = TITLE_3(reqID); + stub[5] = TITLE_2(reqID); + stub[12] = TITLE_1(reqID); + stub[13] = ((u8)(reqID)); DCFlushRange(stub, 0x10); - return 1; - -} - -s32 Set_Stub_Split(u32 type, const char* reqID) -{ - const u32 lower = ((u32)reqID[0] << 24) | - ((u32)reqID[1] << 16) | - ((u32)reqID[2] << 8) | - ((u32)reqID[3]); - - u64 reqID64 = TITLE_ID( type, lower ); - return Set_Stub(reqID64); - } void loadStub() { - char *stubLoc = (char *) 0x80001800; + char *stubLoc = (char *)0x80001800; memcpy(stubLoc, stub_bin, stub_bin_size); DCFlushRange(stubLoc, stub_bin_size); } u64 getStubDest() { - if (!hbcStubAvailable()) return 0; + if (!hbcStubAvailable()) + return 0; char ret[8]; u64 retu = 0; char *stub = determineStubTIDLocation(); - if (!stub) return 0; + if (!stub) + return 0; ret[0] = stub[0]; ret[1] = stub[1]; @@ -90,13 +83,44 @@ u64 getStubDest() ret[7] = stub[13]; memcpy(&retu, ret, 8); - return retu; } u8 hbcStubAvailable() { - char * sig = (char *) 0x80001804; + char *sig = (char *)0x80001804; return (strncmp(sig, "STUBHAXX", 8) == 0); } +u64 returnTo(u64 currentStub) +{ + // UNEO + if (NandTitles.IndexOf(0x00010001554E454FULL) > 0) + return 0x00010001554E454FULL; + // ULNR + else if (NandTitles.IndexOf(0x00010001554C4E52ULL) > 0) + return 0x00010001554C4E52ULL; + // IDCL + else if (NandTitles.IndexOf(0x000100014944434CULL) > 0) + return 0x000100014944434CULL; + // OHBC + else if (NandTitles.IndexOf(0x000100014F484243ULL) > 0) + return 0x000100014F484243ULL; + // LULZ + else if (NandTitles.IndexOf(0x000100014C554C5AULL) > 0) + return 0x000100014C554C5AULL; + // 1.0.7 + else if (NandTitles.IndexOf(0x00010001AF1BF516ULL) > 0) + return 0x00010001AF1BF516ULL; + // JODI + else if (NandTitles.IndexOf(0x000100014A4F4449ULL) > 0) + return 0x000100014A4F4449ULL; + // HAXX + else if (NandTitles.IndexOf(0x0001000148415858ULL) > 0) + return 0x0001000148415858ULL; + // System menu + else if (!currentStub) + return 0x100000002ULL; + // Current stub + return currentStub; +} diff --git a/source/lstub.h b/source/lstub.h index 978d563f..4314d2bb 100644 --- a/source/lstub.h +++ b/source/lstub.h @@ -11,9 +11,6 @@ //!1 if successful s32 Set_Stub(u64 reqID); -//!same as the above function, but expects a type and 4 char channel ID -s32 Set_Stub_Split(u32 type, const char* reqID); - //load the default HBC stub into memory. as long as nothing writes to the 0x80001800 // +0xDC7 memory block it will stay there. by default it has 0x00010001/JODI. void loadStub(); @@ -26,4 +23,7 @@ u64 getStubDest(); //returns 0 or 1 depending on wether the stub is available u8 hbcStubAvailable(); +//returns a valid title to return to +u64 returnTo(u64 currentStub); + #endif