mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2024-12-22 20:31:14 +00:00
fs.mitm: experimental support for save redirection to sd.
This commit is contained in:
parent
fb5e02050b
commit
938169cd3c
15 changed files with 434 additions and 66 deletions
|
@ -15,4 +15,10 @@ dmnt_cheats_enabled_by_default = u8!0x1
|
||||||
; Controls whether dmnt should always save cheat toggle state
|
; Controls whether dmnt should always save cheat toggle state
|
||||||
; for restoration on new game launch. 1 = always save toggles,
|
; for restoration on new game launch. 1 = always save toggles,
|
||||||
; 0 = only save toggles if toggle file exists.
|
; 0 = only save toggles if toggle file exists.
|
||||||
dmnt_always_save_cheat_toggles = u8!0x0
|
dmnt_always_save_cheat_toggles = u8!0x0
|
||||||
|
; Controls whether fs.mitm should redirect save files
|
||||||
|
; to directories on the sd card.
|
||||||
|
; 0 = Do not redirect, 1 = Redirect.
|
||||||
|
; NOTE: EXPERIMENTAL
|
||||||
|
; If you do not know what you are doing, do not touch this yet.
|
||||||
|
fsmitm_redirect_saves_to_sd = u8!0x0
|
|
@ -60,20 +60,20 @@ Result FsDirUtils::CopyFile(IFileSystem *dst_fs, IFileSystem *src_fs, const FsPa
|
||||||
|
|
||||||
offset += read_size;
|
offset += read_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ResultSuccess;
|
return ResultSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result FsDirUtils::CopyDirectoryRecursively(IFileSystem *dst_fs, IFileSystem *src_fs, const FsPath &dst_path, const FsPath &src_path, void *work_buf, size_t work_buf_size) {
|
Result FsDirUtils::CopyDirectoryRecursively(IFileSystem *dst_fs, IFileSystem *src_fs, const FsPath &dst_path, const FsPath &src_path, void *work_buf, size_t work_buf_size) {
|
||||||
FsPath work_path = dst_path;
|
FsPath work_path = dst_path;
|
||||||
|
|
||||||
return IterateDirectoryRecursively(src_fs, src_path,
|
return IterateDirectoryRecursively(src_fs, src_path,
|
||||||
[&](const FsPath &path, const FsDirectoryEntry *dir_ent) -> Result { /* On Enter Directory */
|
[&](const FsPath &path, const FsDirectoryEntry *dir_ent) -> Result { /* On Enter Directory */
|
||||||
/* Update path, create new dir. */
|
/* Update path, create new dir. */
|
||||||
strncat(work_path.str, dir_ent->name, sizeof(work_path) - strnlen(work_path.str, sizeof(work_path) - 1) - 1);
|
strncat(work_path.str, dir_ent->name, sizeof(work_path) - strnlen(work_path.str, sizeof(work_path) - 1) - 1);
|
||||||
strncat(work_path.str, "/", sizeof(work_path) - strnlen(work_path.str, sizeof(work_path) - 1) - 1);
|
strncat(work_path.str, "/", sizeof(work_path) - strnlen(work_path.str, sizeof(work_path) - 1) - 1);
|
||||||
return dst_fs->CreateDirectory(work_path);
|
return dst_fs->CreateDirectory(work_path);
|
||||||
},
|
},
|
||||||
[&](const FsPath &path, const FsDirectoryEntry *dir_ent) -> Result { /* On Exit Directory */
|
[&](const FsPath &path, const FsDirectoryEntry *dir_ent) -> Result { /* On Exit Directory */
|
||||||
/* Check we have a parent directory. */
|
/* Check we have a parent directory. */
|
||||||
const size_t work_path_len = strnlen(work_path.str, sizeof(work_path));
|
const size_t work_path_len = strnlen(work_path.str, sizeof(work_path));
|
||||||
|
@ -89,9 +89,45 @@ Result FsDirUtils::CopyDirectoryRecursively(IFileSystem *dst_fs, IFileSystem *sr
|
||||||
p[1] = 0;
|
p[1] = 0;
|
||||||
|
|
||||||
return ResultSuccess;
|
return ResultSuccess;
|
||||||
},
|
},
|
||||||
[&](const FsPath &path, const FsDirectoryEntry *dir_ent) -> Result { /* On File */
|
[&](const FsPath &path, const FsDirectoryEntry *dir_ent) -> Result { /* On File */
|
||||||
/* Just copy the file to the new fs. */
|
/* Just copy the file to the new fs. */
|
||||||
return CopyFile(dst_fs, src_fs, work_path, path, dir_ent, work_buf, work_buf_size);
|
return CopyFile(dst_fs, src_fs, work_path, path, dir_ent, work_buf, work_buf_size);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Result FsDirUtils::EnsureDirectoryExists(IFileSystem *fs, const FsPath &path) {
|
||||||
|
FsPath normal_path;
|
||||||
|
size_t normal_path_len;
|
||||||
|
Result rc;
|
||||||
|
|
||||||
|
/* Normalize the path. */
|
||||||
|
if (R_FAILED((rc = FsPathUtils::Normalize(normal_path.str, sizeof(normal_path.str) - 1, path.str, &normal_path_len)))) {
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Repeatedly call CreateDirectory on each directory leading to the target. */
|
||||||
|
for (size_t i = 1; i < normal_path_len; i++) {
|
||||||
|
/* If we detect a separator, we're done. */
|
||||||
|
if (normal_path.str[i] == '/') {
|
||||||
|
normal_path.str[i] = 0;
|
||||||
|
{
|
||||||
|
rc = fs->CreateDirectory(normal_path);
|
||||||
|
if (rc == ResultFsPathAlreadyExists) {
|
||||||
|
rc = ResultSuccess;
|
||||||
|
}
|
||||||
|
if (R_FAILED(rc)) {
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
normal_path.str[i] = '/';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Call CreateDirectory on the final path. */
|
||||||
|
rc = fs->CreateDirectory(normal_path);
|
||||||
|
if (rc == ResultFsPathAlreadyExists) {
|
||||||
|
rc = ResultSuccess;
|
||||||
|
}
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
|
@ -132,6 +132,9 @@ class FsDirUtils {
|
||||||
static Result CopyDirectoryRecursively(IFileSystem *fs, const FsPath &dst_path, const FsPath &src_path, void *work_buf, size_t work_buf_size) {
|
static Result CopyDirectoryRecursively(IFileSystem *fs, const FsPath &dst_path, const FsPath &src_path, void *work_buf, size_t work_buf_size) {
|
||||||
return CopyDirectoryRecursively(fs, fs, dst_path, src_path, work_buf, work_buf_size);
|
return CopyDirectoryRecursively(fs, fs, dst_path, src_path, work_buf, work_buf_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Ensure directory existence. */
|
||||||
|
static Result EnsureDirectoryExists(IFileSystem *fs, const FsPath &path);
|
||||||
|
|
||||||
/* Other Utility. */
|
/* Other Utility. */
|
||||||
template<typename F>
|
template<typename F>
|
||||||
|
|
|
@ -166,6 +166,27 @@ void DirectorySaveDataFileSystem::OnWritableFileClose() {
|
||||||
/* TODO: Abort if < 0? N does not. */
|
/* TODO: Abort if < 0? N does not. */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Result DirectorySaveDataFileSystem::CopySaveFromProxy() {
|
||||||
|
if (this->proxy_save_fs != nullptr) {
|
||||||
|
Result rc;
|
||||||
|
|
||||||
|
/* Get a buffer to work with. */
|
||||||
|
void *work_buf = nullptr;
|
||||||
|
size_t work_buf_size = 0;
|
||||||
|
if (R_FAILED((rc = this->AllocateWorkBuffer(&work_buf, &work_buf_size, IdealWorkBuffersize)))) {
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
ON_SCOPE_EXIT { free(work_buf); };
|
||||||
|
|
||||||
|
rc = FsDirUtils::CopyDirectoryRecursively(this, this->proxy_save_fs.get(), FsPathUtils::RootPath, FsPathUtils::RootPath, work_buf, work_buf_size);
|
||||||
|
if (R_FAILED(rc)) {
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
return this->Commit();
|
||||||
|
}
|
||||||
|
return ResultSuccess;
|
||||||
|
}
|
||||||
|
|
||||||
/* ================================================================================================ */
|
/* ================================================================================================ */
|
||||||
|
|
||||||
Result DirectorySaveDataFileSystem::CreateFileImpl(const FsPath &path, uint64_t size, int flags) {
|
Result DirectorySaveDataFileSystem::CreateFileImpl(const FsPath &path, uint64_t size, int flags) {
|
||||||
|
|
|
@ -35,12 +35,13 @@ class DirectorySaveDataFileSystem : public IFileSystem {
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<IFileSystem> shared_fs;
|
std::shared_ptr<IFileSystem> shared_fs;
|
||||||
std::unique_ptr<IFileSystem> unique_fs;
|
std::unique_ptr<IFileSystem> unique_fs;
|
||||||
|
std::unique_ptr<IFileSystem> proxy_save_fs;
|
||||||
IFileSystem *fs;
|
IFileSystem *fs;
|
||||||
HosMutex lock;
|
HosMutex lock;
|
||||||
size_t open_writable_files = 0;
|
size_t open_writable_files = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
DirectorySaveDataFileSystem(IFileSystem *fs) : unique_fs(fs) {
|
DirectorySaveDataFileSystem(IFileSystem *fs, std::unique_ptr<IFileSystem> pfs) : unique_fs(fs), proxy_save_fs(std::move(pfs)) {
|
||||||
this->fs = this->unique_fs.get();
|
this->fs = this->unique_fs.get();
|
||||||
Result rc = this->Initialize();
|
Result rc = this->Initialize();
|
||||||
if (R_FAILED(rc)) {
|
if (R_FAILED(rc)) {
|
||||||
|
@ -48,7 +49,7 @@ class DirectorySaveDataFileSystem : public IFileSystem {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DirectorySaveDataFileSystem(std::unique_ptr<IFileSystem> fs) : unique_fs(std::move(fs)) {
|
DirectorySaveDataFileSystem(std::unique_ptr<IFileSystem> fs, std::unique_ptr<IFileSystem> pfs) : unique_fs(std::move(fs)), proxy_save_fs(std::move(pfs)) {
|
||||||
this->fs = this->unique_fs.get();
|
this->fs = this->unique_fs.get();
|
||||||
Result rc = this->Initialize();
|
Result rc = this->Initialize();
|
||||||
if (R_FAILED(rc)) {
|
if (R_FAILED(rc)) {
|
||||||
|
@ -56,7 +57,7 @@ class DirectorySaveDataFileSystem : public IFileSystem {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DirectorySaveDataFileSystem(std::shared_ptr<IFileSystem> fs) : shared_fs(fs) {
|
DirectorySaveDataFileSystem(std::shared_ptr<IFileSystem> fs, std::unique_ptr<IFileSystem> pfs) : shared_fs(fs), proxy_save_fs(std::move(pfs)) {
|
||||||
this->fs = this->shared_fs.get();
|
this->fs = this->shared_fs.get();
|
||||||
Result rc = this->Initialize();
|
Result rc = this->Initialize();
|
||||||
if (R_FAILED(rc)) {
|
if (R_FAILED(rc)) {
|
||||||
|
@ -64,7 +65,6 @@ class DirectorySaveDataFileSystem : public IFileSystem {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
virtual ~DirectorySaveDataFileSystem() { }
|
virtual ~DirectorySaveDataFileSystem() { }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -79,6 +79,7 @@ class DirectorySaveDataFileSystem : public IFileSystem {
|
||||||
}
|
}
|
||||||
public:
|
public:
|
||||||
void OnWritableFileClose();
|
void OnWritableFileClose();
|
||||||
|
Result CopySaveFromProxy();
|
||||||
public:
|
public:
|
||||||
virtual Result CreateFileImpl(const FsPath &path, uint64_t size, int flags) override;
|
virtual Result CreateFileImpl(const FsPath &path, uint64_t size, int flags) override;
|
||||||
virtual Result DeleteFileImpl(const FsPath &path) override;
|
virtual Result DeleteFileImpl(const FsPath &path) override;
|
||||||
|
|
|
@ -198,13 +198,18 @@ class IFileSystem {
|
||||||
|
|
||||||
class IFileSystemInterface : public IServiceObject {
|
class IFileSystemInterface : public IServiceObject {
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<IFileSystem> base_fs;
|
std::unique_ptr<IFileSystem> unique_fs;
|
||||||
|
std::shared_ptr<IFileSystem> shared_fs;
|
||||||
|
IFileSystem *base_fs;
|
||||||
public:
|
public:
|
||||||
IFileSystemInterface(IFileSystem *fs) : base_fs(fs) {
|
IFileSystemInterface(IFileSystem *fs) : unique_fs(fs) {
|
||||||
/* ... */
|
this->base_fs = this->unique_fs.get();
|
||||||
};
|
};
|
||||||
IFileSystemInterface(std::unique_ptr<IFileSystem> fs) : base_fs(std::move(fs)) {
|
IFileSystemInterface(std::unique_ptr<IFileSystem> fs) : unique_fs(std::move(fs)) {
|
||||||
/* ... */
|
this->base_fs = this->unique_fs.get();
|
||||||
|
};
|
||||||
|
IFileSystemInterface(std::shared_ptr<IFileSystem> fs) : shared_fs(fs) {
|
||||||
|
this->base_fs = this->shared_fs.get();
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
127
stratosphere/ams_mitm/source/fs_mitm/fs_save_utils.cpp
Normal file
127
stratosphere/ams_mitm/source/fs_mitm/fs_save_utils.cpp
Normal file
|
@ -0,0 +1,127 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2018 Atmosphère-NX
|
||||||
|
*
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
#include <cstring>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <switch.h>
|
||||||
|
|
||||||
|
#include "fs_save_utils.hpp"
|
||||||
|
|
||||||
|
Result FsSaveUtils::GetSaveDataSpaceIdString(const char **out_str, u8 space_id) {
|
||||||
|
const char *str = nullptr;
|
||||||
|
|
||||||
|
switch (space_id) {
|
||||||
|
case FsSaveDataSpaceId_NandSystem:
|
||||||
|
case 100: /* ProperSystem */
|
||||||
|
case 101: /* SafeMode */
|
||||||
|
str = "sys";
|
||||||
|
break;
|
||||||
|
case FsSaveDataSpaceId_NandUser:
|
||||||
|
str = "user";
|
||||||
|
break;
|
||||||
|
case FsSaveDataSpaceId_SdCard:
|
||||||
|
str = "sd_sys";
|
||||||
|
break;
|
||||||
|
case FsSaveDataSpaceId_TemporaryStorage:
|
||||||
|
str = "temp";
|
||||||
|
break;
|
||||||
|
case 4: /* SdUser */
|
||||||
|
str = "sd_user";
|
||||||
|
break;
|
||||||
|
default: /* Unexpected */
|
||||||
|
str = nullptr;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (str == nullptr) {
|
||||||
|
return ResultFsInvalidSaveDataSpaceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (out_str) {
|
||||||
|
*out_str = str;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ResultSuccess;
|
||||||
|
}
|
||||||
|
|
||||||
|
Result FsSaveUtils::GetSaveDataTypeString(const char **out_str, u8 save_data_type) {
|
||||||
|
const char *str = nullptr;
|
||||||
|
|
||||||
|
switch (save_data_type) {
|
||||||
|
case FsSaveDataType_SystemSaveData:
|
||||||
|
str = "system";
|
||||||
|
break;
|
||||||
|
case FsSaveDataType_SaveData:
|
||||||
|
str = "account";
|
||||||
|
break;
|
||||||
|
case FsSaveDataType_BcatDeliveryCacheStorage:
|
||||||
|
str = "bcat";
|
||||||
|
break;
|
||||||
|
case FsSaveDataType_DeviceSaveData:
|
||||||
|
str = "device";
|
||||||
|
break;
|
||||||
|
case FsSaveDataType_TemporaryStorage:
|
||||||
|
str = "temp";
|
||||||
|
break;
|
||||||
|
case FsSaveDataType_CacheStorage:
|
||||||
|
str = "cache";
|
||||||
|
break;
|
||||||
|
case 6: /* System Bcat Save */
|
||||||
|
str = "bcat_sys";
|
||||||
|
break;
|
||||||
|
default: /* Unexpected */
|
||||||
|
str = nullptr;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (str == nullptr) {
|
||||||
|
/* TODO: Better result? */
|
||||||
|
return ResultFsInvalidArgument;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (out_str) {
|
||||||
|
*out_str = str;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ResultSuccess;
|
||||||
|
}
|
||||||
|
|
||||||
|
Result FsSaveUtils::GetSaveDataDirectoryPath(FsPath &out_path, u8 space_id, u8 save_data_type, u64 title_id, u128 user_id, u64 save_id) {
|
||||||
|
const char *space_id_str, *save_type_str;
|
||||||
|
Result rc;
|
||||||
|
|
||||||
|
/* Get space_id, save_data_type strings. */
|
||||||
|
if (R_FAILED((rc = GetSaveDataSpaceIdString(&space_id_str, space_id))) || R_FAILED((rc = GetSaveDataTypeString(&save_type_str, save_data_type)))) {
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Clear and initialize the path. */
|
||||||
|
std::memset(&out_path, 0, sizeof(out_path));
|
||||||
|
const bool is_system = (save_id != 0 && user_id == 0);
|
||||||
|
size_t out_path_len;
|
||||||
|
if (is_system) {
|
||||||
|
out_path_len = static_cast<size_t>(snprintf(out_path.str, sizeof(out_path.str), "/atmosphere/saves/sysnand/%s/%s/%016lx",
|
||||||
|
space_id_str, save_type_str, save_id));
|
||||||
|
} else {
|
||||||
|
out_path_len = static_cast<size_t>(snprintf(out_path.str, sizeof(out_path.str), "/atmosphere/saves/sysnand/%s/%s/%016lx/%016lx%016lx",
|
||||||
|
space_id_str, save_type_str, title_id, static_cast<u64>(user_id >> 64ul), static_cast<u64>(user_id)));
|
||||||
|
}
|
||||||
|
if (out_path_len >= sizeof(out_path)) {
|
||||||
|
/* TODO: Should we abort here? */
|
||||||
|
return ResultFsTooLongPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ResultSuccess;
|
||||||
|
}
|
29
stratosphere/ams_mitm/source/fs_mitm/fs_save_utils.hpp
Normal file
29
stratosphere/ams_mitm/source/fs_mitm/fs_save_utils.hpp
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2018 Atmosphère-NX
|
||||||
|
*
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
#include <switch.h>
|
||||||
|
|
||||||
|
#include "fs_path_utils.hpp"
|
||||||
|
#include "fs_ifilesystem.hpp"
|
||||||
|
|
||||||
|
class FsSaveUtils {
|
||||||
|
private:
|
||||||
|
static Result GetSaveDataSpaceIdString(const char **out_str, u8 space_id);
|
||||||
|
static Result GetSaveDataTypeString(const char **out_str, u8 save_data_type);
|
||||||
|
public:
|
||||||
|
static Result GetSaveDataDirectoryPath(FsPath &out_path, u8 space_id, u8 save_data_type, u64 title_id, u128 user_id, u64 save_id);
|
||||||
|
};
|
|
@ -225,6 +225,46 @@ Result fsOpenFileSystemWithIdFwd(Service* s, FsFileSystem* out, u64 titleId, FsF
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Result fsOpenSaveDataFileSystemFwd(Service *s, FsFileSystem* out, u8 inval, FsSave *save) {
|
||||||
|
IpcCommand c;
|
||||||
|
ipcInitialize(&c);
|
||||||
|
|
||||||
|
struct {
|
||||||
|
u64 magic;
|
||||||
|
u64 cmd_id;
|
||||||
|
u64 inval;//Actually u8.
|
||||||
|
FsSave save;
|
||||||
|
} PACKED *raw;
|
||||||
|
|
||||||
|
raw = serviceIpcPrepareHeader(s, &c, sizeof(*raw));
|
||||||
|
|
||||||
|
raw->magic = SFCI_MAGIC;
|
||||||
|
raw->cmd_id = 51;
|
||||||
|
raw->inval = (u64)inval;
|
||||||
|
memcpy(&raw->save, save, sizeof(FsSave));
|
||||||
|
|
||||||
|
Result rc = serviceIpcDispatch(s);
|
||||||
|
|
||||||
|
if (R_SUCCEEDED(rc)) {
|
||||||
|
IpcParsedCommand r;
|
||||||
|
struct {
|
||||||
|
u64 magic;
|
||||||
|
u64 result;
|
||||||
|
} *resp;
|
||||||
|
|
||||||
|
serviceIpcParse(s, &r, sizeof(*resp));
|
||||||
|
resp = r.Raw;
|
||||||
|
|
||||||
|
rc = resp->result;
|
||||||
|
|
||||||
|
if (R_SUCCEEDED(rc)) {
|
||||||
|
serviceCreateSubservice(&out->s, s, &r, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
/* Missing FS File commands. */
|
/* Missing FS File commands. */
|
||||||
Result fsFileOperateRange(FsFile* f, u32 op_id, u64 off, u64 len, FsRangeInfo *out) {
|
Result fsFileOperateRange(FsFile* f, u32 op_id, u64 off, u64 len, FsRangeInfo *out) {
|
||||||
IpcCommand c;
|
IpcCommand c;
|
||||||
|
|
|
@ -22,6 +22,7 @@ Result fsOpenDataStorageByCurrentProcessFwd(Service* s, FsStorage* out);
|
||||||
Result fsOpenDataStorageByDataIdFwd(Service* s, FsStorageId storage_id, u64 data_id, FsStorage* out);
|
Result fsOpenDataStorageByDataIdFwd(Service* s, FsStorageId storage_id, u64 data_id, FsStorage* out);
|
||||||
Result fsOpenFileSystemWithPatchFwd(Service* s, FsFileSystem* out, u64 titleId, FsFileSystemType fsType);
|
Result fsOpenFileSystemWithPatchFwd(Service* s, FsFileSystem* out, u64 titleId, FsFileSystemType fsType);
|
||||||
Result fsOpenFileSystemWithIdFwd(Service* s, FsFileSystem* out, u64 titleId, FsFileSystemType fsType, const char* contentPath);
|
Result fsOpenFileSystemWithIdFwd(Service* s, FsFileSystem* out, u64 titleId, FsFileSystemType fsType, const char* contentPath);
|
||||||
|
Result fsOpenSaveDataFileSystemFwd(Service* s, FsFileSystem* out, u8 inval, FsSave *save);
|
||||||
|
|
||||||
/* Missing FS File commands. */
|
/* Missing FS File commands. */
|
||||||
Result fsFileOperateRange(FsFile* f, u32 op_id, u64 off, u64 len, FsRangeInfo *out);
|
Result fsFileOperateRange(FsFile* f, u32 op_id, u64 off, u64 len, FsRangeInfo *out);
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
@ -28,6 +28,8 @@
|
||||||
#include "fsmitm_romstorage.hpp"
|
#include "fsmitm_romstorage.hpp"
|
||||||
#include "fsmitm_layeredrom.hpp"
|
#include "fsmitm_layeredrom.hpp"
|
||||||
|
|
||||||
|
#include "fs_dir_utils.hpp"
|
||||||
|
#include "fs_save_utils.hpp"
|
||||||
#include "fs_subdirectory_filesystem.hpp"
|
#include "fs_subdirectory_filesystem.hpp"
|
||||||
#include "fs_directory_savedata_filesystem.hpp"
|
#include "fs_directory_savedata_filesystem.hpp"
|
||||||
|
|
||||||
|
@ -41,7 +43,7 @@ static bool StorageCacheGetEntry(u64 title_id, std::shared_ptr<IStorageInterface
|
||||||
if (g_StorageCache.find(title_id) == g_StorageCache.end()) {
|
if (g_StorageCache.find(title_id) == g_StorageCache.end()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto intf = g_StorageCache[title_id].lock();
|
auto intf = g_StorageCache[title_id].lock();
|
||||||
if (intf != nullptr) {
|
if (intf != nullptr) {
|
||||||
*out = intf;
|
*out = intf;
|
||||||
|
@ -52,7 +54,7 @@ static bool StorageCacheGetEntry(u64 title_id, std::shared_ptr<IStorageInterface
|
||||||
|
|
||||||
static void StorageCacheSetEntry(u64 title_id, std::shared_ptr<IStorageInterface> *ptr) {
|
static void StorageCacheSetEntry(u64 title_id, std::shared_ptr<IStorageInterface> *ptr) {
|
||||||
std::scoped_lock<HosMutex> lock(g_StorageCacheLock);
|
std::scoped_lock<HosMutex> lock(g_StorageCacheLock);
|
||||||
|
|
||||||
/* Ensure we always use the cached copy if present. */
|
/* Ensure we always use the cached copy if present. */
|
||||||
if (g_StorageCache.find(title_id) != g_StorageCache.end()) {
|
if (g_StorageCache.find(title_id) != g_StorageCache.end()) {
|
||||||
auto intf = g_StorageCache[title_id].lock();
|
auto intf = g_StorageCache[title_id].lock();
|
||||||
|
@ -60,7 +62,7 @@ static void StorageCacheSetEntry(u64 title_id, std::shared_ptr<IStorageInterface
|
||||||
*ptr = intf;
|
*ptr = intf;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g_StorageCache[title_id] = *ptr;
|
g_StorageCache[title_id] = *ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,7 +89,7 @@ Result FsMitmService::OpenHblWebContentFileSystem(Out<std::shared_ptr<IFileSyste
|
||||||
std::shared_ptr<IFileSystemInterface> fs = nullptr;
|
std::shared_ptr<IFileSystemInterface> fs = nullptr;
|
||||||
u32 out_domain_id = 0;
|
u32 out_domain_id = 0;
|
||||||
Result rc = ResultSuccess;
|
Result rc = ResultSuccess;
|
||||||
|
|
||||||
ON_SCOPE_EXIT {
|
ON_SCOPE_EXIT {
|
||||||
if (R_SUCCEEDED(rc)) {
|
if (R_SUCCEEDED(rc)) {
|
||||||
out_fs.SetValue(std::move(fs));
|
out_fs.SetValue(std::move(fs));
|
||||||
|
@ -96,12 +98,13 @@ Result FsMitmService::OpenHblWebContentFileSystem(Out<std::shared_ptr<IFileSyste
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Mount the SD card using fs.mitm's session. */
|
/* Mount the SD card using fs.mitm's session. */
|
||||||
FsFileSystem sd_fs;
|
FsFileSystem sd_fs;
|
||||||
rc = fsMountSdcard(&sd_fs);
|
rc = fsMountSdcard(&sd_fs);
|
||||||
if (R_SUCCEEDED(rc)) {
|
if (R_SUCCEEDED(rc)) {
|
||||||
fs = std::make_shared<IFileSystemInterface>(std::make_unique<SubDirectoryFileSystem>(std::make_shared<ProxyFileSystem>(sd_fs), AtmosphereHblWebContentDir));
|
std::unique_ptr<IFileSystem> web_ifs = std::make_unique<SubDirectoryFileSystem>(std::make_shared<ProxyFileSystem>(sd_fs), AtmosphereHblWebContentDir);
|
||||||
|
fs = std::make_shared<IFileSystemInterface>(std::move(web_ifs));
|
||||||
if (out_fs.IsDomain()) {
|
if (out_fs.IsDomain()) {
|
||||||
out_domain_id = sd_fs.s.object_id;
|
out_domain_id = sd_fs.s.object_id;
|
||||||
}
|
}
|
||||||
|
@ -130,7 +133,7 @@ Result FsMitmService::OpenFileSystemWithPatch(Out<std::shared_ptr<IFileSystemInt
|
||||||
return ResultAtmosphereMitmShouldForwardToSession;
|
return ResultAtmosphereMitmShouldForwardToSession;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return this->OpenHblWebContentFileSystem(out_fs);
|
return this->OpenHblWebContentFileSystem(out_fs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,7 +141,7 @@ Result FsMitmService::OpenFileSystemWithId(Out<std::shared_ptr<IFileSystemInterf
|
||||||
/* Check for eligibility. */
|
/* Check for eligibility. */
|
||||||
{
|
{
|
||||||
FsDir d;
|
FsDir d;
|
||||||
if (!Utils::IsWebAppletTid(this->title_id) || filesystem_type != FsFileSystemType_ContentManual || !Utils::IsHblTid(title_id) ||
|
if (!Utils::IsWebAppletTid(this->title_id) || filesystem_type != FsFileSystemType_ContentManual || !Utils::IsHblTid(title_id) ||
|
||||||
R_FAILED(Utils::OpenSdDir(AtmosphereHblWebContentDir, &d))) {
|
R_FAILED(Utils::OpenSdDir(AtmosphereHblWebContentDir, &d))) {
|
||||||
return ResultAtmosphereMitmShouldForwardToSession;
|
return ResultAtmosphereMitmShouldForwardToSession;
|
||||||
}
|
}
|
||||||
|
@ -158,12 +161,90 @@ Result FsMitmService::OpenFileSystemWithId(Out<std::shared_ptr<IFileSystemInterf
|
||||||
return this->OpenHblWebContentFileSystem(out_fs);
|
return this->OpenHblWebContentFileSystem(out_fs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Result FsMitmService::OpenSaveDataFileSystem(Out<std::shared_ptr<IFileSystemInterface>> out_fs, u8 space_id, FsSave save_struct) {
|
||||||
|
bool should_redirect_saves = false;
|
||||||
|
if (R_FAILED(Utils::GetSettingsItemBooleanValue("atmosphere", "fsmitm_redirect_saves_to_sd", &should_redirect_saves))) {
|
||||||
|
return ResultAtmosphereMitmShouldForwardToSession;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* For now, until we're sure this is robust, only intercept normal savedata. */
|
||||||
|
if (!should_redirect_saves || save_struct.SaveDataType != FsSaveDataType_SaveData) {
|
||||||
|
return ResultAtmosphereMitmShouldForwardToSession;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Verify we can open the save. */
|
||||||
|
FsFileSystem save_fs;
|
||||||
|
if (R_FAILED(fsOpenSaveDataFileSystemFwd(this->forward_service.get(), &save_fs, space_id, &save_struct))) {
|
||||||
|
return ResultAtmosphereMitmShouldForwardToSession;
|
||||||
|
}
|
||||||
|
std::unique_ptr<IFileSystem> save_ifs = std::make_unique<ProxyFileSystem>(save_fs);
|
||||||
|
|
||||||
|
{
|
||||||
|
std::shared_ptr<IFileSystemInterface> fs = nullptr;
|
||||||
|
u32 out_domain_id = 0;
|
||||||
|
Result rc = ResultSuccess;
|
||||||
|
|
||||||
|
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;
|
||||||
|
if (R_FAILED((rc = fsMountSdcard(&sd_fs)))) {
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
std::shared_ptr<IFileSystem> sd_ifs = std::make_shared<ProxyFileSystem>(sd_fs);
|
||||||
|
|
||||||
|
|
||||||
|
/* Verify that we can open the save directory, and that it exists. */
|
||||||
|
const u64 target_tid = save_struct.titleID == 0 ? this->title_id : save_struct.titleID;
|
||||||
|
FsPath save_dir_path;
|
||||||
|
if (R_FAILED((rc = FsSaveUtils::GetSaveDataDirectoryPath(save_dir_path, space_id, save_struct.SaveDataType, target_tid, save_struct.userID, save_struct.saveID)))) {
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check if this is the first time we're making the save. */
|
||||||
|
bool is_new_save = false;
|
||||||
|
{
|
||||||
|
DirectoryEntryType ent;
|
||||||
|
if (sd_ifs->GetEntryType(&ent, save_dir_path) == ResultFsPathNotFound) {
|
||||||
|
is_new_save = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Ensure the directory exists. */
|
||||||
|
if (R_FAILED((rc = FsDirUtils::EnsureDirectoryExists(sd_ifs.get(), save_dir_path)))) {
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<DirectorySaveDataFileSystem> dirsave_ifs = std::make_shared<DirectorySaveDataFileSystem>(new SubDirectoryFileSystem(sd_ifs, save_dir_path.str), std::move(save_ifs));
|
||||||
|
|
||||||
|
/* If it's the first time we're making the save, copy existing savedata over. */
|
||||||
|
if (is_new_save) {
|
||||||
|
/* TODO: Check error? */
|
||||||
|
dirsave_ifs->CopySaveFromProxy();
|
||||||
|
}
|
||||||
|
|
||||||
|
fs = std::make_shared<IFileSystemInterface>(static_cast<std::shared_ptr<IFileSystem>>(dirsave_ifs));
|
||||||
|
if (out_fs.IsDomain()) {
|
||||||
|
out_domain_id = sd_fs.s.object_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Gate access to the BIS partitions. */
|
/* Gate access to the BIS partitions. */
|
||||||
Result FsMitmService::OpenBisStorage(Out<std::shared_ptr<IStorageInterface>> out_storage, u32 bis_partition_id) {
|
Result FsMitmService::OpenBisStorage(Out<std::shared_ptr<IStorageInterface>> out_storage, u32 bis_partition_id) {
|
||||||
std::shared_ptr<IStorageInterface> storage = nullptr;
|
std::shared_ptr<IStorageInterface> storage = nullptr;
|
||||||
u32 out_domain_id = 0;
|
u32 out_domain_id = 0;
|
||||||
Result rc = ResultSuccess;
|
Result rc = ResultSuccess;
|
||||||
|
|
||||||
ON_SCOPE_EXIT {
|
ON_SCOPE_EXIT {
|
||||||
if (R_SUCCEEDED(rc)) {
|
if (R_SUCCEEDED(rc)) {
|
||||||
out_storage.SetValue(std::move(storage));
|
out_storage.SetValue(std::move(storage));
|
||||||
|
@ -172,7 +253,7 @@ Result FsMitmService::OpenBisStorage(Out<std::shared_ptr<IStorageInterface>> out
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
{
|
{
|
||||||
FsStorage bis_storage;
|
FsStorage bis_storage;
|
||||||
rc = fsOpenBisStorageFwd(this->forward_service.get(), &bis_storage, bis_partition_id);
|
rc = fsOpenBisStorageFwd(this->forward_service.get(), &bis_storage, bis_partition_id);
|
||||||
|
@ -195,7 +276,7 @@ Result FsMitmService::OpenBisStorage(Out<std::shared_ptr<IStorageInterface>> out
|
||||||
if (is_sysmodule || has_bis_write_flag) {
|
if (is_sysmodule || has_bis_write_flag) {
|
||||||
/* Sysmodules should still be allowed to read and write. */
|
/* Sysmodules should still be allowed to read and write. */
|
||||||
storage = std::make_shared<IStorageInterface>(new ProxyStorage(bis_storage));
|
storage = std::make_shared<IStorageInterface>(new ProxyStorage(bis_storage));
|
||||||
} else if (Utils::IsHblTid(this->title_id) &&
|
} else if (Utils::IsHblTid(this->title_id) &&
|
||||||
((BisStorageId_BcPkg2_1 <= bis_partition_id && bis_partition_id <= BisStorageId_BcPkg2_6) || bis_partition_id == BisStorageId_Boot1)) {
|
((BisStorageId_BcPkg2_1 <= bis_partition_id && bis_partition_id <= BisStorageId_BcPkg2_6) || bis_partition_id == BisStorageId_Boot1)) {
|
||||||
/* Allow HBL to write to boot1 (safe firm) + package2. */
|
/* Allow HBL to write to boot1 (safe firm) + package2. */
|
||||||
/* This is needed to not break compatibility with ChoiDujourNX, which does not check for write access before beginning an update. */
|
/* This is needed to not break compatibility with ChoiDujourNX, which does not check for write access before beginning an update. */
|
||||||
|
@ -211,7 +292,7 @@ Result FsMitmService::OpenBisStorage(Out<std::shared_ptr<IStorageInterface>> out
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -220,27 +301,27 @@ Result FsMitmService::OpenDataStorageByCurrentProcess(Out<std::shared_ptr<IStora
|
||||||
std::shared_ptr<IStorageInterface> storage = nullptr;
|
std::shared_ptr<IStorageInterface> storage = nullptr;
|
||||||
u32 out_domain_id = 0;
|
u32 out_domain_id = 0;
|
||||||
Result rc = ResultSuccess;
|
Result rc = ResultSuccess;
|
||||||
|
|
||||||
if (!this->should_override_contents) {
|
if (!this->should_override_contents) {
|
||||||
return ResultAtmosphereMitmShouldForwardToSession;
|
return ResultAtmosphereMitmShouldForwardToSession;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool has_cache = StorageCacheGetEntry(this->title_id, &storage);
|
bool has_cache = StorageCacheGetEntry(this->title_id, &storage);
|
||||||
|
|
||||||
ON_SCOPE_EXIT {
|
ON_SCOPE_EXIT {
|
||||||
if (R_SUCCEEDED(rc)) {
|
if (R_SUCCEEDED(rc)) {
|
||||||
if (!has_cache) {
|
if (!has_cache) {
|
||||||
StorageCacheSetEntry(this->title_id, &storage);
|
StorageCacheSetEntry(this->title_id, &storage);
|
||||||
}
|
}
|
||||||
|
|
||||||
out_storage.SetValue(std::move(storage));
|
out_storage.SetValue(std::move(storage));
|
||||||
if (out_storage.IsDomain()) {
|
if (out_storage.IsDomain()) {
|
||||||
out_storage.ChangeObjectId(out_domain_id);
|
out_storage.ChangeObjectId(out_domain_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
if (has_cache) {
|
if (has_cache) {
|
||||||
if (out_storage.IsDomain()) {
|
if (out_storage.IsDomain()) {
|
||||||
FsStorage s = {0};
|
FsStorage s = {0};
|
||||||
|
@ -257,7 +338,7 @@ Result FsMitmService::OpenDataStorageByCurrentProcess(Out<std::shared_ptr<IStora
|
||||||
} else {
|
} else {
|
||||||
FsStorage data_storage;
|
FsStorage data_storage;
|
||||||
FsFile data_file;
|
FsFile data_file;
|
||||||
|
|
||||||
rc = fsOpenDataStorageByCurrentProcessFwd(this->forward_service.get(), &data_storage);
|
rc = fsOpenDataStorageByCurrentProcessFwd(this->forward_service.get(), &data_storage);
|
||||||
|
|
||||||
Log(armGetTls(), 0x100);
|
Log(armGetTls(), 0x100);
|
||||||
|
@ -279,7 +360,7 @@ Result FsMitmService::OpenDataStorageByCurrentProcess(Out<std::shared_ptr<IStora
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,30 +369,30 @@ Result FsMitmService::OpenDataStorageByDataId(Out<std::shared_ptr<IStorageInterf
|
||||||
FsStorageId storage_id = (FsStorageId)sid;
|
FsStorageId storage_id = (FsStorageId)sid;
|
||||||
FsStorage data_storage;
|
FsStorage data_storage;
|
||||||
FsFile data_file;
|
FsFile data_file;
|
||||||
|
|
||||||
if (!this->should_override_contents) {
|
if (!this->should_override_contents) {
|
||||||
return ResultAtmosphereMitmShouldForwardToSession;
|
return ResultAtmosphereMitmShouldForwardToSession;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<IStorageInterface> storage = nullptr;
|
std::shared_ptr<IStorageInterface> storage = nullptr;
|
||||||
u32 out_domain_id = 0;
|
u32 out_domain_id = 0;
|
||||||
Result rc = ResultSuccess;
|
Result rc = ResultSuccess;
|
||||||
|
|
||||||
bool has_cache = StorageCacheGetEntry(data_id, &storage);
|
bool has_cache = StorageCacheGetEntry(data_id, &storage);
|
||||||
|
|
||||||
ON_SCOPE_EXIT {
|
ON_SCOPE_EXIT {
|
||||||
if (R_SUCCEEDED(rc)) {
|
if (R_SUCCEEDED(rc)) {
|
||||||
if (!has_cache) {
|
if (!has_cache) {
|
||||||
StorageCacheSetEntry(data_id, &storage);
|
StorageCacheSetEntry(data_id, &storage);
|
||||||
}
|
}
|
||||||
|
|
||||||
out_storage.SetValue(std::move(storage));
|
out_storage.SetValue(std::move(storage));
|
||||||
if (out_storage.IsDomain()) {
|
if (out_storage.IsDomain()) {
|
||||||
out_storage.ChangeObjectId(out_domain_id);
|
out_storage.ChangeObjectId(out_domain_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (has_cache) {
|
if (has_cache) {
|
||||||
if (out_storage.IsDomain()) {
|
if (out_storage.IsDomain()) {
|
||||||
FsStorage s = {0};
|
FsStorage s = {0};
|
||||||
|
@ -346,6 +427,6 @@ Result FsMitmService::OpenDataStorageByDataId(Out<std::shared_ptr<IStorageInterf
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
|
@ -13,7 +13,7 @@
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <switch.h>
|
#include <switch.h>
|
||||||
#include <stratosphere.hpp>
|
#include <stratosphere.hpp>
|
||||||
|
@ -23,12 +23,14 @@
|
||||||
|
|
||||||
enum FspSrvCmd : u32 {
|
enum FspSrvCmd : u32 {
|
||||||
FspSrvCmd_OpenFileSystemDeprecated = 0,
|
FspSrvCmd_OpenFileSystemDeprecated = 0,
|
||||||
|
|
||||||
FspSrvCmd_SetCurrentProcess = 1,
|
FspSrvCmd_SetCurrentProcess = 1,
|
||||||
|
|
||||||
FspSrvCmd_OpenFileSystemWithPatch = 7,
|
FspSrvCmd_OpenFileSystemWithPatch = 7,
|
||||||
FspSrvCmd_OpenFileSystemWithId = 8,
|
FspSrvCmd_OpenFileSystemWithId = 8,
|
||||||
|
|
||||||
|
FspSrvCmd_OpenSaveDataFileSystem = 51,
|
||||||
|
|
||||||
FspSrvCmd_OpenBisStorage = 12,
|
FspSrvCmd_OpenBisStorage = 12,
|
||||||
FspSrvCmd_OpenDataStorageByCurrentProcess = 200,
|
FspSrvCmd_OpenDataStorageByCurrentProcess = 200,
|
||||||
FspSrvCmd_OpenDataStorageByDataId = 202,
|
FspSrvCmd_OpenDataStorageByDataId = 202,
|
||||||
|
@ -48,13 +50,13 @@ class FsMitmService : public IMitmServiceObject {
|
||||||
this->should_override_contents = (this->title_id >= TitleId_ApplicationStart || Utils::HasSdMitMFlag(this->title_id)) && Utils::HasOverrideButton(this->title_id);
|
this->should_override_contents = (this->title_id >= TitleId_ApplicationStart || Utils::HasSdMitMFlag(this->title_id)) && Utils::HasOverrideButton(this->title_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool ShouldMitm(u64 pid, u64 tid) {
|
static bool ShouldMitm(u64 pid, u64 tid) {
|
||||||
/* Don't Mitm KIPs */
|
/* Don't Mitm KIPs */
|
||||||
if (pid < 0x50) {
|
if (pid < 0x50) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::atomic_bool has_launched_qlaunch = false;
|
static std::atomic_bool has_launched_qlaunch = false;
|
||||||
|
|
||||||
/* TODO: intercepting everything seems to cause issues with sleep mode, for some reason. */
|
/* TODO: intercepting everything seems to cause issues with sleep mode, for some reason. */
|
||||||
|
@ -62,10 +64,10 @@ class FsMitmService : public IMitmServiceObject {
|
||||||
if (tid == TitleId_AppletQlaunch) {
|
if (tid == TitleId_AppletQlaunch) {
|
||||||
has_launched_qlaunch = true;
|
has_launched_qlaunch = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return has_launched_qlaunch || tid == TitleId_Ns || tid >= TitleId_ApplicationStart || Utils::HasSdMitMFlag(tid);
|
return has_launched_qlaunch || tid == TitleId_Ns || tid >= TitleId_ApplicationStart || Utils::HasSdMitMFlag(tid);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void PostProcess(IMitmServiceObject *obj, IpcResponseContext *ctx);
|
static void PostProcess(IMitmServiceObject *obj, IpcResponseContext *ctx);
|
||||||
private:
|
private:
|
||||||
Result OpenHblWebContentFileSystem(Out<std::shared_ptr<IFileSystemInterface>> &out);
|
Result OpenHblWebContentFileSystem(Out<std::shared_ptr<IFileSystemInterface>> &out);
|
||||||
|
@ -73,6 +75,7 @@ class FsMitmService : public IMitmServiceObject {
|
||||||
/* Overridden commands. */
|
/* Overridden commands. */
|
||||||
Result OpenFileSystemWithPatch(Out<std::shared_ptr<IFileSystemInterface>> out, u64 title_id, u32 filesystem_type);
|
Result OpenFileSystemWithPatch(Out<std::shared_ptr<IFileSystemInterface>> out, u64 title_id, u32 filesystem_type);
|
||||||
Result OpenFileSystemWithId(Out<std::shared_ptr<IFileSystemInterface>> out, InPointer<char> path, u64 title_id, u32 filesystem_type);
|
Result OpenFileSystemWithId(Out<std::shared_ptr<IFileSystemInterface>> out, InPointer<char> path, u64 title_id, u32 filesystem_type);
|
||||||
|
Result OpenSaveDataFileSystem(Out<std::shared_ptr<IFileSystemInterface>> out, u8 space_id, FsSave save_struct);
|
||||||
Result OpenBisStorage(Out<std::shared_ptr<IStorageInterface>> out, u32 bis_partition_id);
|
Result OpenBisStorage(Out<std::shared_ptr<IStorageInterface>> out, u32 bis_partition_id);
|
||||||
Result OpenDataStorageByCurrentProcess(Out<std::shared_ptr<IStorageInterface>> out);
|
Result OpenDataStorageByCurrentProcess(Out<std::shared_ptr<IStorageInterface>> out);
|
||||||
Result OpenDataStorageByDataId(Out<std::shared_ptr<IStorageInterface>> out, u64 data_id, u8 storage_id);
|
Result OpenDataStorageByDataId(Out<std::shared_ptr<IStorageInterface>> out, u64 data_id, u8 storage_id);
|
||||||
|
@ -81,6 +84,7 @@ class FsMitmService : public IMitmServiceObject {
|
||||||
/* TODO MakeServiceCommandMeta<FspSrvCmd_OpenFileSystemDeprecated, &FsMitmService::OpenFileSystemDeprecated>(), */
|
/* TODO MakeServiceCommandMeta<FspSrvCmd_OpenFileSystemDeprecated, &FsMitmService::OpenFileSystemDeprecated>(), */
|
||||||
MakeServiceCommandMeta<FspSrvCmd_OpenFileSystemWithPatch, &FsMitmService::OpenFileSystemWithPatch, FirmwareVersion_200>(),
|
MakeServiceCommandMeta<FspSrvCmd_OpenFileSystemWithPatch, &FsMitmService::OpenFileSystemWithPatch, FirmwareVersion_200>(),
|
||||||
MakeServiceCommandMeta<FspSrvCmd_OpenFileSystemWithId, &FsMitmService::OpenFileSystemWithId, FirmwareVersion_200>(),
|
MakeServiceCommandMeta<FspSrvCmd_OpenFileSystemWithId, &FsMitmService::OpenFileSystemWithId, FirmwareVersion_200>(),
|
||||||
|
MakeServiceCommandMeta<FspSrvCmd_OpenSaveDataFileSystem, &FsMitmService::OpenSaveDataFileSystem>(),
|
||||||
MakeServiceCommandMeta<FspSrvCmd_OpenBisStorage, &FsMitmService::OpenBisStorage>(),
|
MakeServiceCommandMeta<FspSrvCmd_OpenBisStorage, &FsMitmService::OpenBisStorage>(),
|
||||||
MakeServiceCommandMeta<FspSrvCmd_OpenDataStorageByCurrentProcess, &FsMitmService::OpenDataStorageByCurrentProcess>(),
|
MakeServiceCommandMeta<FspSrvCmd_OpenDataStorageByCurrentProcess, &FsMitmService::OpenDataStorageByCurrentProcess>(),
|
||||||
MakeServiceCommandMeta<FspSrvCmd_OpenDataStorageByDataId, &FsMitmService::OpenDataStorageByDataId>(),
|
MakeServiceCommandMeta<FspSrvCmd_OpenDataStorageByDataId, &FsMitmService::OpenDataStorageByDataId>(),
|
||||||
|
|
|
@ -640,3 +640,15 @@ Result Utils::GetSettingsItemValueSize(const char *name, const char *key, u64 *o
|
||||||
Result Utils::GetSettingsItemValue(const char *name, const char *key, void *out, size_t max_size, u64 *out_size) {
|
Result Utils::GetSettingsItemValue(const char *name, const char *key, void *out, size_t max_size, u64 *out_size) {
|
||||||
return SettingsItemManager::GetValue(name, key, out, max_size, out_size);
|
return SettingsItemManager::GetValue(name, key, out, max_size, out_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Result Utils::GetSettingsItemBooleanValue(const char *name, const char *key, bool *out) {
|
||||||
|
u8 val = 0;
|
||||||
|
u64 out_size;
|
||||||
|
Result rc = Utils::GetSettingsItemValue(name, key, &val, sizeof(val), &out_size);
|
||||||
|
if (R_SUCCEEDED(rc)) {
|
||||||
|
if (out) {
|
||||||
|
*out = val != 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <switch.h>
|
#include <switch.h>
|
||||||
#include <stratosphere.hpp>
|
#include <stratosphere.hpp>
|
||||||
|
@ -46,45 +46,47 @@ class Utils {
|
||||||
public:
|
public:
|
||||||
static bool IsSdInitialized();
|
static bool IsSdInitialized();
|
||||||
static void WaitSdInitialized();
|
static void WaitSdInitialized();
|
||||||
|
|
||||||
static Result OpenSdFile(const char *fn, int flags, FsFile *out);
|
static Result OpenSdFile(const char *fn, int flags, FsFile *out);
|
||||||
static Result OpenSdFileForAtmosphere(u64 title_id, const char *fn, int flags, FsFile *out);
|
static Result OpenSdFileForAtmosphere(u64 title_id, const char *fn, int flags, FsFile *out);
|
||||||
static Result OpenRomFSSdFile(u64 title_id, const char *fn, int flags, FsFile *out);
|
static Result OpenRomFSSdFile(u64 title_id, const char *fn, int flags, FsFile *out);
|
||||||
static Result OpenSdDir(const char *path, FsDir *out);
|
static Result OpenSdDir(const char *path, FsDir *out);
|
||||||
static Result OpenSdDirForAtmosphere(u64 title_id, const char *path, FsDir *out);
|
static Result OpenSdDirForAtmosphere(u64 title_id, const char *path, FsDir *out);
|
||||||
static Result OpenRomFSSdDir(u64 title_id, const char *path, FsDir *out);
|
static Result OpenRomFSSdDir(u64 title_id, const char *path, FsDir *out);
|
||||||
|
|
||||||
static Result OpenRomFSFile(FsFileSystem *fs, u64 title_id, const char *fn, int flags, FsFile *out);
|
static Result OpenRomFSFile(FsFileSystem *fs, u64 title_id, const char *fn, int flags, FsFile *out);
|
||||||
static Result OpenRomFSDir(FsFileSystem *fs, u64 title_id, const char *path, FsDir *out);
|
static Result OpenRomFSDir(FsFileSystem *fs, u64 title_id, const char *path, FsDir *out);
|
||||||
|
|
||||||
static Result SaveSdFileForAtmosphere(u64 title_id, const char *fn, void *data, size_t size);
|
static Result SaveSdFileForAtmosphere(u64 title_id, const char *fn, void *data, size_t size);
|
||||||
|
|
||||||
static bool HasSdRomfsContent(u64 title_id);
|
static bool HasSdRomfsContent(u64 title_id);
|
||||||
|
|
||||||
/* Delayed Initialization + MitM detection. */
|
/* Delayed Initialization + MitM detection. */
|
||||||
static void InitializeThreadFunc(void *args);
|
static void InitializeThreadFunc(void *args);
|
||||||
|
|
||||||
static bool IsHblTid(u64 tid);
|
static bool IsHblTid(u64 tid);
|
||||||
static bool IsWebAppletTid(u64 tid);
|
static bool IsWebAppletTid(u64 tid);
|
||||||
|
|
||||||
static bool HasTitleFlag(u64 tid, const char *flag);
|
static bool HasTitleFlag(u64 tid, const char *flag);
|
||||||
static bool HasHblFlag(const char *flag);
|
static bool HasHblFlag(const char *flag);
|
||||||
static bool HasGlobalFlag(const char *flag);
|
static bool HasGlobalFlag(const char *flag);
|
||||||
static bool HasFlag(u64 tid, const char *flag);
|
static bool HasFlag(u64 tid, const char *flag);
|
||||||
|
|
||||||
static bool HasSdMitMFlag(u64 tid);
|
static bool HasSdMitMFlag(u64 tid);
|
||||||
static bool HasSdDisableMitMFlag(u64 tid);
|
static bool HasSdDisableMitMFlag(u64 tid);
|
||||||
|
|
||||||
|
|
||||||
static bool IsHidAvailable();
|
static bool IsHidAvailable();
|
||||||
static Result GetKeysHeld(u64 *keys);
|
static Result GetKeysHeld(u64 *keys);
|
||||||
|
|
||||||
static OverrideKey GetTitleOverrideKey(u64 tid);
|
static OverrideKey GetTitleOverrideKey(u64 tid);
|
||||||
static bool HasOverrideButton(u64 tid);
|
static bool HasOverrideButton(u64 tid);
|
||||||
|
|
||||||
/* Settings! */
|
/* Settings! */
|
||||||
static Result GetSettingsItemValueSize(const char *name, const char *key, u64 *out_size);
|
static Result GetSettingsItemValueSize(const char *name, const char *key, u64 *out_size);
|
||||||
static Result GetSettingsItemValue(const char *name, const char *key, void *out, size_t max_size, u64 *out_size);
|
static Result GetSettingsItemValue(const char *name, const char *key, void *out, size_t max_size, u64 *out_size);
|
||||||
|
|
||||||
|
static Result GetSettingsItemBooleanValue(const char *name, const char *key, bool *out);
|
||||||
private:
|
private:
|
||||||
static void RefreshConfiguration();
|
static void RefreshConfiguration();
|
||||||
};
|
};
|
|
@ -1 +1 @@
|
||||||
Subproject commit b6ca2d89ae5106ea21454f332f07076159ad2e92
|
Subproject commit 8021b07eb82b9941c1820b211bbe6d898589e59b
|
Loading…
Reference in a new issue