mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-23 22:55:37 -07:00
Merge pull request #2217 from hazardousvoltage/work
SPIFFS: implement dumping from SPIFFS to client trace buffer
This commit is contained in:
commit
6d34bbfa27
3 changed files with 51 additions and 16 deletions
|
@ -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"
|
||||||
|
@ -369,17 +370,21 @@ static int CmdFlashMemSpiFFSDump(const char *Cmd) {
|
||||||
CLIParserInit(&ctx, "mem spiffs dump",
|
CLIParserInit(&ctx, "mem spiffs dump",
|
||||||
"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,21 +421,31 @@ static int CmdFlashMemSpiFFSDump(const char *Cmd) {
|
||||||
return PM3_EFLASH;
|
return PM3_EFLASH;
|
||||||
}
|
}
|
||||||
|
|
||||||
// save to file
|
if (use_buffer == true) {
|
||||||
char fn[FILE_PATH_SIZE] = {0};
|
// copy to client trace buffer
|
||||||
if (dlen == 0) {
|
if (!ImportTraceBuffer(dump, len))
|
||||||
strncpy(fn, src, slen);
|
{
|
||||||
|
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 {
|
} 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);
|
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"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -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};
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue