mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2024-12-22 20:31:14 +00:00
set.mitm: mitm everything
We still only lie about firmware version to qlaunch/maintenance. This is to prepare for loading settings off of the SD card.
This commit is contained in:
parent
f61f5feaf4
commit
4711d0565d
7 changed files with 222 additions and 37 deletions
|
@ -85,7 +85,7 @@ int main(int argc, char **argv)
|
|||
auto server_manager = new SetMitmManager(1);
|
||||
|
||||
/* Create set:sys mitm. */
|
||||
AddMitmServerToManager<SetSysMitmService>(server_manager, "set:sys", 4);
|
||||
AddMitmServerToManager<SetSysMitmService>(server_manager, "set:sys", 60);
|
||||
|
||||
/* Connect to set:sys. */
|
||||
{
|
||||
|
|
55
stratosphere/set_mitm/source/setsys_firmware_version.cpp
Normal file
55
stratosphere/set_mitm/source/setsys_firmware_version.cpp
Normal file
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* 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_firmware_version.hpp"
|
||||
|
||||
static HosMutex g_version_mutex;
|
||||
static bool g_got_version = false;
|
||||
static SetSysFirmwareVersion g_fw_version = {0};
|
||||
|
||||
Result VersionManager::GetFirmwareVersion(u64 title_id, SetSysFirmwareVersion *out) {
|
||||
std::scoped_lock<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;
|
||||
}
|
||||
|
||||
/* Report atmosphere string to qlaunch, maintenance and nothing else. */
|
||||
if (title_id == 0x0100000000001000ULL || title_id == 0x0100000000001015ULL) {
|
||||
*out = g_fw_version;
|
||||
return 0;
|
||||
} else {
|
||||
return setsysGetFirmwareVersion(out);
|
||||
}
|
||||
}
|
24
stratosphere/set_mitm/source/setsys_firmware_version.hpp
Normal file
24
stratosphere/set_mitm/source/setsys_firmware_version.hpp
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* 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>
|
||||
|
||||
class VersionManager {
|
||||
public:
|
||||
static Result GetFirmwareVersion(u64 title_id, SetSysFirmwareVersion *out);
|
||||
};
|
|
@ -15,45 +15,17 @@
|
|||
*/
|
||||
|
||||
#include <mutex>
|
||||
#include <algorithm>
|
||||
#include <switch.h>
|
||||
#include "setsys_mitm_service.hpp"
|
||||
|
||||
static HosMutex g_version_mutex;
|
||||
static bool g_got_version = false;
|
||||
static SetSysFirmwareVersion g_fw_version = {0};
|
||||
|
||||
static Result _GetFirmwareVersion(SetSysFirmwareVersion *out) {
|
||||
std::scoped_lock<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;
|
||||
}
|
||||
#include "setsys_firmware_version.hpp"
|
||||
|
||||
void SetSysMitmService::PostProcess(IMitmServiceObject *obj, IpcResponseContext *ctx) {
|
||||
/* No commands need postprocessing. */
|
||||
}
|
||||
|
||||
Result SetSysMitmService::GetFirmwareVersion(OutPointerWithServerSize<SetSysFirmwareVersion, 0x1> out) {
|
||||
Result rc = _GetFirmwareVersion(out.pointer);
|
||||
Result rc = VersionManager::GetFirmwareVersion(this->title_id, out.pointer);
|
||||
|
||||
/* GetFirmwareVersion sanitizes these fields. */
|
||||
if (R_SUCCEEDED(rc)) {
|
||||
|
@ -65,5 +37,47 @@ Result SetSysMitmService::GetFirmwareVersion(OutPointerWithServerSize<SetSysFirm
|
|||
}
|
||||
|
||||
Result SetSysMitmService::GetFirmwareVersion2(OutPointerWithServerSize<SetSysFirmwareVersion, 0x1> out) {
|
||||
return _GetFirmwareVersion(out.pointer);
|
||||
return VersionManager::GetFirmwareVersion(this->title_id, out.pointer);
|
||||
}
|
||||
|
||||
Result SetSysMitmService::GetSettingsItemValueSize(Out<u64> out_size, InPointer<char> in_name, InPointer<char> in_key) {
|
||||
char name[SET_MAX_NAME_SIZE] = {0};
|
||||
char key[SET_MAX_NAME_SIZE] = {0};
|
||||
|
||||
if (in_name.num_elements < SET_MAX_NAME_SIZE) {
|
||||
strncpy(name, in_name.pointer, in_name.num_elements);
|
||||
} else {
|
||||
strncpy(name, in_name.pointer, SET_MAX_NAME_SIZE-1);
|
||||
}
|
||||
|
||||
if (in_key.num_elements < SET_MAX_NAME_SIZE) {
|
||||
strncpy(key, in_key.pointer, in_key.num_elements);
|
||||
} else {
|
||||
strncpy(key, in_key.pointer, SET_MAX_NAME_SIZE-1);
|
||||
}
|
||||
|
||||
return setsysGetSettingsItemValueSize(name, key, out_size.GetPointer());
|
||||
}
|
||||
|
||||
Result SetSysMitmService::GetSettingsItemValue(Out<u64> out_size, OutBuffer<u8> out_value, InPointer<char> in_name, InPointer<char> in_key) {
|
||||
char name[SET_MAX_NAME_SIZE] = {0};
|
||||
char key[SET_MAX_NAME_SIZE] = {0};
|
||||
|
||||
if (in_name.num_elements < SET_MAX_NAME_SIZE) {
|
||||
strncpy(name, in_name.pointer, in_name.num_elements);
|
||||
} else {
|
||||
strncpy(name, in_name.pointer, SET_MAX_NAME_SIZE-1);
|
||||
}
|
||||
|
||||
if (in_key.num_elements < SET_MAX_NAME_SIZE) {
|
||||
strncpy(key, in_key.pointer, in_key.num_elements);
|
||||
} else {
|
||||
strncpy(key, in_key.pointer, SET_MAX_NAME_SIZE-1);
|
||||
}
|
||||
|
||||
return setsysGetSettingsItemValue(name, key, out_value.buffer, out_value.num_elements);
|
||||
}
|
||||
|
||||
Result SetSysMitmService::GetEdid(OutPointerWithServerSize<SetSysEdid, 0x1> out) {
|
||||
return setsysGetEdidFwd(this->forward_service.get(), out.pointer);
|
||||
}
|
|
@ -18,9 +18,17 @@
|
|||
#include <switch.h>
|
||||
#include <stratosphere.hpp>
|
||||
|
||||
#include "setsys_shim.h"
|
||||
|
||||
enum SetSysCmd : u32 {
|
||||
SetSysCmd_GetFirmwareVersion = 3,
|
||||
SetSysCmd_GetFirmwareVersion2 = 4,
|
||||
SetSysCmd_GetSettingsItemValueSize = 37,
|
||||
SetSysCmd_GetSettingsItemValue = 38,
|
||||
|
||||
/* Commands for which set:sys *must* act as a passthrough. */
|
||||
/* TODO: Solve the relevant IPC detection problem. */
|
||||
SetSysCmd_GetEdid = 41,
|
||||
};
|
||||
|
||||
class SetSysMitmService : public IMitmServiceObject {
|
||||
|
@ -30,8 +38,8 @@ class SetSysMitmService : public IMitmServiceObject {
|
|||
}
|
||||
|
||||
static bool ShouldMitm(u64 pid, u64 tid) {
|
||||
/* Only MitM qlaunch, maintenance. */
|
||||
return tid == 0x0100000000001000ULL || tid == 0x0100000000001015ULL;
|
||||
/* Mitm everything. */
|
||||
return true;
|
||||
}
|
||||
|
||||
static void PostProcess(IMitmServiceObject *obj, IpcResponseContext *ctx);
|
||||
|
@ -40,9 +48,18 @@ class SetSysMitmService : public IMitmServiceObject {
|
|||
/* Overridden commands. */
|
||||
Result GetFirmwareVersion(OutPointerWithServerSize<SetSysFirmwareVersion, 0x1> out);
|
||||
Result GetFirmwareVersion2(OutPointerWithServerSize<SetSysFirmwareVersion, 0x1> out);
|
||||
Result GetSettingsItemValueSize(Out<u64> out_size, InPointer<char> name, InPointer<char> key);
|
||||
Result GetSettingsItemValue(Out<u64> out_size, OutBuffer<u8> out_value, InPointer<char> name, InPointer<char> key);
|
||||
|
||||
/* Forced passthrough commands. */
|
||||
Result GetEdid(OutPointerWithServerSize<SetSysEdid, 0x1> out);
|
||||
public:
|
||||
DEFINE_SERVICE_DISPATCH_TABLE {
|
||||
MakeServiceCommandMeta<SetSysCmd_GetFirmwareVersion, &SetSysMitmService::GetFirmwareVersion>(),
|
||||
MakeServiceCommandMeta<SetSysCmd_GetFirmwareVersion2, &SetSysMitmService::GetFirmwareVersion2>(),
|
||||
MakeServiceCommandMeta<SetSysCmd_GetSettingsItemValueSize, &SetSysMitmService::GetSettingsItemValueSize>(),
|
||||
MakeServiceCommandMeta<SetSysCmd_GetSettingsItemValue, &SetSysMitmService::GetSettingsItemValue>(),
|
||||
|
||||
MakeServiceCommandMeta<SetSysCmd_GetEdid, &SetSysMitmService::GetEdid>(),
|
||||
};
|
||||
};
|
||||
|
|
52
stratosphere/set_mitm/source/setsys_shim.c
Normal file
52
stratosphere/set_mitm/source/setsys_shim.c
Normal file
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* 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 <switch.h>
|
||||
#include "setsys_shim.h"
|
||||
|
||||
/* Command forwarders. */
|
||||
Result setsysGetEdidFwd(Service* s, SetSysEdid* out) {
|
||||
IpcCommand c;
|
||||
ipcInitialize(&c);
|
||||
ipcAddRecvStatic(&c, out, sizeof(*out), 0);
|
||||
|
||||
struct {
|
||||
u64 magic;
|
||||
u64 cmd_id;
|
||||
} *raw;
|
||||
|
||||
raw = serviceIpcPrepareHeader(s, &c, sizeof(*raw));
|
||||
|
||||
raw->magic = SFCI_MAGIC;
|
||||
raw->cmd_id = 41;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
23
stratosphere/set_mitm/source/setsys_shim.h
Normal file
23
stratosphere/set_mitm/source/setsys_shim.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
/**
|
||||
* @file setsys_shim.h
|
||||
* @brief System Settings Services (set:sys) IPC wrapper. To be merged into libnx, eventually.
|
||||
* @author SciresM
|
||||
* @copyright libnx Authors
|
||||
*/
|
||||
#pragma once
|
||||
#include <switch.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
char edid[0x100];
|
||||
} SetSysEdid;
|
||||
|
||||
/* Command forwarders. */
|
||||
Result setsysGetEdidFwd(Service* s, SetSysEdid* out);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
Loading…
Reference in a new issue