atr fixes and regex test

This commit is contained in:
iceman1001 committed 2021-10-10 11:45:43 +02:00
1 parent dd391cda01
commit c93dfb712f
4 files changed
+42 -20

No files matched your search

+2 -2
View File
@@ -36,7 +36,7 @@ def main():
print(
"""#ifndef ATRS_H__
#define ATRS_H__
#include <stddef.h>
@@ -49,7 +49,7 @@ def main():
const char *getAtrInfo(const char *atr_str);
// atr_t array are expected to be NULL terminated
static atr_t AtrTable[] = {""")
const static atr_t AtrTable[] = {""")
print_atr(df)
+23 -17
View File
@@ -10,7 +10,9 @@
#include "atrs.h"
#include <ctype.h>
#include <string.h>
#include <regex.h> // regex?
#include "commonutil.h" // ARRAYLEN
#include "ui.h" // get PrintAndLogEx
#include "util.h" // startswith
// get a ATR description based on the atr bytes
@@ -22,26 +24,30 @@ const char *getAtrInfo(const char *atr_str) {
// check for dots in atr table.
// dots indicate those bytes at those positions are optional.
// need a special case for them
if (strstr(AtrTable[i].bytes, "..") != NULL) {
// need to loop
const char *foo = atr_str;
int j = 0;
while (foo++, j++) {
char c = foo[0];
if (c == '.') {
continue;
}
// mismatch, return default message
if (c != AtrTable[i].bytes[j]) {
return AtrTable[ARRAYLEN(AtrTable) - 1].desc;
}
if (strstr(AtrTable[i].bytes, ".") != NULL) {
regex_t r;
int ret = regcomp(&r, AtrTable[i].bytes, 0);
if (ret) {
// take next ATR value.
PrintAndLogEx(DEBUG, "can't compile regex");
continue;
}
return AtrTable[i].desc;
/* Execute regular expression */
ret = regexec(&r, atr_str, 0, NULL, 0);
regfree(&r);
if (!ret) {
return AtrTable[i].desc;
}
else if (ret == REG_NOMATCH) {
continue;
}
else {
PrintAndLogEx(DEBUG, "regex failed");
continue;
}
} else {
if (str_startswith(atr_str, AtrTable[i].bytes)) {
+1 -1
View File
@@ -12,7 +12,7 @@
const char *getAtrInfo(const char *atr_str);
// atr_t array are expected to be NULL terminated
static atr_t AtrTable[] = {
const static atr_t AtrTable[] = {
{ "3B021450", "Schlumberger Multiflex 3k" },
{ "3B025301", "Gemplus GemClub Memo SuperShop clubcard" },
{ "3B0400000000", "Laundromat payment card Spanish ID (“DNIe: Documento Nacional de Identidad electrónico). http://www.dnie.es/" },
+16
View File
@@ -23,6 +23,7 @@
#include "fileutils.h"
#include "crc16.h" // crc
#include "cliparser.h" // cliparsing
#include "atrs.h" // ATR lookup
static int CmdHelp(const char *Cmd);
@@ -691,8 +692,11 @@ static int CmdSmartInfo(const char *Cmd) {
// print header
PrintAndLogEx(INFO, "--- " _CYAN_("Smartcard Information") " ---------");
PrintAndLogEx(INFO, "ISO7618-3 ATR : %s", sprint_hex(card.atr, card.atr_len));
PrintAndLogEx(INFO, "http://smartcard-atr.apdu.fr/parse?ATR=%s", sprint_hex_inrow(card.atr, card.atr_len));
//PrintAndLogEx(INFO, "ATR loopup : %s", getAtrInfo("3FFF112503108041B00669FF4A50700000415A010011"));
// print ATR
PrintAndLogEx(INFO, "ATR");
PrintATR(card.atr, card.atr_len);
@@ -755,6 +759,18 @@ static int CmdSmartReader(const char *Cmd) {
}
smart_card_atr_t *card = (smart_card_atr_t *)resp.data.asBytes;
PrintAndLogEx(INFO, "ISO7816-3 ATR : %s", sprint_hex(card->atr, card->atr_len));
// test with normal lookup, with existing ATR in table
PrintAndLogEx(INFO, "ATR loopup : %s", getAtrInfo("3FFF112503108041B00669FF4A50700000415A010011")); // Astro (Pay TV)
//PrintAndLogEx(INFO, "ATR loopup : %s", getAtrInfo("3FFD13250250800F..B0..69FF4A50D08000495403"));
// test with random bytes in .. space
PrintAndLogEx(INFO, "ATR loopup : %s", getAtrInfo("3FFD13250250800FEEB00269FF4A50D08000495403")); // Sky (Italy) VideoGuard CAM card
// test w shorted str, not in ATR table
PrintAndLogEx(INFO, "ATR loopup : %s", getAtrInfo("3FFD13250250800FEEB00269FF4A50D080004954")); // Sky (Italy) VideoGuard CAM card
return PM3_SUCCESS;
}