From a211d8fc27d1eead97da48549072a1d03d961215 Mon Sep 17 00:00:00 2001 From: chaoskagami Date: Fri, 19 Aug 2016 17:44:11 -0400 Subject: [PATCH] Get NAND CID with loader for config file --- external/loader/loader.rsf | 1 + external/loader/source/fsldr.c | 17 +++++++++++++++++ external/loader/source/fsldr.h | 1 + external/loader/source/patcher.c | 18 +++++++++++++++++- 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/external/loader/loader.rsf b/external/loader/loader.rsf index c2412b6..1abce90 100644 --- a/external/loader/loader.rsf +++ b/external/loader/loader.rsf @@ -112,6 +112,7 @@ AccessControlInfo: FileSystemAccess: - DirectSdmc - CtrNandRw + - CategoryFileSystemTool # For FSLDR_GetNandCID SystemControlInfo: SaveDataSize: 0KB # It doesn't use any save data. diff --git a/external/loader/source/fsldr.c b/external/loader/source/fsldr.c index ba55828..6414a34 100644 --- a/external/loader/source/fsldr.c +++ b/external/loader/source/fsldr.c @@ -116,3 +116,20 @@ FSLDR_OpenFileDirectly(Handle *out, FS_ArchiveID archiveId, FS_Path archivePath, return cmdbuf[1]; } + +Result +FSLDR_GetNandCid(u8* out, u32 length) +{ + u32 *cmdbuf = getThreadCommandBuffer(); + + cmdbuf[0] = IPC_MakeHeader(0x81A, 1, 2); // 0x81A0042 + cmdbuf[1] = length; + cmdbuf[2] = IPC_Desc_Buffer(length, IPC_BUFFER_W); + cmdbuf[3] = (u32) out; + + Result ret = 0; + if(R_FAILED(ret = svcSendSyncRequest(fsldrHandle))) + return ret; + + return cmdbuf[1]; +} diff --git a/external/loader/source/fsldr.h b/external/loader/source/fsldr.h index 36dac0c..1d57a31 100644 --- a/external/loader/source/fsldr.h +++ b/external/loader/source/fsldr.h @@ -8,5 +8,6 @@ void fsldrExit(void); Result FSLDR_InitializeWithSdkVersion(Handle session, u32 version); Result FSLDR_SetPriority(u32 priority); Result FSLDR_OpenFileDirectly(Handle *out, FS_ArchiveID archiveId, FS_Path archivePath, FS_Path filePath, u32 openFlags, u32 attributes); +Result FSLDR_GetNandCid(u8* out, u32 length); #endif diff --git a/external/loader/source/patcher.c b/external/loader/source/patcher.c index 9950b27..a94c2e8 100644 --- a/external/loader/source/patcher.c +++ b/external/loader/source/patcher.c @@ -48,9 +48,25 @@ load_config() { static Handle file; static u32 total; + static u32 cid[4]; + static char config_file_path[] = SYSCONFDIR "/config-00000000"; + + if (!R_SUCCEEDED(FSLDR_GetNandCid((u8*)cid, 0x10))) { + return; + } + + char* cfg = config_file_path; + while(cfg[1] != 0) cfg++; + + // Get path of actual config. + while (cid[0]) { + cfg[0] = hexDigits[(uint32_t)(cid[0] & 0xF)]; + cfg--; + cid[0] >>= 4; + } // Open file. - if (!R_SUCCEEDED(fileOpen(&file, ARCHIVE_SDMC, PATH_CONFIG, FS_OPEN_READ))) { + if (!R_SUCCEEDED(fileOpen(&file, ARCHIVE_SDMC, config_file_path, FS_OPEN_READ))) { // Failed to open. return; } -- 2.39.5