From fbe8a5e51d4e8a14c55c3188634dcfc50e3c5819 Mon Sep 17 00:00:00 2001 From: wh201906 Date: Sat, 8 Aug 2020 11:23:17 +0800 Subject: [PATCH] Fix a small bug --- README.md | 2 +- module/mifare.cpp | 54 ++++++++++++++++++++++++++++++++++++----------- module/mifare.h | 14 ++++++------ ui/mainwindow.cpp | 8 +++++-- 4 files changed, 56 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 1d1dd84..7edf9b7 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ A GUI for [Proxmark3](https://github.com/Proxmark/proxmark3) client + Have a friendly UI to test Mifare cards + Support different card size(MINI, 1K, 2K, 4K) + Easy to edit Mifare data files - + Easy to read all blocks with well-designed read logic + + Easy to read all/selected blocks with well-designed read logic + Support binary(.bin .dump) files and text(.eml) files + Analyze Access Bits + Support Chinese Magic Card diff --git a/module/mifare.cpp b/module/mifare.cpp index 6e1c7da..905f8df 100644 --- a/module/mifare.cpp +++ b/module/mifare.cpp @@ -833,21 +833,51 @@ void Mifare::data_syncWithKeyWidget(bool syncAll, int sector, KeyType keyType) ui->MF_keyWidget->blockSignals(false); } -void Mifare::data_clearData() +void Mifare::data_clearData(bool clearAll) { - dataList->clear(); - for(int i = 0; i < cardType.block_size; i++) - dataList->append(""); + if(clearAll) + { + dataList->clear(); + } + + int delta = cardType.block_size - dataList->length() ; + if(delta >= 0) + { + for(int i = 0; i < delta; i++) + dataList->append(""); + } + else if(delta < 0) + { + for(int i = 0; i < -delta; i++) + + dataList->removeLast(); + } } -void Mifare::data_clearKey() +void Mifare::data_clearKey(bool clearAll) { - keyAList->clear(); - keyBList->clear(); - for(int i = 0; i < cardType.sector_size; i++) + if(clearAll) { - keyAList->append(""); - keyBList->append(""); + keyAList->clear(); + keyBList->clear(); + } + + int delta = cardType.sector_size - keyAList->length() ; + if(delta >= 0) + { + for(int i = 0; i < delta; i++) + { + keyAList->append(""); + keyBList->append(""); + } + } + else if(delta < 0) + { + for(int i = 0; i < -delta; i++) + { + keyAList->removeLast(); + keyBList->removeLast(); + } } } @@ -912,8 +942,8 @@ void Mifare::setCardType(int type) cardType = card_2k; else if(type == 4) cardType = card_4k; - data_clearKey(); - data_clearData(); + data_clearKey(false); + data_clearData(false); } } diff --git a/module/mifare.h b/module/mifare.h index ecc5e2e..4b701e1 100644 --- a/module/mifare.h +++ b/module/mifare.h @@ -46,11 +46,11 @@ public: struct CardType { - int type; - int sector_size; - int block_size; - int blk[40]; - int blks[40]; + quint8 type; + quint8 sector_size; + quint16 block_size; + quint8 blk[40]; + quint8 blks[40]; }; enum AccessType @@ -70,8 +70,8 @@ public: static const AccessType trailerReadCondition[8][3]; static const AccessType trailerWriteCondition[8][3]; - void data_clearData(); - void data_clearKey(); + void data_clearData(bool clearAll = true); + void data_clearKey(bool clearAll = true); static bool data_isKeyValid(const QString& key); static Mifare::DataType data_isDataValid(const QString& data); void data_syncWithDataWidget(bool syncAll = true, int block = 0); diff --git a/ui/mainwindow.cpp b/ui/mainwindow.cpp index 96390b5..29270d9 100644 --- a/ui/mainwindow.cpp +++ b/ui/mainwindow.cpp @@ -181,7 +181,7 @@ void MainWindow::MF_onTypeChanged(int id, bool st) int result; if(id > typeBtnGroup->checkedId()) // id is specified in uiInit() with a proper order, so I can compare the size by id. { - result = QMessageBox::question(this, tr("Info"), tr("When Changeing card type, the data and keys in this app will be cleard.") + "\n" + tr("Continue?"), QMessageBox::Yes | QMessageBox::No); + result = QMessageBox::question(this, tr("Info"), tr("Some of the data and key will be cleared.") + "\n" + tr("Continue?"), QMessageBox::Yes | QMessageBox::No); } else { @@ -192,6 +192,8 @@ void MainWindow::MF_onTypeChanged(int id, bool st) qDebug() << "Yes"; mifare->setCardType(typeBtnGroup->checkedId()); MF_widgetReset(); + mifare->data_syncWithDataWidget(); + mifare->data_syncWithKeyWidget(); } else { @@ -698,6 +700,7 @@ void MainWindow::MF_widgetReset() ui->MF_dataWidget->setRowCount(blks); ui->MF_dataWidget->blockSignals(true); + ui->MF_keyWidget->blockSignals(true); ui->MF_selectAllBox->blockSignals(true); for(int i = 0; i < blks; i++) @@ -720,6 +723,7 @@ void MainWindow::MF_widgetReset() ui->MF_selectAllBox->setCheckState(Qt::Checked); ui->MF_dataWidget->blockSignals(false); + ui->MF_keyWidget->blockSignals(false); ui->MF_selectAllBox->blockSignals(false); } // ************************************************ @@ -746,7 +750,7 @@ void MainWindow::uiInit() ui->MF_dataWidget->setHorizontalHeaderItem(1, new QTableWidgetItem(tr("Blk"))); ui->MF_dataWidget->setHorizontalHeaderItem(2, new QTableWidgetItem(tr("Data"))); ui->MF_dataWidget->verticalHeader()->setVisible(false); - ui->MF_dataWidget->setColumnWidth(0, 45); + ui->MF_dataWidget->setColumnWidth(0, 55); ui->MF_dataWidget->setColumnWidth(1, 55); ui->MF_dataWidget->setColumnWidth(2, 430);