mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-24 23:25:40 -07:00
print refactoring
This commit is contained in:
parent
ed310ed432
commit
0951b31175
3 changed files with 65 additions and 39 deletions
|
@ -6014,6 +6014,8 @@ static int CmdHF14ADesLsApp(const char *Cmd) {
|
||||||
SetAPDULogging(APDULogging);
|
SetAPDULogging(APDULogging);
|
||||||
CLIParserFree(ctx);
|
CLIParserFree(ctx);
|
||||||
|
|
||||||
|
PrintAndLogEx(INPLACE, _YELLOW_("It may take up to 15 seconds. Processing...."));
|
||||||
|
|
||||||
res = DesfireSelectAndAuthenticateEx(&dctx, securechann, 0x000000, noauth, verbose);
|
res = DesfireSelectAndAuthenticateEx(&dctx, securechann, 0x000000, noauth, verbose);
|
||||||
if (res != PM3_SUCCESS) {
|
if (res != PM3_SUCCESS) {
|
||||||
DropField();
|
DropField();
|
||||||
|
@ -6022,43 +6024,14 @@ static int CmdHF14ADesLsApp(const char *Cmd) {
|
||||||
|
|
||||||
PICCInfoS PICCInfo = {0};
|
PICCInfoS PICCInfo = {0};
|
||||||
AppListS AppList = {0};
|
AppListS AppList = {0};
|
||||||
DesfireFillAppList(&dctx, &PICCInfo, AppList, true);
|
DesfireFillAppList(&dctx, &PICCInfo, AppList, true, false);
|
||||||
|
|
||||||
|
printf("\33[2K\r"); // clear current line before printing
|
||||||
|
PrintAndLogEx(NORMAL, "");
|
||||||
|
|
||||||
// print zone
|
// print zone
|
||||||
PrintAndLogEx(SUCCESS, "------------------- " _CYAN_("PICC level") " ------------------");
|
DesfirePrintPICCInfo(&dctx, &PICCInfo);
|
||||||
PrintAndLogEx(SUCCESS, "Applications count: " _GREEN_("%zu") " free memory " _GREEN_("%d"), PICCInfo.appCount, PICCInfo.freemem);
|
DesfirePrintAppList(&dctx, &PICCInfo, AppList);
|
||||||
PrintAndLogEx(SUCCESS, "PICC level auth commands: " NOLF);
|
|
||||||
DesfireCheckAuthCommandsPrint(&PICCInfo.authCmdCheck);
|
|
||||||
if (PICCInfo.numberOfKeys > 0) {
|
|
||||||
PrintKeySettings(PICCInfo.keySettings, PICCInfo.numKeysRaw, false, true);
|
|
||||||
PrintAndLogEx(SUCCESS, "PICC key 0 version: %d (0x%02x)", PICCInfo.keyVersion0, PICCInfo.keyVersion0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (PICCInfo.appCount > 0) {
|
|
||||||
PrintAndLogEx(NORMAL, "");
|
|
||||||
PrintAndLogEx(SUCCESS, "-------------- " _CYAN_("Alications list") " --------------");
|
|
||||||
|
|
||||||
for (int i = 0; i < PICCInfo.appCount; i++) {
|
|
||||||
PrintAndLogEx(SUCCESS, _CYAN_("Application number: 0x%02x") " iso id: " _GREEN_("0x%04x") " name: " _GREEN_("%s"), AppList[i].appNum, AppList[i].appISONum, AppList[i].appDFName);
|
|
||||||
|
|
||||||
DesfirePrintAIDFunctions(AppList[i].appNum);
|
|
||||||
|
|
||||||
PrintAndLogEx(SUCCESS, "Auth commands: " NOLF);
|
|
||||||
DesfireCheckAuthCommandsPrint(&AppList[i].authCmdCheck);
|
|
||||||
PrintAndLogEx(SUCCESS, "");
|
|
||||||
if (AppList[i].numberOfKeys > 0) {
|
|
||||||
PrintKeySettings(AppList[i].keySettings, AppList[i].numKeysRaw, true, true);
|
|
||||||
|
|
||||||
if (AppList[i].numberOfKeys > 0) {
|
|
||||||
PrintAndLogEx(SUCCESS, "Key versions [0..%d]: " NOLF, AppList[i].numberOfKeys - 1);
|
|
||||||
for (uint8_t keyn = 0; keyn < AppList[i].numberOfKeys; keyn++) {
|
|
||||||
PrintAndLogEx(NORMAL, "%s %02x" NOLF, (keyn == 0) ? "" : ",", AppList[i].keyVersions[keyn]);
|
|
||||||
}
|
|
||||||
PrintAndLogEx(NORMAL, "\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DropField();
|
DropField();
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
|
|
|
@ -1498,12 +1498,10 @@ static int AppListSearchAID(uint32_t appNum, AppListS AppList, size_t appcount)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int DesfireFillAppList(DesfireContext *dctx, PICCInfoS *PICCInfo, AppListS appList, bool deepmode) {
|
int DesfireFillAppList(DesfireContext *dctx, PICCInfoS *PICCInfo, AppListS appList, bool deepmode, bool readFiles) {
|
||||||
uint8_t buf[250] = {0};
|
uint8_t buf[250] = {0};
|
||||||
size_t buflen = 0;
|
size_t buflen = 0;
|
||||||
|
|
||||||
DesfireFillPICCInfo(dctx, PICCInfo, deepmode);
|
|
||||||
|
|
||||||
int res = DesfireGetAIDList(dctx, buf, &buflen);
|
int res = DesfireGetAIDList(dctx, buf, &buflen);
|
||||||
if (res != PM3_SUCCESS) {
|
if (res != PM3_SUCCESS) {
|
||||||
PrintAndLogEx(ERR, "Desfire GetAIDList command " _RED_("error") ". Result: %d", res);
|
PrintAndLogEx(ERR, "Desfire GetAIDList command " _RED_("error") ". Result: %d", res);
|
||||||
|
@ -1550,11 +1548,19 @@ int DesfireFillAppList(DesfireContext *dctx, PICCInfoS *PICCInfo, AppListS appLi
|
||||||
appList[i].keyVersions[keyn] = buf[0];
|
appList[i].keyVersions[keyn] = buf[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
appList[i].filesReaded = false;
|
||||||
|
if (readFiles) {
|
||||||
|
res = DesfireFillFileList(dctx, appList[i].fileList, &appList[i].filesCount, &appList[i].isoPresent);
|
||||||
|
appList[i].filesReaded = (res == PM3_SUCCESS);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// field on-off zone
|
// field on-off zone
|
||||||
|
DesfireFillPICCInfo(dctx, PICCInfo, deepmode);
|
||||||
|
|
||||||
if (PICCInfo->appCount > 0 && deepmode) {
|
if (PICCInfo->appCount > 0 && deepmode) {
|
||||||
for (int i = 0; i < PICCInfo->appCount; i++) {
|
for (int i = 0; i < PICCInfo->appCount; i++) {
|
||||||
DesfireCheckAuthCommands(appList[i].appNum, appList[i].appDFName, 0, &appList[i].authCmdCheck);
|
DesfireCheckAuthCommands(appList[i].appNum, appList[i].appDFName, 0, &appList[i].authCmdCheck);
|
||||||
|
@ -1564,6 +1570,46 @@ int DesfireFillAppList(DesfireContext *dctx, PICCInfoS *PICCInfo, AppListS appLi
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DesfirePrintPICCInfo(DesfireContext *dctx, PICCInfoS *PICCInfo) {
|
||||||
|
PrintAndLogEx(SUCCESS, "------------------- " _CYAN_("PICC level") " ------------------");
|
||||||
|
PrintAndLogEx(SUCCESS, "Applications count: " _GREEN_("%zu") " free memory " _GREEN_("%d"), PICCInfo->appCount, PICCInfo->freemem);
|
||||||
|
PrintAndLogEx(SUCCESS, "PICC level auth commands: " NOLF);
|
||||||
|
DesfireCheckAuthCommandsPrint(&PICCInfo->authCmdCheck);
|
||||||
|
if (PICCInfo->numberOfKeys > 0) {
|
||||||
|
PrintKeySettings(PICCInfo->keySettings, PICCInfo->numKeysRaw, false, true);
|
||||||
|
PrintAndLogEx(SUCCESS, "PICC key 0 version: %d (0x%02x)", PICCInfo->keyVersion0, PICCInfo->keyVersion0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DesfirePrintAppList(DesfireContext *dctx, PICCInfoS *PICCInfo, AppListS appList) {
|
||||||
|
if (PICCInfo->appCount == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
PrintAndLogEx(NORMAL, "");
|
||||||
|
PrintAndLogEx(SUCCESS, "-------------- " _CYAN_("Alications list") " --------------");
|
||||||
|
|
||||||
|
for (int i = 0; i < PICCInfo->appCount; i++) {
|
||||||
|
PrintAndLogEx(SUCCESS, _CYAN_("Application number: 0x%02x") " iso id: " _GREEN_("0x%04x") " name: " _GREEN_("%s"), appList[i].appNum, appList[i].appISONum, appList[i].appDFName);
|
||||||
|
|
||||||
|
DesfirePrintAIDFunctions(appList[i].appNum);
|
||||||
|
|
||||||
|
PrintAndLogEx(SUCCESS, "Auth commands: " NOLF);
|
||||||
|
DesfireCheckAuthCommandsPrint(&appList[i].authCmdCheck);
|
||||||
|
PrintAndLogEx(SUCCESS, "");
|
||||||
|
if (appList[i].numberOfKeys > 0) {
|
||||||
|
PrintKeySettings(appList[i].keySettings, appList[i].numKeysRaw, true, true);
|
||||||
|
|
||||||
|
if (appList[i].numberOfKeys > 0) {
|
||||||
|
PrintAndLogEx(SUCCESS, "Key versions [0..%d]: " NOLF, appList[i].numberOfKeys - 1);
|
||||||
|
for (uint8_t keyn = 0; keyn < appList[i].numberOfKeys; keyn++) {
|
||||||
|
PrintAndLogEx(NORMAL, "%s %02x" NOLF, (keyn == 0) ? "" : ",", appList[i].keyVersions[keyn]);
|
||||||
|
}
|
||||||
|
PrintAndLogEx(NORMAL, "\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int DesfireCommandEx(DesfireContext *dctx, uint8_t cmd, uint8_t *data, size_t datalen, uint8_t *resp, size_t *resplen, int checklength, size_t splitbysize) {
|
static int DesfireCommandEx(DesfireContext *dctx, uint8_t cmd, uint8_t *data, size_t datalen, uint8_t *resp, size_t *resplen, int checklength, size_t splitbysize) {
|
||||||
if (resplen)
|
if (resplen)
|
||||||
*resplen = 0;
|
*resplen = 0;
|
||||||
|
|
|
@ -106,6 +106,11 @@ typedef struct {
|
||||||
DesfireCryptoAlgorythm keyType; // from numKeysRaw
|
DesfireCryptoAlgorythm keyType; // from numKeysRaw
|
||||||
|
|
||||||
uint8_t keyVersions[16];
|
uint8_t keyVersions[16];
|
||||||
|
|
||||||
|
bool filesReaded;
|
||||||
|
size_t filesCount;
|
||||||
|
bool isoPresent;
|
||||||
|
FileListS fileList;
|
||||||
} AppListElmS;
|
} AppListElmS;
|
||||||
typedef AppListElmS AppListS[64];
|
typedef AppListElmS AppListS[64];
|
||||||
|
|
||||||
|
@ -165,7 +170,9 @@ int DesfireGetUID(DesfireContext *dctx, uint8_t *resp, size_t *resplen);
|
||||||
int DesfireGetAIDList(DesfireContext *dctx, uint8_t *resp, size_t *resplen);
|
int DesfireGetAIDList(DesfireContext *dctx, uint8_t *resp, size_t *resplen);
|
||||||
int DesfireGetDFList(DesfireContext *dctx, uint8_t *resp, size_t *resplen);
|
int DesfireGetDFList(DesfireContext *dctx, uint8_t *resp, size_t *resplen);
|
||||||
int DesfireFillPICCInfo(DesfireContext *dctx, PICCInfoS *PICCInfo, bool deepmode);
|
int DesfireFillPICCInfo(DesfireContext *dctx, PICCInfoS *PICCInfo, bool deepmode);
|
||||||
int DesfireFillAppList(DesfireContext *dctx, PICCInfoS *PICCInfo, AppListS appList, bool deepmode);
|
int DesfireFillAppList(DesfireContext *dctx, PICCInfoS *PICCInfo, AppListS appList, bool deepmode, bool readFiles);
|
||||||
|
void DesfirePrintPICCInfo(DesfireContext *dctx, PICCInfoS *PICCInfo);
|
||||||
|
void DesfirePrintAppList(DesfireContext *dctx, PICCInfoS *PICCInfo, AppListS appList);
|
||||||
|
|
||||||
int DesfireCreateApplication(DesfireContext *dctx, uint8_t *appdata, size_t appdatalen);
|
int DesfireCreateApplication(DesfireContext *dctx, uint8_t *appdata, size_t appdatalen);
|
||||||
int DesfireDeleteApplication(DesfireContext *dctx, uint32_t aid);
|
int DesfireDeleteApplication(DesfireContext *dctx, uint32_t aid);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue