diff --git a/HelloScript.gm9 b/HelloScript.gm9 index 5303d23..28bf2da 100644 --- a/HelloScript.gm9 +++ b/HelloScript.gm9 @@ -106,17 +106,24 @@ mv -w -k $[TESTPATH] $[RENPATH] # The 'find' command has two main uses, (1) checking if files / dirs exist and (2) finding files / dirs # Here we use it to check for RENPATH, thus we use NULL as second argument (we're not interested in the output) find $[RENPATH] NULL -# Wildcards ('*' / '?') are allowed when searching for a file / directory name: -# find S:/nand.* NANDIMAGE +# Wildcards ('*' / '?') are allowed when searching for a file / directory name +# If wildcards are used, 'find' will always return the last alphanumerical match +find S:/nand.* NANDIMAGE # 'sha' COMMAND # Use this to check a files' SHA256 sha $[RENPATH] $[TESTPATH].sha # Instead of an .sha file you can also use the SHA256 in hex as second argument # sha S:/sector0x96.bin 82F2730D2C2DA3F30165F987FDCCAC5CBAB24B4E5F65C981CD7BE6F438E6D9D3 -# This also allows partial SHA checks (for @x:y handling see below) +# This also allows partial SHA checks (for @x:y handling see 'inject' below) # sha S:/firm0.bin@100:100 078CC0CFD850A27093DDA2630C3603CA0C96969BD1F26DA48AC7B1BAE5DD5219 +# 'shaget' COMMAND +# Use this to calculate and store a files' SHA256 +# shaget 0:/boot.firm 0:/boot.firm.sha +# Partial SHA calculation is also possible (for @x:y handling see 'inject' below) +# shaget 0:/boot.firm@100:100 0:/boot.firm.partial.sha + # 'inject' COMMAND # This command is used to inject part of one file into another # The syntax is: inject origin@x:y destination@z @@ -165,6 +172,10 @@ verify S:/firm1.bin # boot 0:/boot.firm # disabled cause it would leave the script +# 'switchsd' COMMAND +# Use this to allow the user to switch the SD card +# switchsd "Please switch SD card." + # 'reboot' / 'poweroff' COMMAND # These are used to reboot or power off the 3DS console set ERRORMSG "Test script finished,\n(without reboot)\n \nIgnore the error message." diff --git a/source/filesys/fsscript.c b/source/filesys/fsscript.c index 7d2f644..c93e1b4 100644 --- a/source/filesys/fsscript.c +++ b/source/filesys/fsscript.c @@ -2,6 +2,7 @@ #include "fsutil.h" #include "fsinit.h" #include "fsperm.h" +#include "nand.h" #include "nandcmac.h" #include "nandutil.h" #include "gameutil.h" @@ -13,6 +14,7 @@ #include "vff.h" #include "rtc.h" #include "sha.h" +#include "hid.h" #include "ui.h" #define _MAX_ARGS 2 @@ -44,12 +46,14 @@ typedef enum { CMD_ID_FIND, CMD_ID_FINDNOT, CMD_ID_SHA, + CMD_ID_SHAGET, CMD_ID_FIXCMAC, CMD_ID_VERIFY, CMD_ID_DECRYPT, CMD_ID_ENCRYPT, CMD_ID_BUILDCIA, CMD_ID_BOOT, + CMD_ID_SWITCHSD, CMD_ID_REBOOT, CMD_ID_POWEROFF } cmd_id; @@ -82,12 +86,14 @@ Gm9ScriptCmd cmd_list[] = { { CMD_ID_FIND , "find" , 2, 0 }, { CMD_ID_FINDNOT , "findnot" , 2, 0 }, { CMD_ID_SHA , "sha" , 2, 0 }, + { CMD_ID_SHAGET , "shaget" , 2, 0 }, { CMD_ID_FIXCMAC , "fixcmac" , 1, 0 }, { CMD_ID_VERIFY , "verify" , 1, 0 }, { CMD_ID_DECRYPT , "decrypt" , 1, 0 }, { CMD_ID_ENCRYPT , "encrypt" , 1, 0 }, { CMD_ID_BUILDCIA, "buildcia", 1, _FLG('l') }, { CMD_ID_BOOT , "boot" , 1, 0 }, + { CMD_ID_SWITCHSD, "switchsd", 1, 0 }, { CMD_ID_REBOOT , "reboot" , 0, 0 }, { CMD_ID_POWEROFF, "poweroff", 0, 0 } }; @@ -466,6 +472,13 @@ bool run_cmd(cmd_id id, u32 flags, char** argv, char* err_str) { ret = (memcmp(sha256_fil, sha256_cmp, 0x20) == 0); if (err_str) snprintf(err_str, _ERR_STR_LEN, "sha does not match"); } + } else if (id == CMD_ID_SHAGET) { + u8 sha256_fil[0x20]; + if (!(ret = FileGetSha256(argv[0], sha256_fil, at_org, sz_org))) { + if (err_str) snprintf(err_str, _ERR_STR_LEN, "sha arg0 fail"); + } else if (!(ret = FileSetData(argv[1], sha256_fil, 0x20, 0, true))) { + if (err_str) snprintf(err_str, _ERR_STR_LEN, "sha write fail"); + } } else if (id == CMD_ID_FIXCMAC) { ShowString("Fixing CMACs..."); ret = (RecursiveFixFileCmac(argv[0]) == 0); @@ -500,6 +513,27 @@ bool run_cmd(cmd_id id, u32 flags, char** argv, char* err_str) { BootFirm((FirmHeader*)(void*)TEMP_BUFFER, fixpath); while(1); } else if (err_str) snprintf(err_str, _ERR_STR_LEN, "not a bootable firm"); + } else if (id == CMD_ID_SWITCHSD) { + DeinitExtFS(); + if (!(ret = CheckSDMountState())) { + if (err_str) snprintf(err_str, _ERR_STR_LEN, "SD not mounted"); + } else { + u32 pad_state; + DeinitSDCardFS(); + ShowString("%s\n \nEject SD card...", argv[0]); + while (!((pad_state = InputWait(0)) & (BUTTON_B|SD_EJECT))); + if (pad_state & SD_EJECT) { + ShowString("%s\n \nInsert SD card...", argv[0]); + while (!((pad_state = InputWait(0)) & (BUTTON_B|SD_INSERT))); + } + if (pad_state & BUTTON_B) { + ret = false; + if (err_str) snprintf(err_str, _ERR_STR_LEN, "user abort"); + } + } + InitSDCardFS(); + AutoEmuNandBase(true); + InitExtFS(); } else if (id == CMD_ID_REBOOT) { Reboot(); } else if (id == CMD_ID_POWEROFF) {