From 9f12a47cfce2910d8d6075c29fe26ed739b09c2d Mon Sep 17 00:00:00 2001 From: TuxSH Date: Fri, 19 May 2017 22:40:07 +0200 Subject: [PATCH] Fix string handling bugs --- loader/source/main.c | 2 +- patches/reboot.s | 7 +++++-- source/main.c | 10 +++++++--- source/patches.c | 4 ++-- source/types.h | 2 +- 5 files changed, 16 insertions(+), 9 deletions(-) diff --git a/loader/source/main.c b/loader/source/main.c index d51815f..cc45b5f 100644 --- a/loader/source/main.c +++ b/loader/source/main.c @@ -32,7 +32,7 @@ void main(int argc __attribute__((unused)), char **argv) u32 i; for(i = 0; i < 91 && argv[1] != 0; i++) absPath[i] = argv[1][i]; - for(; i < 91; i++) + for(; i < 92; i++) absPath[i] = 0; char *argvPassed[1] = {absPath}; diff --git a/patches/reboot.s b/patches/reboot.s index 78d5b9a..76b5ea7 100644 --- a/patches/reboot.s +++ b/patches/reboot.s @@ -105,8 +105,11 @@ arm11_entrypoint_addr equ 0x1FFFFFFC bytes_read: .word 0 fopen: .ascii "OPEN" .pool -fname: .dcw "sdmc:/arm9loaderha.firm" - .word 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + +.area 82, 0 +fname: .dcw "sdmc:/boot.firm" +.endarea + .pool nand_mount: .dcw "nand" diff --git a/source/main.c b/source/main.c index 6c5ab62..7a7f976 100644 --- a/source/main.c +++ b/source/main.c @@ -33,13 +33,14 @@ #include "crypto.h" #include "fmt.h" #include "memory.h" +#include "i2c.h" extern CfgData configData; extern ConfigurationStatus needConfig; extern FirmwareSource firmSource; u16 launchedFirmTidLow[8]; -u16 launchedPath[42]; +u16 launchedPath[41]; void main(int argc, char **argv) { @@ -58,7 +59,7 @@ void main(int argc, char **argv) case 1: //Normal boot { u32 i; - for(i = 0; i < 41 && launchedPath[i] != 0; i++) //Copy and convert the path to utf16 + for(i = 0; i < 40 && launchedPath[i] != 0; i++) //Copy and convert the path to utf16 launchedPath[2 * i] = argv[0][i]; for(; i < 41; i++) launchedPath[i] = 0; @@ -70,9 +71,12 @@ void main(int argc, char **argv) case 2: //Firmlaunch { + + i2cWriteRegister(I2C_DEV_MCU, 0x20, 1 << 0); + while(true); u32 i; u16 *p = (u16 *)argv[0]; - for(i = 0; i < 41 && launchedPath[i] != 0; i++) + for(i = 0; i < 40 && launchedPath[i] != 0; i++) launchedPath[i] = p[i]; for(; i < 41; i++) launchedPath[i] = 0; diff --git a/source/patches.c b/source/patches.c index 89850fd..88a358d 100644 --- a/source/patches.c +++ b/source/patches.c @@ -135,8 +135,8 @@ u32 patchFirmlaunches(u8 *pos, u32 size, u32 process9MemAddr) u32 *pos_fopen = (u32 *)memsearch(off, "OPEN", reboot_bin_size, 4); *pos_fopen = fOpenOffset; - //u16 *fname = (u16 *)memsearch(off, u"sd", reboot_bin_size, 4); - //memcpy(fname, u"sdmc:/test.firm", 32); + u16 *fname = (u16 *)memsearch(off, u"sd", reboot_bin_size, 4); + memcpy(fname, launchedPath, 82); return 0; } diff --git a/source/types.h b/source/types.h index 419068b..c3376ee 100644 --- a/source/types.h +++ b/source/types.h @@ -116,4 +116,4 @@ typedef enum FirmwareType } FirmwareType; extern u16 launchedFirmTidLow[8]; -extern u16 launchedPath[42]; +extern u16 launchedPath[41];