]> Chaos Git - corbenik/corbenik.git/commitdiff
Inject system modules in TWL/AGB (god apache, that was out of nowhere, gg)
authorchaoskagami <chaos.kagami@gmail.com>
Sun, 21 Aug 2016 19:28:56 +0000 (15:28 -0400)
committerchaoskagami <chaos.kagami@gmail.com>
Sun, 21 Aug 2016 19:28:56 +0000 (15:28 -0400)
Makefile.am
include/patch_format.h
source/firm/firm.c
source/patch/module.c

index 4acfea8ea95943575fb5a669c8a150d80b559e23..d7f4b632bf642c82ed188bef68ffad081fe70f14 100644 (file)
@@ -9,6 +9,9 @@ all-local:
        mkdir -p out
        mkdir -p out@prefix@
        mkdir -p out@libdir@/module
+       mkdir -p out@libdir@/module/native
+       mkdir -p out@libdir@/module/twl
+       mkdir -p out@libdir@/module/agb
        mkdir -p out@libdir@/firmware
        mkdir -p out@datarootdir@/keys
        mkdir -p out@datarootdir@/locale/emu
@@ -19,7 +22,7 @@ all-local:
        mkdir -p out@sysconfdir@
        mkdir -p out@localstatedir@
        cp source/corbenik.bin out/arm9loaderhax.bin
-       cp external/loader/loader.cxi out@libdir@/module/loader.cxi
+       cp external/loader/loader.cxi out@libdir@/module/native/loader.cxi
        cp external/bits/*.bin out@libexecdir@/
        cp host/termfont.bin out@datarootdir@/
        cp patch/*.vco out@sbindir@
index 28668f9719d7bc7115cec9a3355c858d6596351d..9c3bd4b8be9dd1c1a4e1068a7bf0c378d6e43a13 100644 (file)
 // TODO - We also need to handle patches for internal system modules here, performing lzss decompression (and either recompression, or getting a patch to skip that if needed
 
 #define PATH_MODULES         LIBDIR "/module"        ///< Sysmodule location
+
+#define PATH_MODULE_NATIVE   PATH_MODULES "/native"     ///< Native FIRM Sysmodule location
+#define PATH_MODULE_AGB      PATH_MODULES "/agb"        ///< AGB FIRM Sysmodule location
+#define PATH_MODULE_TWL      PATH_MODULES "/twl"        ///< TWL FIRM Sysmodule location
+
 #define PATH_PATCHES         SBINDIR                 ///< Patch binary folder.
 
 #define PATH_BITS            LIBEXECDIR              ///< Path to misc bits we need (emunand code, reboot code, etc)
index c132cb8c43d11d90bd5b6c6390d0d3ae7a4afe75..df5f046cd23ab02f2f2c7db08a4537035d505a96 100644 (file)
@@ -558,7 +558,7 @@ boot_cfw()
     if (patch_firm_all() != 0)
         return;
 
-    if (config->options[OPTION_REBOOT] && config->options[OPTION_RECONFIGURED]) {
+    if (config->options[OPTION_REBOOT]) {
         fprintf(stderr, "Saving FIRM for reboot...\n");
         if (!write_file(firm_loc, PATH_NATIVE_P, firm_size))
             abort("Failed to save prepatched native\n");
index b6bf20f458bbbef3246237922dc8e98481120924..aba1a61ffc884a1b70f4efd275e6acd4b77e9988 100644 (file)
@@ -2,6 +2,8 @@
 
 /* Not possible to be implemented as bytecode. Hey, can't win em all. */
 
+firm_h* firm_modules;
+
 void
 inject_module(char* fpath)
 {
@@ -25,10 +27,10 @@ inject_module(char* fpath)
     fclose(f);
 
     int section_index = 0;
-    firm_section_h *sysmodule_section = &firm_loc->section[0];
+    firm_section_h *sysmodule_section = &firm_modules->section[0];
 
     ncch_h *module = (ncch_h *)temp;
-    ncch_h *sysmodule = (ncch_h *)((uint32_t)firm_loc + sysmodule_section->offset);
+    ncch_h *sysmodule = (ncch_h *)((uint32_t)firm_modules + sysmodule_section->offset);
 
     // Check if we want to replace an existing sysmodule
     while (sysmodule->magic == NCCH_MAGIC) {
@@ -38,13 +40,13 @@ inject_module(char* fpath)
                 uint32_t need_units = (module->contentSize - sysmodule->contentSize);
 
                 memmove((uint8_t *)sysmodule + module->contentSize * 0x200, (uint8_t *)sysmodule + sysmodule->contentSize * 0x200,
-                        ((uint32_t)firm_loc + firm_size) - ((uint32_t)sysmodule + (module->contentSize * 0x200)));
+                        ((uint32_t)firm_modules + firm_size) - ((uint32_t)sysmodule + (module->contentSize * 0x200)));
 
                 sysmodule_section->size += 0x200 * need_units;
                 for (int i = 1; i < 4; i++) {
-                    if (firm_loc->section[i].size != 0) { // The last section (3) is usually empty.
-                        firm_loc->section[i].offset += 0x200 * need_units;
-                        firm_loc->section[i].size += 0x200 * need_units;
+                    if (firm_modules->section[i].size != 0) { // The last section (3) is usually empty.
+                        firm_modules->section[i].offset += 0x200 * need_units;
+                        firm_modules->section[i].size += 0x200 * need_units;
                     }
                 }
 
@@ -56,7 +58,7 @@ inject_module(char* fpath)
                 // NOTE - This doesn't change the sysmodule section size; it isn't needed to do so.
                 fprintf(stderr, "Module: Shrink %lu units\n", sysmodule->contentSize - module->contentSize);
                 uint32_t remaining_size =
-                    sysmodule_section->size - (((uint32_t)sysmodule + sysmodule->contentSize * 0x200) - ((uint32_t)firm_loc + sysmodule_section->offset));
+                    sysmodule_section->size - (((uint32_t)sysmodule + sysmodule->contentSize * 0x200) - ((uint32_t)firm_modules + sysmodule_section->offset));
                 // Sysmodule section size - (End location of this sysmodule -
                 // Sysmodule section) =>
                 memmove((uint8_t *)sysmodule + module->contentSize * 0x200, (uint8_t *)sysmodule + sysmodule->contentSize * 0x200, remaining_size);
@@ -84,7 +86,13 @@ end_inj:
 int
 patch_modules()
 {
-    recurse_call(PATH_MODULES, inject_module);
+    firm_modules = firm_loc;
+    recurse_call(PATH_MODULE_NATIVE, inject_module);
+    firm_modules = twl_firm_loc;
+    recurse_call(PATH_MODULE_TWL, inject_module);
+    firm_modules = agb_firm_loc;
+    recurse_call(PATH_MODULE_AGB, inject_module);
 
     return 0;
 }
+