From ae4d29a49ffbec767609fe8e1cc10a38e952fa27 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Thu, 29 Nov 2018 12:30:32 -0800 Subject: [PATCH] fs.mitm: add flag support for writing bis/reading cal0 --- stratosphere/fs_mitm/source/fsmitm_service.cpp | 12 +++++++----- stratosphere/fs_mitm/source/fsmitm_utils.cpp | 12 +++++++++++- stratosphere/fs_mitm/source/fsmitm_utils.hpp | 4 +++- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/stratosphere/fs_mitm/source/fsmitm_service.cpp b/stratosphere/fs_mitm/source/fsmitm_service.cpp index 9897edf6f..0b1e1cf18 100644 --- a/stratosphere/fs_mitm/source/fsmitm_service.cpp +++ b/stratosphere/fs_mitm/source/fsmitm_service.cpp @@ -100,11 +100,13 @@ Result FsMitmService::OpenBisStorage(Out> out rc = fsOpenBisStorageFwd(this->forward_service.get(), &bis_storage, bis_partition_id); if (R_SUCCEEDED(rc)) { const bool is_sysmodule = this->title_id < 0x0100000000001000; + const bool has_bis_write_flag = Utils::HasFlag(this->title_id, "bis_write"); + const bool has_cal0_read_flag = Utils::HasFlag(this->title_id, "cal_read"); if (bis_partition_id == BisStorageId_Boot0) { storage = std::make_shared(new Boot0Storage(bis_storage, this->title_id)); } else if (bis_partition_id == BisStorageId_Prodinfo) { /* PRODINFO should *never* be writable. */ - if (is_sysmodule) { + if (is_sysmodule || has_cal0_read_flag) { storage = std::make_shared(new ROProxyStorage(bis_storage)); } else { /* Do not allow non-sysmodules to read *or* write CAL0. */ @@ -112,12 +114,12 @@ Result FsMitmService::OpenBisStorage(Out> out return 0x320002; } } else { - if (!is_sysmodule) { - /* Non-sysmodules should be allowed to read. */ - storage = std::make_shared(new ROProxyStorage(bis_storage)); - } else { + if (is_sysmodule || has_bis_write_flag) { /* Sysmodules should still be allowed to read and write. */ storage = std::make_shared(new ProxyStorage(bis_storage)); + } else { + /* Non-sysmodules should be allowed to read. */ + storage = std::make_shared(new ROProxyStorage(bis_storage)); } } if (out_storage.IsDomain()) { diff --git a/stratosphere/fs_mitm/source/fsmitm_utils.cpp b/stratosphere/fs_mitm/source/fsmitm_utils.cpp index e692bdc5b..c1683eda9 100644 --- a/stratosphere/fs_mitm/source/fsmitm_utils.cpp +++ b/stratosphere/fs_mitm/source/fsmitm_utils.cpp @@ -346,7 +346,7 @@ Result Utils::SaveSdFileForAtmosphere(u64 title_id, const char *fn, void *data, return rc; } -bool Utils::HasFlag(u64 tid, const char *flag) { +bool Utils::HasTitleFlag(u64 tid, const char *flag) { if (IsSdInitialized()) { FsFile f; char flag_path[FS_MAX_PATH]; @@ -381,6 +381,16 @@ bool Utils::HasGlobalFlag(const char *flag) { return false; } +bool Utils::HasHblFlag(const char *flag) { + char hbl_flag[FS_MAX_PATH] = {0}; + snprintf(hbl_flag, sizeof(hbl_flag), "hbl_%s", flag); + return HasGlobalFlag(hbl_flag); +} + +bool Utils::HasFlag(u64 tid, const char *flag) { + return HasTitleFlag(tid, flag) || (tid == g_override_hbl_tid && HasHblFlag(flag)); +} + bool Utils::HasSdMitMFlag(u64 tid) { if (tid == g_override_hbl_tid) { return true; diff --git a/stratosphere/fs_mitm/source/fsmitm_utils.hpp b/stratosphere/fs_mitm/source/fsmitm_utils.hpp index 71efe768b..0811c1f7e 100644 --- a/stratosphere/fs_mitm/source/fsmitm_utils.hpp +++ b/stratosphere/fs_mitm/source/fsmitm_utils.hpp @@ -58,8 +58,10 @@ class Utils { /* SD card Initialization + MitM detection. */ static void InitializeSdThreadFunc(void *args); - static bool HasFlag(u64 tid, const char *flag); + static bool HasTitleFlag(u64 tid, const char *flag); + static bool HasHblFlag(const char *flag); static bool HasGlobalFlag(const char *flag); + static bool HasFlag(u64 tid, const char *flag); static bool HasSdMitMFlag(u64 tid); static bool HasSdDisableMitMFlag(u64 tid);