more ARRAYLEN

This commit is contained in:
Philippe Teuwen 2019-08-01 00:14:09 +02:00
parent f276dca3f1
commit 733a7d836d
12 changed files with 20 additions and 20 deletions

View file

@ -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)) {

View file

@ -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]);

View file

@ -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++);
}

View file

@ -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;

View file

@ -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;
}

View file

@ -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) {

View file

@ -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);

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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);

View file

@ -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;

View file

@ -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) {