Merge pull request #2217 from hazardousvoltage/work

SPIFFS: implement dumping from SPIFFS to client trace buffer
This commit is contained in:
Iceman 2024-01-02 21:43:57 +01:00 committed by GitHub
commit 6d34bbfa27
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 16 deletions

View file

@ -16,6 +16,7 @@
// Proxmark3 RDV40 Flash memory commands // Proxmark3 RDV40 Flash memory commands
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#include "cmdflashmemspiffs.h" #include "cmdflashmemspiffs.h"
#include "cmdtrace.h"
#include <ctype.h> #include <ctype.h>
#include "cmdparser.h" // command_t #include "cmdparser.h" // command_t
#include "pmflash.h" #include "pmflash.h"
@ -370,16 +371,20 @@ static int CmdFlashMemSpiFFSDump(const char *Cmd) {
"Dumps device SPIFFS file to a local file\n" "Dumps device SPIFFS file to a local file\n"
"Size is handled by first sending a STAT command against file to verify existence", "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\n"
"mem spiffs dump -s tag.bin -d a001 -e --> download tag.bin, save as `a001.bin`" "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[] = { void *argtable[] = {
arg_param_begin, arg_param_begin,
arg_str1("s", "src", "<fn>", "SPIFFS file to save"), arg_str1("s", "src", "<fn>", "SPIFFS file to save"),
arg_str0("d", "dest", "<fn>", "file name to save to <w/o .bin>"), arg_str0("d", "dest", "<fn>", "file name to save to <w/o .bin>"),
arg_lit0("t", "trace", "download into trace buffer, not local file"),
arg_param_end arg_param_end
}; };
CLIExecWithReturn(ctx, Cmd, argtable, false); CLIExecWithReturn(ctx, Cmd, argtable, false);
bool use_buffer = arg_get_lit(ctx, 3);
int slen = 0; int slen = 0;
char src[32] = {0}; char src[32] = {0};
@ -416,6 +421,16 @@ static int CmdFlashMemSpiFFSDump(const char *Cmd) {
return PM3_EFLASH; return PM3_EFLASH;
} }
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 {
// save to file // save to file
char fn[FILE_PATH_SIZE] = {0}; char fn[FILE_PATH_SIZE] = {0};
if (dlen == 0) { if (dlen == 0) {
@ -430,7 +445,7 @@ static int CmdFlashMemSpiFFSDump(const char *Cmd) {
saveFile(fn, suffix, dump, len); saveFile(fn, suffix, dump, len);
else else
saveFile(fn, ".bin", dump, len); // default saveFile(fn, ".bin", dump, len); // default
}
free(dump); free(dump);
return PM3_SUCCESS; return PM3_SUCCESS;
} }
@ -513,7 +528,7 @@ static int CmdFlashMemSpiFFSView(const char *Cmd) {
CLIParserContext *ctx; CLIParserContext *ctx;
CLIParserInit(&ctx, "mem spiffs view", 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" "mem spiffs view -f tag.bin"
); );

View file

@ -91,6 +91,25 @@ static uint8_t calc_pos(const uint8_t *d) {
return pos; 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_uid[10] = {0};
static uint8_t extract_uidlen = 0; static uint8_t extract_uidlen = 0;
static uint8_t extract_epurse[8] = {0}; static uint8_t extract_epurse[8] = {0};

View file

@ -24,5 +24,6 @@
int CmdTrace(const char *Cmd); int CmdTrace(const char *Cmd);
int CmdTraceList(const char *Cmd); int CmdTraceList(const char *Cmd);
int CmdTraceListAlias(const char *Cmd, const char *alias, const char *protocol); int CmdTraceListAlias(const char *Cmd, const char *alias, const char *protocol);
bool ImportTraceBuffer(uint8_t *trace_src, uint16_t trace_len);
#endif #endif