Merge fs.mitm and set.mitm.

This commit is contained in:
Michael Scire
2019-01-29 02:29:29 -08:00
parent 5f836aca6d
commit e715197290
50 changed files with 426 additions and 630 deletions

View File

@@ -0,0 +1,59 @@
/*
* 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/>.
*/
#include <cstdlib>
#include <cstdint>
#include <cstring>
#include <malloc.h>
#include <switch.h>
#include <atmosphere.h>
#include <stratosphere.hpp>
#include "setmitm_main.hpp"
#include "setsys_mitm_service.hpp"
#include "setsys_settings_items.hpp"
#include "../utils.hpp"
struct SetSysManagerOptions {
static const size_t PointerBufferSize = 0x100;
static const size_t MaxDomains = 4;
static const size_t MaxDomainObjects = 0x100;
};
using SetMitmManager = WaitableManager<SetSysManagerOptions>;
void SetMitmMain(void *arg) {
/* Wait for SD to initialize. */
Utils::WaitSdInitialized();
/* Load settings */
SettingsItemManager::LoadConfiguration();
/* Create server manager */
auto server_manager = new SetMitmManager(3);
/* Create set:sys mitm. */
AddMitmServerToManager<SetSysMitmService>(server_manager, "set:sys", 60);
/* Loop forever, servicing our services. */
server_manager->Process();
delete server_manager;
}

View File

@@ -0,0 +1,29 @@
/*
* 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/>.
*/
#include <cstdlib>
#include <cstdint>
#include <cstring>
#include <malloc.h>
#include <switch.h>
#include <atmosphere.h>
#include <stratosphere.hpp>
constexpr u32 SetMitmPriority = 43;
constexpr u32 SetMitmStackSize = 0x8000;
void SetMitmMain(void *arg);

View File

@@ -0,0 +1,55 @@
/*
* 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/>.
*/
#include <mutex>
#include <switch.h>
#include "setsys_firmware_version.hpp"
static HosMutex g_version_mutex;
static bool g_got_version = false;
static SetSysFirmwareVersion g_fw_version = {0};
Result VersionManager::GetFirmwareVersion(u64 title_id, SetSysFirmwareVersion *out) {
std::scoped_lock<HosMutex> lock(g_version_mutex);
if (!g_got_version) {
Result rc = setsysGetFirmwareVersion(&g_fw_version);
if (R_FAILED(rc)) {
return rc;
}
/* Modify the output firmware version. */
{
u32 major, minor, micro;
char display_version[sizeof(g_fw_version.display_version)] = {0};
GetAtmosphereApiVersion(&major, &minor, &micro, nullptr, nullptr);
snprintf(display_version, sizeof(display_version), "%s (AMS %u.%u.%u)", g_fw_version.display_version, major, minor, micro);
memcpy(g_fw_version.display_version, display_version, sizeof(g_fw_version.display_version));
}
g_got_version = true;
}
/* Report atmosphere string to qlaunch, maintenance and nothing else. */
if (title_id == 0x0100000000001000ULL || title_id == 0x0100000000001015ULL) {
*out = g_fw_version;
return 0;
} else {
return setsysGetFirmwareVersion(out);
}
}

View File

@@ -0,0 +1,24 @@
/*
* 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/>.
*/
#pragma once
#include <switch.h>
#include <stratosphere.hpp>
class VersionManager {
public:
static Result GetFirmwareVersion(u64 title_id, SetSysFirmwareVersion *out);
};

View File

@@ -0,0 +1,119 @@
/*
* 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/>.
*/
#include <mutex>
#include <algorithm>
#include <switch.h>
#include "setsys_mitm_service.hpp"
#include "setsys_firmware_version.hpp"
#include "setsys_settings_items.hpp"
void SetSysMitmService::PostProcess(IMitmServiceObject *obj, IpcResponseContext *ctx) {
/* No commands need postprocessing. */
}
Result SetSysMitmService::GetFirmwareVersion(OutPointerWithServerSize<SetSysFirmwareVersion, 0x1> out) {
Result rc = VersionManager::GetFirmwareVersion(this->title_id, out.pointer);
/* GetFirmwareVersion sanitizes these fields. */
if (R_SUCCEEDED(rc)) {
out.pointer->revision_major = 0;
out.pointer->revision_minor = 0;
}
return rc;
}
Result SetSysMitmService::GetFirmwareVersion2(OutPointerWithServerSize<SetSysFirmwareVersion, 0x1> out) {
return VersionManager::GetFirmwareVersion(this->title_id, out.pointer);
}
Result SetSysMitmService::GetSettingsItemValueSize(Out<u64> out_size, InPointer<char> in_name, InPointer<char> in_key) {
char name[SET_MAX_NAME_SIZE] = {0};
char key[SET_MAX_NAME_SIZE] = {0};
Result rc = SettingsItemManager::ValidateName(in_name.pointer);
if (R_FAILED(rc)) {
return rc;
}
rc = SettingsItemManager::ValidateKey(in_key.pointer);
if (R_FAILED(rc)) {
return rc;
}
if (in_name.num_elements < SET_MAX_NAME_SIZE) {
strncpy(name, in_name.pointer, in_name.num_elements);
} else {
strncpy(name, in_name.pointer, SET_MAX_NAME_SIZE-1);
}
if (in_key.num_elements < SET_MAX_NAME_SIZE) {
strncpy(key, in_key.pointer, in_key.num_elements);
} else {
strncpy(key, in_key.pointer, SET_MAX_NAME_SIZE-1);
}
rc = SettingsItemManager::GetValueSize(name, key, out_size.GetPointer());
if (R_FAILED(rc)) {
rc = setsysGetSettingsItemValueSize(name, key, out_size.GetPointer());
}
return rc;
}
Result SetSysMitmService::GetSettingsItemValue(Out<u64> out_size, OutBuffer<u8> out_value, InPointer<char> in_name, InPointer<char> in_key) {
char name[SET_MAX_NAME_SIZE] = {0};
char key[SET_MAX_NAME_SIZE] = {0};
Result rc = SettingsItemManager::ValidateName(in_name.pointer);
if (R_FAILED(rc)) {
return rc;
}
rc = SettingsItemManager::ValidateKey(in_key.pointer);
if (R_FAILED(rc)) {
return rc;
}
if (out_value.buffer == nullptr) {
return 0x19A69;
}
if (in_name.num_elements < SET_MAX_NAME_SIZE) {
strncpy(name, in_name.pointer, in_name.num_elements);
} else {
strncpy(name, in_name.pointer, SET_MAX_NAME_SIZE-1);
}
if (in_key.num_elements < SET_MAX_NAME_SIZE) {
strncpy(key, in_key.pointer, in_key.num_elements);
} else {
strncpy(key, in_key.pointer, SET_MAX_NAME_SIZE-1);
}
rc = SettingsItemManager::GetValue(name, key, out_value.buffer, out_value.num_elements, out_size.GetPointer());
if (R_FAILED(rc)) {
rc = setsysGetSettingsItemValueFwd(this->forward_service.get(), name, key, out_value.buffer, out_value.num_elements, out_size.GetPointer());
}
return rc;
}
Result SetSysMitmService::GetEdid(OutPointerWithServerSize<SetSysEdid, 0x1> out) {
return setsysGetEdidFwd(this->forward_service.get(), out.pointer);
}

View File

@@ -0,0 +1,65 @@
/*
* 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/>.
*/
#pragma once
#include <switch.h>
#include <stratosphere.hpp>
#include "setsys_shim.h"
enum SetSysCmd : u32 {
SetSysCmd_GetFirmwareVersion = 3,
SetSysCmd_GetFirmwareVersion2 = 4,
SetSysCmd_GetSettingsItemValueSize = 37,
SetSysCmd_GetSettingsItemValue = 38,
/* Commands for which set:sys *must* act as a passthrough. */
/* TODO: Solve the relevant IPC detection problem. */
SetSysCmd_GetEdid = 41,
};
class SetSysMitmService : public IMitmServiceObject {
public:
SetSysMitmService(std::shared_ptr<Service> s, u64 pid) : IMitmServiceObject(s, pid) {
/* ... */
}
static bool ShouldMitm(u64 pid, u64 tid) {
/* Mitm everything. */
return true;
}
static void PostProcess(IMitmServiceObject *obj, IpcResponseContext *ctx);
protected:
/* Overridden commands. */
Result GetFirmwareVersion(OutPointerWithServerSize<SetSysFirmwareVersion, 0x1> out);
Result GetFirmwareVersion2(OutPointerWithServerSize<SetSysFirmwareVersion, 0x1> out);
Result GetSettingsItemValueSize(Out<u64> out_size, InPointer<char> name, InPointer<char> key);
Result GetSettingsItemValue(Out<u64> out_size, OutBuffer<u8> out_value, InPointer<char> name, InPointer<char> key);
/* Forced passthrough commands. */
Result GetEdid(OutPointerWithServerSize<SetSysEdid, 0x1> out);
public:
DEFINE_SERVICE_DISPATCH_TABLE {
MakeServiceCommandMeta<SetSysCmd_GetFirmwareVersion, &SetSysMitmService::GetFirmwareVersion>(),
MakeServiceCommandMeta<SetSysCmd_GetFirmwareVersion2, &SetSysMitmService::GetFirmwareVersion2>(),
MakeServiceCommandMeta<SetSysCmd_GetSettingsItemValueSize, &SetSysMitmService::GetSettingsItemValueSize>(),
MakeServiceCommandMeta<SetSysCmd_GetSettingsItemValue, &SetSysMitmService::GetSettingsItemValue>(),
MakeServiceCommandMeta<SetSysCmd_GetEdid, &SetSysMitmService::GetEdid>(),
};
};

View File

@@ -0,0 +1,309 @@
/*
* 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/>.
*/
#include <mutex>
#include <algorithm>
#include <map>
#include <string>
#include <utility>
#include <switch.h>
#include <strings.h>
#include <ctype.h>
#include "setsys_settings_items.hpp"
#include "../utils.hpp"
#include "../ini.h"
struct SettingsItemValue {
size_t size;
u8 *data;
};
std::map<std::string, SettingsItemValue> g_settings_items;
static bool g_threw_fatal = false;
static HosThread g_fatal_thread;
static void FatalThreadFunc(void *arg) {
Result rc = (Result)((uintptr_t)arg);
svcSleepThread(5000000000ULL);
fatalSimple(rc);
}
static bool IsCorrectFormat(const char *str, size_t len) {
if (len > 0 && str[len - 1] == '.') {
return false;
}
for (size_t i = 0; i < len; i++) {
const char c = *(str++);
if ('a' <= c && c <= 'z') {
continue;
}
if ('0' <= c && c <= '9') {
continue;
}
if (c == '-' || c == '.' || c == '_') {
continue;
}
return false;
}
return true;
}
Result SettingsItemManager::ValidateName(const char *name, size_t max_size) {
if (name == nullptr) {
return 0x19269;
}
const size_t name_len = strnlen(name, std::min(max_size, MaxNameLength + 1));
if (name_len == 0) {
return 0x1BA69;
} else if (name_len > MaxNameLength) {
return 0x1E269;
}
if (!IsCorrectFormat(name, name_len)) {
return 0x20A69;
}
return 0x0;
}
Result SettingsItemManager::ValidateName(const char *name) {
return ValidateName(name, MaxNameLength + 1);
}
Result SettingsItemManager::ValidateKey(const char *key, size_t max_size) {
if (key == nullptr) {
return 0x19469;
}
const size_t key_len = strnlen(key, std::min(max_size, MaxKeyLength + 1));
if (key_len == 0) {
return 0x1BC69;
} else if (key_len > MaxKeyLength) {
return 0x1E469;
}
if (!IsCorrectFormat(key, key_len)) {
return 0x20C69;
}
return 0x0;
}
Result SettingsItemManager::ValidateKey(const char *key) {
return ValidateKey(key, MaxKeyLength + 1);
}
static bool IsHexadecimal(const char *str) {
while (*str) {
if (isxdigit(*str)) {
str++;
} else {
return false;
}
}
return true;
}
static char hextoi(char c) {
if ('a' <= c && c <= 'f') return c - 'a' + 0xA;
if ('A' <= c && c <= 'F') return c - 'A' + 0xA;
if ('0' <= c && c <= '9') return c - '0';
return 0;
}
static Result ParseValue(const char *name, const char *key, const char *val_tup) {
const char *delimiter = strchr(val_tup, '!');
const char *value_str = delimiter + 1;
const char *type = val_tup;
if (delimiter == NULL) {
return 0x20E69;
}
while (isspace(*type) && type != delimiter) {
type++;
}
size_t type_len = delimiter - type;
size_t value_len = strlen(value_str);
if (delimiter == NULL || value_len == 0 || type_len == 0) {
return 0x20E69;
}
std::string kv = std::string(name) + "!" + std::string(key);
SettingsItemValue value;
if (strncasecmp(type, "str", type_len) == 0 || strncasecmp(type, "string", type_len) == 0) {
/* String */
value.size = value_len + 1;
value.data = reinterpret_cast<u8 *>(strdup(value_str));
if (value.data == nullptr) {
return 0xCC69;
}
} else if (strncasecmp(type, "hex", type_len) == 0 || strncasecmp(type, "bytes", type_len) == 0) {
/* hex */
if (value_len % 2 || !IsHexadecimal(value_str)) {
return 0x20E69;
}
value.size = value_len / 2;
u8 *data = reinterpret_cast<u8 *>(malloc(value.size));
if (data == nullptr) {
return 0xCC69;
}
memset(data, 0, value.size);
for (size_t i = 0; i < value_len; i++) {
data[i >> 1] |= hextoi(value_str[i]) << (4 * (i & 1));
}
value.data = data;
} else if (strncasecmp(type, "u8", type_len) == 0) {
/* u8 */
value.size = sizeof(u8);
u8 *data = reinterpret_cast<u8 *>(malloc(value.size));
if (data == nullptr) {
return 0xCC69;
}
*data = (u8)(strtoul(value_str, nullptr, 0));
value.data = reinterpret_cast<u8 *>(data);
} else if (strncasecmp(type, "u16", type_len) == 0) {
/* u16 */
value.size = sizeof(u16);
u16 *data = reinterpret_cast<u16 *>(malloc(value.size));
if (data == nullptr) {
return 0xCC69;
}
*data = (u16)(strtoul(value_str, nullptr, 0));
value.data = reinterpret_cast<u8 *>(data);
} else if (strncasecmp(type, "u32", type_len) == 0) {
/* u32 */
value.size = sizeof(u32);
u32 *data = reinterpret_cast<u32 *>(malloc(value.size));
if (data == nullptr) {
return 0xCC69;
}
*data = (u32)(strtoul(value_str, nullptr, 0));
value.data = reinterpret_cast<u8 *>(data);
} else if (strncasecmp(type, "u64", type_len) == 0) {
/* u64 */
value.size = sizeof(u64);
u64 *data = reinterpret_cast<u64 *>(malloc(value.size));
if (data == nullptr) {
return 0xCC69;
}
*data = (u64)(strtoul(value_str, nullptr, 0));
value.data = reinterpret_cast<u8 *>(data);
} else {
return 0x20E69;
}
g_settings_items[kv] = value;
return 0x0;
}
static int SettingsItemIniHandler(void *user, const char *name, const char *key, const char *value) {
Result rc = *(reinterpret_cast<Result *>(user));
ON_SCOPE_EXIT { *(reinterpret_cast<Result *>(user)) = rc; };
if (R_SUCCEEDED(rc)) {
rc = SettingsItemManager::ValidateName(name);
}
if (R_SUCCEEDED(rc)) {
rc = SettingsItemManager::ValidateKey(name);
}
if (R_SUCCEEDED(rc)) {
rc = ParseValue(name, key, value);
}
return R_SUCCEEDED(rc) ? 1 : 0;
}
void SettingsItemManager::LoadConfiguration() {
/* Open file. */
FsFile config_file;
Result rc = Utils::OpenSdFile("/atmosphere/system_settings.ini", FS_OPEN_READ, &config_file);
if (R_FAILED(rc)) {
return;
}
ON_SCOPE_EXIT {
fsFileClose(&config_file);
};
/* Allocate buffer. */
char *config_buf = new char[0x10000];
std::memset(config_buf, 0, 0x10000);
ON_SCOPE_EXIT {
delete config_buf;
};
/* Read from file. */
if (R_SUCCEEDED(rc)) {
size_t actual_size;
rc = fsFileRead(&config_file, 0, config_buf, 0xFFFF, &actual_size);
}
if (R_SUCCEEDED(rc)) {
ini_parse_string(config_buf, SettingsItemIniHandler, &rc);
}
/* Report error if we encountered one. */
if (R_FAILED(rc) && !g_threw_fatal) {
g_threw_fatal = true;
g_fatal_thread.Initialize(&FatalThreadFunc, reinterpret_cast<void *>(rc), 0x1000, 49);
g_fatal_thread.Start();
}
}
Result SettingsItemManager::GetValueSize(const char *name, const char *key, u64 *out_size) {
std::string kv = std::string(name) + "!" + std::string(key);
auto it = g_settings_items.find(kv);
if (it == g_settings_items.end()) {
return 0x1669;
}
*out_size = it->second.size;
return 0x0;
}
Result SettingsItemManager::GetValue(const char *name, const char *key, void *out, size_t max_size, u64 *out_size) {
std::string kv = std::string(name) + "!" + std::string(key);
auto it = g_settings_items.find(kv);
if (it == g_settings_items.end()) {
return 0x1669;
}
size_t copy_size = it->second.size;
if (max_size < copy_size) {
copy_size = max_size;
}
*out_size = copy_size;
memcpy(out, it->second.data, copy_size);
return 0x0;
}

View File

@@ -0,0 +1,36 @@
/*
* 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/>.
*/
#pragma once
#include <switch.h>
#include <stratosphere.hpp>
class SettingsItemManager {
public:
static constexpr size_t MaxNameLength = 64;
static constexpr size_t MaxKeyLength = 64;
public:
static Result ValidateName(const char *name, size_t max_size);
static Result ValidateName(const char *name);
static Result ValidateKey(const char *key, size_t max_size);
static Result ValidateKey(const char *key);
static void LoadConfiguration();
static Result GetValueSize(const char *name, const char *key, u64 *out_size);
static Result GetValue(const char *name, const char *key, void *out, size_t max_size, u64 *out_size);
};

View File

@@ -0,0 +1,100 @@
/*
* 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/>.
*/
#include <string.h>
#include <switch.h>
#include "setsys_shim.h"
/* Command forwarders. */
Result setsysGetEdidFwd(Service* s, SetSysEdid* out) {
IpcCommand c;
ipcInitialize(&c);
ipcAddRecvStatic(&c, out, sizeof(*out), 0);
struct {
u64 magic;
u64 cmd_id;
} *raw;
raw = serviceIpcPrepareHeader(s, &c, sizeof(*raw));
raw->magic = SFCI_MAGIC;
raw->cmd_id = 41;
Result rc = serviceIpcDispatch(s);
if (R_SUCCEEDED(rc)) {
IpcParsedCommand r;
struct {
u64 magic;
u64 result;
} *resp;
serviceIpcParse(s, &r, sizeof(*resp));
resp = r.Raw;
rc = resp->result;
}
return rc;
}
Result setsysGetSettingsItemValueFwd(Service *s, const char *name, const char *item_key, void *value_out, size_t value_out_size, u64 *size_out) {
char send_name[SET_MAX_NAME_SIZE];
char send_item_key[SET_MAX_NAME_SIZE];
memset(send_name, 0, SET_MAX_NAME_SIZE);
memset(send_item_key, 0, SET_MAX_NAME_SIZE);
strncpy(send_name, name, SET_MAX_NAME_SIZE-1);
strncpy(send_item_key, item_key, SET_MAX_NAME_SIZE-1);
IpcCommand c;
ipcInitialize(&c);
ipcAddSendStatic(&c, send_name, SET_MAX_NAME_SIZE, 0);
ipcAddSendStatic(&c, send_item_key, SET_MAX_NAME_SIZE, 0);
ipcAddRecvBuffer(&c, value_out, value_out_size, 0);
struct {
u64 magic;
u64 cmd_id;
} *raw;
raw = serviceIpcPrepareHeader(s, &c, sizeof(*raw));
raw->magic = SFCI_MAGIC;
raw->cmd_id = 38;
Result rc = serviceIpcDispatch(s);
if (R_SUCCEEDED(rc)) {
IpcParsedCommand r;
struct {
u64 magic;
u64 result;
u64 size_out;
} *resp;
serviceIpcParse(s, &r, sizeof(*resp));
resp = r.Raw;
rc = resp->result;
if (R_SUCCEEDED(rc)) {
*size_out = resp->size_out;
}
}
return rc;
}

View File

@@ -0,0 +1,24 @@
/**
* @file setsys_shim.h
* @brief System Settings Services (set:sys) IPC wrapper. To be merged into libnx, eventually.
* @author SciresM
* @copyright libnx Authors
*/
#pragma once
#include <switch.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
char edid[0x100];
} SetSysEdid;
/* Command forwarders. */
Result setsysGetEdidFwd(Service* s, SetSysEdid* out);
Result setsysGetSettingsItemValueFwd(Service* s, const char *name, const char *item_key, void *value_out, size_t value_out_size, u64 *size_out);
#ifdef __cplusplus
}
#endif