From 9d5ca47ac8a2afe2fc1f2f67d460efc96bb15902 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Fri, 22 Mar 2019 12:38:23 -0700 Subject: [PATCH] fs.mitm: Add Hbl Web override support, also support choinx" --- .../source/fs_mitm/fsmitm_service.cpp | 52 +++++++++++++++++++ .../source/fs_mitm/fsmitm_service.hpp | 17 +++++- 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/stratosphere/ams_mitm/source/fs_mitm/fsmitm_service.cpp b/stratosphere/ams_mitm/source/fs_mitm/fsmitm_service.cpp index 0732c0652..fa09cc202 100644 --- a/stratosphere/ams_mitm/source/fs_mitm/fsmitm_service.cpp +++ b/stratosphere/ams_mitm/source/fs_mitm/fsmitm_service.cpp @@ -82,6 +82,53 @@ void FsMitmService::PostProcess(IMitmServiceObject *obj, IpcResponseContext *ctx } } +Result FsMitmService::OpenHblWebContentFileSystem(Out> &out_fs) { + std::shared_ptr fs = nullptr; + u32 out_domain_id = 0; + Result rc = 0; + + ON_SCOPE_EXIT { + if (R_SUCCEEDED(rc)) { + out_fs.SetValue(std::move(fs)); + if (out_fs.IsDomain()) { + out_fs.ChangeObjectId(out_domain_id); + } + } + }; + + /* Mount the SD card using fs.mitm's session. */ + FsFileSystem sd_fs; + rc = fsMountSdcard(&sd_fs); + if (R_SUCCEEDED(rc)) { + fs = std::make_shared(std::make_unique(std::make_shared(sd_fs), AtmosphereHblWebContentDir)); + if (out_fs.IsDomain()) { + out_domain_id = sd_fs.s.object_id; + } + } + + return rc; +} + +Result FsMitmService::OpenFileSystemWithPatch(Out> out_fs, u64 title_id, u32 filesystem_type) { + FsDir d; + if (filesystem_type != FsFileSystemType_ContentManual || !Utils::IsHblTid(title_id) || R_FAILED(Utils::OpenSdDir(AtmosphereHblWebContentDir, &d))) { + return RESULT_FORWARD_TO_SESSION; + } + fsDirClose(&d); + + return this->OpenHblWebContentFileSystem(out_fs); +} + +Result FsMitmService::OpenFileSystemWithId(Out> out_fs, InPointer path, u64 title_id, u32 filesystem_type) { + FsDir d; + if (filesystem_type != FsFileSystemType_ContentManual || !Utils::IsHblTid(title_id) || R_FAILED(Utils::OpenSdDir(AtmosphereHblWebContentDir, &d))) { + return RESULT_FORWARD_TO_SESSION; + } + fsDirClose(&d); + + return this->OpenHblWebContentFileSystem(out_fs); +} + /* Gate access to the BIS partitions. */ Result FsMitmService::OpenBisStorage(Out> out_storage, u32 bis_partition_id) { std::shared_ptr storage = nullptr; @@ -119,6 +166,11 @@ Result FsMitmService::OpenBisStorage(Out> out 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 if (Utils::IsHblTid(this->title_id) && (BisStorageId_BcPkg2_1 <= bis_partition_id && bis_partition_id <= BisStorageId_BcPkg2_6)) { + /* Allow HBL to write to package2. */ + /* This is needed to not break compatibility with ChoiDujourNX, which does not check error codes. */ + /* TODO: get fixed so that this can be turned off without causing bricks :/ */ + storage = std::make_shared(new ProxyStorage(bis_storage)); } else { /* Non-sysmodules should be allowed to read. */ storage = std::make_shared(new ROProxyStorage(bis_storage)); diff --git a/stratosphere/ams_mitm/source/fs_mitm/fsmitm_service.hpp b/stratosphere/ams_mitm/source/fs_mitm/fsmitm_service.hpp index c7cd6ed54..f7cbad84b 100644 --- a/stratosphere/ams_mitm/source/fs_mitm/fsmitm_service.hpp +++ b/stratosphere/ams_mitm/source/fs_mitm/fsmitm_service.hpp @@ -18,16 +18,25 @@ #include #include #include "fs_istorage.hpp" +#include "fs_ifilesystem.hpp" #include "../utils.hpp" enum FspSrvCmd : u32 { + FspSrvCmd_OpenFileSystemDeprecated = 0, + FspSrvCmd_SetCurrentProcess = 1, + + FspSrvCmd_OpenFileSystemWithPatch = 7, + FspSrvCmd_OpenFileSystemWithId = 8, + FspSrvCmd_OpenBisStorage = 12, FspSrvCmd_OpenDataStorageByCurrentProcess = 200, FspSrvCmd_OpenDataStorageByDataId = 202, }; class FsMitmService : public IMitmServiceObject { + private: + static constexpr const char *AtmosphereHblWebContentDir = "/atmosphere/hbl_html"; private: bool has_initialized = false; bool should_override_contents; @@ -58,14 +67,20 @@ class FsMitmService : public IMitmServiceObject { } static void PostProcess(IMitmServiceObject *obj, IpcResponseContext *ctx); - + private: + Result OpenHblWebContentFileSystem(Out> &out); protected: /* Overridden commands. */ + Result OpenFileSystemWithPatch(Out> out, u64 title_id, u32 filesystem_type); + Result OpenFileSystemWithId(Out> out, InPointer path, u64 title_id, u32 filesystem_type); Result OpenBisStorage(Out> out, u32 bis_partition_id); Result OpenDataStorageByCurrentProcess(Out> out); Result OpenDataStorageByDataId(Out> out, u64 data_id, u8 storage_id); public: DEFINE_SERVICE_DISPATCH_TABLE { + /* TODO MakeServiceCommandMeta(), */ + MakeServiceCommandMeta(), + MakeServiceCommandMeta(), MakeServiceCommandMeta(), MakeServiceCommandMeta(), MakeServiceCommandMeta(),