mirror of
https://github.com/Atmosphere-NX/Atmosphere-libs.git
synced 2025-06-22 11:32:38 +02:00
dns.mitm: support % in hosts file as stand-in for environment identifier
This commit is contained in:
parent
0ea3e456d1
commit
66212b7926
@ -61,6 +61,7 @@
|
|||||||
#include <stratosphere/ncm.hpp>
|
#include <stratosphere/ncm.hpp>
|
||||||
#include <stratosphere/nim.hpp>
|
#include <stratosphere/nim.hpp>
|
||||||
#include <stratosphere/ns.hpp>
|
#include <stratosphere/ns.hpp>
|
||||||
|
#include <stratosphere/nsd.hpp>
|
||||||
#include <stratosphere/patcher.hpp>
|
#include <stratosphere/patcher.hpp>
|
||||||
#include <stratosphere/pcv.hpp>
|
#include <stratosphere/pcv.hpp>
|
||||||
#include <stratosphere/pgl.hpp>
|
#include <stratosphere/pgl.hpp>
|
||||||
|
18
libstratosphere/include/stratosphere/nsd.hpp
Normal file
18
libstratosphere/include/stratosphere/nsd.hpp
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018-2020 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 <stratosphere/nsd/nsd_types.hpp>
|
||||||
|
#include <stratosphere/nsd/impl/device/nsd_device.hpp>
|
@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018-2020 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 <vapours.hpp>
|
||||||
|
#include <stratosphere/nsd/nsd_types.hpp>
|
||||||
|
|
||||||
|
namespace ams::nsd::impl::device {
|
||||||
|
|
||||||
|
const EnvironmentIdentifier &GetEnvironmentIdentifierFromSettings();
|
||||||
|
|
||||||
|
}
|
37
libstratosphere/include/stratosphere/nsd/nsd_types.hpp
Normal file
37
libstratosphere/include/stratosphere/nsd/nsd_types.hpp
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018-2020 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 <vapours.hpp>
|
||||||
|
|
||||||
|
namespace ams::nsd {
|
||||||
|
|
||||||
|
struct EnvironmentIdentifier {
|
||||||
|
static constexpr size_t Size = 8;
|
||||||
|
char value[Size];
|
||||||
|
|
||||||
|
constexpr friend bool operator==(const EnvironmentIdentifier &lhs, const EnvironmentIdentifier &rhs) {
|
||||||
|
return util::Strncmp(lhs.value, rhs.value, Size) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr friend bool operator!=(const EnvironmentIdentifier &lhs, const EnvironmentIdentifier &rhs) {
|
||||||
|
return !(lhs == rhs);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
constexpr inline const EnvironmentIdentifier EnvironmentIdentifierOfProductDevice = {"lp1"};
|
||||||
|
constexpr inline const EnvironmentIdentifier EnvironmentIdentifierOfNotProductDevice = {"dd1"};
|
||||||
|
|
||||||
|
}
|
49
libstratosphere/source/nsd/impl/device/nsd_device.cpp
Normal file
49
libstratosphere/source/nsd/impl/device/nsd_device.cpp
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018-2020 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 <stratosphere.hpp>
|
||||||
|
|
||||||
|
namespace ams::nsd::impl::device {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
constexpr const char SettingsName[] = "nsd";
|
||||||
|
constexpr const char SettingsKey[] = "environment_identifier";
|
||||||
|
|
||||||
|
constinit os::SdkMutex g_environment_identifier_lock;
|
||||||
|
constinit EnvironmentIdentifier g_environment_identifier = {};
|
||||||
|
constinit bool g_determined_environment_identifier = false;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const EnvironmentIdentifier &GetEnvironmentIdentifierFromSettings() {
|
||||||
|
std::scoped_lock lk(g_environment_identifier_lock);
|
||||||
|
|
||||||
|
if (!g_determined_environment_identifier) {
|
||||||
|
/* Check size. */
|
||||||
|
AMS_ABORT_UNLESS(settings::fwdbg::GetSettingsItemValueSize(SettingsName, SettingsKey) != 0);
|
||||||
|
|
||||||
|
/* Get value. */
|
||||||
|
const size_t size = settings::fwdbg::GetSettingsItemValue(g_environment_identifier.value, EnvironmentIdentifier::Size, SettingsName, SettingsKey);
|
||||||
|
AMS_ABORT_UNLESS(size < EnvironmentIdentifier::Size);
|
||||||
|
AMS_ABORT_UNLESS(g_environment_identifier == EnvironmentIdentifierOfProductDevice || g_environment_identifier == EnvironmentIdentifierOfNotProductDevice);
|
||||||
|
|
||||||
|
g_determined_environment_identifier = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return g_environment_identifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -31,7 +31,7 @@ namespace ams::util {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
int Strncmp(const T *lhs, const T *rhs, int count) {
|
constexpr int Strncmp(const T *lhs, const T *rhs, int count) {
|
||||||
AMS_ASSERT(lhs != nullptr);
|
AMS_ASSERT(lhs != nullptr);
|
||||||
AMS_ASSERT(rhs != nullptr);
|
AMS_ASSERT(rhs != nullptr);
|
||||||
AMS_ABORT_UNLESS(count >= 0);
|
AMS_ABORT_UNLESS(count >= 0);
|
||||||
@ -50,7 +50,7 @@ namespace ams::util {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
int Strnicmp(const T *lhs, const T *rhs, int count) {
|
constexpr int Strnicmp(const T *lhs, const T *rhs, int count) {
|
||||||
AMS_ASSERT(lhs != nullptr);
|
AMS_ASSERT(lhs != nullptr);
|
||||||
AMS_ASSERT(rhs != nullptr);
|
AMS_ASSERT(rhs != nullptr);
|
||||||
AMS_ABORT_UNLESS(count >= 0);
|
AMS_ABORT_UNLESS(count >= 0);
|
||||||
|
Loading…
Reference in New Issue
Block a user