]> Chaos Git - corbenik/corbenik.git/commitdiff
I really need to stop forgetting to run make reformat v0.0.6
authorchaoskagami <chaos.kagami@gmail.com>
Tue, 7 Jun 2016 16:07:33 +0000 (12:07 -0400)
committerchaoskagami <chaos.kagami@gmail.com>
Tue, 7 Jun 2016 16:07:33 +0000 (12:07 -0400)
21 files changed:
external/loader/source/interp.h
external/loader/source/loader.c
external/loader/source/patcher.c
external/loader/source/patcher.h
source/display.c
source/fatfs/ff.c
source/fatfs/ff.h
source/firm/firm.c
source/interp.c
source/main.c
source/menu.c
source/patch/emunand.c
source/patch/reboot.c
source/patch/svc.c
source/patch_format.h
source/patcher.c
source/screeninit.c
source/std/abort.h
source/std/draw.c
source/std/fs.c
source/std/fs.h

index 4399324710076c6c154c001f307d982497f4d2f9..4bafff4afc2c949dcda4633db87bc75f9f8f6536 100644 (file)
@@ -1,9 +1,6 @@
 #ifndef __INTERP_H
 #define __INTERP_H
 
-int execb(uint64_t tid, uint16_t ver,
-    uint8_t *text_mem, uint32_t text_len,
-    uint8_t *data_mem, uint32_t data_size,
-    uint8_t *ro_mem, uint32_t ro_size);
+int execb(uint64_t tid, uint16_t ver, uint8_t *text_mem, uint32_t text_len, uint8_t *data_mem, uint32_t data_size, uint8_t *ro_mem, uint32_t ro_size);
 
 #endif
index 9ddf277c7406041331a8923bc83e1cc0306f9999..e157df84917e667b9614a2ba22d74627cf42a7c0 100644 (file)
@@ -98,9 +98,8 @@ load_code(u64 progid, u16 progver, prog_addrs_t *shared, prog_addrs_t *original,
     dump_code(progid, (u8 *)shared->text_addr, shared->total_size << 12);
 
     // Patch segments
-    patch_exe (progid, progver, (u8 *)shared->text_addr, shared->text_size << 12, original->text_size << 12,
-                                (u8 *)shared->data_addr, shared->data_size << 12, original->data_size << 12,
-                                (u8 *)shared->ro_addr, shared->ro_size << 12, original->ro_size << 12);
+    patch_exe(progid, progver, (u8 *)shared->text_addr, shared->text_size << 12, original->text_size << 12, (u8 *)shared->data_addr, shared->data_size << 12,
+              original->data_size << 12, (u8 *)shared->ro_addr, shared->ro_size << 12, original->ro_size << 12);
 
     return 0;
 }
index 0c2a211952437ecc0c56b446f09a4f41df3e8896..332526e9c268663681c81b63d835c93b3adbc82b 100644 (file)
@@ -339,10 +339,8 @@ dump_code(u64 progId, u8 *code_loc, u32 code_len)
         return;
     }
 
-    else
-    {
-        if (R_SUCCEEDED(fileOpen(&code_f, ARCHIVE_SDMC, code_path, FS_OPEN_WRITE | FS_OPEN_CREATE)))
-        {
+    else {
+        if (R_SUCCEEDED(fileOpen(&code_f, ARCHIVE_SDMC, code_path, FS_OPEN_WRITE | FS_OPEN_CREATE))) {
             u32 len = 0;
             FSFILE_Write(code_f, &len, 0, code_loc, code_len, FS_WRITE_FLUSH | FS_WRITE_UPDATE_TIME);
             logstr("  dumped code to ");
@@ -356,10 +354,7 @@ dump_code(u64 progId, u8 *code_loc, u32 code_len)
 
 // This is only for the .code segment.
 void
-patch_exe(u64 progId, u16 progver,
-    u8 *text, u32 text_size, u32 orig_text,
-    u8* data, u32 data_size, u32 orig_data,
-    u8* ro, u32 ro_size, u32 orig_ro)
+patch_exe(u64 progId, u16 progver, u8 *text, u32 text_size, u32 orig_text, u8 *data, u32 data_size, u32 orig_data, u8 *ro, u32 ro_size, u32 orig_ro)
 {
     if (progId == 0x0004013000008002LL)
         adjust_cpu_settings(progId, text, orig_text);
index 69350637b658e18245266542c9776256c7254492..9eedb64df84882463b928d66b151d42056bcf6bb 100644 (file)
@@ -3,10 +3,7 @@
 
 #include <3ds/types.h>
 
-void patch_exe(u64 progId, u16 progver,
-    u8 *text, u32 text_size, u32 orig_text,
-    u8* data, u32 data_size, u32 orig_data,
-    u8* ro, u32 ro_size, u32 orig_ro);
+void patch_exe(u64 progId, u16 progver, u8 *text, u32 text_size, u32 orig_text, u8 *data, u32 data_size, u32 orig_data, u8 *ro, u32 ro_size, u32 orig_ro);
 
 void dump_code(u64 progId, u8 *code_loc, u32 code_len);
 
index bacd5cc12aae54bec94305f015fa08284d454b0d..d7ad66331882bf4527ae4ff59ad58ab8cdcaadfc 100644 (file)
@@ -79,7 +79,7 @@ show_menu(struct options_s *options, uint8_t *toggles)
                     fprintf(TOP_SCREEN, "   ");
 
                 fprintf(TOP_SCREEN, "[%u]  %s  \n", toggles[options[i].index], options[i].name);
-                       } else if (options[i].allowed == not_option) {
+            } else if (options[i].allowed == not_option) {
                 fprintf(TOP_SCREEN, "%s\n", options[i].name);
             }
             ++i;
@@ -112,21 +112,21 @@ show_menu(struct options_s *options, uint8_t *toggles)
                 break;
             case BUTTON_A:
                 if (options[cursor_y].allowed == boolean_val) {
-                       toggles[options[cursor_y].index] = !toggles[options[cursor_y].index];
-                               } else if (options[cursor_y].allowed == ranged_val) {
-                                       if (toggles[options[cursor_y].index] == options[cursor_y].b)
-                                               toggles[options[cursor_y].index] = options[cursor_y].a;
-                                       else
-                                               toggles[options[cursor_y].index]++;
-                               }
+                    toggles[options[cursor_y].index] = !toggles[options[cursor_y].index];
+                } else if (options[cursor_y].allowed == ranged_val) {
+                    if (toggles[options[cursor_y].index] == options[cursor_y].b)
+                        toggles[options[cursor_y].index] = options[cursor_y].a;
+                    else
+                        toggles[options[cursor_y].index]++;
+                }
                 break;
             case BUTTON_X:
-                               if (options[cursor_y].allowed == ranged_val) {
-                                       if (toggles[options[cursor_y].index] == options[cursor_y].a)
-                                               toggles[options[cursor_y].index] = options[cursor_y].b;
+                if (options[cursor_y].allowed == ranged_val) {
+                    if (toggles[options[cursor_y].index] == options[cursor_y].a)
+                        toggles[options[cursor_y].index] = options[cursor_y].b;
                     else
-                                       toggles[options[cursor_y].index]--;
-                               }
+                        toggles[options[cursor_y].index]--;
+                }
                 break;
             case BUTTON_B:
                 exit = 1;
index ad5cb7e6de67a5eb2c360d029fd194a2c98b0642..5eb62ecab9be1bbe98e6af1a1c54ac1b2494e4c9 100644 (file)
@@ -2733,11 +2733,10 @@ f_open(FIL *fp,           /* Pointer to the blank file object */
 /* Read File                                                             */
 /*-----------------------------------------------------------------------*/
 
-
 FRESULT
-f_getsector(FIL *fp,    /* Pointer to the file object */
-       UINT *sec    /* Pointer to uint which will contain the sector */
-       )
+f_getsector(FIL *fp,  /* Pointer to the file object */
+            UINT *sec /* Pointer to uint which will contain the sector */
+            )
 {
     FRESULT res;
     DWORD clst = 0, sect = 0;
@@ -2753,31 +2752,30 @@ f_getsector(FIL *fp,    /* Pointer to the file object */
         LEAVE_FF(fp->fs, FR_DENIED);
 
     if ((fp->fptr % SS(fp->fs)) == 0) {                              /* On the sector boundary? */
-       csect = (BYTE)(fp->fptr / SS(fp->fs) & (fp->fs->csize - 1)); /* Sector offset in the cluster */
-       if (!csect) {                                                /* On the cluster boundary? */
-           if (fp->fptr == 0) {                                     /* On the top of the file? */
-               clst = fp->sclust;                                   /* Follow from the origin */
-           } else {                                                 /* Middle or end of the file */
-               clst = get_fat(fp->fs, fp->clust); /* Follow cluster chain on the FAT */
-           }
-
-           if (clst < 2)
-               ABORT(fp->fs, FR_INT_ERR);
-           if (clst == 0xFFFFFFFF)
-               ABORT(fp->fs, FR_DISK_ERR);
-       }
-
-           sect = clust2sect(fp->fs, clst); /* Get current sector */
-       if (!sect)
-               ABORT(fp->fs, FR_INT_ERR);
-       sect += csect;
-       }
-
-       *sec = sect;
-
-       return 0;
-}
+        csect = (BYTE)(fp->fptr / SS(fp->fs) & (fp->fs->csize - 1)); /* Sector offset in the cluster */
+        if (!csect) {                                                /* On the cluster boundary? */
+            if (fp->fptr == 0) {                                     /* On the top of the file? */
+                clst = fp->sclust;                                   /* Follow from the origin */
+            } else {                                                 /* Middle or end of the file */
+                clst = get_fat(fp->fs, fp->clust);                   /* Follow cluster chain on the FAT */
+            }
 
+            if (clst < 2)
+                ABORT(fp->fs, FR_INT_ERR);
+            if (clst == 0xFFFFFFFF)
+                ABORT(fp->fs, FR_DISK_ERR);
+        }
+
+        sect = clust2sect(fp->fs, clst); /* Get current sector */
+        if (!sect)
+            ABORT(fp->fs, FR_INT_ERR);
+        sect += csect;
+    }
+
+    *sec = sect;
+
+    return 0;
+}
 
 /*-----------------------------------------------------------------------*/
 /* Read File                                                             */
index 0bbe5bba9274b1245217c68d7472cb46d1c33e12..3758f2f161e5355b2d97a8d5b2cd1463e735d712 100644 (file)
@@ -226,10 +226,10 @@ FRESULT f_mount(FATFS *fs, const TCHAR *path, BYTE opt);
 FRESULT f_mkfs(const TCHAR *path, BYTE sfd, UINT au);                                /* Create a file system on the volume */
 FRESULT f_fdisk(BYTE pdrv, const DWORD szt[], void *work);                           /* Divide a physical drive into some partitions */
 FRESULT f_getsector(FIL *fp, UINT *sec);
-int f_putc(TCHAR c, FIL *fp);                                                        /* Put a character to the file */
-int f_puts(const TCHAR *str, FIL *cp);                                               /* Put a string to the file */
-int f_printf(FIL *fp, const TCHAR *str, ...);                                        /* Put a formatted string to the file */
-TCHAR *f_gets(TCHAR *buff, int len, FIL *fp);                                        /* Get a string from the file */
+int f_putc(TCHAR c, FIL *fp);                 /* Put a character to the file */
+int f_puts(const TCHAR *str, FIL *cp);        /* Put a string to the file */
+int f_printf(FIL *fp, const TCHAR *str, ...); /* Put a formatted string to the file */
+TCHAR *f_gets(TCHAR *buff, int len, FIL *fp); /* Get a string from the file */
 
 #define f_eof(fp) ((int)((fp)->fptr == (fp)->fsize))
 #define f_error(fp) ((fp)->err)
index bb09de9b861fe76c33ffa2c9b00ab20eddce9318..242c1304c4aa56952cb13e4a5f37516d419b253c 100644 (file)
@@ -43,53 +43,56 @@ slot0x11key96_init()
     // this.
 }
 
-int decrypt_cetk_key(void *key, const void *cetk) {
-       static int common_key_y_init = 0;
-       uint8_t iv[AES_BLOCK_SIZE] = {0};
-       uint32_t sigtype = __builtin_bswap32(*(uint32_t *)cetk);
+int
+decrypt_cetk_key(void *key, const void *cetk)
+{
+    static int common_key_y_init = 0;
+    uint8_t iv[AES_BLOCK_SIZE] = { 0 };
+    uint32_t sigtype = __builtin_bswap32(*(uint32_t *)cetk);
 
-       if (sigtype != SIG_TYPE_RSA2048_SHA256)
-               return 1;
+    if (sigtype != SIG_TYPE_RSA2048_SHA256)
+        return 1;
 
-       ticket_h *ticket = (ticket_h *)(cetk + sizeof(sigtype) + 0x13C);
+    ticket_h *ticket = (ticket_h *)(cetk + sizeof(sigtype) + 0x13C);
 
-       if (ticket->ticketCommonKeyYIndex != 1)
-               return 1;
+    if (ticket->ticketCommonKeyYIndex != 1)
+        return 1;
 
-       if (!common_key_y_init) {
-               uint8_t common_key_y[AES_BLOCK_SIZE] = {0};
-               uint8_t *p9_base = (uint8_t *)0x08028000;
-               uint8_t *i;
-               for (i = p9_base + 0x70000 - AES_BLOCK_SIZE; i >= p9_base; i--) {
-                       if (i[0] == 0xD0 && i[4] == 0x9C && i[8] == 0x32 && i[12] == 0x23) {
-                               // At i, there's 7 keys with 4 bytes padding between them.
-                               // We only need the 2nd.
-                               memcpy(common_key_y, i + AES_BLOCK_SIZE + 4, sizeof(common_key_y));
-                               fprintf(stderr, "y");
-                               break;
-                       }
-               }
+    if (!common_key_y_init) {
+        uint8_t common_key_y[AES_BLOCK_SIZE] = { 0 };
+        uint8_t *p9_base = (uint8_t *)0x08028000;
+        uint8_t *i;
+        for (i = p9_base + 0x70000 - AES_BLOCK_SIZE; i >= p9_base; i--) {
+            if (i[0] == 0xD0 && i[4] == 0x9C && i[8] == 0x32 && i[12] == 0x23) {
+                // At i, there's 7 keys with 4 bytes padding between them.
+                // We only need the 2nd.
+                memcpy(common_key_y, i + AES_BLOCK_SIZE + 4, sizeof(common_key_y));
+                fprintf(stderr, "y");
+                break;
+            }
+        }
 
-               if (i < p9_base)
-                       return 1;
+        if (i < p9_base)
+            return 1;
 
-               aes_setkey(0x3D, common_key_y, AES_KEYY, AES_INPUT_BE | AES_INPUT_NORMAL);
-               common_key_y_init = 1;
-       }
+        aes_setkey(0x3D, common_key_y, AES_KEYY, AES_INPUT_BE | AES_INPUT_NORMAL);
+        common_key_y_init = 1;
+    }
 
-       aes_use_keyslot(0x3D);
-       memcpy(iv, ticket->titleID, sizeof(ticket->titleID));
+    aes_use_keyslot(0x3D);
+    memcpy(iv, ticket->titleID, sizeof(ticket->titleID));
 
-       memcpy(key, ticket->titleKey, sizeof(ticket->titleKey));
-       aes(key, key, 1, iv, AES_CBC_DECRYPT_MODE, AES_INPUT_BE | AES_INPUT_NORMAL);
+    memcpy(key, ticket->titleKey, sizeof(ticket->titleKey));
+    aes(key, key, 1, iv, AES_CBC_DECRYPT_MODE, AES_INPUT_BE | AES_INPUT_NORMAL);
 
-       fprintf(stderr, "g");
+    fprintf(stderr, "g");
 
-       return 0;
+    return 0;
 }
 
 int
-decrypt_firm_title(firm_h *dest, ncch_h *ncch, uint32_t *size, void *key) {
+decrypt_firm_title(firm_h *dest, ncch_h *ncch, uint32_t *size, void *key)
+{
     uint8_t firm_iv[16] = { 0 };
     uint8_t exefs_key[16] = { 0 };
     uint8_t exefs_iv[16] = { 0 };
@@ -164,21 +167,20 @@ decrypt_arm9bin(arm9bin_h *header, uint64_t firm_title, uint8_t version)
 }
 
 int
-decrypt_firm(firm_h *dest, char *path_firmkey, charpath_cetk, uint32_t *size)
+decrypt_firm(firm_h *dest, char *path_firmkey, char *path_cetk, uint32_t *size)
 {
     uint8_t firm_key[AES_BLOCK_SIZE];
 
     // Firmware is likely encrypted. Decrypt.
     if (!read_file(firm_key, path_firmkey, AES_BLOCK_SIZE)) {
-               // Missing firmkey. Attempt to get from CETK (only works if system was booted)
-               if (!read_file((void*)FCRAM_JUNK_LOC, path_cetk, FCRAM_SPACING) ||
-                       decrypt_cetk_key(firm_key, (void*)FCRAM_JUNK_LOC)) {
-               fprintf(BOTTOM_SCREEN, "!");
-               return 1;
-               } else {
-               fprintf(BOTTOM_SCREEN, "t");
-                       write_file(firm_key, path_firmkey, AES_BLOCK_SIZE);
-               }
+        // Missing firmkey. Attempt to get from CETK (only works if system was booted)
+        if (!read_file((void *)FCRAM_JUNK_LOC, path_cetk, FCRAM_SPACING) || decrypt_cetk_key(firm_key, (void *)FCRAM_JUNK_LOC)) {
+            fprintf(BOTTOM_SCREEN, "!");
+            return 1;
+        } else {
+            fprintf(BOTTOM_SCREEN, "t");
+            write_file(firm_key, path_firmkey, AES_BLOCK_SIZE);
+        }
     } else {
         fprintf(BOTTOM_SCREEN, "k");
     }
@@ -210,9 +212,9 @@ load_firm(firm_h *dest, char *path, char *path_firmkey, char *path_cetk, uint32_
     if (dest->magic != FIRM_MAGIC) {
         status = decrypt_firm(dest, path_firmkey, path_cetk, size);
         if (status != 0) {
-               fprintf(BOTTOM_SCREEN, "!");
+            fprintf(BOTTOM_SCREEN, "!");
             return 1;
-               }
+        }
         firmware_changed = 1; // Decryption performed.
     } else {
         fprintf(BOTTOM_SCREEN, "_");
@@ -331,7 +333,7 @@ boot_firm()
     wait();
 
     clear_disp(BOTTOM_SCREEN);
-       set_cursor(BOTTOM_SCREEN, 0, 0);
+    set_cursor(BOTTOM_SCREEN, 0, 0);
 
     fumount(); // Unmount SD. No longer needed.
 
@@ -432,22 +434,22 @@ boot_cfw()
     if (patch_firm_all() != 0)
         return;
 
-       if (config.options[OPTION_REBOOT] && config.options[OPTION_RECONFIGURED]) {
-               fprintf(stderr, "Saving FIRM for reboot...\n");
-               if (!write_file(firm_loc, PATH_NATIVE_P, firm_size))
-                       abort("Failed to save prepatched native\n");
+    if (config.options[OPTION_REBOOT] && config.options[OPTION_RECONFIGURED]) {
+        fprintf(stderr, "Saving FIRM for reboot...\n");
+        if (!write_file(firm_loc, PATH_NATIVE_P, firm_size))
+            abort("Failed to save prepatched native\n");
 
-               if (!write_file(twl_firm_loc, PATH_TWL_P, twl_firm_size))
-                       abort("Failed to save prepatched twl\n");
+        if (!write_file(twl_firm_loc, PATH_TWL_P, twl_firm_size))
+            abort("Failed to save prepatched twl\n");
 
-               if (!write_file(agb_firm_loc, PATH_AGB_P, agb_firm_size))
-                       abort("Failed to save prepatched agb\n");
-       }
+        if (!write_file(agb_firm_loc, PATH_AGB_P, agb_firm_size))
+            abort("Failed to save prepatched agb\n");
+    }
 
     if (config.options[OPTION_RECONFIGURED]) {
         config.options[OPTION_RECONFIGURED] = 0;
         save_config();
-       }
+    }
 
     boot_firm();
 }
index 24926c973d3e6e77d4ffdc6415a11074b7fe7f94..ff1a1de1b331d155e37f3f0ae5034471a39bacae 100644 (file)
@@ -132,7 +132,7 @@ exec_bytecode(uint8_t *bytecode, uint16_t ver, uint32_t len, int debug)
 
     uint32_t i;
 
-       int eq = 0, gt = 0, lt = 0; // Flags.
+    int eq = 0, gt = 0, lt = 0; // Flags.
 
     uint8_t *code = bytecode;
     uint8_t *end = code + len;
@@ -198,78 +198,78 @@ exec_bytecode(uint8_t *bytecode, uint16_t ver, uint32_t len, int debug)
                     log("test\n");
                 code += 2;
                 eq = memcmp(current_mode->memory + offset, code, *(code - 1));
-                               if (eq < 0)
-                                       lt = 1;
-                               if (eq > 0)
-                                       gt = 1;
-                               eq = !eq;
+                if (eq < 0)
+                    lt = 1;
+                if (eq > 0)
+                    gt = 1;
+                eq = !eq;
                 code += *(code - 1);
                 break;
             case OP_JMP: // Jump to offset.
                 if (debug)
                     log("jmp\n");
                 code++;
-                   code = bytecode + (code[0] + (code[1] << 8));
+                code = bytecode + (code[0] + (code[1] << 8));
                 break;
             case OP_JMPEQ: // Jump to offset if equal
                 if (debug)
                     log("jmpeq\n");
-                   code++;
-                               if (eq)
-                           code = bytecode + (code[0] + (code[1] << 8));
-                               else
-                                       code += 2;
+                code++;
+                if (eq)
+                    code = bytecode + (code[0] + (code[1] << 8));
+                else
+                    code += 2;
                 break;
             case OP_JMPNE: // Jump to offset if not equal
                 if (debug)
                     log("jmpne\n");
-                   code++;
-                               if (!eq)
-                           code = bytecode + (code[0] + (code[1] << 8));
-                               else
-                                       code += 2;
+                code++;
+                if (!eq)
+                    code = bytecode + (code[0] + (code[1] << 8));
+                else
+                    code += 2;
                 break;
             case OP_JMPLT: // Jump to offset if less than
                 if (debug)
                     log("jmplt\n");
-                   code++;
-                               if (lt)
-                           code = bytecode + (code[0] + (code[1] << 8));
-                               else
-                                       code += 2;
+                code++;
+                if (lt)
+                    code = bytecode + (code[0] + (code[1] << 8));
+                else
+                    code += 2;
                 break;
             case OP_JMPGT: // Jump to offset if greater than
                 if (debug)
                     log("jmpgt\n");
-                   code++;
-                               if (gt)
-                           code = bytecode + (code[0] + (code[1] << 8));
-                               else
-                                       code += 2;
+                code++;
+                if (gt)
+                    code = bytecode + (code[0] + (code[1] << 8));
+                else
+                    code += 2;
                 break;
             case OP_JMPLE: // Jump to offset if less than or equal
                 if (debug)
                     log("jmple\n");
-                   code++;
-                               if (lt || eq)
-                           code = bytecode + (code[0] + (code[1] << 8));
-                               else
-                                       code += 2;
+                code++;
+                if (lt || eq)
+                    code = bytecode + (code[0] + (code[1] << 8));
+                else
+                    code += 2;
                 break;
             case OP_JMPGE: // Jump to offset if greater than or equal
                 if (debug)
                     log("jmpge\n");
-                   code++;
-                               if (gt || eq)
-                           code = bytecode + (code[0] + (code[1] << 8));
-                               else
-                                       code += 2;
+                code++;
+                if (gt || eq)
+                    code = bytecode + (code[0] + (code[1] << 8));
+                else
+                    code += 2;
                 break;
             case OP_CLF: // Clear flags.
                 if (debug)
                     log("clf\n");
-                   code++;
-                               gt = lt = eq = 0;
+                code++;
+                gt = lt = eq = 0;
                 break;
             case OP_REWIND:
                 if (debug)
@@ -321,26 +321,26 @@ exec_bytecode(uint8_t *bytecode, uint16_t ver, uint32_t len, int debug)
                     log("ver\n");
                 code++;
                 eq = memcmp(&ver, code, 2);
-                               if (eq < 0)
-                                       lt = 1;
-                               if (eq > 0)
-                                       gt = 1;
-                               eq = !eq;
+                if (eq < 0)
+                    lt = 1;
+                if (eq > 0)
+                    gt = 1;
+                eq = !eq;
                 code += 2;
                 break;
             case OP_SEEK: // Jump to offset if greater than or equal
                 if (debug)
                     log("seek\n");
-                   code++;
-                   offset = code[0] + (code[1] << 8) + (code[2] << 16) + (code[3] << 24);
+                code++;
+                offset = code[0] + (code[1] << 8) + (code[2] << 16) + (code[3] << 24);
                 if (offset > current_mode->size) { // Went out of bounds. Error.
 #ifndef LOADER
-                                       fprintf(stderr, "%x", offset);
+                    fprintf(stderr, "%x", offset);
 #endif
                     abort("seeked out of bounds\n");
-                               }
+                }
 
-                               code += 4;
+                code += 4;
                 break;
             case OP_NEXT:
                 if (debug)
@@ -383,10 +383,7 @@ exec_bytecode(uint8_t *bytecode, uint16_t ver, uint32_t len, int debug)
 
 #ifdef LOADER
 int
-execb(uint64_t tid, uint16_t ver,
-      uint8_t *text_mem, uint32_t text_len,
-      uint8_t* data_mem, uint32_t data_len,
-      uint8_t* ro_mem, uint32_t ro_len)
+execb(uint64_t tid, uint16_t ver, uint8_t *text_mem, uint32_t text_len, uint8_t *data_mem, uint32_t data_len, uint8_t *ro_mem, uint32_t ro_len)
 {
 #else
 int
@@ -449,15 +446,15 @@ execb(char *filename, int build_cache)
 
     // Set memory.
     modes[18].memory = text_mem;
-    modes[18].size   = text_len;
+    modes[18].size = text_len;
 
     // Set memory.
     modes[19].memory = data_mem;
-    modes[19].size   = data_len;
+    modes[19].size = data_len;
 
     // Set memory.
     modes[20].memory = ro_mem;
-    modes[20].size   = ro_len;
+    modes[20].size = ro_len;
 
     log("  exec\n");
 
index 6c6a0f0ba121968f884d886686bbb73720ce6148..18669f8d1615236f71f7b535e816acdfcbfafd16 100644 (file)
@@ -13,8 +13,8 @@ void shut_up();
 int
 main()
 {
-       int c = fmount();
-       screen_init();
+    int c = fmount();
+    screen_init();
 
     if (c) {
         // Failed to mount SD. Bomb out.
index 488cabdb31b5ef11b776aa5dad21c525633bb9c5..7275301f9a4176951232339fb34d99dc8530530f 100644 (file)
@@ -43,7 +43,9 @@ static struct options_s options[] = {
     { OPTION_LOADER_CPU_800MHZ, "  CPU - 800Mhz (n3ds)", "Forces the system to run in 800Mhz mode. Ignored if not a N3DS.", boolean_val, 0, 0 },
     { OPTION_LOADER_LANGEMU, "  Language Emulation", "Reads language emulation configuration and imitates the region/language.", boolean_val, 0, 0 },
 
-    { OPTION_LOADER_DUMPCODE, "  Dump Code Sections (dev)", "Dumps code sections for titles to SD card the first time they're loaded. This doesn't dump system titles. Slows things down considerably.", boolean_val, 0, 0 },
+    { OPTION_LOADER_DUMPCODE, "  Dump Code Sections (dev)",
+      "Dumps code sections for titles to SD card the first time they're loaded. This doesn't dump system titles. Slows things down considerably.", boolean_val,
+      0, 0 },
 
     // space
     { 0, "", "", not_option, 0, 0 },
@@ -300,7 +302,7 @@ menu_poweroff()
 int
 menu_main()
 {
-       // TODO - Stop using different menu code here.
+    // TODO - Stop using different menu code here.
     set_cursor(TOP_SCREEN, 0, 0);
 
     const char *list[] = { "Options", "Patches", "Info", "Help/Readme", "Reboot", "Power off", "Boot Firmware" };
index dfeab0a0e0ad58a03286dec67ad817844976c320..0f3186a06094a5de0c358acef8fb2a77c19c1bd9 100644 (file)
 #include "../firm/headers.h"
 #include "../patch_format.h"
 
-uint8_t *temp = (uint8_t*)FCRAM_JUNK_LOC;
+uint8_t *temp = (uint8_t *)FCRAM_JUNK_LOC;
 
-void verify_loop_emunand(char* filename) {
-       // FIXME - This won't work unless the NAND file is completely contiguous on disk, sadly.
-       // Technically speaking if I were to defrag my SD this would work, I suspect.
+void
+verify_loop_emunand(char *filename)
+{
+    // FIXME - This won't work unless the NAND file is completely contiguous on disk, sadly.
+    // Technically speaking if I were to defrag my SD this would work, I suspect.
 
-       uint32_t offset = get_file_sector(filename); // Get the sector of the file
+    uint32_t offset = get_file_sector(filename); // Get the sector of the file
 
     // Check for RedNAND image on SD
-    if(!sdmmc_sdcard_readsectors(offset, 1, temp) && *(uint32_t *)(temp + 0x100) == NCSD_MAGIC) {
-               fprintf(stderr, "emunand: found NCSD magic\n");
+    if (!sdmmc_sdcard_readsectors(offset, 1, temp) && *(uint32_t *)(temp + 0x100) == NCSD_MAGIC) {
+        fprintf(stderr, "emunand: found NCSD magic\n");
     } else {
-               abort("emunand: selected NAND image is not valid.\n");
-       }
+        abort("emunand: selected NAND image is not valid.\n");
+    }
 }
 
-void verify_emunand(uint32_t index, uint32_t* off, uint32_t* head) {
-       uint32_t nandSize = getMMCDevice(0)->total_size;
+void
+verify_emunand(uint32_t index, uint32_t *off, uint32_t *head)
+{
+    uint32_t nandSize = getMMCDevice(0)->total_size;
 
-       uint32_t offset;
-       if (nandSize > 0x200000)
-               offset = 0x400000 * index;
-       else
-               offset = 0x200000 * index;
+    uint32_t offset;
+    if (nandSize > 0x200000)
+        offset = 0x400000 * index;
+    else
+        offset = 0x200000 * index;
 
     // Check for RedNAND/Normal physical layout on SD
-    if(!sdmmc_sdcard_readsectors(offset + 1, 1, temp) && *(uint32_t *)(temp + 0x100) == NCSD_MAGIC) {
-               *off  = offset + 1;
-               *head = offset + 1;
+    if (!sdmmc_sdcard_readsectors(offset + 1, 1, temp) && *(uint32_t *)(temp + 0x100) == NCSD_MAGIC) {
+        *off = offset + 1;
+        *head = offset + 1;
 
-               fprintf(stderr, "emunand: found NCSD magic for #%u\n", index);
-               fprintf(stderr, "emunand: layout is normal\n");
+        fprintf(stderr, "emunand: found NCSD magic for #%u\n", index);
+        fprintf(stderr, "emunand: layout is normal\n");
     }
     // Check for GW EmuNAND on SD
-    else if(!sdmmc_sdcard_readsectors(offset + nandSize, 1, temp) && *(uint32_t *)(temp + 0x100) == NCSD_MAGIC) {
-               *off  = offset;
-               *head = offset + nandSize;
+    else if (!sdmmc_sdcard_readsectors(offset + nandSize, 1, temp) && *(uint32_t *)(temp + 0x100) == NCSD_MAGIC) {
+        *off = offset;
+        *head = offset + nandSize;
 
-               fprintf(stderr, "emunand: found NCSD magic for %u\n", index);
-               fprintf(stderr, "emunand: layout is gateway\n");
+        fprintf(stderr, "emunand: found NCSD magic for %u\n", index);
+        fprintf(stderr, "emunand: layout is gateway\n");
     } else {
-               abort("emunand: selected NAND image is not valid.\n");
-       }
+        abort("emunand: selected NAND image is not valid.\n");
+    }
 }
 
-static void *getEmuCode(uint8_t *pos, uint32_t size)
+static void *
+getEmuCode(uint8_t *pos, uint32_t size)
 {
-    const uint8_t pattern[] = {0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00};
+    const uint8_t pattern[] = { 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00 };
 
-    //Looking for the last free space before Process9
-    voidret = memfind(pos + 0x13500, size - 0x13500, pattern, 6) + 0x455;
+    // Looking for the last free space before Process9
+    void *ret = memfind(pos + 0x13500, size - 0x13500, pattern, 6) + 0x455;
 
-       if (ret) {
-               fprintf(stderr, "emunand: free space @ %x\n", ret);
-               fprintf(stderr, "emunand: size is %u bytes\n", (uint8_t*)ret - pos);
-       }
+    if (ret) {
+        fprintf(stderr, "emunand: free space @ %x\n", ret);
+        fprintf(stderr, "emunand: size is %u bytes\n", (uint8_t *)ret - pos);
+    }
 
-       return ret;
+    return ret;
 }
 
-static uint32_t getSDMMC(uint8_t *pos, uint32_t size)
+static uint32_t
+getSDMMC(uint8_t *pos, uint32_t size)
 {
-    //Look for struct code
-    const uint8_t pattern[] = {0x21, 0x20, 0x18, 0x20};
+    // Look for struct code
+    const uint8_t pattern[] = { 0x21, 0x20, 0x18, 0x20 };
     const uint8_t *off = memfind(pos, size, pattern, 4);
 
     uint32_t ret = *(uint32_t *)(off + 9) + *(uint32_t *)(off + 0xD);
 
-       fprintf(stderr, "emunand: SDMMC code @ %x\n", ret);
+    fprintf(stderr, "emunand: SDMMC code @ %x\n", ret);
 
-       return ret;
+    return ret;
 }
 
-static void patchNANDRW(uint8_t *pos, uint32_t size, uint32_t branchOffset)
+static void
+patchNANDRW(uint8_t *pos, uint32_t size, uint32_t branchOffset)
 {
-    const uint16_t nandRedir[2] = {0x4C00, 0x47A0};
+    const uint16_t nandRedir[2] = { 0x4C00, 0x47A0 };
 
-    //Look for read/write code
-    const uint8_t pattern[] = {0x1E, 0x00, 0xC8, 0x05};
+    // Look for read/write code
+    const uint8_t pattern[] = { 0x1E, 0x00, 0xC8, 0x05 };
 
-    uint16_t *readOffset  = (uint16_t *)memfind(pos, size, pattern, 4) - 3;
+    uint16_t *readOffset = (uint16_t *)memfind(pos, size, pattern, 4) - 3;
     uint16_t *writeOffset = (uint16_t *)memfind((uint8_t *)(readOffset + 5), 0x100, pattern, 4) - 3;
 
     *readOffset = nandRedir[0];
@@ -104,16 +111,17 @@ static void patchNANDRW(uint8_t *pos, uint32_t size, uint32_t branchOffset)
     writeOffset[1] = nandRedir[1];
     ((uint32_t *)writeOffset)[1] = branchOffset;
 
-       fprintf(stderr, "emunand: write @ %x\n", writeOffset);
-       fprintf(stderr, "emunand: read @ %x\n", readOffset);
+    fprintf(stderr, "emunand: write @ %x\n", writeOffset);
+    fprintf(stderr, "emunand: read @ %x\n", readOffset);
 }
 
-static void patchMPU(uint8_t *pos, uint32_t size)
+static void
+patchMPU(uint8_t *pos, uint32_t size)
 {
-    const uint32_t mpuPatch[3] = {0x00360003, 0x00200603, 0x001C0603};
+    const uint32_t mpuPatch[3] = { 0x00360003, 0x00200603, 0x001C0603 };
 
-    //Look for MPU pattern
-    const uint8_t pattern[] = {0x03, 0x00, 0x24, 0x00};
+    // Look for MPU pattern
+    const uint8_t pattern[] = { 0x03, 0x00, 0x24, 0x00 };
 
     uint32_t *off = (uint32_t *)memfind(pos, size, pattern, 4);
 
@@ -121,61 +129,62 @@ static void patchMPU(uint8_t *pos, uint32_t size)
     off[6] = mpuPatch[1];
     off[9] = mpuPatch[2];
 
-       fprintf(stderr, "emunand: mpu @ %x\n", off);
+    fprintf(stderr, "emunand: mpu @ %x\n", off);
 }
 
-void patch_emunand(uint32_t index) {
-       //uint8_t *arm9Section, uint32_t arm9SectionSize, uint8_t *process9Offset, uint32_t process9Size, uint32_t emuOffset, uint32_t emuHeader, uint32_t branchAdditive)
+void
+patch_emunand(uint32_t index)
+{
+    // uint8_t *arm9Section, uint32_t arm9SectionSize, uint8_t *process9Offset, uint32_t process9Size, uint32_t emuOffset, uint32_t emuHeader, uint32_t
+    // branchAdditive)
 
     // ARM9 section.
-       uint8_t* arm9Section  = (uint8_t*)firm_loc + firm_loc->section[2].offset;
-       uint32_t arm9SectionSize = firm_loc->section[2].size;
+    uint8_t *arm9Section = (uint8_t *)firm_loc + firm_loc->section[2].offset;
+    uint32_t arm9SectionSize = firm_loc->section[2].size;
 
-       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;
+    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;
 
-    //Copy emuNAND code
+    // Copy emuNAND code
     void *emuCodeOffset = getEmuCode(arm9Section, arm9SectionSize);
-       if (!emuCodeOffset)
-               abort("emunand: code missing from arm9?\n");
+    if (!emuCodeOffset)
+        abort("emunand: code missing from arm9?\n");
 
-       FILE* f = fopen(PATH_EMUNAND_CODE, "r");
-       if (!f)
-               abort("emunand: code not found on SD.\n");
+    FILE *f = fopen(PATH_EMUNAND_CODE, "r");
+    if (!f)
+        abort("emunand: code not found on SD.\n");
 
-       uint32_t emunand_size = fsize(f);
-       fread(emuCodeOffset, 1, emunand_size, f);
-       fclose(f);
+    uint32_t emunand_size = fsize(f);
+    fread(emuCodeOffset, 1, emunand_size, f);
+    fclose(f);
 
     uint32_t branchOffset = (uint32_t)emuCodeOffset - ((uint32_t)firm_loc + firm_loc->section[2].offset - firm_loc->section[2].address);
 
-       fprintf(stderr, "emunand: read in emunand code - %x\n", emuCodeOffset);
+    fprintf(stderr, "emunand: read in emunand code - %x\n", emuCodeOffset);
 
-    //Add the data of the found emuNAND
-    uint32_t *pos_offset = (uint32_t *)memfind(emuCodeOffset, emunand_size, "NAND", 4),
-             *pos_head   = (uint32_t *)memfind(emuCodeOffset, emunand_size, "NCSD", 4),
-             *pos_sdmmc  = (uint32_t *)memfind(emuCodeOffset, emunand_size, "SDMC", 4);
+    // Add the data of the found emuNAND
+    uint32_t *pos_offset = (uint32_t *)memfind(emuCodeOffset, emunand_size, "NAND", 4), *pos_head = (uint32_t *)memfind(emuCodeOffset, emunand_size, "NCSD", 4),
+             *pos_sdmmc = (uint32_t *)memfind(emuCodeOffset, emunand_size, "SDMC", 4);
 
-       verify_emunand(index, pos_offset, pos_head);
+    verify_emunand(index, pos_offset, pos_head);
 
-       fprintf(stderr, "emunand: nand is on sector %u\n", *pos_offset);
-       fprintf(stderr, "emunand: head is on sector %u\n", *pos_head);
+    fprintf(stderr, "emunand: nand is on sector %u\n", *pos_offset);
+    fprintf(stderr, "emunand: head is on sector %u\n", *pos_head);
 
-       if (!pos_offset || !pos_head || !pos_sdmmc)
-               abort("emunand: couldn't find pattern in hook?\n");
+    if (!pos_offset || !pos_head || !pos_sdmmc)
+        abort("emunand: couldn't find pattern in hook?\n");
 
-    //Add emuNAND hooks
+    // Add emuNAND hooks
     patchNANDRW(process9Offset, process9Size, branchOffset);
 
-       fprintf(stderr, "emunand: patched read/write calls\n");
+    fprintf(stderr, "emunand: patched read/write calls\n");
 
-    //Find and add the SDMMC struct
+    // Find and add the SDMMC struct
 
     *pos_sdmmc = getSDMMC(process9Offset, process9Size);
 
-    //Set MPU for emu code region
+    // Set MPU for emu code region
     patchMPU(arm9Section, arm9SectionSize);
 
-       fprintf(stderr, "emunand: patched MPU settings\n");
+    fprintf(stderr, "emunand: patched MPU settings\n");
 }
-
index 4b120f6f589f6f692b7cf66c335a416efb07a8c7..48770dd06a478976ca00aeb9675c047bf6a4cc15 100644 (file)
 
 int wait();
 
-uint8_t *getProcess9(uint8_t *pos, uint32_t size, uint32_t *process9Size, uint32_t *process9MemAddr) {
-       uint8_t *off = memfind(pos, size, "ess9", 4);
-       *process9Size = *(uint32_t *)(off - 0x60) * 0x200;
-       *process9MemAddr = *(uint32_t *)(off + 0xC);
-       //Process9 code offset (start of NCCH + ExeFS offset + ExeFS header size)
-       return off - 0x204 + (*(uint32_t *)(off - 0x64) * 0x200) + 0x200;
+uint8_t *
+getProcess9(uint8_t *pos, uint32_t size, uint32_t *process9Size, uint32_t *process9MemAddr)
+{
+    uint8_t *off = memfind(pos, size, "ess9", 4);
+    *process9Size = *(uint32_t *)(off - 0x60) * 0x200;
+    *process9MemAddr = *(uint32_t *)(off + 0xC);
+    // Process9 code offset (start of NCCH + ExeFS offset + ExeFS header size)
+    return off - 0x204 + (*(uint32_t *)(off - 0x64) * 0x200) + 0x200;
 }
 
-void patch_reboot() {
-       //Look for firmlaunch code
-       const uint8_t pattern[] = {0xDE, 0x1F, 0x8D, 0xE2};
+void
+patch_reboot()
+{
+    // Look for firmlaunch code
+    const uint8_t pattern[] = { 0xDE, 0x1F, 0x8D, 0xE2 };
 
-       uint32_t process9Size, process9MemAddr;
-       uint8_t *process9Offset = getProcess9((uint8_t*)firm_loc + firm_loc->section[2].offset + 0x15000, firm_loc->section[2].size - 0x15000, &process9Size, &process9MemAddr);
+    uint32_t process9Size, process9MemAddr;
+    uint8_t *process9Offset =
+        getProcess9((uint8_t *)firm_loc + firm_loc->section[2].offset + 0x15000, firm_loc->section[2].size - 0x15000, &process9Size, &process9MemAddr);
 
-       fprintf(stderr, "reboot: proc9 mem @ %x\n", process9MemAddr);
+    fprintf(stderr, "reboot: proc9 mem @ %x\n", process9MemAddr);
 
-       wait();
+    wait();
 
-       uint8_t *off = memfind(process9Offset, process9Size, pattern, 4) - 0x10;
+    uint8_t *off = memfind(process9Offset, process9Size, pattern, 4) - 0x10;
 
-       fprintf(stderr, "reboot: firmlaunch @ %x\n", off);
+    fprintf(stderr, "reboot: firmlaunch @ %x\n", off);
 
-       //Firmlaunch function offset - offset in BLX opcode (A4-16 - ARM DDI 0100E) + 1
-       uint32_t fOpenOffset = (uint32_t)(off + 9 - (-((*(uint32_t *)off & 0x00FFFFFF) << 2) & (0xFFFFFF << 2)) - process9Offset + process9MemAddr);
+    // Firmlaunch function offset - offset in BLX opcode (A4-16 - ARM DDI 0100E) + 1
+    uint32_t fOpenOffset = (uint32_t)(off + 9 - (-((*(uint32_t *)off & 0x00FFFFFF) << 2) & (0xFFFFFF << 2)) - process9Offset + process9MemAddr);
 
-       fprintf(stderr, "reboot: fopen @ %x\n", fOpenOffset);
+    fprintf(stderr, "reboot: fopen @ %x\n", fOpenOffset);
 
-       wait();
+    wait();
 
-       //Copy firmlaunch code
-       FILE* f = fopen(PATH_BITS "/reboot_hook.bin", "r");
-       if (!f)
-               abort("reboot: hook not found on SD\n");
+    // Copy firmlaunch code
+    FILE *f = fopen(PATH_BITS "/reboot_hook.bin", "r");
+    if (!f)
+        abort("reboot: hook not found on SD\n");
 
-       uint32_t size = fsize(f);
-       fread(off, 1, size, f);
-       fclose(f);
+    uint32_t size = fsize(f);
+    fread(off, 1, size, f);
+    fclose(f);
 
-       //Put the fOpen offset in the right location
-       uint32_t *pos_fopen = (uint32_t *)memfind(off, size, "open", 4);
-       if (!pos_fopen)
-               abort("reboot: fopen location missing\n");
+    // Put the fOpen offset in the right location
+    uint32_t *pos_fopen = (uint32_t *)memfind(off, size, "open", 4);
+    if (!pos_fopen)
+        abort("reboot: fopen location missing\n");
 
-       *pos_fopen = fOpenOffset;
+    *pos_fopen = fOpenOffset;
 
-       uint32_t *pos_native = (uint32_t*)memfind(off, size, "NATF", 4);
-       uint32_t *pos_twl    = (uint32_t*)memfind(off, size, "TWLF", 4);
-       uint32_t *pos_agb    = (uint32_t*)memfind(off, size, "AGBF", 4);
+    uint32_t *pos_native = (uint32_t *)memfind(off, size, "NATF", 4);
+    uint32_t *pos_twl = (uint32_t *)memfind(off, size, "TWLF", 4);
+    uint32_t *pos_agb = (uint32_t *)memfind(off, size, "AGBF", 4);
 
-       if (!pos_native && !pos_twl && !pos_agb)
-               abort("reboot: missing string placeholder?\n");
+    if (!pos_native && !pos_twl && !pos_agb)
+        abort("reboot: missing string placeholder?\n");
 
-       fprintf(stderr, "reboot: NATF @ %x\n", pos_native);
-       fprintf(stderr, "reboot: TWLF @ %x\n", pos_twl);
-       fprintf(stderr, "reboot: AGBF @ %x\n", pos_agb);
+    fprintf(stderr, "reboot: NATF @ %x\n", pos_native);
+    fprintf(stderr, "reboot: TWLF @ %x\n", pos_twl);
+    fprintf(stderr, "reboot: AGBF @ %x\n", pos_agb);
 
-       uint8_t* mem = (uint8_t*)0x01FF8000; // 0x8000 space that will be resident.
+    uint8_t *mem = (uint8_t *)0x01FF8000; // 0x8000 space that will be resident.
 
-       *pos_native = (uint32_t)mem;
-       memcpy(mem, L"sdmc:", 10);
-       mem += 10;
-       for(size_t i=0; i < sizeof(PATH_NATIVE_P); i++, mem += 2) {
-               *mem = PATH_NATIVE_P[i];
-               *(mem + 1) = 0;
-       }
+    *pos_native = (uint32_t)mem;
+    memcpy(mem, L"sdmc:", 10);
+    mem += 10;
+    for (size_t i = 0; i < sizeof(PATH_NATIVE_P); i++, mem += 2) {
+        *mem = PATH_NATIVE_P[i];
+        *(mem + 1) = 0;
+    }
 
-       *pos_twl = (uint32_t)mem;
-       memcpy(mem, L"sdmc:", 10);
-       mem += 10;
-       for(size_t i=0; i < sizeof(PATH_TWL_P); i++, mem += 2) {
-               *mem = PATH_TWL_P[i];
-               *(mem + 1) = 0;
-       }
+    *pos_twl = (uint32_t)mem;
+    memcpy(mem, L"sdmc:", 10);
+    mem += 10;
+    for (size_t i = 0; i < sizeof(PATH_TWL_P); i++, mem += 2) {
+        *mem = PATH_TWL_P[i];
+        *(mem + 1) = 0;
+    }
 
-       *pos_agb = (uint32_t)mem;
-       memcpy(mem, L"sdmc:", 10);
-       mem += 10;
-       for(size_t i=0; i < sizeof(PATH_AGB_P); i++, mem += 2) {
-               *mem = PATH_AGB_P[i];
-               *(mem + 1) = 0;
-       }
+    *pos_agb = (uint32_t)mem;
+    memcpy(mem, L"sdmc:", 10);
+    mem += 10;
+    for (size_t i = 0; i < sizeof(PATH_AGB_P); i++, mem += 2) {
+        *mem = PATH_AGB_P[i];
+        *(mem + 1) = 0;
+    }
 
-       uint32_t *pos_rebc    = (uint32_t*)memfind(off, size, "rebc", 4);
-       *pos_rebc = (uint32_t)mem;
+    uint32_t *pos_rebc = (uint32_t *)memfind(off, size, "rebc", 4);
+    *pos_rebc = (uint32_t)mem;
 
-       fprintf(stderr, "reboot: rebc @ %x\n", pos_rebc);
+    fprintf(stderr, "reboot: rebc @ %x\n", pos_rebc);
 
-       f = fopen(PATH_BITS "/reboot_code.bin", "r");
-       if (!f)
-               abort("reboot: boot not found on SD\n");
+    f = fopen(PATH_BITS "/reboot_code.bin", "r");
+    if (!f)
+        abort("reboot: boot not found on SD\n");
 
-       fread(mem, 1, fsize(f), f);
-       fclose(f);
+    fread(mem, 1, fsize(f), f);
+    fclose(f);
 
-       write_file((void*)0x1FF8000, "/test", 0x8000);
+    write_file((void *)0x1FF8000, "/test", 0x8000);
 }
index 05391eb20b11c18c44621da62710c727699a1a48..27b27aed0c1e5536f16bbbb227d19a65a0acfda0 100644 (file)
@@ -44,7 +44,7 @@ PATCH(services)
             uint32_t svc = (i << 4) & j; // Actual svc index.
 
             // Refuse to replace non-NULL services unless the user has it enabled.
-                       // Also don't bother checking for non-null svc files (it's slow.)
+            // Also don't bother checking for non-null svc files (it's slow.)
             if (svcTable[svc] && !config.options[OPTION_REPLACE_ALLOCATED_SVC])
                 continue;
 
@@ -62,7 +62,8 @@ PATCH(services)
             fprintf(stderr, "Svc: %s, %d bytes\n", at, size);
 
             if (!freeSpace)
-                for (freeSpace = exceptionsPage; *freeSpace != 0xFFFFFFFF; freeSpace++);
+                for (freeSpace = exceptionsPage; *freeSpace != 0xFFFFFFFF; freeSpace++)
+                    ;
 
             fprintf(stderr, "Svc: Copy code to %x\n", (uint32_t)freeSpace);
 
index 8bc587fac762c2c9346133bdbeb0a30758efc5a2..d39e39fef64812f6d3aa9afeaba96ca61aade873 100644 (file)
 #define PATH_AGB_P PATH_TEMP "/p_agb"
 #define PATH_TWL_P PATH_TEMP "/p_twl"
 
-#define PATH_KEYS PATH_CFW "/keys"            // Keyfiles will be loaded from this dir, and
-                                              // additionally the root if not found.
-#define PATH_EXEFS PATH_CFW "/exe"            // ExeFS overrides, named like '<titleid>.exefs' - NYI
+#define PATH_KEYS PATH_CFW "/keys" // Keyfiles will be loaded from this dir, and
+                                   // additionally the root if not found.
+#define PATH_EXEFS PATH_CFW "/exe" // ExeFS overrides, named like '<titleid>.exefs' - NYI
 
-#define PATH_BITS PATH_CFW "/bits"            // Path to misc bits we need (emunand code, reboot code, etc)
+#define PATH_BITS PATH_CFW "/bits" // Path to misc bits we need (emunand code, reboot code, etc)
 
-#define PATH_EMUNAND_CODE PATH_BITS "/emunand.bin" // Emunand hook.
+#define PATH_EMUNAND_CODE PATH_BITS "/emunand.bin"       // Emunand hook.
 #define PATH_SCREENINIT_CODE PATH_BITS "/screeninit.bin" // Screeninit code (ARM11)
 
 #define PATH_NATIVE_F PATH_FIRMWARES "/native"
index b2be51b18486e923cf9457b2c76c6ff98d478f87..066cc10ce0849e65d0e777605c06d8204d03d5c4 100644 (file)
@@ -85,7 +85,6 @@ patch_firm_all()
         wait();
     }
 
-
     // Use ARM9 hook thread?
     if (config.options[OPTION_ARM9THREAD]) {
         // Yes.
@@ -97,7 +96,7 @@ patch_firm_all()
     // Use EmuNAND?
     if (config.options[OPTION_EMUNAND]) {
         // Yes.
-               patch_emunand(config.options[OPTION_EMUNAND_INDEX]);
+        patch_emunand(config.options[OPTION_EMUNAND_INDEX]);
 
         wait();
     }
index 9ce3eac88c92cdd8b2bf4c7139da9ed920720805..81cc4c8f937a76d2c40d69d1c39e69e7ca65ad81 100644 (file)
@@ -6,21 +6,24 @@
 
 static volatile uint32_t *const a11_entry = (volatile uint32_t *)0x1FFFFFF8;
 
-void screen_init() {
-       if (PDN_GPU_CNT == 1) {
-               uint32_t* screenInitAddress = (uint32_t*)0x24FFFC00;
+void
+screen_init()
+{
+    if (PDN_GPU_CNT == 1) {
+        uint32_t *screenInitAddress = (uint32_t *)0x24FFFC00;
 
-               FILE* f = fopen(PATH_SCREENINIT_CODE, "r");
-               fread(screenInitAddress, 1, fsize(f), f); // Read in the screeninit payload.
-               fclose(f);
+        FILE *f = fopen(PATH_SCREENINIT_CODE, "r");
+        fread(screenInitAddress, 1, fsize(f), f); // Read in the screeninit payload.
+        fclose(f);
 
-               //Write brightness level for the stub to pick up
-               screenInitAddress[2] = 0x5F;
-               *a11_entry = (uint32_t)screenInitAddress;
+        // Write brightness level for the stub to pick up
+        screenInitAddress[2] = 0x5F;
+        *a11_entry = (uint32_t)screenInitAddress;
 
-               while(*a11_entry);
+        while (*a11_entry)
+            ;
 
-               //Turn on backlight
-               i2cWriteRegister(I2C_DEV_MCU, 0x22, 0x2A);
-       }
+        // Turn on backlight
+        i2cWriteRegister(I2C_DEV_MCU, 0x22, 0x2A);
+    }
 }
index f6e085f722ec52b333c8e55fff3065d27c83f465..14cce9c3c87fa345a40e2c3b44b975e7b8999b64 100644 (file)
@@ -11,7 +11,7 @@ uint32_t wait_key();
         fprintf(stderr, x);                                                                                                                                    \
         wait_key();                                                                                                                                            \
         clear_disp(stderr);                                                                                                                                    \
-               set_cursor(stderr, 0, 0);                                                                                                                              \
+        set_cursor(stderr, 0, 0);                                                                                                                              \
         menu_poweroff();                                                                                                                                       \
     }
 
index 45225ea1e81a2ae49c915c5eaecb22cd91ae5c23..c8bcd8151021d3515b329e97b9948d7b4214a705 100644 (file)
@@ -51,10 +51,10 @@ clear_disp(uint8_t *screen)
         fseek(f, 0, SEEK_END);
         for (int i = 0; i < TEXT_BOTTOM_HEIGHT - 1; i++) {
             char *text = text_buffer_bottom + (TEXT_BOTTOM_WIDTH * i);
-                       for(int j = 0; j < TEXT_BOTTOM_WIDTH; j++) {
-                               if (text[j] == 0)
-                                       text[j] = ' ';
-                       }
+            for (int j = 0; j < TEXT_BOTTOM_WIDTH; j++) {
+                if (text[j] == 0)
+                    text[j] = ' ';
+            }
             fwrite(text, 1, strnlen(text, TEXT_BOTTOM_WIDTH), f);
             fwrite("\n", 1, 1, f);
         }
index 38ee108a389fb38345da4601358656375f0f478f..0f5f04bc1b6748351bfcb3e91701c63a1055b34d 100644 (file)
@@ -236,17 +236,19 @@ read_file(void *data, char *path, size_t size)
 //    DWORD clust;  /* Current cluster of fpter (not valid when fprt is 0) */
 //    DWORD dsect;  /* Sector number appearing in buf[] (0:invalid) */
 
-size_t get_file_sector(char* path) {
-       FILE* temp = fopen(path, "r");
+size_t
+get_file_sector(char *path)
+{
+    FILE *temp = fopen(path, "r");
 
     if (!temp || !temp->is_open)
         return 0;
 
-       UINT sector;
+    UINT sector;
 
-       f_getsector(& temp->handle, &sector);
+    f_getsector(&temp->handle, &sector);
 
-       fclose(temp);
+    fclose(temp);
 
-       return sector;
+    return sector;
 }
index 5aac56960d2e1437cc6ce186dbfb14d0f3f743c7..e40e150107c30012da6cec7eb3db8e158c37e27a 100644 (file)
@@ -43,6 +43,6 @@ size_t fread(void *buffer, size_t elementSize, size_t elementCnt, FILE *fp);
 size_t write_file(void *data, char *path, size_t size);
 size_t read_file(void *data, char *path, size_t size);
 
-size_t get_file_sector(charpath);
+size_t get_file_sector(char *path);
 
 #endif