From 907c4a4b3958d1cf6b8aca84cf903c33ae2de312 Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Thu, 29 Jul 2021 00:00:38 +0300 Subject: [PATCH] data ready --- client/src/cmdhfmfdes.c | 53 ++++++++++++++++++++++++++++----- client/src/mifare/desfirecore.c | 10 +++++++ client/src/mifare/desfirecore.h | 9 ++++++ 3 files changed, 64 insertions(+), 8 deletions(-) diff --git a/client/src/cmdhfmfdes.c b/client/src/cmdhfmfdes.c index eddce2944..5826282d6 100644 --- a/client/src/cmdhfmfdes.c +++ b/client/src/cmdhfmfdes.c @@ -6784,7 +6784,8 @@ static int CmdHF14ADesLsFiles(const char *Cmd) { //int DesfireGetFileIDList(DesfireContext *dctx, uint8_t *resp, size_t *resplen); //int DesfireGetFileISOIDList(DesfireContext *dctx, uint8_t *resp, size_t *resplen); - + FileListS FileList; + memset(FileList, 0, sizeof(FileList)); uint8_t buf[APDU_RES_LEN] = {0}; size_t buflen = 0; @@ -6795,14 +6796,50 @@ static int CmdHF14ADesLsFiles(const char *Cmd) { DropField(); return PM3_ESOFT; } - - if (buflen > 0) { - PrintAndLogEx(INFO, "---- " _CYAN_("File list") " ----"); - for (int i = 0; i < buflen; i++) - PrintAndLogEx(INFO, "File ID: %02x", buf[i]); - } else { + + if (buflen == 0) { PrintAndLogEx(INFO, "There is no files in the application %06x", appid); - } + DropField(); + return PM3_SUCCESS; + } + + for (int i = 0; i < buflen; i++) { + FileList[i].fileNum = buf[i]; + DesfireGetFileSettingsStruct(&dctx, FileList[i].fileNum, &FileList[i].fileSettings); + } + size_t filescount = buflen; + + buflen = 0; + res = DesfireGetFileISOIDList(&dctx, buf, &buflen); + if (res != PM3_SUCCESS) { + PrintAndLogEx(ERR, "Desfire GetFileISOIDList command " _RED_("error") ". Result: %d", res); + } + + if (buflen > 0) { + size_t isoindx = 0; + for (int i = 0; i < filescount; i++) { + if (FileList[i].fileSettings.fileType != 0x03 && FileList[i].fileSettings.fileType != 0x05) { + FileList[i].fileISONum = MemBeToUint2byte(&buf[isoindx * 2]); + isoindx++; + } + } + if (isoindx * 2 != buflen) + PrintAndLogEx(WARNING, "Wrong ISO ID list length. must be %d but %d", buflen, isoindx * 2); + } else { + PrintAndLogEx(WARNING, "ISO ID list returned no data"); + } + + PrintAndLogEx(INFO, "---- " _CYAN_("File list") " ----"); + for (int i = 0; i < filescount; i++) { + PrintAndLogEx(SUCCESS, "ID: " _GREEN_("%02x ") NOLF, FileList[i].fileNum); + if (FileList[i].fileISONum != 0) + PrintAndLogEx(NORMAL, "ISO ID: %04x " NOLF, FileList[i].fileISONum); + else + PrintAndLogEx(NORMAL, "ISO ID: n/a " NOLF); + + DesfirePrintFileSettingsOneLine(&FileList[i].fileSettings); + } + DropField(); diff --git a/client/src/mifare/desfirecore.c b/client/src/mifare/desfirecore.c index d97dbe16a..dbe562d1d 100644 --- a/client/src/mifare/desfirecore.c +++ b/client/src/mifare/desfirecore.c @@ -1473,6 +1473,16 @@ void DesfireFillFileSettings(uint8_t *data, size_t datalen, FileSettingsS *fsett } } +void DesfirePrintFileSettingsOneLine(FileSettingsS *fsettings) { + PrintAndLogEx(NORMAL, "(%-5s) " NOLF, GetDesfireCommunicationMode(fsettings->fileCommMode)); + PrintAndLogEx(NORMAL, "[0x%02x] %-13s ", fsettings->fileType, GetDesfireFileType(fsettings->fileType)); + + + /* PrintAndLogEx(SUCCESS, "read : %s", GetDesfireAccessRightStr(r)); + PrintAndLogEx(SUCCESS, "write : %s", GetDesfireAccessRightStr(w)); + PrintAndLogEx(SUCCESS, "readwrite: %s", GetDesfireAccessRightStr(rw)); + PrintAndLogEx(SUCCESS, "change : %s", GetDesfireAccessRightStr(ch));*/ +} static void DesfirePrintFileSettDynPart(uint8_t filetype, uint8_t *data, size_t datalen, uint8_t *dynlen, bool create) { switch (filetype) { diff --git a/client/src/mifare/desfirecore.h b/client/src/mifare/desfirecore.h index 8933e7e10..0a4a8f0dd 100644 --- a/client/src/mifare/desfirecore.h +++ b/client/src/mifare/desfirecore.h @@ -68,6 +68,14 @@ typedef struct { } FileSettingsS; +typedef struct { + uint8_t fileNum; + uint16_t fileISONum; + FileSettingsS fileSettings; +} FileListElmS; + +typedef FileListElmS FileListS[32]; + typedef enum { RFTAuto, RFTData, @@ -125,6 +133,7 @@ int DesfireGetFileIDList(DesfireContext *dctx, uint8_t *resp, size_t *resplen); int DesfireGetFileISOIDList(DesfireContext *dctx, uint8_t *resp, size_t *resplen); void DesfireFillFileSettings(uint8_t *data, size_t datalen, FileSettingsS *fsettings); +void DesfirePrintFileSettingsOneLine(FileSettingsS *fsettings); int DesfireGetFileSettings(DesfireContext *dctx, uint8_t fileid, uint8_t *resp, size_t *resplen); int DesfireGetFileSettingsStruct(DesfireContext *dctx, uint8_t fileid, FileSettingsS *fsettings); int DesfireChangeFileSettings(DesfireContext *dctx, uint8_t *data, size_t datalen);