From: chaoskagami Date: Wed, 7 Sep 2016 22:41:50 +0000 (-0400) Subject: Update emuNAND code (untested) X-Git-Tag: v0.3.0~16 X-Git-Url: https://chaos.moe/g/?a=commitdiff_plain;h=1d84bd7e68916f918107843693497eb87bab4c82;p=corbenik%2Fcorbenik.git Update emuNAND code (untested) --- diff --git a/include/firm/firm.h b/include/firm/firm.h index 453bd60..df233ae 100644 --- a/include/firm/firm.h +++ b/include/firm/firm.h @@ -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 diff --git a/source/firm/util.c b/source/firm/util.c index 3ba183c..f16a90c 100644 --- a/source/firm/util.c +++ b/source/firm/util.c @@ -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; +} diff --git a/source/patch/emunand.c b/source/patch/emunand.c index 69a6e09..b3e5852 100644 --- a/source/patch/emunand.c +++ b/source/patch/emunand.c @@ -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; }