diff --git a/client/src/cmdflashmemspiffs.c b/client/src/cmdflashmemspiffs.c index 70efd5db6..2f5c94324 100644 --- a/client/src/cmdflashmemspiffs.c +++ b/client/src/cmdflashmemspiffs.c @@ -370,22 +370,19 @@ static int CmdFlashMemSpiFFSDump(const char *Cmd) { CLIParserInit(&ctx, "mem spiffs dump", "Dumps device SPIFFS file to a local file\n" "Size is handled by first sending a STAT command against file to verify existence", - "mem spiffs dump -s tag.bin --> download binary file from device\n" + "mem spiffs dump -s tag.bin --> download binary file from device, saved as `tag.bin`\n" "mem spiffs dump -s tag.bin -d a001 --> download tag.bin, save as `a001.bin`\n" - "mem spiffs dump -s tag.bin -t --> download tag.bin into client trace buffer" + "mem spiffs dump -s tag.bin -t --> download tag.bin into trace buffer" ); void *argtable[] = { arg_param_begin, arg_str1("s", "src", "", "SPIFFS file to save"), arg_str0("d", "dest", "", "file name to save to "), - arg_lit0("t", "trace", "download into trace buffer, not local file"), + arg_lit0("t", "trace", "download into trace buffer"), arg_param_end }; CLIExecWithReturn(ctx, Cmd, argtable, false); - bool use_buffer = arg_get_lit(ctx, 3); - - int slen = 0; char src[32] = {0}; CLIParamStrToBuf(arg_get_str(ctx, 1), (uint8_t *)src, 32, &slen); @@ -394,6 +391,7 @@ static int CmdFlashMemSpiFFSDump(const char *Cmd) { char dest[FILE_PATH_SIZE] = {0}; CLIParamStrToBuf(arg_get_str(ctx, 2), (uint8_t *)dest, FILE_PATH_SIZE, &dlen); + bool to_trace = arg_get_lit(ctx, 3); CLIParserFree(ctx); // get size from spiffs itself ! @@ -407,7 +405,7 @@ static int CmdFlashMemSpiFFSDump(const char *Cmd) { uint32_t len = resp.data.asDwords[0]; uint8_t *dump = calloc(len, sizeof(uint8_t)); - if (!dump) { + if (dump == NULL) { PrintAndLogEx(ERR, "error, cannot allocate memory "); return PM3_EMALLOC; } @@ -415,36 +413,37 @@ static int CmdFlashMemSpiFFSDump(const char *Cmd) { // download from device uint32_t start_index = 0; PrintAndLogEx(INFO, "downloading "_YELLOW_("%u") " bytes from `" _YELLOW_("%s") "` (spiffs)", len, src); - if (!GetFromDevice(SPIFFS, dump, len, start_index, (uint8_t *)src, slen, NULL, -1, true)) { + if (GetFromDevice(SPIFFS, dump, len, start_index, (uint8_t *)src, slen, NULL, -1, true) == false) { PrintAndLogEx(FAILED, "error, downloading from spiffs"); free(dump); return PM3_EFLASH; } - if (use_buffer == true) { + if (to_trace) { // copy to client trace buffer - if (!ImportTraceBuffer(dump, len)) - { + if (ImportTraceBuffer(dump, len) == false) { PrintAndLogEx(FAILED, "error, copying to trace buffer"); free(dump); return PM3_EMALLOC; } - PrintAndLogEx(SUCCESS, "Use 'trace list -1 -t ...' to view, 'trace save -f ...' to save"); + PrintAndLogEx(HINT, "Use 'trace list -1 -t ...' to view, 'trace save -f ...' to save"); } else { + // save to file char fn[FILE_PATH_SIZE] = {0}; - if (dlen == 0) { - strncpy(fn, src, slen); - } else { + if (dlen) { strncpy(fn, dest, dlen); + } else { + strncpy(fn, src, slen); } // set file extension char *suffix = strchr(fn, '.'); - if (suffix) + if (suffix) { saveFile(fn, suffix, dump, len); - else - saveFile(fn, ".bin", dump, len); // default + } else { + saveFile(fn, ".bin", dump, len); + } } free(dump); return PM3_SUCCESS;