*/
firm_h* load_firm(const char *path, size_t *size_out);
+exefs_h* find_proc9(firm_h *firm);
+
#endif
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;
+}
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;
patchMPU(arm9Section, arm9SectionSize);
fprintf(stderr, "emunand: patched MPU settings\n");
-#endif
+
return 0;
}