From 635f0401e8db2920d06a57a628297de7b4256332 Mon Sep 17 00:00:00 2001 From: Adubbz Date: Thu, 31 May 2018 16:50:01 +1000 Subject: [PATCH] Added a few misc IPC wrappers Signed-off-by: Adubbz --- nx/include/switch/services/ns.h | 6 +++ nx/include/switch/services/pm.h | 1 + nx/include/switch/services/set.h | 16 ++++++ nx/source/services/ns.c | 90 +++++++++++++++++++++++++++++++- nx/source/services/pm.c | 33 ++++++++++++ nx/source/services/set.c | 70 +++++++++++++++++++++++++ 6 files changed, 214 insertions(+), 2 deletions(-) diff --git a/nx/include/switch/services/ns.h b/nx/include/switch/services/ns.h index ab435f30..da326488 100644 --- a/nx/include/switch/services/ns.h +++ b/nx/include/switch/services/ns.h @@ -17,3 +17,9 @@ Result nsInitialize(void); void nsExit(void); Result nsGetApplicationControlData(u8 flag, u64 titleID, NsApplicationControlData* buffer, size_t size, size_t* actual_size); + +Result nsvmInitialize(void); +void nsvmExit(void); + +Result nsvmNeedsUpdateVulnerability(u8 *out); +Result nsvmGetSafeSystemVersion(u16 *out); diff --git a/nx/include/switch/services/pm.h b/nx/include/switch/services/pm.h index 8ca894fa..6365b9d1 100644 --- a/nx/include/switch/services/pm.h +++ b/nx/include/switch/services/pm.h @@ -27,3 +27,4 @@ Result pmdmntEnableDebugForApplication(Handle* handle_out); Result pminfoGetTitleId(u64* title_id_out, u64 pid); Result pmshellLaunchProcess(u32 launch_flags, u64 titleID, u64 storageID, u64 *pid); +Result pmshellTerminateProcessByTitleId(u64 title_id); \ No newline at end of file diff --git a/nx/include/switch/services/set.h b/nx/include/switch/services/set.h index 41ae0b1f..91018cfe 100644 --- a/nx/include/switch/services/set.h +++ b/nx/include/switch/services/set.h @@ -7,6 +7,8 @@ */ #include "../result.h" +#define SET_MAX_NAME_SIZE 0x30 + typedef enum { ColorSetId_Light=0, ColorSetId_Dark=1 @@ -67,6 +69,18 @@ void setsysExit(void); /// Gets the current system theme. Result setsysGetColorSetId(ColorSetId* out); +/** + * @brief Gets the size of a settings item value. + * @param out Pointer to output the size to. + */ +Result setsysGetSettingsItemValueSize(const char *name, const char *item_key, u64 *size_out); + +/** + * @brief Gets the value of a settings item value. + * @param out Pointer to output the value to. + */ +Result setsysGetSettingsItemValue(const char *name, const char *item_key, u64 *value_out); + /** * @brief Gets the system's serial number. * @param serial Pointer to output the serial to. (The buffer size needs to be at least 0x19 bytes) @@ -108,3 +122,5 @@ Result setsysGetWirelessLanEnableFlag(bool *out); * @param out Pointer to output the status to. */ Result setsysGetBluetoothEnableFlag(bool *out); + + diff --git a/nx/source/services/ns.c b/nx/source/services/ns.c index 69661bed..b2fbefc5 100644 --- a/nx/source/services/ns.c +++ b/nx/source/services/ns.c @@ -6,8 +6,8 @@ #include "services/sm.h" #include "services/ns.h" -static Service g_nsAppManSrv, g_nsGetterSrv; -static u64 g_nsRefCnt; +static Service g_nsAppManSrv, g_nsGetterSrv, g_nsvmSrv; +static u64 g_nsRefCnt, g_nsvmRefCnt; static Result _nsGetInterface(Service* srv_out, u64 cmd_id); @@ -116,3 +116,89 @@ Result nsGetApplicationControlData(u8 flag, u64 titleID, NsApplicationControlDat return rc; } + +Result nsvmInitialize(void) +{ + atomicIncrement64(&g_nsvmRefCnt); + + if (serviceIsActive(&g_nsvmSrv)) + return MAKERESULT(Module_Libnx, LibnxError_AlreadyInitialized); + + return smGetService(&g_nsvmSrv, "ns:vm"); +} + +void nsvmExit(void) +{ + if (atomicDecrement64(&g_nsvmRefCnt) == 0) { + serviceClose(&g_nsvmSrv); + } +} + +Result nsvmNeedsUpdateVulnerability(u8 *out) { + IpcCommand c; + ipcInitialize(&c); + + struct { + u64 magic; + u64 cmd_id; + } *raw; + + raw = ipcPrepareHeader(&c, sizeof(*raw)); + + raw->magic = SFCI_MAGIC; + raw->cmd_id = 1200; + + Result rc = serviceIpcDispatch(&g_nsvmSrv); + + if (R_SUCCEEDED(rc)) { + IpcParsedCommand r; + ipcParse(&r); + + struct { + u64 magic; + u64 result; + u8 out; + } *resp = r.Raw; + + rc = resp->result; + + if (R_SUCCEEDED(rc) && out) *out = resp->out; + } + + return rc; +} + +Result nsvmGetSafeSystemVersion(u16 *out) +{ + IpcCommand c; + ipcInitialize(&c); + + struct { + u64 magic; + u64 cmd_id; + } *raw; + + raw = ipcPrepareHeader(&c, sizeof(*raw)); + + raw->magic = SFCI_MAGIC; + raw->cmd_id = 1202; + + Result rc = serviceIpcDispatch(&g_nsvmSrv); + + if (R_SUCCEEDED(rc)) { + IpcParsedCommand r; + ipcParse(&r); + + struct { + u64 magic; + u64 result; + u16 out; + } *resp = r.Raw; + + rc = resp->result; + + if (R_SUCCEEDED(rc) && out) *out = resp->out; + } + + return rc; +} \ No newline at end of file diff --git a/nx/source/services/pm.c b/nx/source/services/pm.c index c901767e..99e10090 100644 --- a/nx/source/services/pm.c +++ b/nx/source/services/pm.c @@ -314,3 +314,36 @@ Result pmshellLaunchProcess(u32 launch_flags, u64 titleID, u64 storageID, u64 *p return rc; } + +Result pmshellTerminateProcessByTitleId(u64 title_id) { + IpcCommand c; + ipcInitialize(&c); + + struct { + u64 magic; + u64 cmd_id; + u64 title_id; + } *raw; + + raw = ipcPrepareHeader(&c, sizeof(*raw)); + + raw->magic = SFCI_MAGIC; + raw->cmd_id = 2; + raw->title_id = title_id; + + Result rc = serviceIpcDispatch(&g_pmshellSrv); + + if (R_SUCCEEDED(rc)) { + IpcParsedCommand r; + ipcParse(&r); + + struct { + u64 magic; + u64 result; + } *resp = r.Raw; + + rc = resp->result; + } + + return rc; +} \ No newline at end of file diff --git a/nx/source/services/set.c b/nx/source/services/set.c index 5fb2ff2a..f88f7f22 100644 --- a/nx/source/services/set.c +++ b/nx/source/services/set.c @@ -348,6 +348,76 @@ Result setsysGetColorSetId(ColorSetId* out) } +Result setsysGetSettingsItemValue(const char *name, const char *item_key, u64 *value_out) { + IpcCommand c; + ipcInitialize(&c); + ipcAddSendStatic(&c, name, SET_MAX_NAME_SIZE, 0); + ipcAddSendStatic(&c, item_key, SET_MAX_NAME_SIZE, 0); + ipcAddRecvBuffer(&c, value_out, sizeof(u64), 0); + + struct { + u64 magic; + u64 cmd_id; + } *raw; + + raw = ipcPrepareHeader(&c, sizeof(*raw)); + + raw->magic = SFCI_MAGIC; + raw->cmd_id = 38; + + Result rc = serviceIpcDispatch(&g_setsysSrv); + + if (R_SUCCEEDED(rc)) { + IpcParsedCommand r; + ipcParse(&r); + + struct { + u64 magic; + u64 result; + } *resp = r.Raw; + + rc = resp->result; + } + + return rc; +} + +Result setsysGetSettingsItemValueSize(const char *name, const char *item_key, u64 *size_out) { + IpcCommand c; + ipcInitialize(&c); + ipcAddSendStatic(&c, name, SET_MAX_NAME_SIZE, 0); + ipcAddSendStatic(&c, item_key, SET_MAX_NAME_SIZE, 0); + + struct { + u64 magic; + u64 cmd_id; + } *raw; + + raw = ipcPrepareHeader(&c, sizeof(*raw)); + + raw->magic = SFCI_MAGIC; + raw->cmd_id = 37; + + Result rc = serviceIpcDispatch(&g_setsysSrv); + + if (R_SUCCEEDED(rc)) { + IpcParsedCommand r; + ipcParse(&r); + + struct { + u64 magic; + u64 result; + u64 size; + } *resp = r.Raw; + + rc = resp->result; + + if (R_SUCCEEDED(rc) && size_out) *size_out = resp->size; + } + + return rc; +} + Result setsysGetSerialNumber(char *serial) { IpcCommand c; ipcInitialize(&c);