Implement set_mitm

This commit is contained in:
Michael Scire
2019-11-21 19:32:41 -08:00
committed by SciresM
parent 5228768841
commit 8764d94fd9
13 changed files with 341 additions and 12 deletions

View File

@@ -60,7 +60,7 @@ namespace ams::mitm {
constexpr ModuleDefinition g_module_definitions[ModuleId_Count] = {
GetModuleDefinition<fs::MitmModule>(),
GetModuleDefinition<set::MitmModule>(),
GetModuleDefinition<settings::MitmModule>(),
GetModuleDefinition<bpc::MitmModule>(),
GetModuleDefinition<ns::MitmModule>(),
GetModuleDefinition<hid::MitmModule>(),

View File

@@ -0,0 +1,63 @@
/*
* 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/>.
*/
#include "set_mitm_service.hpp"
namespace ams::mitm::settings {
using namespace ams::settings;
Result SetMitmService::EnsureLocale() {
std::scoped_lock lk(this->lock);
const bool is_ns = this->client_info.program_id == ncm::ProgramId::Ns;
if (!this->got_locale) {
std::memset(&this->locale, 0xCC, sizeof(this->locale));
ncm::ProgramId program_id = this->client_info.program_id;
if (program_id == ncm::ProgramId::Ns) {
/* When NS asks for a locale, refresh to get the current application locale. */
os::ProcessId application_process_id;
R_TRY(pm::dmnt::GetApplicationProcessId(&application_process_id));
R_TRY(pm::info::GetProgramId(&program_id, application_process_id));
}
this->locale = cfg::GetOverrideLocale(program_id);
this->got_locale = !is_ns;
}
return ResultSuccess();
}
Result SetMitmService::GetLanguageCode(sf::Out<settings::LanguageCode> out) {
this->EnsureLocale();
/* If there's no override locale, just use the actual one. */
R_UNLESS(settings::IsValidLanguageCode(this->locale.language_code), sm::mitm::ResultShouldForwardToSession());
out.SetValue(this->locale.language_code);
return ResultSuccess();
}
Result SetMitmService::GetRegionCode(sf::Out<settings::RegionCode> out) {
this->EnsureLocale();
/* If there's no override locale, just use the actual one. */
R_UNLESS(settings::IsValidRegionCode(this->locale.region_code), sm::mitm::ResultShouldForwardToSession());
out.SetValue(this->locale.region_code);
return ResultSuccess();
}
}

View File

@@ -16,25 +16,39 @@
#pragma once
#include <stratosphere.hpp>
namespace ams::mitm::set {
namespace ams::mitm::settings {
class SetMitmService : public sf::IMitmServiceObject {
private:
enum class CommandId {
/* TODO */
GetLanguageCode = 0,
GetRegionCode = 4,
};
private:
os::Mutex lock;
cfg::OverrideLocale locale;
bool got_locale;
public:
static bool ShouldMitm(const sm::MitmProcessInfo &client_info) {
/* TODO */
return false;
/* We will mitm:
* - ns and games, to allow for overriding game locales.
*/
const bool is_game = (ncm::IsApplicationProgramId(client_info.program_id) && !client_info.override_status.IsHbl());
return client_info.program_id == ncm::ProgramId::Ns || is_game;
}
public:
SF_MITM_SERVICE_OBJECT_CTOR(SetMitmService) { /* ... */ }
SF_MITM_SERVICE_OBJECT_CTOR(SetMitmService) {
this->got_locale = false;
}
private:
Result EnsureLocale();
protected:
/* TODO */
Result GetLanguageCode(sf::Out<ams::settings::LanguageCode> out);
Result GetRegionCode(sf::Out<ams::settings::RegionCode> out);
public:
DEFINE_SERVICE_DISPATCH_TABLE {
/* TODO */
MAKE_SERVICE_COMMAND_META(GetLanguageCode),
MAKE_SERVICE_COMMAND_META(GetRegionCode),
};
};

View File

@@ -17,7 +17,7 @@
#include "set_mitm_service.hpp"
#include "setsys_mitm_service.hpp"
namespace ams::mitm::set {
namespace ams::mitm::settings {
namespace {

View File

@@ -17,7 +17,7 @@
#include <stratosphere.hpp>
#include "../amsmitm_module.hpp"
namespace ams::mitm::set {
namespace ams::mitm::settings {
DEFINE_MITM_MODULE_CLASS(0x8000, 43);

View File

@@ -16,7 +16,7 @@
#pragma once
#include <stratosphere.hpp>
namespace ams::mitm::set {
namespace ams::mitm::settings {
class SetSysMitmService : public sf::IMitmServiceObject {
private: