2018-09-07 17:00:13 +02:00
|
|
|
/*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2018-06-10 03:33:22 +02:00
|
|
|
#pragma once
|
|
|
|
#include <switch.h>
|
2018-10-30 01:30:39 +01:00
|
|
|
#include <stratosphere.hpp>
|
2018-06-13 00:00:09 +02:00
|
|
|
#include "fs_istorage.hpp"
|
2018-07-28 05:15:06 +02:00
|
|
|
#include "fsmitm_utils.hpp"
|
2018-06-10 03:33:22 +02:00
|
|
|
|
2018-10-30 01:30:39 +01:00
|
|
|
enum FspSrvCmd : u32 {
|
|
|
|
FspSrvCmd_SetCurrentProcess = 1,
|
|
|
|
FspSrvCmd_OpenDataStorageByCurrentProcess = 200,
|
|
|
|
FspSrvCmd_OpenDataStorageByDataId = 202,
|
2018-06-10 11:06:50 +02:00
|
|
|
};
|
|
|
|
|
2018-10-30 01:30:39 +01:00
|
|
|
class FsMitmService : public IMitmServiceObject {
|
2018-06-10 11:06:50 +02:00
|
|
|
private:
|
2018-07-02 16:26:03 +02:00
|
|
|
bool has_initialized = false;
|
2018-06-28 07:02:06 +02:00
|
|
|
std::shared_ptr<IStorageInterface> romfs_storage;
|
2018-06-10 03:33:22 +02:00
|
|
|
public:
|
2018-10-30 01:30:39 +01:00
|
|
|
FsMitmService(std::shared_ptr<Service> s) : IMitmServiceObject(s) {
|
2018-06-10 11:12:34 +02:00
|
|
|
/* ... */
|
|
|
|
}
|
2018-06-13 00:00:09 +02:00
|
|
|
|
2018-10-30 01:30:39 +01:00
|
|
|
static bool ShouldMitm(u64 pid, u64 tid) {
|
2018-10-17 05:41:19 +02:00
|
|
|
if (Utils::HasSdDisableMitMFlag(tid)) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-10-17 04:01:41 +02:00
|
|
|
return (tid >= 0x0100000000010000ULL || Utils::HasSdMitMFlag(tid)) && Utils::HasOverrideButton(tid);
|
2018-06-15 01:50:01 +02:00
|
|
|
}
|
|
|
|
|
2018-10-30 01:30:39 +01:00
|
|
|
static void PostProcess(IMitmServiceObject *obj, IpcResponseContext *ctx);
|
|
|
|
|
2018-06-10 19:11:05 +02:00
|
|
|
protected:
|
|
|
|
/* Overridden commands. */
|
2018-10-30 01:30:39 +01:00
|
|
|
Result OpenDataStorageByCurrentProcess(Out<std::shared_ptr<IStorageInterface>> out);
|
|
|
|
Result OpenDataStorageByDataId(Out<std::shared_ptr<IStorageInterface>> out, u64 storage_id, u64 data_id);
|
|
|
|
public:
|
|
|
|
DEFINE_SERVICE_DISPATCH_TABLE {
|
|
|
|
MakeServiceCommandMeta<FspSrvCmd_OpenDataStorageByCurrentProcess, &FsMitmService::OpenDataStorageByCurrentProcess>(),
|
|
|
|
MakeServiceCommandMeta<FspSrvCmd_OpenDataStorageByDataId, &FsMitmService::OpenDataStorageByDataId>(),
|
|
|
|
};
|
2018-06-19 20:07:31 +02:00
|
|
|
};
|