use memcmp

This commit is contained in:
Ray Lee 2021-08-24 14:23:32 +08:00
commit cc3e2cc3a9
3 changed files with 6 additions and 16 deletions

View file

@ -689,22 +689,22 @@ static int CmdHF14ADesInfo(const char *Cmd) {
iso14a_card_select_t card; iso14a_card_select_t card;
res = SelectCard14443A_4(true, false, &card); res = SelectCard14443A_4(true, false, &card);
if (res == PM3_SUCCESS) { if (res == PM3_SUCCESS) {
static const uint8_t STANDALONE_DESFIRE[] = { 0x75, 0x77, 0x81, 0x02 }; static const char STANDALONE_DESFIRE[] = { 0x75, 0x77, 0x81, 0x02 };
static const uint8_t JCOP_DESFIRE[] = { 0x75, 0xf7, 0xb1, 0x02 }; static const char JCOP_DESFIRE[] = { 0x75, 0xf7, 0xb1, 0x02 };
static const uint8_t JCOP3_DESFIRE[] = { 0x78, 0x77, 0x71, 0x02 }; static const char JCOP3_DESFIRE[] = { 0x78, 0x77, 0x71, 0x02 };
if (card.sak == 0x20) { if (card.sak == 0x20) {
if (card.ats_len >= 5) { if (card.ats_len >= 5) {
if (bytes_compare((const uint8_t *)card.ats + 1, STANDALONE_DESFIRE, 4)) { if (!memcmp(card.ats + 1, STANDALONE_DESFIRE, 4)) {
PrintAndLogEx(INFO, "Standalone DESFire"); PrintAndLogEx(INFO, "Standalone DESFire");
} }
if (bytes_compare((const uint8_t *)card.ats + 1, JCOP_DESFIRE, 4)) { if (!memcmp(card.ats + 1, JCOP_DESFIRE, 4)) {
PrintAndLogEx(INFO, "JCOP DESFire"); PrintAndLogEx(INFO, "JCOP DESFire");
} }
} }
if (card.ats_len == 4) { if (card.ats_len == 4) {
if (bytes_compare((const uint8_t *)card.ats + 1, JCOP3_DESFIRE, 4)) { if (!memcmp(card.ats + 1, JCOP3_DESFIRE, 4)) {
PrintAndLogEx(INFO, "JCOP3 DESFire"); PrintAndLogEx(INFO, "JCOP3 DESFire");
} }
} }

View file

@ -505,15 +505,6 @@ 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 // aa,bb,cc,dd,ee,ff,gg,hh, ii,jj,kk,ll,mm,nn,oo,pp
// to // to
// hh,gg,ff,ee,dd,cc,bb,aa, pp,oo,nn,mm,ll,kk,jj,ii // hh,gg,ff,ee,dd,cc,bb,aa, pp,oo,nn,mm,ll,kk,jj,ii

View file

@ -61,7 +61,6 @@ 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_bytebits(uint64_t n, size_t len, uint8_t *dest);
void num_to_bytebitsLSBF(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); 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. // Swap endian on arrays up to 64bytes.
uint8_t *SwapEndian64(const uint8_t *src, const size_t len, const uint8_t blockSize); uint8_t *SwapEndian64(const uint8_t *src, const size_t len, const uint8_t blockSize);