2019-05-22 19:11:40 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2019 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 "../utils.hpp"
|
|
|
|
|
|
|
|
class SetMitmService : public IMitmServiceObject {
|
2019-06-28 06:34:26 +00:00
|
|
|
private:
|
|
|
|
enum class CommandId {
|
|
|
|
GetLanguageCode = 0,
|
|
|
|
GetRegionCode = 4,
|
|
|
|
|
|
|
|
/* Commands for which set:sys *must* act as a passthrough. */
|
|
|
|
/* TODO: Solve the relevant IPC detection problem. */
|
|
|
|
GetAvailableLanguageCodes = 1,
|
|
|
|
};
|
2019-05-22 19:11:40 +00:00
|
|
|
private:
|
|
|
|
HosMutex lock;
|
|
|
|
OverrideLocale locale;
|
|
|
|
bool got_locale;
|
|
|
|
public:
|
2019-07-04 05:57:49 +00:00
|
|
|
SetMitmService(std::shared_ptr<Service> s, u64 pid, sts::ncm::TitleId tid) : IMitmServiceObject(s, pid, tid) {
|
2019-05-22 19:11:40 +00:00
|
|
|
this->got_locale = false;
|
|
|
|
}
|
|
|
|
|
2019-07-03 03:54:16 +00:00
|
|
|
static bool ShouldMitm(u64 pid, sts::ncm::TitleId tid) {
|
2019-05-22 19:11:40 +00:00
|
|
|
/* Mitm all applications. */
|
2019-07-03 03:54:16 +00:00
|
|
|
return tid == sts::ncm::TitleId::Ns || sts::ncm::IsApplicationTitleId(tid);
|
2019-05-22 19:11:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void PostProcess(IMitmServiceObject *obj, IpcResponseContext *ctx);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static bool IsValidLanguageCode(u64 lang_code);
|
|
|
|
static bool IsValidRegionCode(u32 region_code);
|
|
|
|
|
2019-06-20 11:04:33 +00:00
|
|
|
Result EnsureLocale();
|
2019-05-22 19:11:40 +00:00
|
|
|
protected:
|
|
|
|
/* Overridden commands. */
|
|
|
|
Result GetLanguageCode(Out<u64> out_lang_code);
|
|
|
|
Result GetRegionCode(Out<u32> out_region_code);
|
|
|
|
|
|
|
|
/* Forced passthrough commands. */
|
|
|
|
Result GetAvailableLanguageCodes(OutPointerWithClientSize<u64> out_language_codes, Out<s32> out_count);
|
|
|
|
public:
|
|
|
|
DEFINE_SERVICE_DISPATCH_TABLE {
|
2019-06-28 06:34:26 +00:00
|
|
|
MAKE_SERVICE_COMMAND_META(SetMitmService, GetLanguageCode),
|
|
|
|
MAKE_SERVICE_COMMAND_META(SetMitmService, GetRegionCode),
|
2019-05-22 19:11:40 +00:00
|
|
|
|
2019-06-28 06:34:26 +00:00
|
|
|
MAKE_SERVICE_COMMAND_META(SetMitmService, GetAvailableLanguageCodes),
|
2019-05-22 19:11:40 +00:00
|
|
|
};
|
|
|
|
};
|