From 494498681424cc8d2cc59b6bb8b90e378e27e5fd Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Tue, 16 Oct 2018 20:41:19 -0700 Subject: [PATCH] fs.mitm: Allow for disabling mitm for a title via flag. --- stratosphere/fs_mitm/source/fsmitm_service.hpp | 3 +++ stratosphere/fs_mitm/source/fsmitm_utils.cpp | 17 +++++++++++++++++ stratosphere/fs_mitm/source/fsmitm_utils.hpp | 1 + 3 files changed, 21 insertions(+) diff --git a/stratosphere/fs_mitm/source/fsmitm_service.hpp b/stratosphere/fs_mitm/source/fsmitm_service.hpp index 5c6de0a97..0dfa441e3 100644 --- a/stratosphere/fs_mitm/source/fsmitm_service.hpp +++ b/stratosphere/fs_mitm/source/fsmitm_service.hpp @@ -38,6 +38,9 @@ class FsMitMService : public IMitMServiceObject { } static bool should_mitm(u64 pid, u64 tid) { + if (Utils::HasSdDisableMitMFlag(tid)) { + return false; + } return (tid >= 0x0100000000010000ULL || Utils::HasSdMitMFlag(tid)) && Utils::HasOverrideButton(tid); } diff --git a/stratosphere/fs_mitm/source/fsmitm_utils.cpp b/stratosphere/fs_mitm/source/fsmitm_utils.cpp index 57363cfe8..f726357c6 100644 --- a/stratosphere/fs_mitm/source/fsmitm_utils.cpp +++ b/stratosphere/fs_mitm/source/fsmitm_utils.cpp @@ -27,6 +27,7 @@ static FsFileSystem g_sd_filesystem = {0}; static std::vector g_mitm_flagged_tids; +static std::vector g_disable_mitm_flagged_tids; static std::atomic_bool g_has_initialized = false; static std::atomic_bool g_has_hid_session = false; @@ -78,6 +79,15 @@ void Utils::InitializeSdThreadFunc(void *args) { 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"); + if (R_SUCCEEDED(fsFsOpenFile(&g_sd_filesystem, title_path, FS_OPEN_READ, &f))) { + g_disable_mitm_flagged_tids.push_back(title_id); + fsFileClose(&f); + } } } fsDirClose(&titles_dir); @@ -217,6 +227,13 @@ bool Utils::HasSdMitMFlag(u64 tid) { return false; } +bool Utils::HasSdDisableMitMFlag(u64 tid) { + if (IsSdInitialized()) { + return std::find(g_disable_mitm_flagged_tids.begin(), g_disable_mitm_flagged_tids.end(), tid) != g_disable_mitm_flagged_tids.end(); + } + return false; +} + Result Utils::GetKeysDown(u64 *keys) { if (!Utils::IsHidInitialized()) { return MAKERESULT(Module_Libnx, LibnxError_InitFail_HID); diff --git a/stratosphere/fs_mitm/source/fsmitm_utils.hpp b/stratosphere/fs_mitm/source/fsmitm_utils.hpp index 54754474c..77b9d20bc 100644 --- a/stratosphere/fs_mitm/source/fsmitm_utils.hpp +++ b/stratosphere/fs_mitm/source/fsmitm_utils.hpp @@ -37,6 +37,7 @@ class Utils { /* SD card Initialization + MitM detection. */ static void InitializeSdThreadFunc(void *args); static bool HasSdMitMFlag(u64 tid); + static bool HasSdDisableMitMFlag(u64 tid); static bool IsHidInitialized();