mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2024-09-21 15:56:21 +08:00
lf hitag cc - now uses cliparser
This commit is contained in:
parent
fe25e70e6f
commit
55ccd18afd
|
@ -113,19 +113,6 @@ static int usage_hitag_writer(void) {
|
||||||
PrintAndLogEx(NORMAL, " 27 <password> <page> <byte0...byte3> Write page, password mode. Default: 4D494B52 (\"MIKR\")");
|
PrintAndLogEx(NORMAL, " 27 <password> <page> <byte0...byte3> Write page, password mode. Default: 4D494B52 (\"MIKR\")");
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
static int usage_hitag_checkchallenges(void) {
|
|
||||||
PrintAndLogEx(NORMAL, "Check challenges, load a file with save hitag crypto challenges and test them all.");
|
|
||||||
PrintAndLogEx(NORMAL, "The file should be 8 * 60 bytes long, the file extension defaults to " _YELLOW_("`.cc`"));
|
|
||||||
PrintAndLogEx(NORMAL, "");
|
|
||||||
PrintAndLogEx(NORMAL, "Usage: lf hitag cc [h] f <filename w/o extension>");
|
|
||||||
PrintAndLogEx(NORMAL, "Options:");
|
|
||||||
PrintAndLogEx(NORMAL, " h This help");
|
|
||||||
PrintAndLogEx(NORMAL, " f <filename> Load data from BIN file");
|
|
||||||
PrintAndLogEx(NORMAL, "");
|
|
||||||
PrintAndLogEx(NORMAL, "Examples:");
|
|
||||||
PrintAndLogEx(NORMAL, " lf hitag cc f lf-hitag-challenges");
|
|
||||||
return PM3_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int CmdLFHitagList(const char *Cmd) {
|
static int CmdLFHitagList(const char *Cmd) {
|
||||||
char args[128] = {0};
|
char args[128] = {0};
|
||||||
|
@ -614,50 +601,46 @@ static int CmdLFHitagReader(const char *Cmd) {
|
||||||
|
|
||||||
static int CmdLFHitagCheckChallenges(const char *Cmd) {
|
static int CmdLFHitagCheckChallenges(const char *Cmd) {
|
||||||
|
|
||||||
char filename[FILE_PATH_SIZE] = { 0x00 };
|
CLIParserContext *ctx;
|
||||||
size_t datalen = 0;
|
CLIParserInit(&ctx, "lf hitag cc",
|
||||||
int res = 0;
|
"Check challenges, load a file with saved hitag crypto challenges and test them all.\n"
|
||||||
bool file_given = false;
|
"The file should be 8 * 60 bytes long, the file extension defaults to " _YELLOW_("`.cc`") " ",
|
||||||
bool errors = false;
|
"lf hitag cc -f my_hitag_challenges"
|
||||||
uint8_t cmdp = 0;
|
);
|
||||||
uint8_t *data = calloc(8 * 60, sizeof(uint8_t));
|
|
||||||
|
|
||||||
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
|
void *argtable[] = {
|
||||||
switch (tolower(param_getchar(Cmd, cmdp))) {
|
arg_param_begin,
|
||||||
case 'h':
|
arg_str0("f", "filename", "<fn w/o ext>", "filename to load from"),
|
||||||
free(data);
|
arg_param_end
|
||||||
return usage_hitag_checkchallenges();
|
};
|
||||||
case 'f':
|
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||||
//file with all the challenges to try
|
|
||||||
param_getstr(Cmd, cmdp + 1, filename, sizeof(filename));
|
|
||||||
res = loadFile(filename, ".cc", data, 8 * 60, &datalen);
|
|
||||||
if (res > 0) {
|
|
||||||
errors = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
file_given = true;
|
|
||||||
cmdp += 2;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp));
|
|
||||||
errors = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Validations
|
int fnlen = 0;
|
||||||
if (errors || strlen(Cmd) == 0) {
|
char filename[FILE_PATH_SIZE] = {0};
|
||||||
free(data);
|
CLIParamStrToBuf(arg_get_str(ctx, 1), (uint8_t *)filename, FILE_PATH_SIZE, &fnlen);
|
||||||
return usage_hitag_checkchallenges();
|
|
||||||
}
|
CLIParserFree(ctx);
|
||||||
|
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
if (file_given)
|
|
||||||
SendCommandOLD(CMD_LF_HITAGS_TEST_TRACES, 1, 0, 0, data, datalen);
|
|
||||||
else
|
|
||||||
SendCommandMIX(CMD_LF_HITAGS_TEST_TRACES, 0, 0, 0, NULL, 0);
|
|
||||||
|
|
||||||
free(data);
|
if (fnlen > 0) {
|
||||||
|
uint8_t *data = NULL;
|
||||||
|
size_t datalen = 0;
|
||||||
|
int res = loadFile_safe(filename, ".cc", (void **)&data, &datalen);
|
||||||
|
if (res == PM3_SUCCESS) {
|
||||||
|
if (datalen == (8 * 60) ) {
|
||||||
|
SendCommandOLD(CMD_LF_HITAGS_TEST_TRACES, 1, 0, 0, data, datalen);
|
||||||
|
} else {
|
||||||
|
PrintAndLogEx(ERR, "Error, file length mismatch. Expected %d, got %d", 8*60, datalen);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (data) {
|
||||||
|
free(data);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
SendCommandMIX(CMD_LF_HITAGS_TEST_TRACES, 0, 0, 0, NULL, 0);
|
||||||
|
}
|
||||||
|
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue