From 06c3215546f58c988360f5e0df3ac5f05090ba30 Mon Sep 17 00:00:00 2001 From: PabloMK7 Date: Sat, 17 Jun 2023 17:21:42 +0200 Subject: [PATCH] Add svcGetSystemInfo option to get booted firm path --- arm9/source/patches.c | 6 ++++++ k11_extension/include/globals.h | 2 ++ k11_extension/source/svc/GetSystemInfo.c | 9 ++++++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/arm9/source/patches.c b/arm9/source/patches.c index f9af12c..e01a631 100644 --- a/arm9/source/patches.c +++ b/arm9/source/patches.c @@ -44,6 +44,8 @@ #define K11EXT_VA 0x70000000 +extern u16 launchedPath[]; + u8 *getProcess9Info(u8 *pos, u32 size, u32 *process9Size, u32 *process9MemAddr) { u8 *temp = memsearch(pos, "NCCH", size, 4); @@ -139,6 +141,8 @@ u32 installK11Extension(u8 *pos, u32 size, bool needToInitSd, u32 baseK11VA, u32 u64 autobootTwlTitleId; u8 autobootCtrAppmemtype; + + u16 launchedPath[80+1]; } info; }; @@ -226,6 +230,8 @@ u32 installK11Extension(u8 *pos, u32 size, bool needToInitSd, u32 baseK11VA, u32 if(needToInitSd) info->flags |= 1 << 5; if(isSdMode) info->flags |= 1 << 6; + memcpy(info->launchedPath, launchedPath, sizeof(info->launchedPath)); + return 0; } diff --git a/k11_extension/include/globals.h b/k11_extension/include/globals.h index 6468589..d6e4dcb 100644 --- a/k11_extension/include/globals.h +++ b/k11_extension/include/globals.h @@ -146,6 +146,8 @@ typedef struct CfwInfo u64 autobootTwlTitleId; u8 autobootCtrAppmemtype; + + u16 launchedPath[80+1]; } CfwInfo; extern CfwInfo cfwInfo; diff --git a/k11_extension/source/svc/GetSystemInfo.c b/k11_extension/source/svc/GetSystemInfo.c index 0e88365..6ed13c0 100644 --- a/k11_extension/source/svc/GetSystemInfo.c +++ b/k11_extension/source/svc/GetSystemInfo.c @@ -37,7 +37,14 @@ Result GetSystemInfoHook(s64 *out, s32 type, s32 param) { case 0x10000: { - switch(param) + if (param >= 0x400 && param < 0x500) { + *out = 0; + s32 offset = param - 0x400; + s32 toCopy = (s32)sizeof(cfwInfo.launchedPath) - offset; + if (toCopy > 8) toCopy = 8; + memcpy(out, (u8*)cfwInfo.launchedPath + offset, (toCopy > 0) ? toCopy : 0); + } + else switch(param) { // Please do not use these, except 0, 1, and 0x200 // Other types may get removed or reordered without notice