Scripting: add dumptxt command

This commit is contained in:
d0k3 2019-03-14 01:50:27 +01:00
parent 82d6e94789
commit d50e6b88ae
2 changed files with 17 additions and 0 deletions

View File

@ -102,6 +102,7 @@ typedef enum {
CMD_ID_FSET, CMD_ID_FSET,
CMD_ID_SHA, CMD_ID_SHA,
CMD_ID_SHAGET, CMD_ID_SHAGET,
CMD_ID_DUMPTXT,
CMD_ID_FIXCMAC, CMD_ID_FIXCMAC,
CMD_ID_VERIFY, CMD_ID_VERIFY,
CMD_ID_DECRYPT, CMD_ID_DECRYPT,
@ -174,6 +175,7 @@ Gm9ScriptCmd cmd_list[] = {
{ CMD_ID_FSET , "fset" , 2, _FLG('e') }, { CMD_ID_FSET , "fset" , 2, _FLG('e') },
{ CMD_ID_SHA , "sha" , 2, 0 }, { CMD_ID_SHA , "sha" , 2, 0 },
{ CMD_ID_SHAGET , "shaget" , 2, 0 }, { CMD_ID_SHAGET , "shaget" , 2, 0 },
{ CMD_ID_DUMPTXT , "dumptxt" , 2, _FLG('p') },
{ CMD_ID_FIXCMAC , "fixcmac" , 1, 0 }, { CMD_ID_FIXCMAC , "fixcmac" , 1, 0 },
{ CMD_ID_VERIFY , "verify" , 1, 0 }, { CMD_ID_VERIFY , "verify" , 1, 0 },
{ CMD_ID_DECRYPT , "decrypt" , 1, 0 }, { CMD_ID_DECRYPT , "decrypt" , 1, 0 },
@ -1275,6 +1277,15 @@ bool run_cmd(cmd_id id, u32 flags, char** argv, char* err_str) {
if (err_str) snprintf(err_str, _ERR_STR_LEN, "sha write fail"); if (err_str) snprintf(err_str, _ERR_STR_LEN, "sha write fail");
} }
} }
else if (id == CMD_ID_DUMPTXT) {
size_t offset = 0;
u32 len = strnlen(argv[1], _ARG_MAX_LEN);
if (flags & _FLG('p')) offset = FileGetSize(argv[0]);
if (!(ret = FileSetData(argv[0], argv[1], len, offset, offset == 0)) ||
!(ret = FileSetData(argv[0], "\n", 1, offset + len, false))) {
if (err_str) snprintf(err_str, _ERR_STR_LEN, "file write fail");
}
}
else if (id == CMD_ID_FIXCMAC) { else if (id == CMD_ID_FIXCMAC) {
ShowString("Fixing CMACs..."); ShowString("Fixing CMACs...");
ret = (RecursiveFixFileCmac(argv[0]) == 0); ret = (RecursiveFixFileCmac(argv[0]) == 0);

View File

@ -242,6 +242,12 @@ fset $[DUMMY]@100 48454c4c4f # 'HELLO'
fget -e $[DUMMY]@100:5 OLLEH fget -e $[DUMMY]@100:5 OLLEH
echo "This is 'HELLO', in hex and reverse:\n$[OLLEH]" echo "This is 'HELLO', in hex and reverse:\n$[OLLEH]"
# 'dumptxt' COMMAND
# This command dumps the given text to a file
# -p / --append appends text instead of writing a new file
# dumptxt 0:/hello.txt HELLO
# dumptxt -p 0:/hello.txt WORLD
# 'fixcmac' COMMAND # 'fixcmac' COMMAND
# Use this to fix the CMACs for a file or a whole folder (recursively) # Use this to fix the CMACs for a file or a whole folder (recursively)
# This will count as success if a file does not contain a CMAC # This will count as success if a file does not contain a CMAC