From 5d9ed651cb1071e64bc93d364b54099c2eade29f Mon Sep 17 00:00:00 2001 From: d0k3 Date: Sun, 24 Sep 2017 13:44:49 +0200 Subject: [PATCH] Scripting: allow 'shaget to store the SHA in a var --- HelloScript.gm9 | 6 +++++- source/utils/scripting.c | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/HelloScript.gm9 b/HelloScript.gm9 index 7b84727..a63b960 100644 --- a/HelloScript.gm9 +++ b/HelloScript.gm9 @@ -154,8 +154,12 @@ sha $[RENPATH] $[TESTPATH].sha # sha S:/firm0.bin@100:100 078CC0CFD850A27093DDA2630C3603CA0C96969BD1F26DA48AC7B1BAE5DD5219 # 'shaget' COMMAND -# Use this to calculate and store a files' SHA256 +# Use this to calculate (and store) a files' SHA256 +# If the second argument is a filename, the SHA256 will be stored there # shaget 0:/boot.firm 0:/boot.firm.sha +# If it's a variable, it will be stored there temporarily instead +shaget S:/nand_hdr.bin NANDHDRSHA +sha S:/nand_hdr.bin $[NANDHDRSHA] # Partial SHA calculation is also possible (for @x:y handling see 'inject' below) # shaget 0:/boot.firm@100:100 0:/boot.firm.partial.sha diff --git a/source/utils/scripting.c b/source/utils/scripting.c index 5a32af1..aac8cd4 100644 --- a/source/utils/scripting.c +++ b/source/utils/scripting.c @@ -673,6 +673,12 @@ bool run_cmd(cmd_id id, u32 flags, char** argv, char* err_str) { 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 (!strchr(argv[1], ':')) { + char sha256_str[64+1]; + snprintf(sha256_str, 64+1, "%016llX%016llX%016llX%016llX", getbe64(sha256_fil + 0), getbe64(sha256_fil + 8), + getbe64(sha256_fil + 16), getbe64(sha256_fil + 24)); + ret = set_var(argv[1], sha256_str); + if (err_str) snprintf(err_str, _ERR_STR_LEN, "var fail"); } else if (!(ret = FileSetData(argv[1], sha256_fil, 0x20, 0, true))) { if (err_str) snprintf(err_str, _ERR_STR_LEN, "sha write fail"); }