mitm/cfg: pass around override status for decision-making
This commit is contained in:
@@ -13,10 +13,8 @@
|
||||
* 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 "../os/os_common_types.hpp"
|
||||
#include "../ncm/ncm_types.hpp"
|
||||
#include "cfg_types.hpp"
|
||||
|
||||
namespace ams::cfg {
|
||||
|
||||
@@ -31,10 +29,7 @@ namespace ams::cfg {
|
||||
void WaitSdCardInitialized();
|
||||
|
||||
/* Override key utilities. */
|
||||
bool IsProgramOverrideKeyHeld(ncm::ProgramId program_id);
|
||||
bool IsHblOverrideKeyHeld(ncm::ProgramId program_id);
|
||||
void GetOverrideKeyHeldStatus(bool *out_hbl, bool *out_program, ncm::ProgramId program_id);
|
||||
bool IsCheatEnableKeyHeld(ncm::ProgramId program_id);
|
||||
OverrideStatus CaptureOverrideStatus(ncm::ProgramId program_id);
|
||||
|
||||
/* Flag utilities. */
|
||||
bool HasFlag(ncm::ProgramId program_id, const char *flag);
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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 "../os/os_common_types.hpp"
|
||||
#include "../ncm/ncm_types.hpp"
|
||||
|
||||
namespace ams::cfg {
|
||||
|
||||
namespace impl {
|
||||
|
||||
enum OverrideStatusFlag : u64 {
|
||||
OverrideStatusFlag_Hbl = BIT(0),
|
||||
OverrideStatusFlag_ProgramSpecific = BIT(1),
|
||||
OverrideStatusFlag_CheatEnabled = BIT(2),
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
struct OverrideStatus {
|
||||
u64 keys_held;
|
||||
u64 flags;
|
||||
|
||||
constexpr inline u64 GetKeysHeld() const { return this->keys_held; }
|
||||
|
||||
#define DEFINE_FLAG_ACCESSORS(flag) \
|
||||
constexpr inline bool Is##flag() const { return this->flags & impl::OverrideStatusFlag_##flag; } \
|
||||
constexpr inline void Set##flag() { this->flags |= impl::OverrideStatusFlag_##flag; } \
|
||||
constexpr inline void Clear##flag() { this->flags &= ~u64(impl::OverrideStatusFlag_##flag); }
|
||||
|
||||
DEFINE_FLAG_ACCESSORS(Hbl)
|
||||
DEFINE_FLAG_ACCESSORS(ProgramSpecific)
|
||||
DEFINE_FLAG_ACCESSORS(CheatEnabled)
|
||||
|
||||
#undef DEFINE_FLAG_ACCESSORS
|
||||
};
|
||||
|
||||
static_assert(sizeof(OverrideStatus) == 0x10, "sizeof(OverrideStatus)");
|
||||
static_assert(std::is_pod<OverrideStatus>::value, "std::is_pod<OverrideStatus>::value");
|
||||
|
||||
constexpr inline bool operator==(const OverrideStatus &lhs, const OverrideStatus &rhs) {
|
||||
return lhs.keys_held == rhs.keys_held && lhs.flags == rhs.flags;
|
||||
}
|
||||
|
||||
constexpr inline bool operator!=(const OverrideStatus &lhs, const OverrideStatus &rhs) {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -26,4 +26,8 @@ namespace ams::ldr::pm {
|
||||
Result UnpinProgram(PinId pin_id);
|
||||
Result HasLaunchedProgram(bool *out, ncm::ProgramId program_id);
|
||||
|
||||
/* Atmosphere extension API. */
|
||||
Result AtmosphereGetProgramInfo(ProgramInfo *out, cfg::OverrideStatus *out_status, const ncm::ProgramLocation &loc);
|
||||
Result AtmospherePinProgram(PinId *out, const ncm::ProgramLocation &loc, const cfg::OverrideStatus &status);
|
||||
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace ams::pm::dmnt {
|
||||
Result GetProcessId(os::ProcessId *out_process_id, const ncm::ProgramId program_id);
|
||||
Result GetApplicationProcessId(os::ProcessId *out_process_id);
|
||||
Result HookToCreateApplicationProcess(Handle *out_handle);
|
||||
Result AtmosphereGetProcessInfo(Handle *out_handle, ncm::ProgramLocation *out_loc, os::ProcessId process_id);
|
||||
Result AtmosphereGetProcessInfo(Handle *out_handle, ncm::ProgramLocation *out_loc, cfg::OverrideStatus *out_status, os::ProcessId process_id);
|
||||
Result AtmosphereGetCurrentLimitInfo(u64 *out_current_value, u64 *out_limit_value, ResourceLimitGroup group, LimitableResource resource);
|
||||
|
||||
}
|
||||
|
||||
@@ -26,6 +26,8 @@ namespace ams::pm::info {
|
||||
Result GetProcessId(os::ProcessId *out_process_id, ncm::ProgramId program_id);
|
||||
Result HasLaunchedProgram(bool *out, ncm::ProgramId program_id);
|
||||
|
||||
Result GetProcessInfo(ncm::ProgramLocation *out_loc, cfg::OverrideStatus *out_status, os::ProcessId process_id);
|
||||
|
||||
/* Information convenience API. */
|
||||
bool HasLaunchedProgram(ncm::ProgramId program_id);
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace ams::sf::hipc {
|
||||
NON_COPYABLE(ServerManagerBase);
|
||||
NON_MOVEABLE(ServerManagerBase);
|
||||
public:
|
||||
using MitmQueryFunction = bool (*)(os::ProcessId, ncm::ProgramId);
|
||||
using MitmQueryFunction = bool (*)(const sm::MitmProcessInfo &);
|
||||
private:
|
||||
enum class UserDataTag : uintptr_t {
|
||||
Server = 1,
|
||||
@@ -106,11 +106,10 @@ namespace ams::sf::hipc {
|
||||
std::shared_ptr<::Service> forward_service = std::move(ServerSession::CreateForwardService());
|
||||
|
||||
/* Get mitm forward session. */
|
||||
os::ProcessId client_process_id;
|
||||
ncm::ProgramId client_program_id;
|
||||
R_ASSERT(sm::mitm::AcknowledgeSession(forward_service.get(), &client_process_id, &client_program_id, this->service_name));
|
||||
sm::MitmProcessInfo client_info;
|
||||
R_ASSERT(sm::mitm::AcknowledgeSession(forward_service.get(), &client_info, this->service_name));
|
||||
|
||||
*out_obj = std::move(cmif::ServiceObjectHolder(std::move(MakeShared(std::shared_ptr<::Service>(forward_service), client_process_id, client_program_id))));
|
||||
*out_obj = std::move(cmif::ServiceObjectHolder(std::move(MakeShared(std::shared_ptr<::Service>(forward_service), client_info))));
|
||||
*out_fsrv = std::move(forward_service);
|
||||
} else {
|
||||
*out_obj = std::move(cmif::ServiceObjectHolder(std::move(MakeShared())));
|
||||
@@ -166,8 +165,8 @@ namespace ams::sf::hipc {
|
||||
}
|
||||
|
||||
template<typename ServiceImpl>
|
||||
static constexpr inline std::shared_ptr<ServiceImpl> MakeSharedMitm(std::shared_ptr<::Service> &&s, os::ProcessId p, ncm::ProgramId r) {
|
||||
return std::make_shared<ServiceImpl>(std::forward<std::shared_ptr<::Service>>(s), p, r);
|
||||
static constexpr inline std::shared_ptr<ServiceImpl> MakeSharedMitm(std::shared_ptr<::Service> &&s, const sm::MitmProcessInfo &client_info) {
|
||||
return std::make_shared<ServiceImpl>(std::forward<std::shared_ptr<::Service>>(s), client_info);
|
||||
}
|
||||
|
||||
Result InstallMitmServerImpl(Handle *out_port_handle, sm::ServiceName service_name, MitmQueryFunction query_func);
|
||||
|
||||
@@ -17,4 +17,5 @@
|
||||
#pragma once
|
||||
#include <atmosphere/common.hpp>
|
||||
#include "../ams.hpp"
|
||||
#include "../os.hpp"
|
||||
#include "../os.hpp"
|
||||
#include "../sm/sm_types.hpp"
|
||||
@@ -25,16 +25,15 @@ namespace ams::sf {
|
||||
class IMitmServiceObject : public IServiceObject {
|
||||
protected:
|
||||
std::shared_ptr<::Service> forward_service;
|
||||
os::ProcessId process_id;
|
||||
ncm::ProgramId program_id;
|
||||
sm::MitmProcessInfo client_info;
|
||||
public:
|
||||
IMitmServiceObject(std::shared_ptr<::Service> &&s, os::ProcessId p, ncm::ProgramId r) : forward_service(std::move(s)), process_id(p), program_id(r) { /* ... */ }
|
||||
IMitmServiceObject(std::shared_ptr<::Service> &&s, const sm::MitmProcessInfo &c) : forward_service(std::move(s)), client_info(c) { /* ... */ }
|
||||
|
||||
static bool ShouldMitm(os::ProcessId process_id, ncm::ProgramId program_id);
|
||||
};
|
||||
|
||||
/* Utility. */
|
||||
#define SF_MITM_SERVICE_OBJECT_CTOR(cls) cls(std::shared_ptr<::Service> &&s, os::ProcessId p, ncm::ProgramId r) : ::ams::sf::IMitmServiceObject(std::forward<std::shared_ptr<::Service>>(s), p, r)
|
||||
#define SF_MITM_SERVICE_OBJECT_CTOR(cls) cls(std::shared_ptr<::Service> &&s, const sm::MitmProcessInfo &c) : ::ams::sf::IMitmServiceObject(std::forward<std::shared_ptr<::Service>>(s), c)
|
||||
|
||||
template<typename T>
|
||||
struct ServiceObjectTraits {
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
namespace ams::sm::manager {
|
||||
|
||||
/* Manager API. */
|
||||
Result RegisterProcess(os::ProcessId process_id, ncm::ProgramId program_id, const void *acid, size_t acid_size, const void *aci, size_t aci_size);
|
||||
Result RegisterProcess(os::ProcessId process_id, ncm::ProgramId program_id, cfg::OverrideStatus status, const void *acid, size_t acid_size, const void *aci, size_t aci_size);
|
||||
Result UnregisterProcess(os::ProcessId process_id);
|
||||
|
||||
/* Atmosphere extensions. */
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "sm_types.hpp"
|
||||
#include "../ncm/ncm_types.hpp"
|
||||
|
||||
namespace ams::sm::mitm {
|
||||
|
||||
@@ -25,7 +24,7 @@ namespace ams::sm::mitm {
|
||||
Result InstallMitm(Handle *out_port, Handle *out_query, ServiceName name);
|
||||
Result UninstallMitm(ServiceName name);
|
||||
Result DeclareFutureMitm(ServiceName name);
|
||||
Result AcknowledgeSession(Service *out_service, os::ProcessId *out_process_id, ncm::ProgramId *out_program_id, ServiceName name);
|
||||
Result AcknowledgeSession(Service *out_service, MitmProcessInfo *out_info, ServiceName name);
|
||||
Result HasMitm(bool *out, ServiceName name);
|
||||
Result WaitMitm(ServiceName name);
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
#pragma once
|
||||
#include <atmosphere/common.hpp>
|
||||
#include "../ncm/ncm_types.hpp"
|
||||
#include "../cfg/cfg_types.hpp"
|
||||
|
||||
namespace ams::sm {
|
||||
|
||||
@@ -65,4 +67,12 @@ namespace ams::sm {
|
||||
};
|
||||
static_assert(sizeof(ServiceRecord) == 0x30, "ServiceRecord definition!");
|
||||
|
||||
/* For Mitm extensions. */
|
||||
struct MitmProcessInfo {
|
||||
os::ProcessId process_id;
|
||||
ncm::ProgramId program_id;
|
||||
cfg::OverrideStatus override_status;
|
||||
};
|
||||
static_assert(std::is_trivial<MitmProcessInfo>::value && sizeof(MitmProcessInfo) == 0x20, "MitmProcessInfo definition!");
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user