From 3098de7901da62f47792d64ce91950422580338a Mon Sep 17 00:00:00 2001 From: mwalker33 <51802811+mwalker33@users.noreply.github.com> Date: Sun, 8 May 2022 12:09:43 +1000 Subject: [PATCH] Update cmdhfmfdes.c Add the ability to use hex for the DFName to support non printable dfname values (e.g. as needed to NDEF AIDs) --- client/src/cmdhfmfdes.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/client/src/cmdhfmfdes.c b/client/src/cmdhfmfdes.c index cdbb163c9..97cc7e6ac 100644 --- a/client/src/cmdhfmfdes.c +++ b/client/src/cmdhfmfdes.c @@ -2415,6 +2415,7 @@ static int CmdHF14ADesCreateApp(const char *Cmd) { arg_str0(NULL, "aid", "", "Application ID for create. Mandatory. (3 hex bytes, big endian)"), arg_str0(NULL, "fid", "", "ISO file ID. Forbidden values: 0000 3F00, 3FFF, FFFF. (2 hex bytes, big endian)"), arg_str0(NULL, "dfname", "", "ISO DF Name (1..16 chars)"), + arg_str0(NULL, "dfhex", "", "ISO DF Name as hex (1..16 bytes)"), arg_str0(NULL, "ks1", "", "Key settings 1 (1 hex byte). Application Master Key Settings (def: 0x0F)"), arg_str0(NULL, "ks2", "", "Key settings 2 (1 hex byte). (def: 0x0E)"), arg_str0(NULL, "dstalgo", "", "Application key crypt algo (def: DES)"), @@ -2451,27 +2452,33 @@ static int CmdHF14ADesCreateApp(const char *Cmd) { int dfnamelen = 16; CLIGetStrWithReturn(ctx, 14, dfname, &dfnamelen); + if (dfnamelen == 0) // no text DF Name supplied + { + dfnamelen = 16; + CLIGetHexWithReturn(ctx, 15, dfname, &dfnamelen); + } + uint32_t ks1 = 0x0f; - if (CLIGetUint32Hex(ctx, 15, 0x0f, &ks1, NULL, 1, "Key settings 1 must have 1 byte length")) { + if (CLIGetUint32Hex(ctx, 16, 0x0f, &ks1, NULL, 1, "Key settings 1 must have 1 byte length")) { CLIParserFree(ctx); return PM3_EINVARG; } uint32_t ks2 = 0x0e; bool ks2present = false; - if (CLIGetUint32Hex(ctx, 16, 0x0e, &ks2, &ks2present, 1, "Key settings 2 must have 1 byte length")) { + if (CLIGetUint32Hex(ctx, 17, 0x0e, &ks2, &ks2present, 1, "Key settings 2 must have 1 byte length")) { CLIParserFree(ctx); return PM3_EINVARG; } int dstalgo = T_DES; - if (CLIGetOptionList(arg_get_str(ctx, 17), DesfireAlgoOpts, &dstalgo)) { + if (CLIGetOptionList(arg_get_str(ctx, 18), DesfireAlgoOpts, &dstalgo)) { CLIParserFree(ctx); return PM3_ESOFT; } - int keycount = arg_get_int_def(ctx, 18, 0x0e); - bool noauth = arg_get_lit(ctx, 19); + int keycount = arg_get_int_def(ctx, 19, 0x0e); + bool noauth = arg_get_lit(ctx, 20); SetAPDULogging(APDULogging); CLIParserFree(ctx); @@ -2540,7 +2547,7 @@ static int CmdHF14ADesCreateApp(const char *Cmd) { PrintAndLogEx(INFO, "ISO file ID %s", (data[4] & 0x20) ? "enabled" : "disabled"); if ((data[4] & 0x20)) { PrintAndLogEx(INFO, "ISO file ID 0x%04x", MemLeToUint2byte(&data[5])); - PrintAndLogEx(INFO, "DF Name[%02zu] %s\n", strnlen((char *)&data[7], 16), (char *)&data[7]); + PrintAndLogEx(INFO, "DF Name[%02zu] %s | %s\n", dfnamelen, sprint_ascii(dfname, dfnamelen), sprint_hex (dfname, dfnamelen)); } PrintKeySettings(data[3], data[4], true, true); PrintAndLogEx(INFO, "---------------------------");