From: chaoskagami Date: Thu, 9 Jun 2016 19:55:52 +0000 (-0400) Subject: resizing sysmodule code X-Git-Tag: v0.0.8~5 X-Git-Url: https://chaos.moe/g/?a=commitdiff_plain;h=f83b9dda18808a43aded9df56f1312c90f72173b;p=corbenik%2Fcorbenik.git resizing sysmodule code --- diff --git a/source/firm/firm.c b/source/firm/firm.c index 7794437..eee914e 100644 --- a/source/firm/firm.c +++ b/source/firm/firm.c @@ -6,17 +6,17 @@ #include "../common.h" firm_h *firm_loc = (firm_h *)FCRAM_FIRM_LOC; -static uint32_t firm_size = FCRAM_SPACING; +uint32_t firm_size = FCRAM_SPACING; firm_section_h firm_proc9; exefs_h *firm_p9_exefs; firm_h *twl_firm_loc = (firm_h *)FCRAM_TWL_FIRM_LOC; -static uint32_t twl_firm_size = FCRAM_SPACING * 2; +uint32_t twl_firm_size = FCRAM_SPACING * 2; firm_section_h twl_firm_proc9; exefs_h *twl_firm_p9_exefs; firm_h *agb_firm_loc = (firm_h *)FCRAM_AGB_FIRM_LOC; -static uint32_t agb_firm_size = FCRAM_SPACING; +uint32_t agb_firm_size = FCRAM_SPACING * 2; firm_section_h agb_firm_proc9; exefs_h *agb_firm_p9_exefs; diff --git a/source/firm/firm.h b/source/firm/firm.h index f71dfff..9fba7e1 100644 --- a/source/firm/firm.h +++ b/source/firm/firm.h @@ -18,16 +18,19 @@ struct firm_signature }; extern firm_h *firm_loc; +extern uint32_t firm_size; extern struct firm_signature *current_firm; extern firm_section_h firm_proc9; extern exefs_h *firm_p9_exefs; extern firm_h *twl_firm_loc; +extern uint32_t twl_firm_size; extern struct firm_signature *current_twl_firm; extern firm_section_h twl_firm_proc9; extern exefs_h *twl_firm_p9_exefs; extern firm_h *agb_firm_loc; +extern uint32_t agb_firm_size; extern struct firm_signature *current_agb_firm; extern firm_section_h agb_firm_proc9; extern exefs_h *agb_firm_p9_exefs; diff --git a/source/patch/module.c b/source/patch/module.c index 5bf79f5..61ed1d4 100644 --- a/source/patch/module.c +++ b/source/patch/module.c @@ -16,12 +16,14 @@ PATCH(modules) fclose(f); // Look for the section that holds all the sysmodules + int section_index = 0; firm_section_h *sysmodule_section = NULL; for (firm_section_h *section = firm_loc->section; section < firm_loc->section + 4; section++) { if (section->address == 0x1FF00000 && section->type == FIRM_TYPE_ARM11) { sysmodule_section = section; break; } + section_index++; } if (!sysmodule_section) { @@ -38,28 +40,24 @@ PATCH(modules) // Expand firmware module size if needed to accomodate replacement. if (module->contentSize > sysmodule->contentSize) { uint32_t need_units = (module->contentSize - sysmodule->contentSize); - fprintf(stderr, "module: Would grow %d units but NYI\n", need_units); - continue; - // TODO - so in a nutshell, the reason Luma works is because it - // relocates - // the sysmodule section to its final location while fixing the - // size. - // Once stuff is at the right place, it no longer cares about - // its' size. + memmove((uint8_t *)sysmodule + module->contentSize * 0x200, + (uint8_t *)sysmodule + sysmodule->contentSize * 0x200, + ((uint8_t *)firm_loc + firm_size) - ((uint8_t*)sysmodule + (module->contentSize * 0x200)) + ); - // Cakes performs an in-place resize and leaves the copy for - // later; essentially, - // this means I need to scale EVERYTHING after the increase, and - // adjust NCCH sections accordingly. + sysmodule_section->size += 0x200 * need_units; + for(int i=section_index+1; i < 4; i++) { + firm_loc->section[i].offset += 0x200 * need_units; + firm_loc->section[i].size += 0x200 * need_units; + } - // It would be hella easier to just patch at the final location - // in memory; - // and this was actually mentioned on Luma's issues. + fprintf(stderr, "module: Grow %d units\n", need_units); } // Move the remaining modules closer - if (module->contentSize < sysmodule->contentSize) { + else if (module->contentSize < sysmodule->contentSize) { + // NOTE - This doesn't change the sysmodule section size; it isn't needed to do so. fprintf(stderr, "Module: Shrink %d units\n", sysmodule->contentSize - module->contentSize); int remaining_size = sysmodule_section->size - (((uint32_t)sysmodule + sysmodule->contentSize * 0x200) - ((uint32_t)firm_loc + sysmodule_section->offset));