Fix display of DF and minor bug

This commit is contained in:
Bjoern Kerler 2020-04-07 21:52:59 +02:00
commit 7085e3a3f1

View file

@ -351,23 +351,23 @@ typedef struct {
uint8_t name[16]; uint8_t name[16];
} dfname_t; } dfname_t;
static int get_desfire_dfnames(dfname_t *dest, uint8_t* dfname_count) { static int get_desfire_dfnames(dfname_t *dest, uint8_t *dfname_count) {
if (dest == NULL) return PM3_ESOFT; if (dest == NULL) return PM3_ESOFT;
uint8_t c[] = {MFDES_GET_DF_NAMES, 0x00, 0x00, 0x00}; //0x6d uint8_t c[] = {MFDES_GET_DF_NAMES, 0x00, 0x00, 0x00}; //0x6d
PacketResponseNG resp; PacketResponseNG resp;
int ret = SendDesfireCmd(c, sizeof(c), INIT, sizeof(c), 0, &resp, 3000); int ret = SendDesfireCmd(c, sizeof(c), INIT, sizeof(c), 0, &resp, 3000);
if (ret != PM3_SUCCESS) return ret; if (ret != PM3_SUCCESS) return ret;
uint8_t count=0; uint8_t count = 1;
memcpy(&dest[count], resp.data.asBytes+1, resp.length - 5); memcpy(&dest[count - 1], resp.data.asBytes + 1, resp.length - 5);
if (resp.data.asBytes[resp.length - 3] == MFDES_ADDITIONAL_FRAME) { if (resp.data.asBytes[resp.length - 3] == MFDES_ADDITIONAL_FRAME) {
c[0] = MFDES_ADDITIONAL_FRAME; //0xAF c[0] = MFDES_ADDITIONAL_FRAME; //0xAF
ret = SendDesfireCmd(c, sizeof(c), NONE, sizeof(c), 0, &resp, 3000); ret = SendDesfireCmd(c, sizeof(c), NONE, sizeof(c), 0, &resp, 3000);
if (ret != PM3_SUCCESS) return ret; if (ret != PM3_SUCCESS) return ret;
count++; count++;
memcpy(&dest[count], resp.data.asBytes+1, resp.length - 5); memcpy(&dest[count - 1], resp.data.asBytes + 1, resp.length - 5);
} }
*dfname_count=count-1; *dfname_count = count;
return PM3_SUCCESS; return PM3_SUCCESS;
} }
@ -388,7 +388,7 @@ static int get_desfire_fileids(uint8_t *dest, uint8_t *file_ids_len) {
return PM3_ESOFT; return PM3_ESOFT;
} }
static int get_desfire_filesettings( uint8_t file_id, uint8_t *dest, uint8_t *destlen) { static int get_desfire_filesettings(uint8_t file_id, uint8_t *dest, uint8_t *destlen) {
uint8_t c[] = {MFDES_GET_FILE_SETTINGS, 0x00, 0x00, 0x01, file_id, 0x00}; // 0xF5 uint8_t c[] = {MFDES_GET_FILE_SETTINGS, 0x00, 0x00, 0x01, file_id, 0x00}; // 0xF5
PacketResponseNG resp; PacketResponseNG resp;
int ret = SendDesfireCmd(c, sizeof(c), NONE, sizeof(c), 0, &resp, 1500); int ret = SendDesfireCmd(c, sizeof(c), NONE, sizeof(c), 0, &resp, 1500);
@ -575,7 +575,7 @@ char *getVersionStr(uint8_t major, uint8_t minor) {
else if (major == 0x12 && minor == 0x00) else if (major == 0x12 && minor == 0x00)
sprintf(retStr, "%x.%x ( " _YELLOW_("DESFire EV2") ")", major, minor); sprintf(retStr, "%x.%x ( " _YELLOW_("DESFire EV2") ")", major, minor);
// else if (major == 0x13 && minor == 0x00) // else if (major == 0x13 && minor == 0x00)
// sprintf(retStr, "%x.%x ( " _YELLOW_("DESFire EV3") ")", major, minor); // sprintf(retStr, "%x.%x ( " _YELLOW_("DESFire EV3") ")", major, minor);
else if (major == 0x30 && minor == 0x00) else if (major == 0x30 && minor == 0x00)
sprintf(retStr, "%x.%x ( " _YELLOW_("DESFire Light") ")", major, minor); sprintf(retStr, "%x.%x ( " _YELLOW_("DESFire Light") ")", major, minor);
else else
@ -705,15 +705,14 @@ static int CmdHF14ADesEnumApplications(const char *Cmd) {
uint8_t file_ids_len = 0; uint8_t file_ids_len = 0;
dfname_t dfnames[255] = {0}; dfname_t dfnames[255] = {0};
uint8_t dfname_count=0; uint8_t dfname_count = 0;
if (get_desfire_appids(app_ids, &app_ids_len) != PM3_SUCCESS) { if (get_desfire_appids(app_ids, &app_ids_len) != PM3_SUCCESS) {
PrintAndLogEx(ERR, "Can't get list of applications on tag"); PrintAndLogEx(ERR, "Can't get list of applications on tag");
return PM3_ESOFT; return PM3_ESOFT;
} }
if (get_desfire_dfnames(dfnames,&dfname_count)!=PM3_SUCCESS) if (get_desfire_dfnames(dfnames, &dfname_count) != PM3_SUCCESS) {
{
PrintAndLogEx(WARNING, _RED_("Can't get DF Names")); PrintAndLogEx(WARNING, _RED_("Can't get DF Names"));
DropField(); DropField();
return PM3_ESOFT; return PM3_ESOFT;
@ -735,15 +734,15 @@ static int CmdHF14ADesEnumApplications(const char *Cmd) {
if (memcmp(aid, "\x00\x00\x00", 3) == 0) { if (memcmp(aid, "\x00\x00\x00", 3) == 0) {
// CARD MASTER KEY // CARD MASTER KEY
PrintAndLogEx(INFO, "--- " _CYAN_("CMK - PICC, Card Master Key settings")); PrintAndLogEx(INFO, "--- " _CYAN_("CMK - PICC, Card Master Key settings"));
} } else {
else {
PrintAndLogEx(SUCCESS, "--- " _CYAN_("AMK - Application Master Key settings")); PrintAndLogEx(SUCCESS, "--- " _CYAN_("AMK - Application Master Key settings"));
} }
if (i<dfname_count) { PrintAndLogEx(SUCCESS, " AID : " _GREEN_("%02X %02X %02X"), aid[0], aid[1], aid[2]);
PrintAndLogEx(SUCCESS, " AID : " _GREEN_("%02X %02X %02X"), aid[0], aid[1], aid[2]); for (int m = 0; m < dfname_count; m++) {
} else { if (dfnames[m].aid[0] == aid[0] && dfnames[m].aid[1] == aid[1] && dfnames[m].aid[2] == aid[2]) {
PrintAndLogEx(SUCCESS, " AID : " _GREEN_("%02X %02X %02X") " - Name : " _YELLOW_("%s"), aid[0], aid[1], aid[2], dfnames[i/3].name); PrintAndLogEx(SUCCESS, " - DF " _YELLOW_("%02X %02X") " Name : " _YELLOW_("%s"), dfnames[m].fid[0], dfnames[m].fid[1], dfnames[m].name);
}
} }
getKeySettings(aid); getKeySettings(aid);
@ -765,13 +764,13 @@ static int CmdHF14ADesEnumApplications(const char *Cmd) {
uint8_t fileset_len = 0; uint8_t fileset_len = 0;
int res = get_desfire_filesettings(j, filesettings, &fileset_len); int res = get_desfire_filesettings(j, filesettings, &fileset_len);
if (res == PM3_SUCCESS) { if (res == PM3_SUCCESS) {
PrintAndLogEx(INFO, " Settings [%u] %s", fileset_len, sprint_hex(filesettings, fileset_len) ); PrintAndLogEx(INFO, " Settings [%u] %s", fileset_len, sprint_hex(filesettings, fileset_len));
} }
} }
} }
/* /*
// Get ISO File IDs // Get ISO File IDs
@ -844,7 +843,7 @@ static int CmdHF14ADesAuth(const char *Cmd) {
uint8_t cmdAuthMode = param_get8(Cmd, 0); uint8_t cmdAuthMode = param_get8(Cmd, 0);
uint8_t cmdAuthAlgo = param_get8(Cmd, 1); uint8_t cmdAuthAlgo = param_get8(Cmd, 1);
// AID // AID
if (param_gethex(Cmd, 2, aid, aidlength*2)) { if (param_gethex(Cmd, 2, aid, aidlength * 2)) {
PrintAndLogEx(WARNING, "aid must include %d HEX symbols", 3); PrintAndLogEx(WARNING, "aid must include %d HEX symbols", 3);
return PM3_EINVARG; return PM3_EINVARG;
} }