From e5293f13899593734f71b71b0010e43dc904d9aa Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Tue, 18 Feb 2025 18:42:21 +0100 Subject: [PATCH] style --- client/src/cmdhfmf.c | 11 ++++++----- client/src/cmdhfmfdes.c | 23 +++++++++++++---------- client/src/cmdhfmfp.c | 8 ++++---- client/src/cmdhfmfu.c | 20 ++++++++++---------- 4 files changed, 33 insertions(+), 29 deletions(-) diff --git a/client/src/cmdhfmf.c b/client/src/cmdhfmf.c index b17e9caf8..096d7c7e3 100644 --- a/client/src/cmdhfmf.c +++ b/client/src/cmdhfmf.c @@ -2542,8 +2542,8 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) { CLIParamStrToBuf(arg_get_str(ctx, 5), (uint8_t *)filename, FILE_PATH_SIZE, &fnlen); int outfnlen = 0; - char outfilename[127] = {0}; - CLIParamStrToBuf(arg_get_str(ctx, 6), (uint8_t *)outfilename, 127, &outfnlen); + char outfilename[FILE_PATH_SIZE] = {0}; + CLIParamStrToBuf(arg_get_str(ctx, 6), (uint8_t *)outfilename, FILE_PATH_SIZE, &outfnlen); bool slow = arg_get_lit(ctx, 7); @@ -4263,8 +4263,9 @@ static int CmdHF14AMfSim(const char *Cmd) { , (uidlen == 0) ? "n/a" : sprint_hex(uid, uidlen) ); - PrintAndLogEx(INFO, "Options [ numreads: %d, flags: 0x%04x ]" + PrintAndLogEx(INFO, "Options [ numreads: %d, flags: %d (0x%04x) ]" , exitAfterNReads + , flags , flags); struct { @@ -4299,7 +4300,7 @@ static int CmdHF14AMfSim(const char *Cmd) { bool keypress = kbd_enter_pressed(); while (keypress == false) { - if (WaitForResponseTimeout(CMD_HF_MIFARE_SIMULATE, &resp, 1500) == 0) { + if (WaitForResponseTimeout(CMD_HF_MIFARE_SIMULATE, &resp, 1500) == false) { keypress = kbd_enter_pressed(); continue; } @@ -9840,7 +9841,7 @@ static int CmdHF14AMfInfo(const char *Cmd) { res = detect_classic_static_nonce(); if (res == NONCE_STATIC) { - PrintAndLogEx(SUCCESS, "Static nonce......... " _YELLOW_("yes")); + PrintAndLogEx(SUCCESS, "Static nonce... " _YELLOW_("yes")); } diff --git a/client/src/cmdhfmfdes.c b/client/src/cmdhfmfdes.c index 3a62c7751..25544ffbe 100644 --- a/client/src/cmdhfmfdes.c +++ b/client/src/cmdhfmfdes.c @@ -756,7 +756,7 @@ static int CmdHF14ADesInfo(const char *Cmd) { if (major == 2 && minor == 2) PrintAndLogEx(INFO, "\t2.2 - DESFire Ev2 XL, Originality check, proximity check, EAL5"); if (major == 3 && minor == 0) - PrintAndLogEx(INFO, "\t3.0 - DESFire Ev3, Originality check, proximity check, badass EAL6 ?"); + PrintAndLogEx(INFO, "\t3.0 - DESFire Ev3, Originality check, proximity check, badass EAL6"); if (major == 0xA0 && minor == 0) PrintAndLogEx(INFO, "\tx.x - DUOX, Originality check, proximity check, EAL6++"); @@ -805,12 +805,16 @@ static int CmdHF14ADesInfo(const char *Cmd) { } if (aidbuflen > 2) { + + uint8_t j = aidbuflen / 3; PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(SUCCESS, "--- " _CYAN_("AID list")); - PrintAndLogEx(SUCCESS, "AIDs: " NOLF); - for (int i = 0; i < aidbuflen; i += 3) - PrintAndLogEx(NORMAL, "%s %06x" NOLF, (i == 0) ? "" : ",", DesfireAIDByteToUint(&aidbuf[i])); - PrintAndLogEx(NORMAL, "\n"); + PrintAndLogEx(SUCCESS, "--- " _CYAN_("AID list") " ( " _YELLOW_("%u") " found )", j); + + j = 0; + for (int i = 0; i < aidbuflen; i += 3, j++) { + uint32_t aid = DesfireAIDByteToUint(&aidbuf[i]); + PrintAndLogEx(SUCCESS, _YELLOW_("%06X") ", %s", aid, getAidCommentStr(aid)); + } } DesfireFillPICCInfo(&dctx, &PICCInfo, true); @@ -821,7 +825,7 @@ static int CmdHF14ADesInfo(const char *Cmd) { PrintAndLogEx(NORMAL, ""); PrintAndLogEx(INFO, "--- " _CYAN_("Free memory")); if (PICCInfo.freemem != 0xffffffff) { - PrintAndLogEx(SUCCESS, " Available free memory on card : " _GREEN_("%d bytes"), PICCInfo.freemem); + PrintAndLogEx(SUCCESS, " Available free memory on card... " _GREEN_("%d") " bytes", PICCInfo.freemem); } else { PrintAndLogEx(SUCCESS, " Card doesn't support 'free mem' cmd"); } @@ -1809,7 +1813,7 @@ static int CmdHF14aDesMAD(const char *Cmd) { AppListS AppList = {{0}}; DesfireFillAppList(&dctx, &PICCInfo, AppList, false, false, false); // no deep scan, no scan files - PrintAndLogEx(SUCCESS, "# Applications... " _GREEN_("%zu"), PICCInfo.appCount); + PrintAndLogEx(SUCCESS, "# Applications.... " _GREEN_("%zu"), PICCInfo.appCount); if (PICCInfo.freemem == 0xffffffff) { PrintAndLogEx(SUCCESS, "Free memory...... " _YELLOW_("n/a")); } else { @@ -5594,7 +5598,7 @@ static int CmdHF14ADesLsApp(const char *Cmd) { SetAPDULogging(APDULogging); CLIParserFree(ctx); - PrintAndLogEx(INPLACE, _YELLOW_("It may take up to 15 seconds. Processing....")); + PrintAndLogEx(INFO, "It may take up to " _YELLOW_("15") " seconds. Processing..."); res = DesfireSelectAndAuthenticateEx(&dctx, securechann, 0x000000, noauth, verbose); if (res != PM3_SUCCESS) { @@ -5606,7 +5610,6 @@ static int CmdHF14ADesLsApp(const char *Cmd) { AppListS AppList = {{0}}; DesfireFillAppList(&dctx, &PICCInfo, AppList, !nodeep, scanfiles, true); - printf("\33[2K\r"); // clear current line before printing PrintAndLogEx(NORMAL, ""); // print zone diff --git a/client/src/cmdhfmfp.c b/client/src/cmdhfmfp.c index 218b87504..70bc28e09 100644 --- a/client/src/cmdhfmfp.c +++ b/client/src/cmdhfmfp.c @@ -1990,9 +1990,9 @@ int CmdHFMFPNDEFRead(const char *Cmd) { memcpy(ndefkey, key, 16); } - uint8_t sector0[16 * 4] = {0}; - uint8_t sector10[16 * 4] = {0}; - uint8_t data[4096] = {0}; + uint8_t sector0[MIFARE_1K_MAXBLOCK] = {0}; + uint8_t sector10[MIFARE_1K_MAXBLOCK] = {0}; + uint8_t data[MIFARE_4K_MAX_BYTES] = {0}; int datalen = 0; if (verbose) @@ -2034,7 +2034,7 @@ int CmdHFMFPNDEFRead(const char *Cmd) { PrintAndLogEx(INFO, "reading data from tag"); for (int i = 0; i < madlen; i++) { if (ndefAID == mad[i]) { - uint8_t vsector[16 * 4] = {0}; + uint8_t vsector[MIFARE_1K_MAXBLOCK] = {0}; if (mfpReadSector(i + 1, keyB ? MF_KEY_B : MF_KEY_A, ndefkey, vsector, false)) { PrintAndLogEx(ERR, "error, reading sector %d", i + 1); return PM3_ESOFT; diff --git a/client/src/cmdhfmfu.c b/client/src/cmdhfmfu.c index e84e55169..ed8ddaf01 100644 --- a/client/src/cmdhfmfu.c +++ b/client/src/cmdhfmfu.c @@ -4071,8 +4071,8 @@ static int CmdHF14AMfUCSetUid(const char *Cmd) { PacketResponseNG resp; clearCommandBuffer(); SendCommandMIX(CMD_HF_MIFAREU_READBL, 2, 0, 0, NULL, 0); - if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) { - PrintAndLogEx(WARNING, "command execution time out"); + if (WaitForResponseTimeout(CMD_ACK, &resp, 1500) == false) { + PrintAndLogEx(WARNING, "Command execute timeout"); return PM3_ETIMEOUT; } @@ -4084,8 +4084,8 @@ static int CmdHF14AMfUCSetUid(const char *Cmd) { // block 1 write and block2 write hf14a_config config; SendCommandNG(CMD_HF_ISO14443A_GET_CONFIG, NULL, 0); - if (!WaitForResponseTimeout(CMD_HF_ISO14443A_GET_CONFIG, &resp, 2000)) { - PrintAndLogEx(WARNING, "command execution time out"); + if (WaitForResponseTimeout(CMD_HF_ISO14443A_GET_CONFIG, &resp, 2000) == false) { + PrintAndLogEx(WARNING, "command execute timeout"); return PM3_ETIMEOUT; } memcpy(&config, resp.data.asBytes, sizeof(hf14a_config)); @@ -4103,8 +4103,8 @@ static int CmdHF14AMfUCSetUid(const char *Cmd) { data[3] = 0x88 ^ uid[0] ^ uid[1] ^ uid[2]; clearCommandBuffer(); SendCommandMIX(CMD_HF_MIFAREU_WRITEBL, 0, 0, 0, data, sizeof(data)); - if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) { - PrintAndLogEx(WARNING, "command execution time out"); + if (WaitForResponseTimeout(CMD_ACK, &resp, 1500) == false) { + PrintAndLogEx(WARNING, "Command execute timeout"); return PM3_ETIMEOUT; } @@ -4115,8 +4115,8 @@ static int CmdHF14AMfUCSetUid(const char *Cmd) { data[3] = uid[6]; clearCommandBuffer(); SendCommandMIX(CMD_HF_MIFAREU_WRITEBL, 1, 0, 0, data, sizeof(data)); - if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) { - PrintAndLogEx(WARNING, "command execution time out"); + if (WaitForResponseTimeout(CMD_ACK, &resp, 1500) == false) { + PrintAndLogEx(WARNING, "Command execute timeout"); return PM3_ETIMEOUT; } @@ -4127,8 +4127,8 @@ static int CmdHF14AMfUCSetUid(const char *Cmd) { data[3] = oldblock2[3]; clearCommandBuffer(); SendCommandMIX(CMD_HF_MIFAREU_WRITEBL, 2, 0, 0, data, sizeof(data)); - if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500)) { - PrintAndLogEx(WARNING, "command execution time out"); + if (WaitForResponseTimeout(CMD_ACK, &resp, 1500) == false) { + PrintAndLogEx(WARNING, "Command execute timeout"); return PM3_ETIMEOUT; }