]> Chaos Git - corbenik/corbenik.git/commitdiff
Cleanups.
authorchaoskagami <chaos.kagami@gmail.com>
Fri, 19 Aug 2016 14:05:08 +0000 (10:05 -0400)
committerchaoskagami <chaos.kagami@gmail.com>
Fri, 19 Aug 2016 21:46:53 +0000 (17:46 -0400)
 * Inject arbitrary system modules.
 * Clean up menu layout.
 * Config is saved automatically now

source/config-file.c
source/firm/firm.c
source/menu.c
source/patch/module.c

index 2ff53a02ffe7066732637871745ab279e136208e..9dc035f7c1ef83e95cd4184dab065b4293c7c1d1 100644 (file)
@@ -107,10 +107,6 @@ save_config()
     if (!(conf_handle = fopen(PATH_CONFIG, "w")))
                while(1);
 
-    config->options[OPTION_RECONFIGURED] = 0; // This should not persist to disk.
-
     fwrite(config, 1, sizeof(struct config_file), conf_handle);
     fclose(conf_handle);
-
-    config->options[OPTION_RECONFIGURED] = 1; // Save caches on boot.
 }
index c8a5ac6275b60bd3402c2ad060d5bba053473e49..10f0b519df1057c22cf9737e1baf0a3c350f7549 100644 (file)
@@ -546,15 +546,8 @@ load_firms()
 void
 boot_cfw()
 {
-    fprintf(stderr, "Loading firmware...\n");
-
     load_firms();
 
-    if (config->options[OPTION_RECONFIGURED]) {
-        fprintf(stderr, "Generating patch cache...\n");
-        generate_patch_cache();
-    }
-
     fprintf(stderr, "Patching firmware...\n");
     if (patch_firm_all() != 0)
         return;
index 84207c5655c1b25ef7755679be582d6348cbb6bc..eefe679dd1c7e2d9a509e0080db97b0c542cd875 100644 (file)
@@ -10,9 +10,11 @@ static struct options_s options[] = {
     // Patches.
     { 0, "General Options", "", not_option, 1, 0, 0 },
 
+    { OPTION_LOADER, "System Module Inject", "Replaces system modules in FIRM like loader, fs, pxi, etc.", boolean_val, 0, 0, 0 },
+
     { OPTION_SVCS, "svcBackdoor Fixup", "Reinserts svcBackdoor on 11.0 NATIVE_FIRM. svcBackdoor allows executing arbitrary functions with ARM11 kernel permissions, and is required by some (poorly coded) applications.", boolean_val, 0, 0, 0 },
 
-    { OPTION_REBOOT, "Reboot Hook", "Hooks firmlaunch to allow largemem games on o3DS. Also allows patching TWL/AGB on all consoles.", boolean_val, 0, 0, 0 },
+    { OPTION_REBOOT, "Firmlaunch Hook", "Hooks firmlaunch to allow largemem games on o3DS. Also allows patching TWL/AGB on all consoles. Previously called 'Reboot hook' but renamed for accuracy.", boolean_val, 0, 0, 0 },
 
     { OPTION_EMUNAND, "Use EmuNAND", "Redirects NAND write/read to the SD. This supports both Gateway and redirected layouts.", boolean_val, 0, 0, 0 },
     { OPTION_EMUNAND_INDEX, "Index", "Which EmuNAND to use. If you only have one, you want 0. Currently the maximum supported is 10 (0-9), but this is arbitrary.", ranged_val, 0, 0x9, 1 },
@@ -31,17 +33,16 @@ static struct options_s options[] = {
     // Patches.
     { 0, "Loader Options", "", not_option, 1, 0, 0 },
 
-    { OPTION_LOADER, "Use Loader Replacement", "Replaces loader with one capable of extra features. You should enable this even if you don't plan to use loader-based patches to kill ASLR and the Ninjhax/OOThax checks.", boolean_val, 0, 0, 0 },
-    { OPTION_LOADER_CPU_L2, "CPU - L2 cache", "Forces the system to use the L2 cache on all applications. If you have issues with crashes, try turning this off.", boolean_val_n3ds, 0, 0, 1 },
-    { OPTION_LOADER_CPU_800MHZ, "CPU - 804Mhz", "Forces the system to run in 804Mhz mode on all applications.", boolean_val_n3ds, 0, 0, 1 },
-    { OPTION_LOADER_LANGEMU, "Language Emulation", "Reads language emulation configuration from `" PATH_LOCEMU "` and imitates the region/language.", boolean_val, 0, 0, 1 },
-    { OPTION_LOADER_LOADCODE, "Load Code Sections", "Loads code sections (text/ro/data) from SD card and patches afterwards.", boolean_val, 0, 0, 1 },
+    { OPTION_LOADER_CPU_L2, "CPU - L2 cache", "Forces the system to use the L2 cache on all applications. If you have issues with crashes, try turning this off.", boolean_val_n3ds, 0, 0, 0 },
+    { OPTION_LOADER_CPU_800MHZ, "CPU - 804Mhz", "Forces the system to run in 804Mhz mode on all applications.", boolean_val_n3ds, 0, 0, 0 },
+    { OPTION_LOADER_LANGEMU, "Language Emulation", "Reads language emulation configuration from `" PATH_LOCEMU "` and imitates the region/language.", boolean_val, 0, 0, 0 },
+    { OPTION_LOADER_LOADCODE, "Load Code Sections", "Loads code sections (text/ro/data) from SD card and patches afterwards.", boolean_val, 0, 0, 0 },
 
     { OPTION_LOADER_DUMPCODE, "Dump Code Sections",
-      "Dumps code sections for titles to SD card the first time they're loaded. Slows things down on first launch.", boolean_val, 0, 0, 1 },
+      "Dumps code sections for titles to SD card the first time they're loaded. Slows things down on first launch.", boolean_val, 0, 0, 0 },
 
     { OPTION_LOADER_DUMPCODE_ALL, "+ System Titles",
-      "Dumps code sections for system titles, too. Expect to sit at a blank screen for >3mins on the first time you do this, because it dumps everything.", boolean_val, 0, 0, 2 },
+      "Dumps code sections for system titles, too. Expect to sit at a blank screen for >3mins on the first time you do this, because it dumps everything.", boolean_val, 0, 0, 1 },
 
     // space
     { 0, "", "", not_option, 0, 0, 0 },
@@ -250,14 +251,28 @@ poweroff()
 void chainload_menu();
 #endif
 
-static struct options_s main_s[] = {
+static struct options_s config_opts[] = {
     { 0, "Options",            "Internal options for the CFW.\nThese are part of " FW_NAME " itself.", call_fun, (uint32_t)menu_options, 0, 0 },
     { 0, "Patches",            "External bytecode patches found in `" PATH_PATCHES "`.\nYou can choose which to enable.", call_fun, (uint32_t)menu_patches, 0, 0 },
+
+    // Sentinel.
+    { -1, "", "", 0, 0, 0, 0 },
+};
+
+void config_main_menu() {
+       show_menu(config_opts, NULL);
+
+    save_config(); // Save config when exiting.
+
+    generate_patch_cache();
+}
+
+static struct options_s main_s[] = {
+    { 0, "Configuration",      "Configuration options for the CFW.", call_fun, (uint32_t)config_main_menu, 0, 0 },
     { 0, "Info",               "Shows the current FIRM versions (and loads them, if needed)", call_fun, (uint32_t)menu_info,    0, 0 },
     { 0, "Readme",             "Mini-readme.\nWhy are you opening help on this, though?\nThat's kind of silly.", call_fun, (uint32_t)menu_help,    0, 0 },
     { 0, "Reboot",             "Reboots the console.", call_fun, (uint32_t)reset,        0, 0 },
     { 0, "Power off",          "Powers off the console.", call_fun, (uint32_t)poweroff,     0, 0 },
-    { 0, "Save Configuration", "Save the configuration.\nYou must do this prior to booting,\notherwise the cache will not be (re)generated..", call_fun, (uint32_t)save_config,  0, 0 },
 #if defined(CHAINLOADER) && CHAINLOADER == 1
     { 0, "Chainload",          "Boot another ARM9 payload file.", call_fun, (uint32_t)chainload_menu, 0, 0 },
 #endif
index db4ac94351473b0302a4af09db04867207124eb0..b6bf20f458bbbef3246237922dc8e98481120924 100644 (file)
@@ -2,14 +2,21 @@
 
 /* Not possible to be implemented as bytecode. Hey, can't win em all. */
 
-int
-patch_modules()
+void
+inject_module(char* fpath)
 {
+    FILINFO f2;
+    if (f_stat(fpath, &f2) != FR_OK)
+        return;
+
+    if (f2.fattrib & AM_DIR)
+        return;
+
     // TODO - load other module cxis here
-    FILE *f = fopen(PATH_MODULES "/loader.cxi", "r");
+    FILE *f = fopen(fpath, "r");
     if (!f) {
-        fprintf(stderr, "Module: loader.cxi not found on FS\n");
-        return 2;
+        fprintf(stderr, "Module: %s not found\n", fpath);
+        return;
     }
 
     size_t size = fsize(f);
@@ -41,7 +48,7 @@ patch_modules()
                     }
                 }
 
-                fprintf(stderr, "module: Grow %lu units\n", need_units);
+                fprintf(stderr, "Module: Grow %lu units\n", need_units);
             }
 
             // Move the remaining modules closer
@@ -56,16 +63,28 @@ patch_modules()
                 // Move end of section to be adjacent
             }
 
-            fprintf(stderr, "Module: Injecting module\n");
             // Copy the module into the firm
             memcpy(sysmodule, module, module->contentSize * 0x200);
+
+            fprintf(stderr, "Module: injected %s\n", fpath);
+
+            goto end_inj;
         }
         sysmodule = (ncch_h *)((uint32_t)sysmodule + sysmodule->contentSize * 0x200);
     }
 
-    fprintf(stderr, "Module: injected modules.\n");
+    fprintf(stderr, "Module: Failed to inject %s\n", fpath);
+
+end_inj:
 
     free(temp);
+    return;
+}
+
+int
+patch_modules()
+{
+    recurse_call(PATH_MODULES, inject_module);
 
     return 0;
 }