mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-12-23 10:52:13 +00:00
fs.mitm: Only create storage interface when needed.
This commit is contained in:
parent
158f7224a7
commit
e786bc7e9a
4 changed files with 39 additions and 28 deletions
|
@ -79,15 +79,21 @@ Result FsMitmService::OpenDataStorageByCurrentProcess(Out<std::shared_ptr<IStora
|
||||||
|
|
||||||
Log(armGetTls(), 0x100);
|
Log(armGetTls(), 0x100);
|
||||||
if (R_SUCCEEDED(rc)) {
|
if (R_SUCCEEDED(rc)) {
|
||||||
/* TODO: Is there a sensible path that ends in ".romfs" we can use?" */
|
if (Utils::HasSdRomfsContent(this->title_id)) {
|
||||||
if (R_SUCCEEDED(Utils::OpenSdFileForAtmosphere(this->title_id, "romfs.bin", FS_OPEN_READ, &data_file))) {
|
/* TODO: Is there a sensible path that ends in ".romfs" we can use?" */
|
||||||
storage = std::make_shared<IStorageInterface>(new LayeredRomFS(std::make_shared<RomInterfaceStorage>(data_storage), std::make_shared<RomFileStorage>(data_file), this->title_id));
|
if (R_SUCCEEDED(Utils::OpenSdFileForAtmosphere(this->title_id, "romfs.bin", FS_OPEN_READ, &data_file))) {
|
||||||
|
storage = std::make_shared<IStorageInterface>(new LayeredRomFS(std::make_shared<RomInterfaceStorage>(data_storage), std::make_shared<RomFileStorage>(data_file), this->title_id));
|
||||||
|
} else {
|
||||||
|
storage = std::make_shared<IStorageInterface>(new LayeredRomFS(std::make_shared<RomInterfaceStorage>(data_storage), nullptr, this->title_id));
|
||||||
|
}
|
||||||
|
this->romfs_storage = storage;
|
||||||
|
if (out_storage.IsDomain()) {
|
||||||
|
out_domain_id = data_storage.s.object_id;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
storage = std::make_shared<IStorageInterface>(new LayeredRomFS(std::make_shared<RomInterfaceStorage>(data_storage), nullptr, this->title_id));
|
/* If we don't have anything to modify, there's no sense in maintaining a copy of the metadata tables. */
|
||||||
}
|
fsStorageClose(&data_storage);
|
||||||
this->romfs_storage = storage;
|
rc = RESULT_FORWARD_TO_SESSION;
|
||||||
if (out_storage.IsDomain()) {
|
|
||||||
out_domain_id = data_storage.s.object_id;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -117,14 +123,20 @@ Result FsMitmService::OpenDataStorageByDataId(Out<std::shared_ptr<IStorageInterf
|
||||||
rc = fsOpenDataStorageByDataIdFwd(this->forward_service.get(), storage_id, data_id, &data_storage);
|
rc = fsOpenDataStorageByDataIdFwd(this->forward_service.get(), storage_id, data_id, &data_storage);
|
||||||
|
|
||||||
if (R_SUCCEEDED(rc)) {
|
if (R_SUCCEEDED(rc)) {
|
||||||
/* TODO: Is there a sensible path that ends in ".romfs" we can use?" */
|
if (Utils::HasSdRomfsContent(data_id)) {
|
||||||
if (R_SUCCEEDED(Utils::OpenSdFileForAtmosphere(data_id, "romfs.bin", FS_OPEN_READ, &data_file))) {
|
/* TODO: Is there a sensible path that ends in ".romfs" we can use?" */
|
||||||
storage = std::make_shared<IStorageInterface>(new LayeredRomFS(std::make_shared<RomInterfaceStorage>(data_storage), std::make_shared<RomFileStorage>(data_file), data_id));
|
if (R_SUCCEEDED(Utils::OpenSdFileForAtmosphere(data_id, "romfs.bin", FS_OPEN_READ, &data_file))) {
|
||||||
|
storage = std::make_shared<IStorageInterface>(new LayeredRomFS(std::make_shared<RomInterfaceStorage>(data_storage), std::make_shared<RomFileStorage>(data_file), data_id));
|
||||||
|
} else {
|
||||||
|
storage = std::make_shared<IStorageInterface>(new LayeredRomFS(std::make_shared<RomInterfaceStorage>(data_storage), nullptr, data_id));
|
||||||
|
}
|
||||||
|
if (out_storage.IsDomain()) {
|
||||||
|
out_domain_id = data_storage.s.object_id;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
storage = std::make_shared<IStorageInterface>(new LayeredRomFS(std::make_shared<RomInterfaceStorage>(data_storage), nullptr, data_id));
|
/* If we don't have anything to modify, there's no sense in maintaining a copy of the metadata tables. */
|
||||||
}
|
fsStorageClose(&data_storage);
|
||||||
if (out_storage.IsDomain()) {
|
rc = RESULT_FORWARD_TO_SESSION;
|
||||||
out_domain_id = data_storage.s.object_id;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -201,20 +201,18 @@ Result Utils::OpenRomFSDir(FsFileSystem *fs, u64 title_id, const char *path, FsD
|
||||||
return fsFsOpenDirectory(fs, safe_path, FS_DIROPEN_DIRECTORY | FS_DIROPEN_FILE, out);
|
return fsFsOpenDirectory(fs, safe_path, FS_DIROPEN_DIRECTORY | FS_DIROPEN_FILE, out);
|
||||||
}
|
}
|
||||||
|
|
||||||
Result Utils::HasSdRomfsContent(u64 title_id, bool *out) {
|
bool Utils::HasSdRomfsContent(u64 title_id) {
|
||||||
Result rc;
|
|
||||||
FsDir dir;
|
FsDir dir;
|
||||||
if (R_FAILED((rc = Utils::OpenRomFSSdDir(title_id, "", &dir)))) {
|
if (R_FAILED(Utils::OpenRomFSSdDir(title_id, "", &dir))) {
|
||||||
return rc;
|
return false;
|
||||||
}
|
}
|
||||||
|
ON_SCOPE_EXIT {
|
||||||
|
fsDirClose(&dir);
|
||||||
|
};
|
||||||
|
|
||||||
FsDirectoryEntry dir_entry;
|
FsDirectoryEntry dir_entry;
|
||||||
u64 read_entries;
|
u64 read_entries;
|
||||||
if (R_SUCCEEDED((rc = fsDirRead(&dir, 0, &read_entries, 1, &dir_entry)))) {
|
return R_SUCCEEDED(fsDirRead(&dir, 0, &read_entries, 1, &dir_entry)) && read_entries == 1;
|
||||||
*out = (read_entries == 1);
|
|
||||||
}
|
|
||||||
fsDirClose(&dir);
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Utils::HasSdMitMFlag(u64 tid) {
|
bool Utils::HasSdMitMFlag(u64 tid) {
|
||||||
|
|
|
@ -28,11 +28,10 @@ class Utils {
|
||||||
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 HasSdRomfsContent(u64 title_id, bool *out);
|
static bool HasSdRomfsContent(u64 title_id);
|
||||||
|
|
||||||
/* SD card Initialization + MitM detection. */
|
/* SD card Initialization + MitM detection. */
|
||||||
static void InitializeSdThreadFunc(void *args);
|
static void InitializeSdThreadFunc(void *args);
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
|
|
||||||
#include "mitm_query_service.hpp"
|
#include "mitm_query_service.hpp"
|
||||||
|
|
||||||
|
#define RESULT_FORWARD_TO_SESSION 0xCAFEFC
|
||||||
|
|
||||||
class MitmSession final : public ServiceSession {
|
class MitmSession final : public ServiceSession {
|
||||||
private:
|
private:
|
||||||
/* This will be for the actual session. */
|
/* This will be for the actual session. */
|
||||||
|
@ -149,7 +151,7 @@ class MitmSession final : public ServiceSession {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!found_entry) {
|
if (!found_entry || rc == RESULT_FORWARD_TO_SESSION) {
|
||||||
memcpy(armGetTls(), this->backup_tls, sizeof(this->backup_tls));
|
memcpy(armGetTls(), this->backup_tls, sizeof(this->backup_tls));
|
||||||
rc = ForwardRequest(ctx);
|
rc = ForwardRequest(ctx);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue