From 566b805357dbd2fbcb8fcabdf68d06bd5c7b2f00 Mon Sep 17 00:00:00 2001 From: George Talusan Date: Sat, 30 Jul 2022 23:30:17 -0400 Subject: [PATCH] add -i to hf emrtd info --- client/src/cmdhfemrtd.c | 82 ++++------------------------------------ client/src/cmdhfemrtd.h | 2 +- client/src/proxgui.cpp | 8 ++-- client/src/proxgui.h | 2 +- client/src/proxguiqt.cpp | 27 +++---------- client/src/proxguiqt.h | 6 +-- 6 files changed, 23 insertions(+), 104 deletions(-) diff --git a/client/src/cmdhfemrtd.c b/client/src/cmdhfemrtd.c index cb656b169..f68f01655 100644 --- a/client/src/cmdhfemrtd.c +++ b/client/src/cmdhfemrtd.c @@ -1433,42 +1433,7 @@ static int emrtd_print_ef_dg2_info(uint8_t *data, size_t datalen) { return PM3_ESOFT; } - bool is_jpg = (data[offset] == 0xFF); - - size_t fn_len = strlen(dg_table[EF_DG2].filename) + 4 + 1; - char *fn = calloc(fn_len, sizeof(uint8_t)); - if (fn == NULL) - return PM3_EMALLOC; - - snprintf(fn, fn_len * sizeof(uint8_t), "%s.%s", dg_table[EF_DG2].filename, (is_jpg) ? "jpg" : "jp2"); - - PrintAndLogEx(DEBUG, "image filename `" _YELLOW_("%s") "`", fn); - - char *path; - if (searchHomeFilePath(&path, NULL, fn, false) != PM3_SUCCESS) { - free(fn); - return PM3_EFILE; - } - free(fn); - - // remove old file - if (fileExists(path)) { - PrintAndLogEx(DEBUG, "Delete old temp file `" _YELLOW_("%s") "`", path); - remove(path); - } - - // temp file. - PrintAndLogEx(DEBUG, "Save temp file `" _YELLOW_("%s") "`", path); - saveFile(path, "", data + offset, datalen); - - PrintAndLogEx(DEBUG, "view temp file `" _YELLOW_("%s") "`", path); - ShowPictureWindow(path); - msleep(500); - - // delete temp file - PrintAndLogEx(DEBUG, "Deleting temp file `" _YELLOW_("%s") "`", path); - remove(path); - //free(path); + ShowPictureWindow(data + offset, datalen); return PM3_SUCCESS; } @@ -1493,42 +1458,7 @@ static int emrtd_print_ef_dg5_info(uint8_t *data, size_t datalen) { return PM3_ESOFT; } - bool is_jpg = (data[offset] == 0xFF); - - size_t fn_len = strlen(dg_table[EF_DG5].filename) + 4 + 1; - char *fn = calloc(fn_len, sizeof(uint8_t)); - if (fn == NULL) - return PM3_EMALLOC; - - snprintf(fn, fn_len * sizeof(uint8_t), "%s.%s", dg_table[EF_DG5].filename, (is_jpg) ? "jpg" : "jp2"); - - PrintAndLogEx(DEBUG, "image filename `" _YELLOW_("%s") "`", fn); - - char *path; - if (searchHomeFilePath(&path, NULL, fn, false) != PM3_SUCCESS) { - free(fn); - return PM3_EFILE; - } - free(fn); - - // remove old file - if (fileExists(path)) { - PrintAndLogEx(DEBUG, "Delete old temp file `" _YELLOW_("%s") "`", path); - remove(path); - } - - // temp file. - PrintAndLogEx(DEBUG, "Save temp file `" _YELLOW_("%s") "`", path); - saveFile(path, "", data + offset, datalen); - - PrintAndLogEx(DEBUG, "view temp file `" _YELLOW_("%s") "`", path); - ShowPictureWindow(path); - msleep(500); - - // delete temp file - PrintAndLogEx(DEBUG, "Deleting temp file `" _YELLOW_("%s") "`", path); - remove(path); - //free(path); + ShowPictureWindow(data + offset, datalen); return PM3_SUCCESS; } @@ -1915,7 +1845,7 @@ static int emrtd_print_ef_cardaccess_info(uint8_t *data, size_t datalen) { return PM3_SUCCESS; } -int infoHF_EMRTD(char *documentnumber, char *dob, char *expiry, bool BAC_available) { +int infoHF_EMRTD(char *documentnumber, char *dob, char *expiry, bool BAC_available, bool only_fast) { uint8_t response[EMRTD_MAX_FILE_SIZE] = { 0x00 }; size_t resplen = 0; uint8_t ssc[8] = { 0x00 }; @@ -2001,7 +1931,7 @@ int infoHF_EMRTD(char *documentnumber, char *dob, char *expiry, bool BAC_availab PrintAndLogEx(INFO, "File tag not found, skipping: %02X", filelist[i]); continue; } - if (dg->fastdump && !dg->pace && !dg->eac) { + if (((dg->fastdump && only_fast) || !only_fast) && !dg->pace && !dg->eac) { if (emrtd_select_and_read(response, &resplen, dg->fileid, ks_enc, ks_mac, ssc, BAC)) { if (dg->parser != NULL) dg->parser(response, resplen); @@ -2263,6 +2193,7 @@ static int CmdHFeMRTDInfo(const char *Cmd) { arg_str0("e", "expiry", "", "expiry in YYMMDD format"), arg_str0("m", "mrz", "<[0-9A-Z<]>", "2nd line of MRZ, 44 chars (passports only)"), arg_str0(NULL, "path", "", "display info from offline dump stored in dirpath"), + arg_lit0("i", "images", "show images"), arg_param_end }; CLIExecWithReturn(ctx, Cmd, argtable, true); @@ -2329,6 +2260,7 @@ static int CmdHFeMRTDInfo(const char *Cmd) { } uint8_t path[FILENAME_MAX] = { 0x00 }; bool is_offline = CLIParamStrToBuf(arg_get_str(ctx, 5), path, sizeof(path), &slen) == 0 && slen > 0; + bool show_images = arg_get_lit(ctx, 6); CLIParserFree(ctx); if ((! IfPm3Iso14443()) && (! is_offline)) { PrintAndLogEx(WARNING, "Only offline mode is available"); @@ -2344,7 +2276,7 @@ static int CmdHFeMRTDInfo(const char *Cmd) { if (g_debugMode >= 2) { SetAPDULogging(true); } - int res = infoHF_EMRTD((char *)docnum, (char *)dob, (char *)expiry, BAC); + int res = infoHF_EMRTD((char *)docnum, (char *)dob, (char *)expiry, BAC, !show_images); SetAPDULogging(restore_apdu_logging); return res; } diff --git a/client/src/cmdhfemrtd.h b/client/src/cmdhfemrtd.h index 1b9588983..962501331 100644 --- a/client/src/cmdhfemrtd.h +++ b/client/src/cmdhfemrtd.h @@ -63,7 +63,7 @@ typedef struct emrtd_pacesdp_s { int CmdHFeMRTD(const char *Cmd); int dumpHF_EMRTD(char *documentnumber, char *dob, char *expiry, bool BAC_available, const char *path); -int infoHF_EMRTD(char *documentnumber, char *dob, char *expiry, bool BAC_available); +int infoHF_EMRTD(char *documentnumber, char *dob, char *expiry, bool BAC_available, bool only_fast); int infoHF_EMRTD_offline(const char *path); #ifdef __cplusplus diff --git a/client/src/proxgui.cpp b/client/src/proxgui.cpp index 5019e1946..9d95a372d 100644 --- a/client/src/proxgui.cpp +++ b/client/src/proxgui.cpp @@ -67,11 +67,13 @@ extern "C" void RepaintGraphWindow(void) { // hook up picture viewer -extern "C" void ShowPictureWindow(char *fn) { +extern "C" void ShowPictureWindow(uint8_t *data, int len) { // No support for jpeg2000 in Qt Image since a while... // https://doc.qt.io/qt-5/qtimageformats-index.html - if (strlen(fn) > 4 && !strcmp(fn + strlen(fn) - 4, ".jp2")) + QImage img = QImage::fromData(data, len); + if (img.isNull()) { return; + } if (!gui) { // Show a notice if X11/XQuartz isn't available #if defined(__MACH__) && defined(__APPLE__) @@ -82,7 +84,7 @@ extern "C" void ShowPictureWindow(char *fn) { return; } - gui->ShowPictureWindow(fn); + gui->ShowPictureWindow(img); } extern "C" void ShowBase64PictureWindow(char *b64) { diff --git a/client/src/proxgui.h b/client/src/proxgui.h index d38d41f1d..56d0d9574 100644 --- a/client/src/proxgui.h +++ b/client/src/proxgui.h @@ -32,7 +32,7 @@ void HideGraphWindow(void); void RepaintGraphWindow(void); // hook up picture viewer -void ShowPictureWindow(char *fn); +void ShowPictureWindow(uint8_t *data, int len); void ShowBase64PictureWindow(char *b64); void HidePictureWindow(void); void RepaintPictureWindow(void); diff --git a/client/src/proxguiqt.cpp b/client/src/proxguiqt.cpp index 6e36af9ee..ff88bce1e 100644 --- a/client/src/proxguiqt.cpp +++ b/client/src/proxguiqt.cpp @@ -65,8 +65,8 @@ void ProxGuiQT::HideGraphWindow(void) { } // emit picture viewer signals -void ProxGuiQT::ShowPictureWindow(char *fn) { - emit ShowPictureWindowSignal(fn); +void ProxGuiQT::ShowPictureWindow(const QImage &img) { + emit ShowPictureWindowSignal(img); } void ProxGuiQT::ShowBase64PictureWindow(char *b64) { @@ -116,24 +116,14 @@ void ProxGuiQT::_HideGraphWindow(void) { } // picture viewer -void ProxGuiQT::_ShowPictureWindow(char *fn) { +void ProxGuiQT::_ShowPictureWindow(const QImage &img) { if (!plotapp) return; - if (fn == NULL) + if (img.isNull()) return; - size_t slen = strlen(fn); - if (slen == 0) - return; - - char *myfn = (char *)calloc(slen + 1, sizeof(uint8_t)); - if (myfn == NULL) - return; - - memcpy(myfn, fn, slen); - if (!pictureWidget) { #if defined(__MACH__) && defined(__APPLE__) @@ -143,12 +133,7 @@ void ProxGuiQT::_ShowPictureWindow(char *fn) { pictureWidget = new PictureWidget(); } - QPixmap pm; - if (pm.load(myfn) == false) { - qWarning("Failed to load %s", myfn); - } - free(myfn); - free(fn); + QPixmap pm = QPixmap::fromImage(img); //QPixmap newPixmap = pm.scaled(QSize(50,50), Qt::KeepAspectRatio); //pm = pm.scaled(pictureController->lbl_pm->size(), Qt::KeepAspectRatio); @@ -264,7 +249,7 @@ void ProxGuiQT::MainLoop() { connect(this, SIGNAL(ExitSignal()), this, SLOT(_Exit())); // hook up picture viewer signals - connect(this, SIGNAL(ShowPictureWindowSignal(char *)), this, SLOT(_ShowPictureWindow(char *))); + connect(this, SIGNAL(ShowPictureWindowSignal(const QImage &)), this, SLOT(_ShowPictureWindow(const QImage &))); connect(this, SIGNAL(ShowBase64PictureWindowSignal(char *)), this, SLOT(_ShowBase64PictureWindow(char *))); connect(this, SIGNAL(RepaintPictureWindowSignal()), this, SLOT(_RepaintPictureWindow())); connect(this, SIGNAL(HidePictureWindowSignal()), this, SLOT(_HidePictureWindow())); diff --git a/client/src/proxguiqt.h b/client/src/proxguiqt.h index 20277f2fd..ac19a99c9 100644 --- a/client/src/proxguiqt.h +++ b/client/src/proxguiqt.h @@ -156,7 +156,7 @@ class ProxGuiQT : public QObject { void HideGraphWindow(void); // hook up picture viewer - void ShowPictureWindow(char *fn); + void ShowPictureWindow(const QImage &img); void ShowBase64PictureWindow(char *b64); void HidePictureWindow(void); void RepaintPictureWindow(void); @@ -170,7 +170,7 @@ class ProxGuiQT : public QObject { void _HideGraphWindow(void); // hook up picture viewer - void _ShowPictureWindow(char *fn); + void _ShowPictureWindow(const QImage &img); void _ShowBase64PictureWindow(char *b64); void _HidePictureWindow(void); void _RepaintPictureWindow(void); @@ -185,7 +185,7 @@ class ProxGuiQT : public QObject { void ExitSignal(void); // hook up picture viewer signals - void ShowPictureWindowSignal(char *fn); + void ShowPictureWindowSignal(const QImage &img); void ShowBase64PictureWindowSignal(char *b64); void HidePictureWindowSignal(void); void RepaintPictureWindowSignal(void);