]> Chaos Git - corbenik/corbenik.git/commitdiff
Update emuNAND code (untested)
authorchaoskagami <chaos.kagami@gmail.com>
Wed, 7 Sep 2016 22:41:50 +0000 (18:41 -0400)
committerchaoskagami <chaos.kagami@gmail.com>
Wed, 7 Sep 2016 22:41:50 +0000 (18:41 -0400)
include/firm/firm.h
source/firm/util.c
source/patch/emunand.c

index 453bd6075d7a813b5ce7542094a7a9281f510fde..df233aed97006820b378f204619cf5c2cd312b8c 100644 (file)
@@ -43,4 +43,6 @@ int boot_firm(const char *firm_path, const char *prepatch_path, const char* modu
  */
 firm_h* load_firm(const char *path, size_t *size_out);
 
+exefs_h* find_proc9(firm_h *firm);
+
 #endif
index 3ba183cac6d50fc09296a1bac53f475891bed1ab..f16a90c5dcfb2723808d94cacf53912dce0b7c8c 100644 (file)
@@ -206,3 +206,26 @@ int patch_section_keys(firm_h* firm_loc, uint32_t k9l) {
 
     return 0;
 }
+
+
+exefs_h*
+find_proc9(firm_h *firm)
+{
+       for (firm_section_h *section = firm->section; section < firm->section + 4; section++) {
+               if (section->address == 0)
+                       break;
+               if (section->type == FIRM_TYPE_ARM9) {
+                       uint8_t* arm9section = memfind((uint8_t *)firm + section->offset, section->size, "Process9", 8);
+                       if (!arm9section)
+                               return NULL;
+
+                       ncch_h *ncch = (ncch_h *)((uint8_t*)arm9section - sizeof(ncch_h));
+                       if (ncch->magic == NCCH_MAGIC) {
+                               // Found Process9
+                               ncch_ex_h *p9exheader = (ncch_ex_h *)(ncch + 1);
+                               return (exefs_h *)(p9exheader + 1);
+                       }
+               }
+       }
+       return NULL;
+}
index 69a6e093ae621edb516ff9f6e9675203912c5b3a..b3e585295c5ffccb9e1b94bcd4def49125cdd98d 100644 (file)
@@ -116,11 +116,12 @@ patchMPU(uint8_t *pos, uint32_t size)
 int
 patch_emunand(firm_h* firm_loc, uint32_t index)
 {
-#if 0
     // ARM9 section.
     uint8_t *arm9Section = (uint8_t *)firm_loc + firm_loc->section[2].offset;
     uint32_t arm9SectionSize = firm_loc->section[2].size;
 
+    exefs_h* firm_p9_exefs = find_proc9(firm_loc);
+
     uint8_t *process9Offset = (uint8_t *)firm_p9_exefs + sizeof(exefs_h) + firm_p9_exefs->fileHeaders[0].offset;
     uint32_t process9Size = firm_p9_exefs->fileHeaders[0].size;
 
@@ -167,6 +168,6 @@ patch_emunand(firm_h* firm_loc, uint32_t index)
     patchMPU(arm9Section, arm9SectionSize);
 
     fprintf(stderr, "emunand: patched MPU settings\n");
-#endif
+
     return 0;
 }