diff --git a/armsrc/epa.c b/armsrc/epa.c index fabeec6d2..7ccb0a8f6 100644 --- a/armsrc/epa.c +++ b/armsrc/epa.c @@ -470,14 +470,14 @@ void EPA_PACE_Replay(PacketCommandNG *c) { uint8_t response_apdu[300] = {0}; // now replay the data and measure the timings - for (int i = 0; i < sizeof(apdu_lengths_replay); i++) { + for (int i = 0; i < ARRAYLEN(apdu_lengths_replay); i++) { StartCountUS(); func_return = EPA_APDU(apdus_replay[i].data, apdu_lengths_replay[i], response_apdu); timings[i] = GetCountUS(); // every step but the last one should succeed - if (i < sizeof(apdu_lengths_replay) - 1 + if (i < ARRAYLEN(apdu_lengths_replay) - 1 && (func_return < 6 || response_apdu[func_return - 4] != 0x90 || response_apdu[func_return - 3] != 0x00)) { diff --git a/armsrc/felica.c b/armsrc/felica.c index 48b6f4464..5420f56d4 100644 --- a/armsrc/felica.c +++ b/armsrc/felica.c @@ -746,7 +746,7 @@ void felica_dump_lite_s() { // for (c=0; c < 8; c++) // ndef[c] = FelicaFrame.framebytes[c+4]; - for (blknum = 0; blknum < sizeof(liteblks);) { + for (blknum = 0; blknum < ARRAYLEN(liteblks);) { // block to read. BuildFliteRdblk(ndef, 1, &liteblks[blknum]); diff --git a/armsrc/mifarecmd.c b/armsrc/mifarecmd.c index 2d56a8a37..26ab16e03 100644 --- a/armsrc/mifarecmd.c +++ b/armsrc/mifarecmd.c @@ -1495,7 +1495,7 @@ OUT: uint16_t bar = 0; uint8_t j = 0; - for (uint8_t m = 64; m < sizeof(found); m++) { + for (uint8_t m = 64; m < ARRAYLEN(found); m++) { bar |= ((uint16_t)(found[m] & 1) << j++); } diff --git a/client/cmddata.c b/client/cmddata.c index 7ade24586..473c5f0b9 100644 --- a/client/cmddata.c +++ b/client/cmddata.c @@ -870,7 +870,7 @@ static int CmdBitsamples(const char *Cmd) { return PM3_ETIMEOUT; } - for (size_t j = 0; j < sizeof(got); j++) { + for (size_t j = 0; j < ARRAYLEN(got); j++) { for (uint8_t k = 0; k < 8; k++) { if (got[j] & (1 << (7 - k))) GraphBuffer[cnt++] = 1; diff --git a/client/cmdhfepa.c b/client/cmdhfepa.c index 9aeaabefd..a2a120764 100644 --- a/client/cmdhfepa.c +++ b/client/cmdhfepa.c @@ -75,7 +75,7 @@ static int CmdHFEPAPACEReplay(const char *Cmd) { int skip = 0, skip_add = 0, scan_return; // for each APDU - for (int i = 0; i < sizeof(apdu_lengths); i++) { + for (int i = 0; i < ARRAYLEN(apdu_lengths); i++) { // scan to next space or end of string while (Cmd[skip] != ' ' && Cmd[skip] != '\0') { // convert @@ -96,7 +96,7 @@ static int CmdHFEPAPACEReplay(const char *Cmd) { // break on EOF if (Cmd[skip] == '\0') { - if (i < sizeof(apdu_lengths) - 1) { + if (i < ARRAYLEN(apdu_lengths) - 1) { PrintAndLogEx(NORMAL, (char *)usage_msg); return 0; @@ -111,7 +111,7 @@ static int CmdHFEPAPACEReplay(const char *Cmd) { uint8_t data[PM3_CMD_DATA_SIZE]; // fast push mode conn.block_after_ACK = true; - for (int i = 0; i < sizeof(apdu_lengths); i++) { + for (int i = 0; i < ARRAYLEN(apdu_lengths); i++) { // transfer the APDU in several parts if necessary for (int j = 0; j * sizeof(data) < apdu_lengths[i]; j++) { // amount of data in this packet @@ -119,7 +119,7 @@ static int CmdHFEPAPACEReplay(const char *Cmd) { if (packet_length > sizeof(data)) { packet_length = sizeof(data); } - if ((i == sizeof(apdu_lengths) - 1) && (j * sizeof(data) >= apdu_lengths[i] - 1)) { + if ((i == ARRAYLEN(apdu_lengths) - 1) && (j * sizeof(data) >= apdu_lengths[i] - 1)) { // Disable fast mode on last packet conn.block_after_ACK = false; } diff --git a/client/cmdhficlass.c b/client/cmdhficlass.c index 91757bbd4..17fd9f127 100644 --- a/client/cmdhficlass.c +++ b/client/cmdhficlass.c @@ -1570,7 +1570,7 @@ static void HFiClassCalcNewKey(uint8_t *CSN, uint8_t *OLDKEY, uint8_t *NEWKEY, u //get new div key HFiClassCalcDivKey(CSN, NEWKEY, new_div_key, elite); - for (uint8_t i = 0; i < sizeof(old_div_key); i++) { + for (uint8_t i = 0; i < ARRAYLEN(old_div_key); i++) { xor_div_key[i] = old_div_key[i] ^ new_div_key[i]; } if (verbose) { diff --git a/client/cmdhfmfp.c b/client/cmdhfmfp.c index fb1118b81..46ee6e680 100644 --- a/client/cmdhfmfp.c +++ b/client/cmdhfmfp.c @@ -227,7 +227,7 @@ static int CmdHFMFPInitPerso(const char *cmd) { } mfpSetVerboseMode(verbose); - for (int i = 0; i < sizeof(CardAddresses) / 2; i++) { + for (int i = 0; i < ARRAYLEN(CardAddresses); i++) { keyNum[0] = CardAddresses[i] >> 8; keyNum[1] = CardAddresses[i] & 0xff; res = MFPWritePerso(keyNum, key, false, true, data, sizeof(data), &datalen); diff --git a/client/cmdhfmfu.c b/client/cmdhfmfu.c index b7d268884..0158d3394 100644 --- a/client/cmdhfmfu.c +++ b/client/cmdhfmfu.c @@ -2298,7 +2298,7 @@ static int CmdHF14AMfURestore(const char *Cmd) { // otp, uid, lock, cfg1, cfg0, dynlockbits uint8_t blocks[] = {3, 0, 1, 2, pages - 5, pages - 4, pages - 3}; - for (uint8_t i = 0; i < sizeof(blocks); i++) { + for (uint8_t i = 0; i < ARRAYLEN(blocks); i++) { uint8_t b = blocks[i]; memcpy(data, mem->data + (b * 4), 4); clearCommandBuffer(); @@ -2635,12 +2635,12 @@ static int CmdHF14AMfUGenDiverseKeys(const char *Cmd) { PrintAndLogEx(NORMAL, "Message :\t %s", sprint_hex(mix, sizeof(mix))); PrintAndLogEx(NORMAL, "Diversified key: %s", sprint_hex(divkey + 1, 6)); - for (int i = 0; i < sizeof(mifarekeyA); ++i) { + for (int i = 0; i < ARRAYLEN(mifarekeyA); ++i) { dkeyA[i] = (mifarekeyA[i] << 1) & 0xff; dkeyA[6] |= ((mifarekeyA[i] >> 7) & 1) << (i + 1); } - for (int i = 0; i < sizeof(mifarekeyB); ++i) { + for (int i = 0; i < ARRAYLEN(mifarekeyB); ++i) { dkeyB[1] |= ((mifarekeyB[i] >> 7) & 1) << (i + 1); dkeyB[2 + i] = (mifarekeyB[i] << 1) & 0xff; } diff --git a/client/cmdlfhid.c b/client/cmdlfhid.c index cc395c8c5..56f9667a3 100644 --- a/client/cmdlfhid.c +++ b/client/cmdlfhid.c @@ -485,7 +485,7 @@ static int CmdHIDWiegand(const char *Cmd) { PrintAndLogEx(NORMAL, "HID | OEM | FC | CN | Wiegand | HID Formatted"); PrintAndLogEx(NORMAL, "----+-----+------+---------+-----------+--------------------"); - for (uint8_t i = 0; i < sizeof(fmtlen); i++) { + for (uint8_t i = 0; i < ARRAYLEN(fmtlen); i++) { memset(bits, 0x00, sizeof(bits)); calcWiegand(fmtlen[i], fc, cardnum, bs, oem); PrintAndLogEx(NORMAL, "ice:: %s \n", sprint_bin(bs, fmtlen[i])); @@ -545,7 +545,7 @@ static int CmdHIDBrute(const char *Cmd) { cmdp += 2; bool is_ftm_ok = false; uint8_t ftms[] = {26, 33, 34, 35, 37}; - for (uint8_t i = 0; i < sizeof(ftms); i++) { + for (uint8_t i = 0; i < ARRAYLEN(ftms); i++) { if (ftms[i] == fmtlen) { is_ftm_ok = true; } diff --git a/client/cmdsmartcard.c b/client/cmdsmartcard.c index c49f0d0e7..c2268fd2f 100644 --- a/client/cmdsmartcard.c +++ b/client/cmdsmartcard.c @@ -878,7 +878,7 @@ static void smart_brute_prim() { PrintAndLogEx(INFO, "Reading primitives"); - for (int i = 0; i < sizeof(get_card_data); i += 5) { + for (int i = 0; i < ARRAYLEN(get_card_data); i += 5) { clearCommandBuffer(); SendCommandOLD(CMD_SMART_RAW, SC_RAW_T0, 5, 0, get_card_data + i, 5); diff --git a/client/loclass/cipherutils.c b/client/loclass/cipherutils.c index c829574e9..b6bea6186 100644 --- a/client/loclass/cipherutils.c +++ b/client/loclass/cipherutils.c @@ -205,7 +205,7 @@ static int testBitStream() { } else { PrintAndLogDevice(FAILED, " Bitstream test 1 failed"); uint8_t i; - for (i = 0 ; i < sizeof(input) ; i++) { + for (i = 0 ; i < ARRAYLEN(input) ; i++) { PrintAndLogDevice(NORMAL, " IN %02x, OUT %02x", input[i], output[i]); } return 1; @@ -235,7 +235,7 @@ static int testReversedBitstream() { } else { PrintAndLogDevice(FAILED, " Bitstream test 2 failed"); uint8_t i; - for (i = 0 ; i < sizeof(input) ; i++) { + for (i = 0 ; i < ARRAYLEN(input) ; i++) { PrintAndLogDevice(NORMAL, " IN %02x, MIDDLE: %02x, OUT %02x", input[i], reverse[i], output[i]); } return 1; diff --git a/client/loclass/ikeys.c b/client/loclass/ikeys.c index 70605942f..67278e3b5 100644 --- a/client/loclass/ikeys.c +++ b/client/loclass/ikeys.c @@ -692,7 +692,7 @@ int doKeyTests(uint8_t debuglevel) { //Test if it's the right key... uint8_t i; uint8_t j = 0; - for (i = 0; i < sizeof(key); i++) + for (i = 0; i < ARRAYLEN(key); i++) j += key[i]; if (j != 185) {