mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-12-23 10:52:13 +00:00
fs.mitm: Intercept qlaunch sysver request
This commit is contained in:
parent
5b219e6f58
commit
c0fe4f7af7
4 changed files with 194 additions and 6 deletions
|
@ -32,6 +32,8 @@
|
|||
|
||||
#include "fsmitm_utils.hpp"
|
||||
|
||||
#include "setsys_mitm_service.hpp"
|
||||
|
||||
extern "C" {
|
||||
extern u32 __start__;
|
||||
|
||||
|
@ -86,13 +88,28 @@ void __appExit(void) {
|
|||
smExit();
|
||||
}
|
||||
|
||||
void CreateSettingsMitMServer(void *arg) {
|
||||
MultiThreadedWaitableManager *server_manager = (MultiThreadedWaitableManager *)arg;
|
||||
|
||||
Result rc;
|
||||
if (R_FAILED((rc = setsysInitialize()))) {
|
||||
fatalSimple(rc);
|
||||
}
|
||||
|
||||
ISession<MitMQueryService<SetSysMitMService>> *setsys_query_srv = NULL;
|
||||
MitMServer<SetSysMitMService> *setsys_srv = new MitMServer<SetSysMitMService>(&setsys_query_srv, "set:sys", 60);
|
||||
server_manager->add_waitable(setsys_srv);
|
||||
server_manager->add_waitable(setsys_query_srv);
|
||||
|
||||
svcExitThread();
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
Thread worker_thread = {0};
|
||||
Thread sd_initializer_thread = {0};
|
||||
Thread hid_initializer_thread = {0};
|
||||
consoleDebugInit(debugDevice_SVC);
|
||||
|
||||
Thread set_mitm_setup_thread = {0};
|
||||
consoleDebugInit(debugDevice_SVC);
|
||||
|
||||
if (R_FAILED(threadCreate(&worker_thread, &FsMitMWorker::Main, NULL, 0x20000, 45, 0))) {
|
||||
|
@ -117,8 +134,7 @@ int main(int argc, char **argv)
|
|||
}
|
||||
|
||||
/* TODO: What's a good timeout value to use here? */
|
||||
auto server_manager = std::make_unique<MultiThreadedWaitableManager>(5, U64_MAX, 0x20000);
|
||||
//auto server_manager = std::make_unique<WaitableManager>(U64_MAX);
|
||||
MultiThreadedWaitableManager *server_manager = new MultiThreadedWaitableManager(5, U64_MAX, 0x20000);
|
||||
|
||||
/* Create fsp-srv mitm. */
|
||||
ISession<MitMQueryService<FsMitMService>> *fs_query_srv = NULL;
|
||||
|
@ -126,9 +142,19 @@ int main(int argc, char **argv)
|
|||
server_manager->add_waitable(fs_srv);
|
||||
server_manager->add_waitable(fs_query_srv);
|
||||
|
||||
/* 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();
|
||||
|
||||
delete server_manager;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
104
stratosphere/fs_mitm/source/setsys_mitm_service.cpp
Normal file
104
stratosphere/fs_mitm/source/setsys_mitm_service.cpp
Normal file
|
@ -0,0 +1,104 @@
|
|||
/*
|
||||
* 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 "mitm_query_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;
|
||||
}
|
||||
|
||||
Result SetSysMitMService::dispatch(IpcParsedCommand &r, IpcCommand &out_c, u64 cmd_id, u8 *pointer_buffer, size_t pointer_buffer_size) {
|
||||
Result rc = 0xF601;
|
||||
|
||||
switch (static_cast<SetSysCmd>(cmd_id)) {
|
||||
case SetSysCmd::GetFirmwareVersion:
|
||||
rc = WrapIpcCommandImpl<&SetSysMitMService::get_firmware_version>(this, r, out_c, pointer_buffer, pointer_buffer_size);
|
||||
break;
|
||||
case SetSysCmd::GetFirmwareVersion2:
|
||||
if (kernelAbove300()) {
|
||||
rc = WrapIpcCommandImpl<&SetSysMitMService::get_firmware_version2>(this, r, out_c, pointer_buffer, pointer_buffer_size);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
void SetSysMitMService::postprocess(IpcParsedCommand &r, IpcCommand &out_c, u64 cmd_id, u8 *pointer_buffer, size_t pointer_buffer_size) {
|
||||
/* No commands need postprocessing. */
|
||||
}
|
||||
|
||||
Result SetSysMitMService::handle_deferred() {
|
||||
/* This service is never deferrable. */
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::tuple<Result> SetSysMitMService::get_firmware_version(OutPointerWithServerSize<SetSysFirmwareVersion, 0x1> out) {
|
||||
if (out.num_elements != 1) {
|
||||
return {0xF601};
|
||||
}
|
||||
|
||||
Result rc = _GetFirmwareVersion(out.pointer);
|
||||
|
||||
/* GetFirmwareVersion sanitizes these fields. */
|
||||
out.pointer->revision_major = 0;
|
||||
out.pointer->revision_minor = 0;
|
||||
|
||||
return {rc};
|
||||
}
|
||||
|
||||
std::tuple<Result> SetSysMitMService::get_firmware_version2(OutPointerWithServerSize<SetSysFirmwareVersion, 0x1> out) {
|
||||
if (out.num_elements != 1) {
|
||||
return {0xF601};
|
||||
}
|
||||
|
||||
Result rc = _GetFirmwareVersion(out.pointer);
|
||||
|
||||
return {rc};
|
||||
}
|
58
stratosphere/fs_mitm/source/setsys_mitm_service.hpp
Normal file
58
stratosphere/fs_mitm/source/setsys_mitm_service.hpp
Normal file
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* 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/iserviceobject.hpp>
|
||||
#include "imitmserviceobject.hpp"
|
||||
#include "fsmitm_utils.hpp"
|
||||
|
||||
enum class SetSysCmd {
|
||||
GetFirmwareVersion = 3,
|
||||
GetFirmwareVersion2 = 4,
|
||||
};
|
||||
|
||||
class SetSysMitMService : public IMitMServiceObject {
|
||||
private:
|
||||
public:
|
||||
SetSysMitMService(Service *s) : IMitMServiceObject(s) {
|
||||
/* ... */
|
||||
}
|
||||
|
||||
static bool should_mitm(u64 pid, u64 tid) {
|
||||
/* Only MitM qlaunch, maintenance. */
|
||||
return tid == 0x0100000000001000ULL || tid == 0x0100000000001015ULL;
|
||||
}
|
||||
|
||||
SetSysMitMService *clone() override {
|
||||
auto new_srv = new SetSysMitMService((Service *)&this->forward_service);
|
||||
this->clone_to(new_srv);
|
||||
return new_srv;
|
||||
}
|
||||
|
||||
void clone_to(void *o) override {
|
||||
/* ... */
|
||||
}
|
||||
|
||||
virtual Result dispatch(IpcParsedCommand &r, IpcCommand &out_c, u64 cmd_id, u8 *pointer_buffer, size_t pointer_buffer_size);
|
||||
virtual void postprocess(IpcParsedCommand &r, IpcCommand &out_c, u64 cmd_id, u8 *pointer_buffer, size_t pointer_buffer_size);
|
||||
virtual Result handle_deferred();
|
||||
|
||||
protected:
|
||||
/* Overridden commands. */
|
||||
std::tuple<Result> get_firmware_version(OutPointerWithServerSize<SetSysFirmwareVersion, 0x1> out);
|
||||
std::tuple<Result> get_firmware_version2(OutPointerWithServerSize<SetSysFirmwareVersion, 0x1> out);
|
||||
};
|
|
@ -196,7 +196,7 @@ class ISession : public IWaitable {
|
|||
/* TODO: Panic? */
|
||||
}
|
||||
IpcParsedCommand r;
|
||||
u64 cmd_id;
|
||||
u64 cmd_id = 0;
|
||||
|
||||
|
||||
Result retval = ipcParse(&r);
|
||||
|
|
Loading…
Reference in a new issue