mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-20 21:33:47 -07:00
msleep, hints, auto, now uses cliparser
This commit is contained in:
parent
57eef7c5a9
commit
381a87c138
1 changed files with 65 additions and 68 deletions
|
@ -38,47 +38,10 @@
|
||||||
#include "util_posix.h"
|
#include "util_posix.h"
|
||||||
#include "commonutil.h" // ARRAYLEN
|
#include "commonutil.h" // ARRAYLEN
|
||||||
#include "preferences.h"
|
#include "preferences.h"
|
||||||
|
#include "cliparser.h"
|
||||||
|
|
||||||
static int CmdHelp(const char *Cmd);
|
static int CmdHelp(const char *Cmd);
|
||||||
|
|
||||||
static int usage_hints(void) {
|
|
||||||
PrintAndLogEx(NORMAL, "Turn on/off hints");
|
|
||||||
PrintAndLogEx(NORMAL, "");
|
|
||||||
PrintAndLogEx(NORMAL, "Usage: hints [h] <0|1>");
|
|
||||||
PrintAndLogEx(NORMAL, "Options:");
|
|
||||||
PrintAndLogEx(NORMAL, " h This help");
|
|
||||||
PrintAndLogEx(NORMAL, " <0|1> off or on");
|
|
||||||
PrintAndLogEx(NORMAL, "");
|
|
||||||
PrintAndLogEx(NORMAL, "Examples:");
|
|
||||||
PrintAndLogEx(NORMAL, _YELLOW_(" hints 1"));
|
|
||||||
return PM3_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int usage_msleep(void) {
|
|
||||||
PrintAndLogEx(NORMAL, "Sleep for given amount of milliseconds");
|
|
||||||
PrintAndLogEx(NORMAL, "");
|
|
||||||
PrintAndLogEx(NORMAL, "Usage: msleep <ms>");
|
|
||||||
PrintAndLogEx(NORMAL, "Options:");
|
|
||||||
PrintAndLogEx(NORMAL, " h This help");
|
|
||||||
PrintAndLogEx(NORMAL, " <ms> time in milliseconds");
|
|
||||||
PrintAndLogEx(NORMAL, "");
|
|
||||||
PrintAndLogEx(NORMAL, "Examples:");
|
|
||||||
PrintAndLogEx(NORMAL, _YELLOW_(" msleep 100"));
|
|
||||||
return PM3_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int usage_auto(void) {
|
|
||||||
PrintAndLogEx(NORMAL, "Run LF SEARCH / HF SEARCH / DATA PLOT / DATA SAVE ");
|
|
||||||
PrintAndLogEx(NORMAL, "");
|
|
||||||
PrintAndLogEx(NORMAL, "Usage: auto <ms>");
|
|
||||||
PrintAndLogEx(NORMAL, "Options:");
|
|
||||||
PrintAndLogEx(NORMAL, " h This help");
|
|
||||||
PrintAndLogEx(NORMAL, "");
|
|
||||||
PrintAndLogEx(NORMAL, "Examples:");
|
|
||||||
PrintAndLogEx(NORMAL, _YELLOW_(" auto"));
|
|
||||||
return PM3_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void AppendDate(char *s, size_t slen, const char *fmt) {
|
static void AppendDate(char *s, size_t slen, const char *fmt) {
|
||||||
struct tm *ct, tm_buf;
|
struct tm *ct, tm_buf;
|
||||||
time_t now = time(NULL);
|
time_t now = time(NULL);
|
||||||
|
@ -157,18 +120,31 @@ static int lf_search_plus(const char *Cmd) {
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int CmdAuto(const char *Cmd) {
|
static int CmdAuto(const char *Cmd) {
|
||||||
char ctmp = tolower(param_getchar(Cmd, 0));
|
CLIParserContext *ctx;
|
||||||
if (ctmp == 'h') return usage_auto();
|
CLIParserInit(&ctx, "auto",
|
||||||
|
"Run LF SEARCH / HF SEARCH / DATA PLOT / DATA SAVE",
|
||||||
|
"auto"
|
||||||
|
);
|
||||||
|
|
||||||
|
void *argtable[] = {
|
||||||
|
arg_param_begin,
|
||||||
|
arg_param_end
|
||||||
|
};
|
||||||
|
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||||
|
CLIParserFree(ctx);
|
||||||
|
|
||||||
|
PrintAndLogEx(INFO, "lf search");
|
||||||
int ret = CmdLFfind("");
|
int ret = CmdLFfind("");
|
||||||
if (ret == PM3_SUCCESS)
|
if (ret == PM3_SUCCESS)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
PrintAndLogEx(INFO, "hf search");
|
||||||
ret = CmdHFSearch("");
|
ret = CmdHFSearch("");
|
||||||
if (ret == PM3_SUCCESS)
|
if (ret == PM3_SUCCESS)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
PrintAndLogEx(INFO, "lf search - unknown");
|
||||||
ret = lf_search_plus("");
|
ret = lf_search_plus("");
|
||||||
if (ret == PM3_SUCCESS)
|
if (ret == PM3_SUCCESS)
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -193,26 +169,35 @@ int CmdRem(const char *Cmd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int CmdHints(const char *Cmd) {
|
static int CmdHints(const char *Cmd) {
|
||||||
uint32_t ms = 0;
|
|
||||||
char ctmp = tolower(param_getchar(Cmd, 0));
|
|
||||||
if (ctmp == 'h') return usage_hints();
|
|
||||||
|
|
||||||
if (strlen(Cmd) > 1) {
|
CLIParserContext *ctx;
|
||||||
str_lower((char *)Cmd);
|
CLIParserInit(&ctx, "hints",
|
||||||
if (str_startswith(Cmd, "of")) {
|
"Turn on/off hints",
|
||||||
session.show_hints = false;
|
"hints --on\n"
|
||||||
} else {
|
"hints -1\n"
|
||||||
session.show_hints = true;
|
);
|
||||||
}
|
|
||||||
} else if (strlen(Cmd) == 1) {
|
void *argtable[] = {
|
||||||
if (param_getchar(Cmd, 0) != 0x00) {
|
arg_param_begin,
|
||||||
ms = param_get32ex(Cmd, 0, 0, 10);
|
arg_lit0("1", "on", "turn on hints"),
|
||||||
if (ms == 0) {
|
arg_lit0("0", "off", "turn off hints"),
|
||||||
session.show_hints = false;
|
arg_param_end
|
||||||
} else {
|
};
|
||||||
session.show_hints = true;
|
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||||
}
|
|
||||||
}
|
bool turn_on = arg_get_lit(ctx, 1);
|
||||||
|
bool turn_off = arg_get_lit(ctx, 2);
|
||||||
|
CLIParserFree(ctx);
|
||||||
|
|
||||||
|
if (turn_on && turn_off) {
|
||||||
|
PrintAndLogEx(ERR, "you can't turn off and on at the same time");
|
||||||
|
return PM3_EINVARG;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (turn_off) {
|
||||||
|
session.show_hints = false;
|
||||||
|
} else if (turn_on) {
|
||||||
|
session.show_hints = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
PrintAndLogEx(INFO, "Hints are %s", (session.show_hints) ? "ON" : "OFF");
|
PrintAndLogEx(INFO, "Hints are %s", (session.show_hints) ? "ON" : "OFF");
|
||||||
|
@ -220,14 +205,26 @@ static int CmdHints(const char *Cmd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int CmdMsleep(const char *Cmd) {
|
static int CmdMsleep(const char *Cmd) {
|
||||||
uint32_t ms = 0;
|
CLIParserContext *ctx;
|
||||||
char ctmp = tolower(param_getchar(Cmd, 0));
|
CLIParserInit(&ctx, "msleep",
|
||||||
if (strlen(Cmd) < 1 || ctmp == 'h') return usage_msleep();
|
"Sleep for given amount of milliseconds",
|
||||||
if (param_getchar(Cmd, 0) != 0x00) {
|
"msleep 100"
|
||||||
ms = param_get32ex(Cmd, 0, 0, 10);
|
);
|
||||||
if (ms == 0)
|
|
||||||
return usage_msleep();
|
void *argtable[] = {
|
||||||
|
arg_param_begin,
|
||||||
|
arg_int0("t", "ms", "<ms>", "time in milliseconds"),
|
||||||
|
arg_param_end
|
||||||
|
};
|
||||||
|
CLIExecWithReturn(ctx, Cmd, argtable, false);
|
||||||
|
uint32_t ms = arg_get_u32_def(ctx, 1, 0);
|
||||||
|
CLIParserFree(ctx);
|
||||||
|
|
||||||
|
if (ms == 0) {
|
||||||
|
PrintAndLogEx(ERR, "Specified invalid input. Can't be zero");
|
||||||
|
return PM3_EINVARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
msleep(ms);
|
msleep(ms);
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue