From 420361597ec60c0fc6f584c9ad37ae456555ea0a Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Thu, 15 Nov 2018 04:26:40 -0800 Subject: [PATCH] all: Change flagging location. Support (but deprecate) old location. --- Makefile | 3 +- stratosphere/fs_mitm/source/fsmitm_utils.cpp | 71 +++++++++++++++++++- stratosphere/fs_mitm/source/fsmitm_utils.hpp | 4 ++ stratosphere/pm/source/pm_boot2.cpp | 13 +++- 4 files changed, 86 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 7eeab49b6..dd524d27e 100644 --- a/Makefile +++ b/Makefile @@ -46,7 +46,8 @@ dist: all cp common/defaults/loader.ini atmosphere-$(AMSVER)/atmosphere/loader.ini cp stratosphere/creport/creport.nsp atmosphere-$(AMSVER)/atmosphere/titles/0100000000000036/exefs.nsp cp stratosphere/set_mitm/set_mitm.nsp atmosphere-$(AMSVER)/atmosphere/titles/0100000000000032/exefs.nsp - touch atmosphere-$(AMSVER)/atmosphere/titles/0100000000000032/boot2.flag + mkdir -p atmosphere-$(AMSVER)/atmosphere/titles/0100000000000032/flags + touch atmosphere-$(AMSVER)/atmosphere/titles/0100000000000032/flags/boot2.flag cd atmosphere-$(AMSVER); zip -r ../atmosphere-$(AMSVER).zip ./*; cd ../; rm -r atmosphere-$(AMSVER) mkdir out diff --git a/stratosphere/fs_mitm/source/fsmitm_utils.cpp b/stratosphere/fs_mitm/source/fsmitm_utils.cpp index 32e37fad6..9ebffae0b 100644 --- a/stratosphere/fs_mitm/source/fsmitm_utils.cpp +++ b/stratosphere/fs_mitm/source/fsmitm_utils.cpp @@ -31,6 +31,7 @@ static std::atomic_bool g_has_initialized = false; static std::atomic_bool g_has_hid_session = false; static u64 g_override_key_combination = KEY_R; +static u64 g_override_hbl_tid = 0x010000000000100DULL; static bool g_override_by_default = true; /* Static buffer for loader.ini contents at runtime. */ @@ -76,19 +77,39 @@ void Utils::InitializeSdThreadFunc(void *args) { char title_path[FS_MAX_PATH] = {0}; strcpy(title_path, "/atmosphere/titles/"); strcat(title_path, dir_entry.name); - strcat(title_path, "/fsmitm.flag"); + strcat(title_path, "/flags/fsmitm.flag"); if (R_SUCCEEDED(fsFsOpenFile(&g_sd_filesystem, title_path, FS_OPEN_READ, &f))) { g_mitm_flagged_tids.push_back(title_id); fsFileClose(&f); + } else { + /* TODO: Deprecate. */ + memset(title_path, 0, sizeof(title_path)); + strcpy(title_path, "/atmosphere/titles/"); + strcat(title_path, dir_entry.name); + strcat(title_path, "/fsmitm.flag"); + if (R_SUCCEEDED(fsFsOpenFile(&g_sd_filesystem, title_path, FS_OPEN_READ, &f))) { + g_mitm_flagged_tids.push_back(title_id); + fsFileClose(&f); + } } memset(title_path, 0, sizeof(title_path)); strcpy(title_path, "/atmosphere/titles/"); strcat(title_path, dir_entry.name); - strcat(title_path, "/fsmitm_disable.flag"); + strcat(title_path, "/flags/fsmitm_disable.flag"); if (R_SUCCEEDED(fsFsOpenFile(&g_sd_filesystem, title_path, FS_OPEN_READ, &f))) { g_disable_mitm_flagged_tids.push_back(title_id); fsFileClose(&f); + } else { + /* TODO: Deprecate. */ + memset(title_path, 0, sizeof(title_path)); + strcpy(title_path, "/atmosphere/titles/"); + strcat(title_path, dir_entry.name); + strcat(title_path, "/fsmitm_disable.flag"); + if (R_SUCCEEDED(fsFsOpenFile(&g_sd_filesystem, title_path, FS_OPEN_READ, &f))) { + g_disable_mitm_flagged_tids.push_back(title_id); + fsFileClose(&f); + } } } } @@ -264,7 +285,46 @@ Result Utils::SaveSdFileForAtmosphere(u64 title_id, const char *fn, void *data, return rc; } +bool Utils::HasFlag(u64 tid, const char *flag) { + if (IsSdInitialized()) { + FsFile f; + char flag_path[FS_MAX_PATH]; + + memset(flag_path, 0, sizeof(flag_path)); + snprintf(flag_path, sizeof(flag_path) - 1, "flags/%s.flag", flag); + if (OpenSdFileForAtmosphere(tid, flag_path, FS_OPEN_READ, &f)) { + fsFileClose(&f); + return true; + } + + /* TODO: Deprecate. */ + snprintf(flag_path, sizeof(flag_path) - 1, "%s.flag", flag); + if (OpenSdFileForAtmosphere(tid, flag_path, FS_OPEN_READ, &f)) { + fsFileClose(&f); + return true; + } + } + return false; +} + +bool Utils::HasGlobalFlag(u64 tid, const char *flag) { + if (IsSdInitialized()) { + FsFile f; + char flag_path[FS_MAX_PATH] = {0}; + snprintf(flag_path, sizeof(flag_path), "/atmosphere/flags/%s.flag", flag); + if (fsFsOpenFile(&g_sd_filesystem, flag_path, FS_OPEN_READ, &f)) { + fsFileClose(&f); + return true; + } + } + return false; +} + bool Utils::HasSdMitMFlag(u64 tid) { + if (tid == g_override_hbl_tid) { + return true; + } + if (IsSdInitialized()) { return std::find(g_mitm_flagged_tids.begin(), g_mitm_flagged_tids.end(), tid) != g_mitm_flagged_tids.end(); } @@ -306,7 +366,12 @@ bool Utils::HasOverrideButton(u64 tid) { static int FsMitMIniHandler(void *user, const char *section, const char *name, const char *value) { /* Taken and modified, with love, from Rajkosto's implementation. */ if (strcasecmp(section, "config") == 0) { - if (strcasecmp(name, "override_key") == 0) { + if (strcasecmp(name, "hbl_tid") == 0) { + u64 override_tid = strtoul(value, NULL, 16); + if (override_tid != 0) { + g_override_hbl_tid = override_tid; + } + } else if (strcasecmp(name, "override_key") == 0) { if (value[0] == '!') { g_override_by_default = true; value++; diff --git a/stratosphere/fs_mitm/source/fsmitm_utils.hpp b/stratosphere/fs_mitm/source/fsmitm_utils.hpp index ad8d176b1..a730d44d6 100644 --- a/stratosphere/fs_mitm/source/fsmitm_utils.hpp +++ b/stratosphere/fs_mitm/source/fsmitm_utils.hpp @@ -38,6 +38,10 @@ class Utils { /* SD card Initialization + MitM detection. */ static void InitializeSdThreadFunc(void *args); + + static bool HasFlag(u64 tid, const char *flag); + static bool HasGlobalFlag(const char *flag); + static bool HasSdMitMFlag(u64 tid); static bool HasSdDisableMitMFlag(u64 tid); diff --git a/stratosphere/pm/source/pm_boot2.cpp b/stratosphere/pm/source/pm_boot2.cpp index 3a6844621..78eddd963 100644 --- a/stratosphere/pm/source/pm_boot2.cpp +++ b/stratosphere/pm/source/pm_boot2.cpp @@ -163,11 +163,22 @@ void EmbeddedBoot2::Main() { char title_path[FS_MAX_PATH] = {0}; strcpy(title_path, "sdmc:/atmosphere/titles/"); strcat(title_path, ent->d_name); - strcat(title_path, "/boot2.flag"); + strcat(title_path, "/flags/boot2.flag"); FILE *f_flag = fopen(title_path, "rb"); if (f_flag != NULL) { fclose(f_flag); LaunchTitle((Boot2KnownTitleId)title_id, FsStorageId_None, 0, NULL); + } else { + /* TODO: Deprecate this in the future. */ + memset(title_path, 0, FS_MAX_PATH); + strcpy(title_path, "sdmc:/atmosphere/titles/"); + strcat(title_path, ent->d_name); + strcat(title_path, "/boot2.flag"); + f_flag = fopen(title_path, "rb"); + if (f_flag != NULL) { + fclose(f_flag); + LaunchTitle((Boot2KnownTitleId)title_id, FsStorageId_None, 0, NULL); + } } } }