diff --git a/client/src/cmdhfmfdes.c b/client/src/cmdhfmfdes.c index d4a8b4944..23bd3127a 100644 --- a/client/src/cmdhfmfdes.c +++ b/client/src/cmdhfmfdes.c @@ -689,23 +689,22 @@ static int CmdHF14ADesInfo(const char *Cmd) { iso14a_card_select_t card; res = SelectCard14443A_4(true, false, &card); if (res == PM3_SUCCESS) { - // convert to str by adding \0 to the end. so we can use strlen() to calc length - static const char STANDALONE_DESFIRE[] = { 0x75, 0x77, 0x81, 0x02, '\0' }; - static const char JCOP_DESFIRE[] = { 0x75, 0xf7, 0xb1, 0x02, '\0' }; - static const char JCOP3_DESFIRE[] = { 0x78, 0x77, 0x71, 0x02, '\0' }; + static const uint8_t STANDALONE_DESFIRE[] = { 0x75, 0x77, 0x81, 0x02 }; + static const uint8_t JCOP_DESFIRE[] = { 0x75, 0xf7, 0xb1, 0x02 }; + static const uint8_t JCOP3_DESFIRE[] = { 0x78, 0x77, 0x71, 0x02 }; if (card.sak == 0x20) { if (card.ats_len >= 5) { - if (str_startswith((const char *)card.ats + 1, STANDALONE_DESFIRE)) { + if (bytes_compare((const uint8_t *)card.ats + 1, STANDALONE_DESFIRE, 4)) { PrintAndLogEx(INFO, "Standalone DESFire"); } - if (str_startswith((const char *)card.ats + 1, JCOP_DESFIRE)) { + if (bytes_compare((const uint8_t *)card.ats + 1, JCOP_DESFIRE, 4)) { PrintAndLogEx(INFO, "JCOP DESFire"); } } if (card.ats_len == 4) { - if (str_startswith((const char *)card.ats + 1, JCOP3_DESFIRE)) { + if (bytes_compare((const uint8_t *)card.ats + 1, JCOP3_DESFIRE, 4)) { PrintAndLogEx(INFO, "JCOP3 DESFire"); } } diff --git a/client/src/util.c b/client/src/util.c index 65694db18..ff99baaf7 100644 --- a/client/src/util.c +++ b/client/src/util.c @@ -505,6 +505,15 @@ void bytes_to_bytebits(const void *src, const size_t srclen, void *dest) { } } +// Compare two arrays +bool bytes_compare(const uint8_t *b1, const uint8_t *b2, const size_t n) { + for (size_t i = 0; i < n; i++) { + if (b1[i] != b2[i]) + return false; + } + return true; +} + // aa,bb,cc,dd,ee,ff,gg,hh, ii,jj,kk,ll,mm,nn,oo,pp // to // hh,gg,ff,ee,dd,cc,bb,aa, pp,oo,nn,mm,ll,kk,jj,ii diff --git a/client/src/util.h b/client/src/util.h index 532f47313..a0b7237c2 100644 --- a/client/src/util.h +++ b/client/src/util.h @@ -61,6 +61,7 @@ int hex_to_bytes(const char *hexValue, uint8_t *bytesValue, size_t maxBytesValue void num_to_bytebits(uint64_t n, size_t len, uint8_t *dest); void num_to_bytebitsLSBF(uint64_t n, size_t len, uint8_t *dest); void bytes_to_bytebits(const void *src, const size_t srclen, void *dest); +bool bytes_compare(const uint8_t *b1, const uint8_t *b2, const size_t n); // Swap endian on arrays up to 64bytes. uint8_t *SwapEndian64(const uint8_t *src, const size_t len, const uint8_t blockSize);