mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-12-23 02:42:09 +00:00
fs.mitm: split out set.mitm
This commit is contained in:
parent
3dc679215b
commit
23a85a7c24
6 changed files with 13 additions and 167 deletions
|
@ -26,8 +26,6 @@
|
|||
|
||||
#include "fsmitm_utils.hpp"
|
||||
|
||||
#include "setsys_mitm_service.hpp"
|
||||
|
||||
extern "C" {
|
||||
extern u32 __start__;
|
||||
|
||||
|
@ -63,11 +61,6 @@ void __appInit(void) {
|
|||
fatalSimple(MAKERESULT(Module_Libnx, LibnxError_InitFail_SM));
|
||||
}
|
||||
|
||||
rc = smMitMInitialize();
|
||||
if (R_FAILED(rc)) {
|
||||
fatalSimple(MAKERESULT(Module_Libnx, LibnxError_InitFail_SM));
|
||||
}
|
||||
|
||||
rc = fsInitialize();
|
||||
if (R_FAILED(rc)) {
|
||||
fatalSimple(MAKERESULT(Module_Libnx, LibnxError_InitFail_FS));
|
||||
|
@ -78,7 +71,6 @@ void __appInit(void) {
|
|||
void __appExit(void) {
|
||||
/* Cleanup services. */
|
||||
fsExit();
|
||||
smMitMExit();
|
||||
smExit();
|
||||
}
|
||||
|
||||
|
@ -87,27 +79,12 @@ struct FsMitmManagerOptions {
|
|||
static const size_t MaxDomains = 0x10;
|
||||
static const size_t MaxDomainObjects = 0x4000;
|
||||
};
|
||||
|
||||
using FsMitmManager = WaitableManager<FsMitmManagerOptions>;
|
||||
|
||||
void CreateSettingsMitMServer(void *arg) {
|
||||
auto server_manager = (FsMitmManager *)arg;
|
||||
|
||||
Result rc;
|
||||
if (R_FAILED((rc = setsysInitialize()))) {
|
||||
fatalSimple(rc);
|
||||
}
|
||||
|
||||
AddMitmServerToManager<SetSysMitmService>(server_manager, "set:sys", 5);
|
||||
|
||||
svcExitThread();
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
Thread sd_initializer_thread = {0};
|
||||
Thread hid_initializer_thread = {0};
|
||||
Thread set_mitm_setup_thread = {0};
|
||||
consoleDebugInit(debugDevice_SVC);
|
||||
|
||||
if (R_FAILED(threadCreate(&sd_initializer_thread, &Utils::InitializeSdThreadFunc, NULL, 0x4000, 0x15, 0))) {
|
||||
|
@ -129,15 +106,7 @@ int main(int argc, char **argv)
|
|||
|
||||
/* Create fsp-srv mitm. */
|
||||
AddMitmServerToManager<FsMitmService>(server_manager, "fsp-srv", 61);
|
||||
|
||||
/* Create set:sys mitm server, delayed until set:sys is available. */
|
||||
if (R_FAILED(threadCreate(&set_mitm_setup_thread, &CreateSettingsMitMServer, server_manager, 0x4000, 0x15, 0))) {
|
||||
/* TODO: Panic. */
|
||||
}
|
||||
if (R_FAILED(threadStart(&set_mitm_setup_thread))) {
|
||||
/* TODO: Panic. */
|
||||
}
|
||||
|
||||
|
||||
/* Loop forever, servicing our services. */
|
||||
server_manager->Process();
|
||||
|
||||
|
|
|
@ -48,6 +48,15 @@ Result FsMitmService::OpenDataStorageByCurrentProcess(Out<std::shared_ptr<IStora
|
|||
std::shared_ptr<IStorageInterface> storage = nullptr;
|
||||
u32 out_domain_id = 0;
|
||||
Result rc = 0;
|
||||
|
||||
ON_SCOPE_EXIT {
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
out_storage.SetValue(std::move(storage));
|
||||
if (out_storage.IsDomain()) {
|
||||
out_storage.ChangeObjectId(out_domain_id);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (this->romfs_storage != nullptr) {
|
||||
if (out_storage.IsDomain()) {
|
||||
|
@ -83,13 +92,6 @@ Result FsMitmService::OpenDataStorageByCurrentProcess(Out<std::shared_ptr<IStora
|
|||
}
|
||||
}
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
out_storage.SetValue(std::move(storage));
|
||||
if (out_storage.IsDomain()) {
|
||||
out_storage.ChangeObjectId(out_domain_id);
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
@ -126,12 +128,5 @@ Result FsMitmService::OpenDataStorageByDataId(Out<std::shared_ptr<IStorageInterf
|
|||
}
|
||||
}
|
||||
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
out_storage.SetValue(std::move(storage));
|
||||
if (out_storage.IsDomain()) {
|
||||
out_storage.ChangeObjectId(out_domain_id);
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
|
@ -1,69 +0,0 @@
|
|||
/*
|
||||
* 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 <mutex>
|
||||
#include <switch.h>
|
||||
#include "setsys_mitm_service.hpp"
|
||||
|
||||
#include "debug.hpp"
|
||||
|
||||
static HosMutex g_version_mutex;
|
||||
static bool g_got_version = false;
|
||||
static SetSysFirmwareVersion g_fw_version = {0};
|
||||
|
||||
static Result _GetFirmwareVersion(SetSysFirmwareVersion *out) {
|
||||
std::lock_guard<HosMutex> lock(g_version_mutex);
|
||||
if (!g_got_version) {
|
||||
Result rc = setsysGetFirmwareVersion(&g_fw_version);
|
||||
if (R_FAILED(rc)) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* Modify the output firmware version. */
|
||||
{
|
||||
u32 major, minor, micro;
|
||||
char display_version[sizeof(g_fw_version.display_version)] = {0};
|
||||
|
||||
GetAtmosphereApiVersion(&major, &minor, µ, nullptr, nullptr);
|
||||
snprintf(display_version, sizeof(display_version), "%s (AMS %u.%u.%u)", g_fw_version.display_version, major, minor, micro);
|
||||
|
||||
memcpy(g_fw_version.display_version, display_version, sizeof(g_fw_version.display_version));
|
||||
}
|
||||
|
||||
g_got_version = true;
|
||||
}
|
||||
|
||||
*out = g_fw_version;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SetSysMitmService::PostProcess(IMitmServiceObject *obj, IpcResponseContext *ctx) {
|
||||
/* No commands need postprocessing. */
|
||||
}
|
||||
|
||||
Result SetSysMitmService::GetFirmwareVersion(OutPointerWithServerSize<SetSysFirmwareVersion, 0x1> out) {
|
||||
Result rc = _GetFirmwareVersion(out.pointer);
|
||||
|
||||
/* GetFirmwareVersion sanitizes these fields. */
|
||||
out.pointer->revision_major = 0;
|
||||
out.pointer->revision_minor = 0;
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
Result SetSysMitmService::GetFirmwareVersion2(OutPointerWithServerSize<SetSysFirmwareVersion, 0x1> out) {
|
||||
return _GetFirmwareVersion(out.pointer);
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
/*
|
||||
* 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 <stratosphere.hpp>
|
||||
#include "fsmitm_utils.hpp"
|
||||
|
||||
enum SetSysCmd : u32 {
|
||||
SetSysCmd_GetFirmwareVersion = 3,
|
||||
SetSysCmd_GetFirmwareVersion2 = 4,
|
||||
};
|
||||
|
||||
class SetSysMitmService : public IMitmServiceObject {
|
||||
public:
|
||||
SetSysMitmService(std::shared_ptr<Service> s) : IMitmServiceObject(s) {
|
||||
/* ... */
|
||||
}
|
||||
|
||||
static bool ShouldMitm(u64 pid, u64 tid) {
|
||||
/* Only MitM qlaunch, maintenance. */
|
||||
return tid == 0x0100000000001000ULL || tid == 0x0100000000001015ULL;
|
||||
}
|
||||
|
||||
static void PostProcess(IMitmServiceObject *obj, IpcResponseContext *ctx);
|
||||
|
||||
protected:
|
||||
/* Overridden commands. */
|
||||
Result GetFirmwareVersion(OutPointerWithServerSize<SetSysFirmwareVersion, 0x1> out);
|
||||
Result GetFirmwareVersion2(OutPointerWithServerSize<SetSysFirmwareVersion, 0x1> out);
|
||||
public:
|
||||
DEFINE_SERVICE_DISPATCH_TABLE {
|
||||
MakeServiceCommandMeta<SetSysCmd_GetFirmwareVersion, &SetSysMitmService::GetFirmwareVersion>(),
|
||||
MakeServiceCommandMeta<SetSysCmd_GetFirmwareVersion2, &SetSysMitmService::GetFirmwareVersion2>(),
|
||||
};
|
||||
};
|
|
@ -44,7 +44,7 @@ class MitmQueryService : public IServiceObject {
|
|||
}
|
||||
public:
|
||||
DEFINE_SERVICE_DISPATCH_TABLE {
|
||||
MakeServiceCommandMeta<MQS_Cmd_ShouldMitm, &MitmQueryService::ShouldMitm>(),
|
||||
MakeServiceCommandMeta<MQS_Cmd_AssociatePidTid, &MitmQueryService::AssociatePidToTid>(),
|
||||
MakeServiceCommandMeta<MQS_Cmd_ShouldMitm, &MitmQueryService<T>::ShouldMitm>(),
|
||||
MakeServiceCommandMeta<MQS_Cmd_AssociatePidTid, &MitmQueryService<T>::AssociatePidToTid>(),
|
||||
};
|
||||
};
|
|
@ -93,8 +93,8 @@ template<typename T>
|
|||
static void AddMitmServerToManager(SessionManagerBase *manager, const char *srv_name, unsigned int max_sessions) {
|
||||
Handle query_h;
|
||||
auto *srv = new MitmServer<T>(&query_h, srv_name, max_sessions);
|
||||
manager->AddWaitable(srv);
|
||||
manager->AddSession(query_h, std::move(ServiceObjectHolder(std::move(std::make_shared<MitmQueryService<T>>()))));
|
||||
manager->AddWaitable(srv);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue