]> Chaos Git - corbenik/corbenik.git/commitdiff
Get NAND CID with loader for config file
authorchaoskagami <chaos.kagami@gmail.com>
Fri, 19 Aug 2016 21:44:11 +0000 (17:44 -0400)
committerchaoskagami <chaos.kagami@gmail.com>
Fri, 19 Aug 2016 21:47:03 +0000 (17:47 -0400)
external/loader/loader.rsf
external/loader/source/fsldr.c
external/loader/source/fsldr.h
external/loader/source/patcher.c

index c2412b616358db697c79ca038e0b075f77c603d5..1abce9094415b708c44370d4c56ad9c30a5be064 100644 (file)
@@ -112,6 +112,7 @@ AccessControlInfo:
   FileSystemAccess:
     - DirectSdmc
     - CtrNandRw
+    - CategoryFileSystemTool # For FSLDR_GetNandCID
 
 SystemControlInfo:
   SaveDataSize: 0KB # It doesn't use any save data.
index ba5582855b979804f1196ff887fce9e82a903fe0..6414a3495d49067b197c7adc7d04756c8238af84 100644 (file)
@@ -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];
+}
index 36dac0c7a49123e5b56ab61c49d839247aed6ae7..1d57a31b3fff6571f97ea51e89121128cba44102 100644 (file)
@@ -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
index 9950b278ec304cd6a371f41d8d6799dee18132c0..a94c2e85b1f683353dc8a89082166316a2cf72b8 100644 (file)
@@ -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;
     }