2019-04-12 22:28:46 +00:00
|
|
|
/*
|
2020-01-24 10:10:40 +00:00
|
|
|
* Copyright (c) 2018-2020 Atmosphère-NX
|
2019-04-12 22:28:46 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2019-06-20 20:00:32 +00:00
|
|
|
|
2019-04-12 22:28:46 +00:00
|
|
|
#pragma once
|
|
|
|
#include <stratosphere.hpp>
|
2019-12-06 07:41:33 +00:00
|
|
|
#include <stratosphere/fssrv/fssrv_interface_adapters.hpp>
|
2019-04-12 22:28:46 +00:00
|
|
|
|
2019-11-21 07:58:18 +00:00
|
|
|
namespace ams::mitm::fs {
|
2019-04-12 22:28:46 +00:00
|
|
|
|
2019-12-06 07:41:33 +00:00
|
|
|
using IStorageInterface = ams::fssrv::impl::StorageInterfaceAdapter;
|
|
|
|
using IFileSystemInterface = ams::fssrv::impl::FileSystemInterfaceAdapter;
|
|
|
|
|
2019-11-28 09:28:20 +00:00
|
|
|
/* TODO: Consider re-enabling the mitm flag logic. */
|
|
|
|
|
2019-11-21 07:58:18 +00:00
|
|
|
class FsMitmService : public sf::IMitmServiceObject {
|
|
|
|
private:
|
|
|
|
enum class CommandId {
|
2019-11-28 09:28:20 +00:00
|
|
|
OpenFileSystemDeprecated = 0,
|
|
|
|
|
|
|
|
SetCurrentProcess = 1,
|
|
|
|
OpenFileSystemWithPatch = 7,
|
|
|
|
OpenFileSystemWithId = 8,
|
|
|
|
|
|
|
|
OpenSdCardFileSystem = 18,
|
|
|
|
|
|
|
|
OpenSaveDataFileSystem = 51,
|
|
|
|
|
|
|
|
OpenBisStorage = 12,
|
|
|
|
OpenDataStorageByCurrentProcess = 200,
|
|
|
|
OpenDataStorageByDataId = 202,
|
2019-11-21 07:58:18 +00:00
|
|
|
};
|
|
|
|
public:
|
2019-12-31 09:57:26 +00:00
|
|
|
NX_CONSTEXPR bool ShouldMitmProgramId(const ncm::ProgramId program_id) {
|
|
|
|
/* We want to mitm everything that isn't a system-module. */
|
|
|
|
if (!ncm::IsSystemProgramId(program_id)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We want to mitm ns, to intercept SD card requests. */
|
2020-03-08 08:06:23 +00:00
|
|
|
if (program_id == ncm::SystemProgramId::Ns) {
|
2019-12-31 09:57:26 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We want to mitm sdb, to support sd-romfs redirection of common system archives (like system font, etc). */
|
2020-03-08 08:06:23 +00:00
|
|
|
if (program_id == ncm::SystemProgramId::Sdb) {
|
2019-12-31 09:57:26 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-11-21 12:03:19 +00:00
|
|
|
static bool ShouldMitm(const sm::MitmProcessInfo &client_info) {
|
2019-11-28 09:28:20 +00:00
|
|
|
static std::atomic_bool has_launched_qlaunch = false;
|
|
|
|
|
|
|
|
/* TODO: intercepting everything seems to cause issues with sleep mode, for some reason. */
|
|
|
|
/* Figure out why, and address it. */
|
|
|
|
/* TODO: This may be because pre-rewrite code really mismanaged domain objects in a way that would cause bad things. */
|
|
|
|
/* Need to verify if this is fixed now. */
|
2020-03-08 08:06:23 +00:00
|
|
|
if (client_info.program_id == ncm::SystemAppletId::Qlaunch || client_info.program_id == ncm::SystemAppletId::MaintenanceMenu) {
|
2019-11-28 09:28:20 +00:00
|
|
|
has_launched_qlaunch = true;
|
|
|
|
}
|
|
|
|
|
2019-12-31 09:57:26 +00:00
|
|
|
return has_launched_qlaunch || ShouldMitmProgramId(client_info.program_id);
|
2019-11-21 07:58:18 +00:00
|
|
|
}
|
|
|
|
public:
|
|
|
|
SF_MITM_SERVICE_OBJECT_CTOR(FsMitmService) { /* ... */ }
|
|
|
|
protected:
|
2019-11-28 09:28:20 +00:00
|
|
|
/* Overridden commands. */
|
2019-12-07 12:30:26 +00:00
|
|
|
Result OpenFileSystemWithPatch(sf::Out<std::shared_ptr<IFileSystemInterface>> out, ncm::ProgramId program_id, u32 _filesystem_type);
|
|
|
|
Result OpenFileSystemWithId(sf::Out<std::shared_ptr<IFileSystemInterface>> out, const fssrv::sf::Path &path, ncm::ProgramId program_id, u32 _filesystem_type);
|
2019-12-06 07:41:33 +00:00
|
|
|
Result OpenSdCardFileSystem(sf::Out<std::shared_ptr<IFileSystemInterface>> out);
|
2020-03-25 00:50:36 +00:00
|
|
|
Result OpenSaveDataFileSystem(sf::Out<std::shared_ptr<IFileSystemInterface>> out, u8 space_id, const ams::fs::SaveDataAttribute &attribute);
|
2019-11-28 09:28:20 +00:00
|
|
|
Result OpenBisStorage(sf::Out<std::shared_ptr<IStorageInterface>> out, u32 bis_partition_id);
|
2019-12-04 14:53:52 +00:00
|
|
|
Result OpenDataStorageByCurrentProcess(sf::Out<std::shared_ptr<IStorageInterface>> out);
|
2020-03-08 08:06:23 +00:00
|
|
|
Result OpenDataStorageByDataId(sf::Out<std::shared_ptr<IStorageInterface>> out, ncm::DataId data_id, u8 storage_id);
|
2019-11-21 07:58:18 +00:00
|
|
|
public:
|
|
|
|
DEFINE_SERVICE_DISPATCH_TABLE {
|
2019-12-07 12:30:26 +00:00
|
|
|
MAKE_SERVICE_COMMAND_META(OpenFileSystemWithPatch, hos::Version_200),
|
|
|
|
MAKE_SERVICE_COMMAND_META(OpenFileSystemWithId, hos::Version_200),
|
2019-12-06 07:41:33 +00:00
|
|
|
MAKE_SERVICE_COMMAND_META(OpenSdCardFileSystem),
|
2019-12-07 07:19:48 +00:00
|
|
|
MAKE_SERVICE_COMMAND_META(OpenSaveDataFileSystem),
|
2019-11-28 09:28:20 +00:00
|
|
|
MAKE_SERVICE_COMMAND_META(OpenBisStorage),
|
2019-12-04 14:53:52 +00:00
|
|
|
MAKE_SERVICE_COMMAND_META(OpenDataStorageByCurrentProcess),
|
|
|
|
MAKE_SERVICE_COMMAND_META(OpenDataStorageByDataId),
|
2019-11-21 07:58:18 +00:00
|
|
|
};
|
2019-06-28 06:34:26 +00:00
|
|
|
};
|
2019-11-21 07:58:18 +00:00
|
|
|
|
|
|
|
}
|