diff --git a/client/src/cmdflashmemspiffs.c b/client/src/cmdflashmemspiffs.c index 218109755..70efd5db6 100644 --- a/client/src/cmdflashmemspiffs.c +++ b/client/src/cmdflashmemspiffs.c @@ -16,6 +16,7 @@ // Proxmark3 RDV40 Flash memory commands //----------------------------------------------------------------------------- #include "cmdflashmemspiffs.h" +#include "cmdtrace.h" #include #include "cmdparser.h" // command_t #include "pmflash.h" @@ -369,17 +370,21 @@ 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 -d a001 -e --> download tag.bin, save as `a001.bin`" + "mem spiffs dump -s tag.bin --> download binary file from device\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" ); 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_param_end }; CLIExecWithReturn(ctx, Cmd, argtable, false); + bool use_buffer = arg_get_lit(ctx, 3); + int slen = 0; char src[32] = {0}; @@ -416,21 +421,31 @@ static int CmdFlashMemSpiFFSDump(const char *Cmd) { return PM3_EFLASH; } - // save to file - char fn[FILE_PATH_SIZE] = {0}; - if (dlen == 0) { - strncpy(fn, src, slen); + if (use_buffer == true) { + // copy to client trace buffer + if (!ImportTraceBuffer(dump, len)) + { + 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"); } else { - strncpy(fn, dest, dlen); + // save to file + char fn[FILE_PATH_SIZE] = {0}; + if (dlen == 0) { + strncpy(fn, src, slen); + } else { + strncpy(fn, dest, dlen); + } + + // set file extension + char *suffix = strchr(fn, '.'); + if (suffix) + saveFile(fn, suffix, dump, len); + else + saveFile(fn, ".bin", dump, len); // default } - - // set file extension - char *suffix = strchr(fn, '.'); - if (suffix) - saveFile(fn, suffix, dump, len); - else - saveFile(fn, ".bin", dump, len); // default - free(dump); return PM3_SUCCESS; } @@ -513,7 +528,7 @@ static int CmdFlashMemSpiFFSView(const char *Cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "mem spiffs view", - "View a file on flash memory on devicer in console", + "View a file on flash memory on device in console", "mem spiffs view -f tag.bin" ); diff --git a/client/src/cmdtrace.c b/client/src/cmdtrace.c index c4d278c0a..b277c2088 100644 --- a/client/src/cmdtrace.c +++ b/client/src/cmdtrace.c @@ -91,6 +91,25 @@ static uint8_t calc_pos(const uint8_t *d) { return pos; } +// Copy an existing buffer into client trace buffer +// I think this is cleaner than further globalizing gs_trace, and may lend itself to more modularity later? +bool ImportTraceBuffer(uint8_t *trace_src, uint16_t trace_len) +{ + if (trace_len == 0 || trace_src == NULL) return(false); + if (gs_trace) { + free(gs_trace); + gs_traceLen = 0; + } + gs_trace = calloc(trace_len, sizeof(uint8_t)); + if (gs_trace == NULL) + { + return(false); + } + memcpy(gs_trace, trace_src, trace_len); + gs_traceLen = trace_len; + return(true); +} + static uint8_t extract_uid[10] = {0}; static uint8_t extract_uidlen = 0; static uint8_t extract_epurse[8] = {0}; diff --git a/client/src/cmdtrace.h b/client/src/cmdtrace.h index 6f2967d44..2be583a06 100644 --- a/client/src/cmdtrace.h +++ b/client/src/cmdtrace.h @@ -24,5 +24,6 @@ int CmdTrace(const char *Cmd); int CmdTraceList(const char *Cmd); int CmdTraceListAlias(const char *Cmd, const char *alias, const char *protocol); +bool ImportTraceBuffer(uint8_t *trace_src, uint16_t trace_len); #endif