From 91eb6345a9dcd9cb4863725f7550e2ee2fa3a29f Mon Sep 17 00:00:00 2001 From: suut Date: Mon, 11 May 2026 11:01:09 +0200 Subject: [PATCH] Uniformize code style --- client/src/cmdhfmfdes.c | 79 +++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 43 deletions(-) diff --git a/client/src/cmdhfmfdes.c b/client/src/cmdhfmfdes.c index 1249a40c9..23fa283e4 100644 --- a/client/src/cmdhfmfdes.c +++ b/client/src/cmdhfmfdes.c @@ -6711,27 +6711,27 @@ static int CmdHF14ADesCreateMFCMapping(const char *Cmd) { void *argtable[] = { arg_param_begin, - /* 1 */ arg_lit0("a", "apdu", "Show APDU requests and responses"), - /* 2 */ arg_lit0("v", "verbose", "Verbose output"), - /* 3 */ arg_int0("n", "keyno", "", "Key number"), - /* 4 */ arg_str0("t", "algo", "", "Crypt algo"), - /* 5 */ arg_str0("k", "key", "", "Key for authenticate (HEX 8(DES), 16(2TDEA or AES) or 24(3TDEA) bytes)"), - /* 6 */ arg_str0(NULL, "kdf", "", "Key Derivation Function (KDF)"), - /* 7 */ arg_str0("i", "kdfi", "", "KDF input (1-31 hex bytes)"), - /* 8 */ arg_str0("m", "cmode", "", "Communicaton mode"), - /* 9 */ arg_str0("c", "ccset", "", "Communicaton command set"), - /* 10 */ arg_str0(NULL, "schann", "", "Secure channel"), - /* 11 */ arg_str0(NULL, "aid", "", "Application ID (3 hex bytes, big endian)"), - /* 12 */ arg_str0(NULL, "isoid", "", "Application ISO ID (ISO DF ID) (2 hex bytes, big endian)"), - /* 13 */ arg_str0(NULL, "fid", "", "File ID to map (1 hex byte)"), - /* 14 */ arg_str0(NULL, "restore-fid", "", "Restore source when mapping value files to value blocks (1 hex byte)"), - /* 15 */ arg_str0("b", "blk", "[,[,...]]", "The MFC blocks to map, must be unique (use value 'data' for all data blocks, and 'trailer' for all trailer blocks)"), - /* 16 */ arg_str0(NULL, "mfc-license", "", "The MFC license (omit to use saved license and license MAC)"), - /* 17 */ arg_str0(NULL, "mfc-license-mac", "", "The MFC license MAC (omit to use saved license and license MAC)"), - /* 18 */ arg_lit0(NULL, "key-a", "Allow updating key A from inside sector trailers mapped to DESFire files"), - /* 19 */ arg_lit0(NULL, "key-b", "Allow updating key B from inside sector trailers mapped to DESFire files"), - /* 20 */ arg_lit0(NULL, "access-conditions", "Allow updating the access conditions from inside sector trailers mapped to DESFire files"), - /* 21 */ arg_lit0(NULL, "restore-transfer", "Enable the RestoreTransfer command for the mapped value blocks"), + arg_lit0("a", "apdu", "Show APDU requests and responses"), + arg_lit0("v", "verbose", "Verbose output"), + arg_int0("n", "keyno", "", "Key number"), + arg_str0("t", "algo", "", "Crypt algo"), + arg_str0("k", "key", "", "Key for authenticate (HEX 8(DES), 16(2TDEA or AES) or 24(3TDEA) bytes)"), + arg_str0(NULL, "kdf", "", "Key Derivation Function (KDF)"), + arg_str0("i", "kdfi", "", "KDF input (1-31 hex bytes)"), + arg_str0("m", "cmode", "", "Communicaton mode"), + arg_str0("c", "ccset", "", "Communicaton command set"), + arg_str0(NULL, "schann", "", "Secure channel"), + arg_str0(NULL, "aid", "", "Application ID (3 hex bytes, big endian)"), + arg_str0(NULL, "isoid", "", "Application ISO ID (ISO DF ID) (2 hex bytes, big endian)"), + arg_str0(NULL, "fid", "", "File ID to map (1 hex byte)"), + arg_str0(NULL, "restore-fid", "", "Restore source when mapping value files to value blocks (1 hex byte)"), + arg_str0("b", "blk", "[,[,...]]", "The MFC blocks to map, must be unique (use value 'data' for all data blocks, and 'trailer' for all trailer blocks)"), + arg_str0(NULL, "mfc-license", "", "The MFC license (omit to use saved license and license MAC)"), + arg_str0(NULL, "mfc-license-mac", "", "The MFC license MAC (omit to use saved license and license MAC)"), + arg_lit0(NULL, "key-a", "Allow updating key A from inside sector trailers mapped to DESFire files"), + arg_lit0(NULL, "key-b", "Allow updating key B from inside sector trailers mapped to DESFire files"), + arg_lit0(NULL, "access-conditions", "Allow updating the access conditions from inside sector trailers mapped to DESFire files"), + arg_lit0(NULL, "restore-transfer", "Enable the RestoreTransfer command for the mapped value blocks"), arg_param_end }; CLIExecWithReturn(ctx, Cmd, argtable, false); @@ -6757,14 +6757,12 @@ static int CmdHF14ADesCreateMFCMapping(const char *Cmd) { if (!arg_get_u32_hexstr_def_nlen(ctx, 13, 0, &fid, 1, false)) { PrintAndLogEx(ERR, "--fid is required"); - CLIParserFree(ctx); - return PM3_EINVARG; + goto createmfcmapping_parsing_error; } if (!arg_get_u32_hexstr_def_nlen(ctx, 14, 0, &restore_fid, 1, false)) { if (restore_transfer) { PrintAndLogEx(ERR, "--restore-fid is required"); - CLIParserFree(ctx); - return PM3_EINVARG; + goto createmfcmapping_parsing_error; } } else if (!restore_transfer) { PrintAndLogEx(WARNING, "--restore-fid is ignored if --restore-transfer is not specified"); @@ -6776,16 +6774,14 @@ static int CmdHF14ADesCreateMFCMapping(const char *Cmd) { if (mfc_license_arg->count == 0 && mfc_license_mac_arg->count == 0) { if (!saved_mfclicense_set || !saved_mfclicense_mac_set) { PrintAndLogEx(ERR, "No saved license, create it with hf mfdes makemfclicense --save"); - CLIParserFree(ctx); - return PM3_EINVARG; + goto createmfcmapping_parsing_error; } use_saved_license = true; } else if (mfc_license_arg->count == 1 && mfc_license_mac_arg->count == 1) { use_saved_license = false; } else { PrintAndLogEx(ERR, "--mfc-license and --mfc-license-mac must be given together"); - CLIParserFree(ctx); - return PM3_EINVARG; + goto createmfcmapping_parsing_error; } if (use_saved_license) { @@ -6794,18 +6790,15 @@ static int CmdHF14ADesCreateMFCMapping(const char *Cmd) { memcpy(license_mac, saved_mfclicense_mac, 8); } else { if (CLIParamHexToBuf(mfc_license_arg, license, sizeof (license), &license_len) != 0) { - CLIParserFree(ctx); - return PM3_EINVARG; + goto createmfcmapping_parsing_error; } int license_mac_len = 0; if (CLIParamHexToBuf(mfc_license_mac_arg, license_mac, 8, &license_mac_len) != 0) { - CLIParserFree(ctx); - return PM3_EINVARG; + goto createmfcmapping_parsing_error; } if (license_mac_len != 8) { PrintAndLogEx(ERR, "The license MAC must be 8 bytes"); - CLIParserFree(ctx); - return PM3_EINVARG; + goto createmfcmapping_parsing_error; } } @@ -6814,27 +6807,23 @@ static int CmdHF14ADesCreateMFCMapping(const char *Cmd) { if (blk_str_arg->count != 1) { PrintAndLogEx(ERR, "--blk is mandatory"); - CLIParserFree(ctx); - return PM3_EINVARG; + goto createmfcmapping_parsing_error; } // parse blocks uint8_t blocks[64]; size_t num_blocks = 0; if (parse_mfc_blocks(blk_str_arg->sval[0], blocks, &num_blocks, false) != PM3_SUCCESS) { - CLIParserFree(ctx); - return PM3_EINVARG; + goto createmfcmapping_parsing_error; } bool trailer = ((blocks[0] + 1) % 4) == 0; if (trailer && restore_transfer) { PrintAndLogEx(ERR, "--restore-transfer not allowed on trailer blocks"); - CLIParserFree(ctx); - return PM3_EINVARG; + goto createmfcmapping_parsing_error; } else if (!trailer && (key_a || key_b || ac)) { PrintAndLogEx(ERR, "--key-a, --key-b, --access-conditions not allowed on data/value blocks"); - CLIParserFree(ctx); - return PM3_EINVARG; + goto createmfcmapping_parsing_error; } DesfireContext_t dctx = {0}; @@ -6895,6 +6884,10 @@ static int CmdHF14ADesCreateMFCMapping(const char *Cmd) { } DropField(); return res; + +createmfcmapping_parsing_error: + CLIParserFree(ctx); + return PM3_EINVARG; } static int DesfileReadISOFileAndPrint(DesfireContext_t *dctx,