From 739a5ab46770673faebb30dcf43a29c9252bf04f Mon Sep 17 00:00:00 2001 From: Edoardo Lolletti Date: Sat, 13 Jul 2024 19:46:19 +0200 Subject: [PATCH] Mark launcher's tmd as read only on install --- arm9/src/main.c | 27 +++++++++++++++++++++------ arm9/src/unlaunch.cpp | 12 ++++++------ arm9/src/unlaunch.h | 4 ++-- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/arm9/src/main.c b/arm9/src/main.c index 026f612..42e48af 100644 --- a/arm9/src/main.c +++ b/arm9/src/main.c @@ -273,6 +273,7 @@ int main(int argc, char **argv) //check for unlaunch and region u8 region = 0xff; char retailLauncherTmdPath[64]; + char retailLauncherPath[64]; const char* hnaaTmdPath = "nand:/title/00030017/484e4141/content/title.tmd"; { FILE* file = fopen("nand:/sys/HWINFO_S.dat", "rb"); @@ -296,7 +297,6 @@ int main(int argc, char **argv) } else { - unsigned long long tmdSize = getFileSize(tmd); if (tmdSize > 520) { unlaunchFound = true; @@ -305,15 +305,15 @@ int main(int argc, char **argv) { mainTmdIsPatched = isLauncherTmdPatched(retailLauncherTmdPath); } - fseek(tmd, 0x1E4, SEEK_SET); - unsigned int contentId; - fread(&contentId, sizeof(contentId), 1, tmd); + fseek(tmd, 0x1DC, SEEK_SET); + unsigned short launcherVersion; + fread(&launcherVersion, sizeof(launcherVersion), 1, tmd); // Launcher v4, build v1024 (shipped with firmware 1.4.2 (not sure about J, and 1.4.3 for china) // will fail to launch if another tmd withouth appropriate application, or an invalid // tmd (in our case the one installed from unlaunch) is found in the HNAA launcher folder // there's really no workaround to that, so that specific version is blacklisted and only uninstalling // an "officially" installed unlaunch without leaving any backup behind will be allowed - if(contentId == 0x04000000) + if(launcherVersion == 4) { isLauncherVersionSupported = false; messageBox("\x1B[41mWARNING:\x1B[47m This system version\n" @@ -322,6 +322,18 @@ int main(int argc, char **argv) "unaunch without backups will\n" "be possible"); } + else if (launcherVersion > 7) + { + char messageBoxError[128]; + sprintf(messageBoxError, "\x1B[41mWARNING:\x1B[47m This system version (%d)\n" + "is unknown\n" + "nothing will be done", (int)launcherVersion); + messageBox("\x1B[41mWARNING:\x1B[47m This system version\n" + "is unknown\n" + "nothing will be done"); + goto abort; + } + sprintf(retailLauncherPath, "nand:/title/00030017/%08lx/content/0000000%d.app", launcherTid, (int)launcherVersion); } if(tmd) { @@ -381,7 +393,7 @@ int main(int argc, char **argv) } needsNocashFooterToBeWritten = false; } - if(uninstallUnlaunch(retailConsole, hnaaUnlaunchFound, retailLauncherTmdPath, unsafeUninstall)) + if(uninstallUnlaunch(retailConsole, hnaaUnlaunchFound, retailLauncherTmdPath, retailLauncherPath, unsafeUninstall)) { messageBox("Uninstall successful!\n"); unlaunchFound = false; @@ -477,6 +489,7 @@ int main(int argc, char **argv) } if(installUnlaunch(retailConsole, retailLauncherTmdPresentAndToBePatched ? retailLauncherTmdPath : NULL, + retailLauncherTmdPresentAndToBePatched ? retailLauncherPath : NULL, disableAllPatches, enableSoundAndSplash ? splashSoundBinaryPatchPath : NULL, customBgPath)) @@ -511,6 +524,8 @@ int main(int argc, char **argv) break; } } + + abort: clearScreen(&bottomScreen); printf("Unmounting NAND...\n"); diff --git a/arm9/src/unlaunch.cpp b/arm9/src/unlaunch.cpp index 3cbc5fa..fb6126b 100644 --- a/arm9/src/unlaunch.cpp +++ b/arm9/src/unlaunch.cpp @@ -225,11 +225,11 @@ static bool restoreProtoTmd(const char* path) return true; } -bool uninstallUnlaunch(bool retailConsole, bool hasHNAABackup, const char* retailLauncherTmdPath, bool removeHNAABackup) +bool uninstallUnlaunch(bool retailConsole, bool hasHNAABackup, const char* retailLauncherTmdPath, const char* retailLauncherPath, bool removeHNAABackup) { // TODO: handle retailLauncherTmdPresentAndToBePatched = false on retail consoles if (retailConsole) { - if (!toggleFileReadOnly(retailLauncherTmdPath, false)) + if (!toggleFileReadOnly(retailLauncherTmdPath, false) || !toggleFileReadOnly(retailLauncherPath, false)) { return false; } @@ -312,7 +312,7 @@ static bool writeUnlaunchToHNAAFolder() return true; } -static bool installUnlaunchRetailConsole(const char* retailLauncherTmdPath) +static bool installUnlaunchRetailConsole(const char* retailLauncherTmdPath, const char* retailLauncherPath) { if(!writeUnlaunchToHNAAFolder()) return false; @@ -328,7 +328,7 @@ static bool installUnlaunchRetailConsole(const char* retailLauncherTmdPath) removeHnaaLauncher(); return false; } - if (!toggleFileReadOnly(retailLauncherTmdPath, true)) + if (!toggleFileReadOnly(retailLauncherTmdPath, true) || !toggleFileReadOnly(retailLauncherPath, true)) { messageBox("\x1B[31mError:\x1B[33m Failed to mark default launcher's title.tmd\nas read only, install might be unstable\n"); } @@ -569,7 +569,7 @@ const char* getUnlaunchVersionString(UNLAUNCH_VERSION version) return unlaunchVersionStrings[version]; } -bool installUnlaunch(bool retailConsole, const char* retailLauncherTmdPath, bool disableAllPatches, const char* splashSoundBinaryPatchPath, const char* customBackgroundPath) +bool installUnlaunch(bool retailConsole, const char* retailLauncherTmdPath, const char* retailLauncherPath, bool disableAllPatches, const char* splashSoundBinaryPatchPath, const char* customBackgroundPath) { if (installerVersion == INVALID || !patchUnlaunchInstaller(disableAllPatches, splashSoundBinaryPatchPath, customBackgroundPath)) return false; @@ -580,5 +580,5 @@ bool installUnlaunch(bool retailConsole, const char* retailLauncherTmdPath, bool return installUnlaunchProtoConsole(); } // Do things normally for production units - return installUnlaunchRetailConsole(retailLauncherTmdPath); + return installUnlaunchRetailConsole(retailLauncherTmdPath, retailLauncherPath); } \ No newline at end of file diff --git a/arm9/src/unlaunch.h b/arm9/src/unlaunch.h index c929e59..72108a9 100644 --- a/arm9/src/unlaunch.h +++ b/arm9/src/unlaunch.h @@ -15,8 +15,8 @@ typedef enum UNLAUNCH_VERSION { const char* getUnlaunchVersionString(UNLAUNCH_VERSION); -bool uninstallUnlaunch(bool notProto, bool hasHNAABackup, const char* retailLauncherTmdPath, bool removeHNAABackup); -bool installUnlaunch(bool retailConsole, const char* retailLauncherTmdPath, bool disableAllPatches, const char* splashSoundBinaryPatchPath, const char* customBackgroundPath); +bool uninstallUnlaunch(bool notProto, bool hasHNAABackup, const char* retailLauncherTmdPath, const char* retailLauncherPath, bool removeHNAABackup); +bool installUnlaunch(bool retailConsole, const char* retailLauncherTmdPath, const char* retailLauncherPath, bool disableAllPatches, const char* splashSoundBinaryPatchPath, const char* customBackgroundPath); bool isLauncherTmdPatched(const char* path);