hf 14a info: added verbose, command optimization, move it to cliparser

This commit is contained in:
merlokk 2019-11-05 00:06:51 +02:00
commit 8befad6d34
3 changed files with 42 additions and 28 deletions

View file

@ -16,7 +16,7 @@
#include "pm3_cmd.h"
int openAIDFile(json_t **root) {
int openAIDFile(json_t **root, bool verbose) {
json_error_t error;
char *path;
@ -39,7 +39,7 @@ int openAIDFile(json_t **root) {
goto out;
}
PrintAndLogEx(SUCCESS, "Loaded file (%s) OK. %d records.", path, json_array_size(*root));
if (verbose) PrintAndLogEx(SUCCESS, "Loaded file (%s) OK. %d records.", path, json_array_size(*root));
out:
free(path);
return retval;
@ -51,9 +51,9 @@ int closeAIDFile(json_t *root) {
return PM3_SUCCESS;
}
json_t *AIDSearchInit() {
json_t *AIDSearchInit(bool verbose) {
json_t *root = NULL;
int res = openAIDFile(&root);
int res = openAIDFile(&root, verbose);
if (res != PM3_SUCCESS)
return NULL;
@ -115,10 +115,12 @@ bool AIDGetFromElm(json_t *data, uint8_t *aid, size_t aidmaxlen, int *aidlen) {
return true;
}
int PrintAIDDescription(char *aid, bool verbose) {
int PrintAIDDescription(json_t *xroot, char *aid, bool verbose) {
int retval = PM3_SUCCESS;
json_t *root = AIDSearchInit();
json_t *root = xroot;
if (root == NULL)
root = AIDSearchInit(verbose);
if (root == NULL)
goto out;
@ -167,11 +169,12 @@ int PrintAIDDescription(char *aid, bool verbose) {
}
out:
AIDSearchFree(root);
if (xroot == NULL)
AIDSearchFree(root);
return retval;
}
int PrintAIDDescriptionBuf(uint8_t *aid, size_t aidlen, bool verbose) {
return PrintAIDDescription(sprint_hex_inrow(aid, aidlen), verbose);
int PrintAIDDescriptionBuf(json_t *root, uint8_t *aid, size_t aidlen, bool verbose) {
return PrintAIDDescription(root, sprint_hex_inrow(aid, aidlen), verbose);
}

View file

@ -18,9 +18,9 @@
#include <jansson.h>
int PrintAIDDescription(char *aid, bool verbose);
int PrintAIDDescriptionBuf(uint8_t *aid, size_t aidlen, bool verbose);
json_t *AIDSearchInit();
int PrintAIDDescription(json_t *root, char *aid, bool verbose);
int PrintAIDDescriptionBuf(json_t *root, uint8_t *aid, size_t aidlen, bool verbose);
json_t *AIDSearchInit(bool verbose);
json_t *AIDSearchGetElm(json_t *root, int elmindx);
bool AIDGetFromElm(json_t *data, uint8_t *aid, size_t aidmaxlen, int *aidlen);
int AIDSearchFree();

View file

@ -227,13 +227,6 @@ static int usage_hf_14a_reader(void) {
PrintAndLogEx(NORMAL, " 3 ISO14443-3 select only (skip RATS)");
return 0;
}
static int usage_hf_14a_info(void) {
PrintAndLogEx(NORMAL, "This command makes more extensive tests against a ISO14443a tag in order to collect information");
PrintAndLogEx(NORMAL, "Usage: hf 14a info [h|s]");
PrintAndLogEx(NORMAL, " s silent (no messages)");
PrintAndLogEx(NORMAL, " n test for nack bug");
return 0;
}
static int CmdHF14AList(const char *Cmd) {
(void)Cmd; // Cmd is not used so far
@ -368,12 +361,30 @@ static int CmdHF14AReader(const char *Cmd) {
}
static int CmdHF14AInfo(const char *Cmd) {
bool verbose = false;
bool do_nack_test = false;
bool do_aid_search = false;
if (Cmd[0] == 'h' || Cmd[0] == 'H') return usage_hf_14a_info();
CLIParserInit("hf 14a info",
"This command makes more extensive tests against a ISO14443a tag in order to collect information",
"Sample:\n\thf 14a info -nsv - shows full information about the card\n");
bool verbose = !(Cmd[0] == 's' || Cmd[0] == 'S');
bool do_nack_test = (Cmd[0] == 'n' || Cmd[0] == 'N');
infoHF14A(verbose, do_nack_test, true);
void *argtable[] = {
arg_param_begin,
arg_lit0("vV", "verbose", "adds some information to results"),
arg_lit0("nN", "naktest", "test for nack bug"),
arg_lit0("sS", "aidsearch", "checks if AIDs from aidlist.json is present on the card and prints information about found AIDs"),
arg_param_end
};
CLIExecWithReturn(Cmd, argtable, true);
verbose = arg_get_lit(1);
do_nack_test = arg_get_lit(2);
do_aid_search = arg_get_lit(3);
CLIParserFree();
infoHF14A(verbose, do_nack_test, do_aid_search);
return 0;
}
@ -1497,7 +1508,7 @@ int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) {
if (do_aid_search) {
int elmindx = 0;
json_t *root = AIDSearchInit();
json_t *root = AIDSearchInit(verbose);
if (root != NULL) {
bool ActivateField = true;
for (elmindx = 0; elmindx < json_array_size(root); elmindx++) {
@ -1516,14 +1527,14 @@ int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) {
continue;
if (sw == 0x9000) {
PrintAndLogEx(NORMAL, "------------- Application OK -----------");
if (verbose) PrintAndLogEx(NORMAL, "------------- Application OK -----------");
PrintAndLogEx(NORMAL, "res: %s", sprint_hex(result, resultlen));
PrintAIDDescriptionBuf(vaid, vaidlen, true);
PrintAIDDescriptionBuf(root, vaid, vaidlen, verbose);
}
if (sw == 0x6283 || sw == 0x6285) {
PrintAndLogEx(NORMAL, "----------- Application blocked --------");
PrintAIDDescriptionBuf(vaid, vaidlen, true);
if (verbose) PrintAndLogEx(NORMAL, "----------- Application blocked --------");
PrintAIDDescriptionBuf(root, vaid, vaidlen, verbose);
}
}