Uniformize code style

This commit is contained in:
suut committed 2026-05-11 11:01:09 +02:00
1 parent 2e3425d537
commit 91eb6345a9
1 file changed
+36 -43
+36 -43
View File
@@ -6711,27 +6711,27 @@ static int CmdHF14ADesCreateMFCMapping(const char *Cmd) {
void *argtable[] = { void *argtable[] = {
arg_param_begin, arg_param_begin,
/* 1 */ arg_lit0("a", "apdu", "Show APDU requests and responses"), arg_lit0("a", "apdu", "Show APDU requests and responses"),
/* 2 */ arg_lit0("v", "verbose", "Verbose output"), arg_lit0("v", "verbose", "Verbose output"),
/* 3 */ arg_int0("n", "keyno", "<dec>", "Key number"), arg_int0("n", "keyno", "<dec>", "Key number"),
/* 4 */ arg_str0("t", "algo", "<DES|2TDEA|3TDEA|AES>", "Crypt algo"), arg_str0("t", "algo", "<DES|2TDEA|3TDEA|AES>", "Crypt algo"),
/* 5 */ arg_str0("k", "key", "<hex>", "Key for authenticate (HEX 8(DES), 16(2TDEA or AES) or 24(3TDEA) bytes)"), arg_str0("k", "key", "<hex>", "Key for authenticate (HEX 8(DES), 16(2TDEA or AES) or 24(3TDEA) bytes)"),
/* 6 */ arg_str0(NULL, "kdf", "<none|AN10922|gallagher>", "Key Derivation Function (KDF)"), arg_str0(NULL, "kdf", "<none|AN10922|gallagher>", "Key Derivation Function (KDF)"),
/* 7 */ arg_str0("i", "kdfi", "<hex>", "KDF input (1-31 hex bytes)"), arg_str0("i", "kdfi", "<hex>", "KDF input (1-31 hex bytes)"),
/* 8 */ arg_str0("m", "cmode", "<plain|mac|encrypt>", "Communicaton mode"), arg_str0("m", "cmode", "<plain|mac|encrypt>", "Communicaton mode"),
/* 9 */ arg_str0("c", "ccset", "<native|niso|iso>", "Communicaton command set"), arg_str0("c", "ccset", "<native|niso|iso>", "Communicaton command set"),
/* 10 */ arg_str0(NULL, "schann", "<d40|ev1|ev2|lrp>", "Secure channel"), arg_str0(NULL, "schann", "<d40|ev1|ev2|lrp>", "Secure channel"),
/* 11 */ arg_str0(NULL, "aid", "<hex>", "Application ID (3 hex bytes, big endian)"), arg_str0(NULL, "aid", "<hex>", "Application ID (3 hex bytes, big endian)"),
/* 12 */ arg_str0(NULL, "isoid", "<hex>", "Application ISO ID (ISO DF ID) (2 hex bytes, big endian)"), arg_str0(NULL, "isoid", "<hex>", "Application ISO ID (ISO DF ID) (2 hex bytes, big endian)"),
/* 13 */ arg_str0(NULL, "fid", "<hex>", "File ID to map (1 hex byte)"), arg_str0(NULL, "fid", "<hex>", "File ID to map (1 hex byte)"),
/* 14 */ arg_str0(NULL, "restore-fid", "<hex>", "Restore source when mapping value files to value blocks (1 hex byte)"), arg_str0(NULL, "restore-fid", "<hex>", "Restore source when mapping value files to value blocks (1 hex byte)"),
/* 15 */ arg_str0("b", "blk", "<num>[,<num>[,...]]", "The MFC blocks to map, must be unique (use value 'data' for all data blocks, and 'trailer' for all trailer blocks)"), arg_str0("b", "blk", "<num>[,<num>[,...]]", "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", "<hex>", "The MFC license (omit to use saved license and license MAC)"), arg_str0(NULL, "mfc-license", "<hex>", "The MFC license (omit to use saved license and license MAC)"),
/* 17 */ arg_str0(NULL, "mfc-license-mac", "<hex>", "The MFC license MAC (omit to use saved license and license MAC)"), arg_str0(NULL, "mfc-license-mac", "<hex>", "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"), 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"), 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"), 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(NULL, "restore-transfer", "Enable the RestoreTransfer command for the mapped value blocks"),
arg_param_end arg_param_end
}; };
CLIExecWithReturn(ctx, Cmd, argtable, false); 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)) { if (!arg_get_u32_hexstr_def_nlen(ctx, 13, 0, &fid, 1, false)) {
PrintAndLogEx(ERR, "--fid is required"); PrintAndLogEx(ERR, "--fid is required");
CLIParserFree(ctx); goto createmfcmapping_parsing_error;
return PM3_EINVARG;
} }
if (!arg_get_u32_hexstr_def_nlen(ctx, 14, 0, &restore_fid, 1, false)) { if (!arg_get_u32_hexstr_def_nlen(ctx, 14, 0, &restore_fid, 1, false)) {
if (restore_transfer) { if (restore_transfer) {
PrintAndLogEx(ERR, "--restore-fid is required"); PrintAndLogEx(ERR, "--restore-fid is required");
CLIParserFree(ctx); goto createmfcmapping_parsing_error;
return PM3_EINVARG;
} }
} else if (!restore_transfer) { } else if (!restore_transfer) {
PrintAndLogEx(WARNING, "--restore-fid is ignored if --restore-transfer is not specified"); 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 (mfc_license_arg->count == 0 && mfc_license_mac_arg->count == 0) {
if (!saved_mfclicense_set || !saved_mfclicense_mac_set) { if (!saved_mfclicense_set || !saved_mfclicense_mac_set) {
PrintAndLogEx(ERR, "No saved license, create it with hf mfdes makemfclicense --save"); PrintAndLogEx(ERR, "No saved license, create it with hf mfdes makemfclicense --save");
CLIParserFree(ctx); goto createmfcmapping_parsing_error;
return PM3_EINVARG;
} }
use_saved_license = true; use_saved_license = true;
} else if (mfc_license_arg->count == 1 && mfc_license_mac_arg->count == 1) { } else if (mfc_license_arg->count == 1 && mfc_license_mac_arg->count == 1) {
use_saved_license = false; use_saved_license = false;
} else { } else {
PrintAndLogEx(ERR, "--mfc-license and --mfc-license-mac must be given together"); PrintAndLogEx(ERR, "--mfc-license and --mfc-license-mac must be given together");
CLIParserFree(ctx); goto createmfcmapping_parsing_error;
return PM3_EINVARG;
} }
if (use_saved_license) { if (use_saved_license) {
@@ -6794,18 +6790,15 @@ static int CmdHF14ADesCreateMFCMapping(const char *Cmd) {
memcpy(license_mac, saved_mfclicense_mac, 8); memcpy(license_mac, saved_mfclicense_mac, 8);
} else { } else {
if (CLIParamHexToBuf(mfc_license_arg, license, sizeof (license), &license_len) != 0) { if (CLIParamHexToBuf(mfc_license_arg, license, sizeof (license), &license_len) != 0) {
CLIParserFree(ctx); goto createmfcmapping_parsing_error;
return PM3_EINVARG;
} }
int license_mac_len = 0; int license_mac_len = 0;
if (CLIParamHexToBuf(mfc_license_mac_arg, license_mac, 8, &license_mac_len) != 0) { if (CLIParamHexToBuf(mfc_license_mac_arg, license_mac, 8, &license_mac_len) != 0) {
CLIParserFree(ctx); goto createmfcmapping_parsing_error;
return PM3_EINVARG;
} }
if (license_mac_len != 8) { if (license_mac_len != 8) {
PrintAndLogEx(ERR, "The license MAC must be 8 bytes"); PrintAndLogEx(ERR, "The license MAC must be 8 bytes");
CLIParserFree(ctx); goto createmfcmapping_parsing_error;
return PM3_EINVARG;
} }
} }
@@ -6814,27 +6807,23 @@ static int CmdHF14ADesCreateMFCMapping(const char *Cmd) {
if (blk_str_arg->count != 1) { if (blk_str_arg->count != 1) {
PrintAndLogEx(ERR, "--blk is mandatory"); PrintAndLogEx(ERR, "--blk is mandatory");
CLIParserFree(ctx); goto createmfcmapping_parsing_error;
return PM3_EINVARG;
} }
// parse blocks // parse blocks
uint8_t blocks[64]; uint8_t blocks[64];
size_t num_blocks = 0; size_t num_blocks = 0;
if (parse_mfc_blocks(blk_str_arg->sval[0], blocks, &num_blocks, false) != PM3_SUCCESS) { if (parse_mfc_blocks(blk_str_arg->sval[0], blocks, &num_blocks, false) != PM3_SUCCESS) {
CLIParserFree(ctx); goto createmfcmapping_parsing_error;
return PM3_EINVARG;
} }
bool trailer = ((blocks[0] + 1) % 4) == 0; bool trailer = ((blocks[0] + 1) % 4) == 0;
if (trailer && restore_transfer) { if (trailer && restore_transfer) {
PrintAndLogEx(ERR, "--restore-transfer not allowed on trailer blocks"); PrintAndLogEx(ERR, "--restore-transfer not allowed on trailer blocks");
CLIParserFree(ctx); goto createmfcmapping_parsing_error;
return PM3_EINVARG;
} else if (!trailer && (key_a || key_b || ac)) { } else if (!trailer && (key_a || key_b || ac)) {
PrintAndLogEx(ERR, "--key-a, --key-b, --access-conditions not allowed on data/value blocks"); PrintAndLogEx(ERR, "--key-a, --key-b, --access-conditions not allowed on data/value blocks");
CLIParserFree(ctx); goto createmfcmapping_parsing_error;
return PM3_EINVARG;
} }
DesfireContext_t dctx = {0}; DesfireContext_t dctx = {0};
@@ -6895,6 +6884,10 @@ static int CmdHF14ADesCreateMFCMapping(const char *Cmd) {
} }
DropField(); DropField();
return res; return res;
createmfcmapping_parsing_error:
CLIParserFree(ctx);
return PM3_EINVARG;
} }
static int DesfileReadISOFileAndPrint(DesfireContext_t *dctx, static int DesfileReadISOFileAndPrint(DesfireContext_t *dctx,