From e7242049782f4a5d03868b9d40c4418c1ce165c1 Mon Sep 17 00:00:00 2001 From: mwalker33 Date: Wed, 30 Sep 2020 16:39:08 +1000 Subject: [PATCH] cliparser cleanup 2 cmdhf14a.c, cmdhfido.c, cmdhficlass.c, cmdhfmf.c menu help updates. cliparser.c : tweak for readability with long examples. --- client/deps/cliparser/cliparser.c | 13 +++++-- client/src/cmdhf14a.c | 38 +++++++++--------- client/src/cmdhffido.c | 62 ++++++++++++++--------------- client/src/cmdhficlass.c | 5 +-- client/src/cmdhfmf.c | 65 ++++++++++++++----------------- 5 files changed, 91 insertions(+), 92 deletions(-) diff --git a/client/deps/cliparser/cliparser.c b/client/deps/cliparser/cliparser.c index 095d93c96..077e5038f 100644 --- a/client/deps/cliparser/cliparser.c +++ b/client/deps/cliparser/cliparser.c @@ -83,16 +83,23 @@ int CLIParserParseArg(CLIParserContext *ctx, int argc, char **argv, void *vargta buf = realloc (buf,strlen (ctx->programHelp)+1); // more then enough as we are splitting char *p2; // pointer to split example from comment. - for (int i = 0; i < strlen (ctx->programHelp); i++) { + int egWidth = 30; + for (int i = 0; i <= strlen (ctx->programHelp); i++) { // <= so to get string terminator. buf[idx++] = ctx->programHelp[i]; if ((ctx->programHelp[i] == '\n') || (ctx->programHelp[i] == 0x00)) { buf[idx-1] = 0x00; p2 = strstr(buf,"->"); // See if the example has a comment. if (p2 != NULL) { *(p2-1) = 0x00; - PrintAndLogEx(NORMAL," "_ExampleColor_("%-50s")" %s",buf,p2); + + if (strlen(buf) > 28) + egWidth = strlen(buf) + 5; + else + egWidth = 30; + + PrintAndLogEx(NORMAL," "_ExampleColor_("%-*s")" %s", egWidth, buf, p2); } else { - PrintAndLogEx(NORMAL," "_ExampleColor_("%-50s"),buf); + PrintAndLogEx(NORMAL," "_ExampleColor_("%-*s"), egWidth, buf); } idx = 0; } diff --git a/client/src/cmdhf14a.c b/client/src/cmdhf14a.c index aa8a29255..2e222eec1 100644 --- a/client/src/cmdhf14a.c +++ b/client/src/cmdhf14a.c @@ -563,13 +563,13 @@ static int CmdHF14AInfo(const char *Cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "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"); + "hf 14a info -nsv -> shows full information about the card\n"); void *argtable[] = { arg_param_begin, - arg_lit0("vV", "verbose", "adds some information to results"), - arg_lit0("nN", "nacktest", "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_lit0("v", "verbose", "adds some information to results"), + arg_lit0("n", "nacktest", "test for nack bug"), + arg_lit0("s", "aidsearch", "checks if AIDs from aidlist.json is present on the card and prints information about found AIDs"), arg_param_end }; CLIExecWithReturn(ctx, Cmd, argtable, true); @@ -1080,20 +1080,20 @@ static int CmdHF14AAPDU(const char *Cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "hf 14a apdu", "Sends an ISO 7816-4 APDU via ISO 14443-4 block transmission protocol (T=CL). works with all apdu types from ISO 7816-4:2013", - "Sample:\n\thf 14a apdu -st 00A404000E325041592E5359532E444446303100\n" - "\thf 14a apdu -sd 00A404000E325041592E5359532E444446303100 - decode apdu\n" - "\thf 14a apdu -sm 00A40400 325041592E5359532E4444463031 -l 256 - encode standard apdu\n" - "\thf 14a apdu -sm 00A40400 325041592E5359532E4444463031 -el 65536 - encode extended apdu\n"); + "hf 14a apdu -st 00A404000E325041592E5359532E444446303100\n" + "hf 14a apdu -sd 00A404000E325041592E5359532E444446303100 -> decode apdu\n" + "hf 14a apdu -sm 00A40400 325041592E5359532E4444463031 -l 256 -> encode standard apdu\n" + "hf 14a apdu -sm 00A40400 325041592E5359532E4444463031 -el 65536 -> encode extended apdu\n"); void *argtable[] = { arg_param_begin, - arg_lit0("sS", "select", "activate field and select card"), - arg_lit0("kK", "keep", "leave the signal field ON after receive response"), - arg_lit0("tT", "tlv", "executes TLV decoder if it possible"), - arg_lit0("dD", "decapdu", "decode apdu request if it possible"), - arg_str0("mM", "make", "", "make apdu with head from this field and data from data field. Must be 4 bytes length: "), - arg_lit0("eE", "extended", "make extended length apdu if `m` parameter included"), - arg_int0("lL", "le", "", "Le apdu parameter if `m` parameter included"), + arg_lit0("s", "select", "activate field and select card"), + arg_lit0("k", "keep", "leave the signal field ON after receive response"), + arg_lit0("t", "tlv", "executes TLV decoder if it possible"), + arg_lit0("d", "decapdu", "decode apdu request if it possible"), + arg_str0("m", "make", "", "make apdu with head from this field and data from data field. Must be 4 bytes length: "), + arg_lit0("e", "extended", "make extended length apdu if `m` parameter included"), + arg_int0("l", "le", "", "Le apdu parameter if `m` parameter included"), arg_strx1(NULL, NULL, "", "data if `m` parameter included"), arg_param_end }; @@ -1369,8 +1369,7 @@ static int CmdHF14AAntiFuzz(const char *Cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "hf 14a antifuzz", "Tries to fuzz the ISO14443a anticollision phase", - "Usage:\n" - "\thf 14a antifuzz -4\n"); + "hf 14a antifuzz -4\n"); void *argtable[] = { arg_param_begin, @@ -1398,9 +1397,8 @@ static int CmdHF14AChaining(const char *Cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "hf 14a chaining", "Enable/Disable ISO14443a input chaining. Maximum input length goes from ATS.", - "Usage:\n" - "\thf 14a chaining disable -> disable chaining\n" - "\thf 14a chaining -> show chaining enable/disable state\n"); + "hf 14a chaining disable -> disable chaining\n" + "hf 14a chaining -> show chaining enable/disable state\n"); void *argtable[] = { arg_param_begin, diff --git a/client/src/cmdhffido.c b/client/src/cmdhffido.c index 50c1495c8..ee2da7bfa 100644 --- a/client/src/cmdhffido.c +++ b/client/src/cmdhffido.c @@ -160,17 +160,17 @@ static int CmdHFFidoRegister(const char *cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "hf fido reg", "Initiate a U2F token registration. Needs two 32-byte hash numbers. \nchallenge parameter (32b) and application parameter (32b).", - "Usage:\n\thf fido reg -> execute command with 2 parameters, filled 0x00\n" - "\thf fido reg 000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f 000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f -> execute command with parameters" - "\thf fido reg -p s0 s1 -> execute command with plain parameters"); + "hf fido reg -> execute command with 2 parameters, filled 0x00\n" + "hf fido reg 000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f 000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f -> execute command with parameters\n" + "hf fido reg -p s0 s1 -> execute command with plain parameters"); void *argtable[] = { arg_param_begin, - arg_lit0("aA", "apdu", "show APDU requests and responses"), - arg_litn("vV", "verbose", 0, 2, "show technical data. vv - show full certificates data"), - arg_lit0("pP", "plain", "send plain ASCII to challenge and application parameters instead of HEX"), - arg_lit0("tT", "tlv", "Show DER certificate contents in TLV representation"), - arg_str0("jJ", "json", "fido.json", "JSON input / output file name for parameters."), + arg_lit0("a", "apdu", "show APDU requests and responses"), + arg_litn("v", "verbose", 0, 2, "show technical data. vv - show full certificates data"), + arg_lit0("p", "plain", "send plain ASCII to challenge and application parameters instead of HEX"), + arg_lit0("t", "tlv", "Show DER certificate contents in TLV representation"), + arg_str0("j", "json", "fido.json", "JSON input / output file name for parameters."), arg_str0(NULL, NULL, "", NULL), arg_str0(NULL, NULL, "", NULL), arg_param_end @@ -397,20 +397,20 @@ static int CmdHFFidoAuthenticate(const char *cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "hf fido auth", "Initiate a U2F token authentication. Needs key handle and two 32-byte hash numbers. \nkey handle(var 0..255), challenge parameter (32b) and application parameter (32b).", - "Usage:\n\thf fido auth 000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f -> execute command with 2 parameters, filled 0x00 and key handle\n" - "\thf fido auth 000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f " + "hf fido auth 000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f -> execute command with 2 parameters, filled 0x00 and key handle\n" + "hf fido auth 000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f " "000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f 000102030405060708090a0b0c0d0e0f000102030405060708090a0b0c0d0e0f -> execute command with parameters"); void *argtable[] = { arg_param_begin, - arg_lit0("aA", "apdu", "show APDU reqests and responses"), - arg_lit0("vV", "verbose", "show technical data"), - arg_lit0("pP", "plain", "send plain ASCII to challenge and application parameters instead of HEX"), + arg_lit0("a", "apdu", "show APDU reqests and responses"), + arg_lit0("v", "verbose", "show technical data"), + arg_lit0("p", "plain", "send plain ASCII to challenge and application parameters instead of HEX"), arg_rem("default mode:", "dont-enforce-user-presence-and-sign"), - arg_lit0("uU", "user", "mode: enforce-user-presence-and-sign"), - arg_lit0("cC", "check", "mode: check-only"), - arg_str0("jJ", "json", "fido.json", "JSON input / output file name for parameters."), - arg_str0("kK", "key", "public key to verify signature", NULL), + arg_lit0("u", "user", "mode: enforce-user-presence-and-sign"), + arg_lit0("c", "check", "mode: check-only"), + arg_str0("j", "json", "fido.json", "JSON input / output file name for parameters."), + arg_str0("k", "key", "public key to verify signature", NULL), arg_str0(NULL, NULL, "", NULL), arg_str0(NULL, NULL, "", NULL), arg_str0(NULL, NULL, "", NULL), @@ -658,16 +658,16 @@ static int CmdHFFido2MakeCredential(const char *cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "hf fido make", - "Execute a FIDO2 Make Credential command. Needs json file with parameters. Sample file " _YELLOW_("`fido2.json`") " in `resources/`.", - "Usage:\n\thf fido make -> execute command with default parameters file `fido2.json`\n" - "\thf fido make test.json -> execute command with parameters file `text.json`"); + "Execute a FIDO2 Make Credential command. Needs json file with parameters. Sample file `fido2.json` in `resources/`.", + "hf fido make -> execute command with default parameters file `fido2.json`\n" + "hf fido make test.json -> execute command with parameters file `text.json`"); void *argtable[] = { arg_param_begin, - arg_lit0("aA", "apdu", "show APDU reqests and responses"), - arg_litn("vV", "verbose", 0, 2, "show technical data. vv - show full certificates data"), - arg_lit0("tT", "tlv", "Show DER certificate contents in TLV representation"), - arg_lit0("cC", "cbor", "show CBOR decoded data"), + arg_lit0("a", "apdu", "show APDU reqests and responses"), + arg_litn("v", "verbose", 0, 2, "show technical data. vv - show full certificates data"), + arg_lit0("t", "tlv", "Show DER certificate contents in TLV representation"), + arg_lit0("c", "cbor", "show CBOR decoded data"), arg_str0(NULL, NULL, "", "JSON input / output file name for parameters. Default `fido2.json`"), arg_param_end }; @@ -783,16 +783,16 @@ static int CmdHFFido2GetAssertion(const char *cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "hf fido assert", - "Execute a FIDO2 Get Assertion command. Needs json file with parameters. Sample file " _YELLOW_("`fido2.json`") " in `resources/`.", - "Usage:\n\thf fido assert -> execute command with default parameters file `fido2.json`\n" - "\thf fido assert test.json -l -> execute command with parameters file `text.json` and add to request CredentialId"); + "Execute a FIDO2 Get Assertion command. Needs json file with parameters. Sample file `fido2.json` in `resources/`.", + "hf fido assert -> execute command with default parameters file `fido2.json`\n" + "hf fido assert test.json -l -> execute command with parameters file `text.json` and add to request CredentialId"); void *argtable[] = { arg_param_begin, - arg_lit0("aA", "apdu", "show APDU reqests and responses"), - arg_litn("vV", "verbose", 0, 2, "show technical data. vv - show full certificates data"), - arg_lit0("cC", "cbor", "show CBOR decoded data"), - arg_lit0("lL", "list", "add CredentialId from json to allowList. Needs if `rk` option is `false` (authenticator doesn't store credential to its memory)"), + arg_lit0("a", "apdu", "show APDU reqests and responses"), + arg_litn("v", "verbose", 0, 2, "show technical data. vv - show full certificates data"), + arg_lit0("c", "cbor", "show CBOR decoded data"), + arg_lit0("l", "list", "add CredentialId from json to allowList. Needs if `rk` option is `false` (authenticator doesn't store credential to its memory)"), arg_str0(NULL, NULL, "", "JSON input / output file name for parameters. Default `fido2.json`"), arg_param_end }; diff --git a/client/src/cmdhficlass.c b/client/src/cmdhficlass.c index 28b74f422..8dfe7720a 100644 --- a/client/src/cmdhficlass.c +++ b/client/src/cmdhficlass.c @@ -641,9 +641,8 @@ static int CmdHFiClassSniff(const char *Cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "hf iclass sniff", "Sniff the communication reader and tag", - "Usage:\n" - _YELLOW_("\thf iclass sniff") "\n" - _YELLOW_("\thf iclass sniff -j") " -> jam e-purse updates\n" + "hf iclass sniff\n" + "hf iclass sniff -j -> jam e-purse updates\n" ); void *argtable[] = { diff --git a/client/src/cmdhfmf.c b/client/src/cmdhfmf.c index df9d07c54..4b822c148 100644 --- a/client/src/cmdhfmf.c +++ b/client/src/cmdhfmf.c @@ -4120,15 +4120,14 @@ static int CmdHF14AMfCWipe(const char *cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "hf mf cwipe", "Wipe gen1 magic chinese card. Set UID/ATQA/SAK/Data/Keys/Access to default values.", - "Usage:\n" - _YELLOW_("\thf mf cwipe") " -> wipe card\n" - _YELLOW_("\thf mf cwipe -u 09080706 -a 0004 -s 18") " -- set UID, ATQA and SAK and wipe card"); + "hf mf cwipe -> wipe card\n" + "hf mf cwipe -u 09080706 -a 0004 -s 18 -> set UID, ATQA and SAK and wipe card"); void *argtable[] = { arg_param_begin, - arg_str0("uU", "uid", "", "UID for card"), - arg_str0("aA", "atqa", "", "ATQA for card"), - arg_str0("sS", "sak", "", "SAK for card"), + arg_str0("u", "uid", "", "UID for card"), + arg_str0("a", "atqa", "", "ATQA for card"), + arg_str0("s", "sak", "", "SAK for card"), arg_param_end }; CLIExecWithReturn(ctx, cmd, argtable, true); @@ -4799,9 +4798,8 @@ static int CmdHF14AMfAuth4(const char *Cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "hf mf auth4", "Executes AES authentication command in ISO14443-4", - "Usage:\n" - _YELLOW_("\thf mf auth4 4000 000102030405060708090a0b0c0d0e0f") " -> executes authentication\n" - _YELLOW_("\thf mf auth4 9003 FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF") " -> executes authentication\n"); + "hf mf auth4 4000 000102030405060708090a0b0c0d0e0f -> executes authentication\n" + "hf mf auth4 9003 FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF -> executes authentication\n"); void *argtable[] = { arg_param_begin, @@ -4834,19 +4832,18 @@ static int CmdHF14AMfMAD(const char *Cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "hf mf mad", "Checks and prints MIFARE Application Directory (MAD)", - "Usage:\n" - _YELLOW_("\thf mf mad") " -> shows MAD if exists\n" - _YELLOW_("\thf mf mad --aid e103 -k ffffffffffff -b") " -> shows NDEF data if exists. read card with custom key and key B\n" - _YELLOW_("\thf mf mad --dch -k ffffffffffff") " -> decode CardHolder information\n"); + "hf mf mad -> shows MAD if exists\n" + "hf mf mad --aid e103 -k ffffffffffff -b -> shows NDEF data if exists. read card with custom key and key B\n" + "hf mf mad --dch -k ffffffffffff -> decode CardHolder information\n"); void *argtable[] = { arg_param_begin, - arg_lit0("vV", "verbose", "show technical data"), - arg_str0("", "aid", "", "print all sectors with specified aid"), - arg_str0("kK", "key", "", "key for printing sectors"), - arg_lit0("bB", "keyb", "use key B for access printing sectors (by default: key A)"), - arg_lit0("", "be", "(optional, BigEndian)"), - arg_lit0("", "dch", "decode Card Holder information"), + arg_lit0("v", "verbose", "show technical data"), + arg_str0(NULL, "aid", "", "print all sectors with specified aid"), + arg_str0("k", "key", "", "key for printing sectors"), + arg_lit0("b", "keyb", "use key B for access printing sectors (by default: key A)"), + arg_lit0(NULL, "be", "(optional, BigEndian)"), + arg_lit0(NULL, "dch", "decode Card Holder information"), arg_param_end }; CLIExecWithReturn(ctx, Cmd, argtable, true); @@ -4976,17 +4973,16 @@ static int CmdHFMFNDEF(const char *Cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "hf mf ndef", "Prints NFC Data Exchange Format (NDEF)", - "Usage:\n" - _YELLOW_("\thf mf ndef") " -> shows NDEF parsed data\n" - _YELLOW_("\thf mf ndef -vv") " -> shows NDEF parsed and raw data\n" - _YELLOW_("\thf mf ndef --aid e103 -k ffffffffffff -b") " -> shows NDEF data with custom AID, key and with key B\n"); + "hf mf ndef -> shows NDEF parsed data\n" + "hf mf ndef -vv -> shows NDEF parsed and raw data\n" + "hf mf ndef --aid e103 -k ffffffffffff -b -> shows NDEF data with custom AID, key and with key B\n"); void *argtable[] = { arg_param_begin, - arg_litn("vV", "verbose", 0, 2, "show technical data"), - arg_str0("", "aid", "", "replace default aid for NDEF"), - arg_str0("kK", "key", "", "replace default key for NDEF"), - arg_lit0("bB", "keyb", "use key B for access sectors (by default: key A)"), + arg_litn("v", "verbose", 0, 2, "show technical data"), + arg_str0(NULL, "aid", "", "replace default aid for NDEF"), + arg_str0("k", "key", "", "replace default key for NDEF"), + arg_lit0("b", "keyb", "use key B for access sectors (by default: key A)"), arg_param_end }; CLIExecWithReturn(ctx, Cmd, argtable, true); @@ -5092,17 +5088,16 @@ static int CmdHFMFPersonalize(const char *cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "hf mf personalize", "Personalize the UID of a MIFARE Classic EV1 card. This is only possible if it is a 7Byte UID card and if it is not already personalized.", - "Usage:\n" - _YELLOW_("\thf mf personalize UIDF0") " -> double size UID according to ISO/IEC14443-3\n" - _YELLOW_("\thf mf personalize UIDF1") " -> double size UID according to ISO/IEC14443-3, optional usage of selection process shortcut\n" - _YELLOW_("\thf mf personalize UIDF2") " -> single size random ID according to ISO/IEC14443-3\n" - _YELLOW_("\thf mf personalize UIDF3") " -> single size NUID according to ISO/IEC14443-3\n" - _YELLOW_("\thf mf personalize -t B -k B0B1B2B3B4B5 UIDF3") " -> use key B = 0xB0B1B2B3B4B5 instead of default key A\n"); + "hf mf personalize UIDF0 -> double size UID according to ISO/IEC14443-3\n" + "hf mf personalize UIDF1 -> double size UID according to ISO/IEC14443-3, optional usage of selection process shortcut\n" + "hf mf personalize UIDF2 -> single size random ID according to ISO/IEC14443-3\n" + "hf mf personalize UIDF3 -> single size NUID according to ISO/IEC14443-3\n" + "hf mf personalize -t B -k B0B1B2B3B4B5 UIDF3 -> use key B = 0xB0B1B2B3B4B5 instead of default key A"); void *argtable[] = { arg_param_begin, - arg_str0("tT", "keytype", "", "key type (A or B) to authenticate sector 0 (default: A)"), - arg_str0("kK", "key", "", "key to authenticate sector 0 (default: FFFFFFFFFFFF)"), + arg_str0("t", "keytype", "", "key type (A or B) to authenticate sector 0 (default: A)"), + arg_str0("k", "key", "", "key to authenticate sector 0 (default: FFFFFFFFFFFF)"), arg_str1(NULL, NULL, "", "Personalization Option"), arg_param_end };