more ARRAYLEN

This commit is contained in:
Philippe Teuwen 2019-08-01 00:14:09 +02:00
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}; uint8_t response_apdu[300] = {0};
// now replay the data and measure the timings // 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(); StartCountUS();
func_return = EPA_APDU(apdus_replay[i].data, func_return = EPA_APDU(apdus_replay[i].data,
apdu_lengths_replay[i], apdu_lengths_replay[i],
response_apdu); response_apdu);
timings[i] = GetCountUS(); timings[i] = GetCountUS();
// every step but the last one should succeed // 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 && (func_return < 6
|| response_apdu[func_return - 4] != 0x90 || response_apdu[func_return - 4] != 0x90
|| response_apdu[func_return - 3] != 0x00)) { || response_apdu[func_return - 3] != 0x00)) {

View file

@ -746,7 +746,7 @@ void felica_dump_lite_s() {
// for (c=0; c < 8; c++) // for (c=0; c < 8; c++)
// ndef[c] = FelicaFrame.framebytes[c+4]; // ndef[c] = FelicaFrame.framebytes[c+4];
for (blknum = 0; blknum < sizeof(liteblks);) { for (blknum = 0; blknum < ARRAYLEN(liteblks);) {
// block to read. // block to read.
BuildFliteRdblk(ndef, 1, &liteblks[blknum]); BuildFliteRdblk(ndef, 1, &liteblks[blknum]);

View file

@ -1495,7 +1495,7 @@ OUT:
uint16_t bar = 0; uint16_t bar = 0;
uint8_t j = 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++); bar |= ((uint16_t)(found[m] & 1) << j++);
} }

View file

@ -870,7 +870,7 @@ static int CmdBitsamples(const char *Cmd) {
return PM3_ETIMEOUT; 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++) { for (uint8_t k = 0; k < 8; k++) {
if (got[j] & (1 << (7 - k))) if (got[j] & (1 << (7 - k)))
GraphBuffer[cnt++] = 1; GraphBuffer[cnt++] = 1;

View file

@ -75,7 +75,7 @@ static int CmdHFEPAPACEReplay(const char *Cmd) {
int skip = 0, skip_add = 0, scan_return; int skip = 0, skip_add = 0, scan_return;
// for each APDU // 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 // scan to next space or end of string
while (Cmd[skip] != ' ' && Cmd[skip] != '\0') { while (Cmd[skip] != ' ' && Cmd[skip] != '\0') {
// convert // convert
@ -96,7 +96,7 @@ static int CmdHFEPAPACEReplay(const char *Cmd) {
// break on EOF // break on EOF
if (Cmd[skip] == '\0') { if (Cmd[skip] == '\0') {
if (i < sizeof(apdu_lengths) - 1) { if (i < ARRAYLEN(apdu_lengths) - 1) {
PrintAndLogEx(NORMAL, (char *)usage_msg); PrintAndLogEx(NORMAL, (char *)usage_msg);
return 0; return 0;
@ -111,7 +111,7 @@ static int CmdHFEPAPACEReplay(const char *Cmd) {
uint8_t data[PM3_CMD_DATA_SIZE]; uint8_t data[PM3_CMD_DATA_SIZE];
// fast push mode // fast push mode
conn.block_after_ACK = true; 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 // transfer the APDU in several parts if necessary
for (int j = 0; j * sizeof(data) < apdu_lengths[i]; j++) { for (int j = 0; j * sizeof(data) < apdu_lengths[i]; j++) {
// amount of data in this packet // amount of data in this packet
@ -119,7 +119,7 @@ static int CmdHFEPAPACEReplay(const char *Cmd) {
if (packet_length > sizeof(data)) { if (packet_length > sizeof(data)) {
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 // Disable fast mode on last packet
conn.block_after_ACK = false; 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 //get new div key
HFiClassCalcDivKey(CSN, NEWKEY, new_div_key, elite); 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]; xor_div_key[i] = old_div_key[i] ^ new_div_key[i];
} }
if (verbose) { if (verbose) {

View file

@ -227,7 +227,7 @@ static int CmdHFMFPInitPerso(const char *cmd) {
} }
mfpSetVerboseMode(verbose); 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[0] = CardAddresses[i] >> 8;
keyNum[1] = CardAddresses[i] & 0xff; keyNum[1] = CardAddresses[i] & 0xff;
res = MFPWritePerso(keyNum, key, false, true, data, sizeof(data), &datalen); 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 // otp, uid, lock, cfg1, cfg0, dynlockbits
uint8_t blocks[] = {3, 0, 1, 2, pages - 5, pages - 4, pages - 3}; 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]; uint8_t b = blocks[i];
memcpy(data, mem->data + (b * 4), 4); memcpy(data, mem->data + (b * 4), 4);
clearCommandBuffer(); clearCommandBuffer();
@ -2635,12 +2635,12 @@ static int CmdHF14AMfUGenDiverseKeys(const char *Cmd) {
PrintAndLogEx(NORMAL, "Message :\t %s", sprint_hex(mix, sizeof(mix))); PrintAndLogEx(NORMAL, "Message :\t %s", sprint_hex(mix, sizeof(mix)));
PrintAndLogEx(NORMAL, "Diversified key: %s", sprint_hex(divkey + 1, 6)); 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[i] = (mifarekeyA[i] << 1) & 0xff;
dkeyA[6] |= ((mifarekeyA[i] >> 7) & 1) << (i + 1); 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[1] |= ((mifarekeyB[i] >> 7) & 1) << (i + 1);
dkeyB[2 + i] = (mifarekeyB[i] << 1) & 0xff; 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, "HID | OEM | FC | CN | Wiegand | HID Formatted");
PrintAndLogEx(NORMAL, "----+-----+------+---------+-----------+--------------------"); 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)); memset(bits, 0x00, sizeof(bits));
calcWiegand(fmtlen[i], fc, cardnum, bs, oem); calcWiegand(fmtlen[i], fc, cardnum, bs, oem);
PrintAndLogEx(NORMAL, "ice:: %s \n", sprint_bin(bs, fmtlen[i])); PrintAndLogEx(NORMAL, "ice:: %s \n", sprint_bin(bs, fmtlen[i]));
@ -545,7 +545,7 @@ static int CmdHIDBrute(const char *Cmd) {
cmdp += 2; cmdp += 2;
bool is_ftm_ok = false; bool is_ftm_ok = false;
uint8_t ftms[] = {26, 33, 34, 35, 37}; 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) { if (ftms[i] == fmtlen) {
is_ftm_ok = true; is_ftm_ok = true;
} }

View file

@ -878,7 +878,7 @@ static void smart_brute_prim() {
PrintAndLogEx(INFO, "Reading primitives"); 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(); clearCommandBuffer();
SendCommandOLD(CMD_SMART_RAW, SC_RAW_T0, 5, 0, get_card_data + i, 5); SendCommandOLD(CMD_SMART_RAW, SC_RAW_T0, 5, 0, get_card_data + i, 5);

View file

@ -205,7 +205,7 @@ static int testBitStream() {
} else { } else {
PrintAndLogDevice(FAILED, " Bitstream test 1 failed"); PrintAndLogDevice(FAILED, " Bitstream test 1 failed");
uint8_t i; 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]); PrintAndLogDevice(NORMAL, " IN %02x, OUT %02x", input[i], output[i]);
} }
return 1; return 1;
@ -235,7 +235,7 @@ static int testReversedBitstream() {
} else { } else {
PrintAndLogDevice(FAILED, " Bitstream test 2 failed"); PrintAndLogDevice(FAILED, " Bitstream test 2 failed");
uint8_t i; 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]); PrintAndLogDevice(NORMAL, " IN %02x, MIDDLE: %02x, OUT %02x", input[i], reverse[i], output[i]);
} }
return 1; return 1;

View file

@ -692,7 +692,7 @@ int doKeyTests(uint8_t debuglevel) {
//Test if it's the right key... //Test if it's the right key...
uint8_t i; uint8_t i;
uint8_t j = 0; uint8_t j = 0;
for (i = 0; i < sizeof(key); i++) for (i = 0; i < ARRAYLEN(key); i++)
j += key[i]; j += key[i];
if (j != 185) { if (j != 185) {