]> Chaos Git - corbenik/corbenik.git/commitdiff
resizing sysmodule code
authorchaoskagami <chaos.kagami@gmail.com>
Thu, 9 Jun 2016 19:55:52 +0000 (15:55 -0400)
committerchaoskagami <chaos.kagami@gmail.com>
Thu, 9 Jun 2016 19:55:52 +0000 (15:55 -0400)
source/firm/firm.c
source/firm/firm.h
source/patch/module.c

index 779443772dbf640e4d293f5eb10162525870552d..eee914e17edc2a9114b94ef061972ee87b0368b2 100644 (file)
@@ -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;
 
index f71dfff185c69ead4b2feb49548b8cfa2f748444..9fba7e1634826757c7102efed13cb1afc95917f7 100644 (file)
@@ -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;
index 5bf79f57bf1d5bb2396cd4e258425a92c0ae0cda..61ed1d4b32f45ff74c55e9d764f31e6f253b9807 100644 (file)
@@ -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));