Skip to content

Commit

Permalink
allow data load to load binary files as raw signal from device (@mwal…
Browse files Browse the repository at this point in the history
  • Loading branch information
iceman1001 committed Aug 28, 2022
1 parent 79cfa1d commit bebfe0a
Showing 1 changed file with 29 additions and 12 deletions.
41 changes: 29 additions & 12 deletions client/src/cmddata.c
Original file line number Diff line number Diff line change
Expand Up @@ -2032,17 +2032,17 @@ static int CmdLoad(const char *Cmd) {
void *argtable[] = {
arg_param_begin,
arg_str1("f", "file", "<fn>", "file to load"),
arg_lit0("n", "no-fix", "Load data from wile without any transformations"),
arg_lit0("b", "bin", "binary file"),
arg_lit0("n", "no-fix", "Load data from file without any transformations"),
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, false);

int fnlen = 0;
char filename[FILE_PATH_SIZE] = {0};
CLIParamStrToBuf(arg_get_str(ctx, 1), (uint8_t *)filename, FILE_PATH_SIZE, &fnlen);

bool nofix = arg_get_lit(ctx, 2);

bool is_bin = arg_get_lit(ctx, 2);
bool nofix = arg_get_lit(ctx, 3);
CLIParserFree(ctx);

char *path = NULL;
Expand All @@ -2052,22 +2052,39 @@ static int CmdLoad(const char *Cmd) {
}
}

FILE *f = fopen(path, "r");
if (!f) {
FILE *f;
if (is_bin)
f = fopen(path, "rb");
else
f = fopen(path, "r");

if (f == NULL) {
PrintAndLogEx(WARNING, "couldn't open '%s'", path);
free(path);
return PM3_EFILE;
}
free(path);

g_GraphTraceLen = 0;
char line[80];
while (fgets(line, sizeof(line), f)) {
g_GraphBuffer[g_GraphTraceLen] = atoi(line);
g_GraphTraceLen++;

if (g_GraphTraceLen >= MAX_GRAPH_TRACE_LEN)
break;
if (is_bin) {
uint8_t val[2];
while (fread(val, 1, 1, f)) {
g_GraphBuffer[g_GraphTraceLen] = val[0] - 127;
g_GraphTraceLen++;

if (g_GraphTraceLen >= MAX_GRAPH_TRACE_LEN)
break;
}
} else {
char line[80];
while (fgets(line, sizeof(line), f)) {
g_GraphBuffer[g_GraphTraceLen] = atoi(line);
g_GraphTraceLen++;

if (g_GraphTraceLen >= MAX_GRAPH_TRACE_LEN)
break;
}
}
fclose(f);

Expand Down

0 comments on commit bebfe0a

Please sign in to comment.