From c25e2f9e4a2d5471d32fe34c7355f3bfe4e0c2a2 Mon Sep 17 00:00:00 2001 From: wh201906 <62299611+wh201906@users.noreply.github.com> Date: Thu, 16 Apr 2020 00:39:10 +0800 Subject: [PATCH] Add MF_ReadAll function --- mainwindow.cpp | 233 +++++++++++++++++++++++++++++++------------------ mainwindow.h | 4 + mainwindow.ui | 34 ++++---- pm3process.cpp | 1 + pm3process.h | 2 +- 5 files changed, 171 insertions(+), 103 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index 45d97f3..9839938 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -6,10 +6,10 @@ MainWindow::MainWindow(QWidget *parent) , ui(new Ui::MainWindow) { ui->setupUi(this); - pm3=new PM3Process; - mifare=new Mifare; - connect(pm3,&PM3Process::readyRead,this,&MainWindow::refresh); - connect(ui->Raw_CMDEdit,&QLineEdit::editingFinished,this,&MainWindow::sendMSG); + pm3 = new PM3Process; + mifare = new Mifare; + connect(pm3, &PM3Process::readyRead, this, &MainWindow::refresh); + connect(ui->Raw_CMDEdit, &QLineEdit::editingFinished, this, &MainWindow::sendMSG); uiInit(); } @@ -24,7 +24,7 @@ void MainWindow::on_PM3_refreshPortButton_clicked() { ui->PM3_portBox->clear(); ui->PM3_portBox->addItem(""); - foreach(QString port,pm3->findPort()) + foreach(QString port, pm3->findPort()) { ui->PM3_portBox->addItem(port); } @@ -32,21 +32,21 @@ void MainWindow::on_PM3_refreshPortButton_clicked() void MainWindow::on_PM3_connectButton_clicked() { - QString port=ui->PM3_portBox->currentText(); - if(port=="") + QString port = ui->PM3_portBox->currentText(); + if(port == "") QMessageBox::information(NULL, "Info", "Plz choose a port first", QMessageBox::Ok); else { pm3->setRequiringOutput(true); - qDebug()<start(ui->PM3_pathEdit->text(),port); + qDebug() << pm3->start(ui->PM3_pathEdit->text(), port); while(pm3->waitForReadyRead()) ; - QString result=pm3->getRequiredOutput(); + QString result = pm3->getRequiredOutput(); pm3->setRequiringOutput(false); - result=result.mid(result.indexOf("os: ")); - result=result.left(result.indexOf("\r\n")); - result=result.mid(3,result.lastIndexOf(" ")-3); - setStatusBar(PM3VersionBar,result); + result = result.mid(result.indexOf("os: ")); + result = result.left(result.indexOf("\r\n")); + result = result.mid(3, result.lastIndexOf(" ") - 3); + setStatusBar(PM3VersionBar, result); } } @@ -61,10 +61,10 @@ void MainWindow::on_PM3_disconnectButton_clicked() void MainWindow::on_Raw_sendCMDButton_clicked() { - if(ui->Raw_CMDHistoryWidget->count()==0 || ui->Raw_CMDHistoryWidget->item(ui->Raw_CMDHistoryWidget->count()-1)->text()!=ui->Raw_CMDEdit->text()) + if(ui->Raw_CMDHistoryWidget->count() == 0 || ui->Raw_CMDHistoryWidget->item(ui->Raw_CMDHistoryWidget->count() - 1)->text() != ui->Raw_CMDEdit->text()) ui->Raw_CMDHistoryWidget->addItem(ui->Raw_CMDEdit->text()); - qDebug()<<(ui->Raw_CMDEdit->text().toLocal8Bit()); - pm3->write((ui->Raw_CMDEdit->text()+"\r\n").toLocal8Bit()); + qDebug() << (ui->Raw_CMDEdit->text().toLocal8Bit()); + pm3->write((ui->Raw_CMDEdit->text() + "\r\n").toLocal8Bit()); pm3->waitForBytesWritten(3000); } @@ -110,58 +110,99 @@ void MainWindow::on_Raw_CMDHistoryWidget_itemDoubleClicked(QListWidgetItem *item void MainWindow::on_MF_Attack_chkButton_clicked() { - pm3->setRequiringOutput(true); - execCMD("hf mf chk *1 ?",false); - on_Raw_sendCMDButton_clicked(); - while(pm3->waitForReadyRead()) - ; - QString result=pm3->getRequiredOutput(); - pm3->setRequiringOutput(false); - result=result.mid(result.indexOf("|---|----------------|----------------|")); - QStringList keys=result.split("\r\n"); - for(int i=0;i<16;i++) + QString result = execCMDWithOutput("hf mf chk *1 ?"); + result = result.mid(result.indexOf("|---|----------------|----------------|")); + QStringList keys = result.split("\r\n"); + for(int i = 0; i < 16; i++) { - ui->MF_keyWidget->setItem(i,1,new QTableWidgetItem(keys[i+3].mid(7,12).trimmed().toUpper())); - ui->MF_keyWidget->setItem(i,2,new QTableWidgetItem(keys[i+3].mid(24,12).trimmed().toUpper())); + ui->MF_keyWidget->setItem(i, 1, new QTableWidgetItem(keys[i + 3].mid(7, 12).trimmed().toUpper())); + ui->MF_keyWidget->setItem(i, 2, new QTableWidgetItem(keys[i + 3].mid(24, 12).trimmed().toUpper())); } - qDebug()<<"***********\n"<setRequiringOutput(true); - execCMD("hf mf nested 1 *",false); - while(pm3->waitForReadyRead()) - ; - QString result=pm3->getRequiredOutput(); - pm3->setRequiringOutput(false); - result=result.mid(result.indexOf("|---|----------------|---|----------------|---|")); - QStringList keys=result.split("\r\n"); - for(int i=0;i<16;i++) + QString result = execCMDWithOutput("hf mf nested 1 *"); + result = result.mid(result.indexOf("|---|----------------|---|----------------|---|")); + QStringList keys = result.split("\r\n"); + for(int i = 0; i < 16; i++) { - if(keys[i+3].at(23)=='1') - ui->MF_keyWidget->setItem(i,1,new QTableWidgetItem(keys[i+3].mid(7,12).trimmed().toUpper())); - if(keys[i+3].at(44)=='1') - ui->MF_keyWidget->setItem(i,2,new QTableWidgetItem(keys[i+3].mid(28,12).trimmed().toUpper())); + if(keys[i + 3].at(23) == '1') + ui->MF_keyWidget->setItem(i, 1, new QTableWidgetItem(keys[i + 3].mid(7, 12).trimmed().toUpper())); + if(keys[i + 3].at(44) == '1') + ui->MF_keyWidget->setItem(i, 2, new QTableWidgetItem(keys[i + 3].mid(28, 12).trimmed().toUpper())); } - qDebug()<<"***********\n"<MF_keyWidget->item(i, 1)->text())) + { + result = execCMDWithOutput("hf mf rdbl " + + QString::number(4 * i) + + " A " + + ui->MF_keyWidget->item(i, 1)->text(),waitTime); + if(result.indexOf("isOk:01") != -1) + { + validkey = 1; + ui->MF_dataWidget->setItem(4 * i, 2,new QTableWidgetItem(result.mid(result.indexOf("isOk:01")+13, 47).toUpper())); + } + } + if(validkey == -1 && MF_isKeyValid(ui->MF_keyWidget->item(i, 2)->text())) + { + result = execCMDWithOutput("hf mf rdbl " + + QString::number(4 * i) + + " B " + + ui->MF_keyWidget->item(i, 2)->text(),waitTime); + if(result.indexOf("isOk:01") != -1) + { + validkey = 2; + ui->MF_dataWidget->setItem(4 * i, 2,new QTableWidgetItem(result.mid(result.indexOf("isOk:01")+13, 47).toUpper())); + } + } + if(validkey!=-1) + { + for(int j = 1; j < 4; j++) + { + QApplication::processEvents(); + result = execCMDWithOutput("hf mf rdbl " + + QString::number(4 * i + j) + + " " + + (validkey==1?"A":"B") + + " " + + ui->MF_keyWidget->item(i, validkey)->text(),waitTime); + ui->MF_dataWidget->setItem(4 * i + j, 2,new QTableWidgetItem(result.mid(result.indexOf("isOk:01")+13, 47).toUpper())); + } + } + } + } // ************************************************ @@ -171,12 +212,12 @@ void MainWindow::on_MF_Attack_listButton_clicked() void MainWindow::refresh() { - QString btay=pm3->readLine(); - while(btay!="") + QString btay = pm3->readLine(); + while(btay != "") { - qDebug()<Raw_outputEdit->insertPlainText(btay); - btay=pm3->readLine(); + btay = pm3->readLine(); } ui->Raw_outputEdit->moveCursor(QTextCursor::End); } @@ -189,61 +230,83 @@ void MainWindow::sendMSG() void MainWindow::uiInit() { - connectStatusBar=new QLabel(this); - programStatusBar=new QLabel(this); - PM3VersionBar=new QLabel(this); - setStatusBar(connectStatusBar,"Not Connected"); - setStatusBar(programStatusBar,"Idle"); - setStatusBar(PM3VersionBar,""); - ui->statusbar->addPermanentWidget(PM3VersionBar,1); - ui->statusbar->addPermanentWidget(connectStatusBar,1); - ui->statusbar->addPermanentWidget(programStatusBar,1); + connectStatusBar = new QLabel(this); + programStatusBar = new QLabel(this); + PM3VersionBar = new QLabel(this); + setStatusBar(connectStatusBar, "Not Connected"); + setStatusBar(programStatusBar, "Idle"); + setStatusBar(PM3VersionBar, ""); + ui->statusbar->addPermanentWidget(PM3VersionBar, 1); + ui->statusbar->addPermanentWidget(connectStatusBar, 1); + ui->statusbar->addPermanentWidget(programStatusBar, 1); ui->MF_dataWidget->setColumnCount(3); ui->MF_dataWidget->setRowCount(64); - ui->MF_dataWidget->setHorizontalHeaderItem(0,new QTableWidgetItem("Sector")); - ui->MF_dataWidget->setHorizontalHeaderItem(1,new QTableWidgetItem("Block")); - ui->MF_dataWidget->setHorizontalHeaderItem(2,new QTableWidgetItem("Data")); - for(int i=0;i<64;i++) - ui->MF_dataWidget->setItem(i,1,new QTableWidgetItem(QString::number(i))); - for(int i=0;i<16;i++) - ui->MF_dataWidget->setItem(i*4,0,new QTableWidgetItem(QString::number(i))); + ui->MF_dataWidget->setHorizontalHeaderItem(0, new QTableWidgetItem("Sector")); + ui->MF_dataWidget->setHorizontalHeaderItem(1, new QTableWidgetItem("Block")); + ui->MF_dataWidget->setHorizontalHeaderItem(2, new QTableWidgetItem("Data")); + for(int i = 0; i < 64; i++) + ui->MF_dataWidget->setItem(i, 1, new QTableWidgetItem(QString::number(i))); + for(int i = 0; i < 16; i++) + ui->MF_dataWidget->setItem(i * 4, 0, new QTableWidgetItem(QString::number(i))); ui->MF_dataWidget->verticalHeader()->setVisible(false); - ui->MF_dataWidget->setColumnWidth(0,50); - ui->MF_dataWidget->setColumnWidth(1,40); - ui->MF_dataWidget->setColumnWidth(2,400); + ui->MF_dataWidget->setColumnWidth(0, 50); + ui->MF_dataWidget->setColumnWidth(1, 40); + ui->MF_dataWidget->setColumnWidth(2, 400); ui->MF_keyWidget->setColumnCount(3); ui->MF_keyWidget->setRowCount(16); - ui->MF_keyWidget->setHorizontalHeaderItem(0,new QTableWidgetItem("Sector")); - ui->MF_keyWidget->setHorizontalHeaderItem(1,new QTableWidgetItem("KeyA")); - ui->MF_keyWidget->setHorizontalHeaderItem(2,new QTableWidgetItem("KeyB")); - for(int i=0;i<16;i++) - ui->MF_keyWidget->setItem(i,0,new QTableWidgetItem(QString::number(i))); + ui->MF_keyWidget->setHorizontalHeaderItem(0, new QTableWidgetItem("Sector")); + ui->MF_keyWidget->setHorizontalHeaderItem(1, new QTableWidgetItem("KeyA")); + ui->MF_keyWidget->setHorizontalHeaderItem(2, new QTableWidgetItem("KeyB")); + for(int i = 0; i < 16; i++) + ui->MF_keyWidget->setItem(i, 0, new QTableWidgetItem(QString::number(i))); ui->MF_keyWidget->verticalHeader()->setVisible(false); - ui->MF_keyWidget->setColumnWidth(0,50); - ui->MF_keyWidget->setColumnWidth(1,200); - ui->MF_keyWidget->setColumnWidth(2,200); + ui->MF_keyWidget->setColumnWidth(0, 50); + ui->MF_keyWidget->setColumnWidth(1, 200); + ui->MF_keyWidget->setColumnWidth(2, 200); on_Raw_moreFuncCheckBox_stateChanged(0); on_PM3_refreshPortButton_clicked(); } -void MainWindow::setStatusBar(QLabel* target,const QString & text) +void MainWindow::setStatusBar(QLabel* target, const QString & text) { - if(target==PM3VersionBar) - target->setText("Version:"+text); - else if(target==connectStatusBar) - target->setText("Connecton State:"+text); - else if(target==programStatusBar) - target->setText("Program State:"+text); + if(target == PM3VersionBar) + target->setText("Version:" + text); + else if(target == connectStatusBar) + target->setText("Connecton State:" + text); + else if(target == programStatusBar) + target->setText("Program State:" + text); } -void MainWindow::execCMD(QString cmd,bool gotoRawTab) +void MainWindow::execCMD(QString cmd, bool gotoRawTab) { ui->Raw_CMDEdit->setText(cmd); on_Raw_sendCMDButton_clicked(); if(gotoRawTab) ui->funcTab->setCurrentIndex(1); } + +QString MainWindow::execCMDWithOutput(QString cmd, int msec) +{ + pm3->setRequiringOutput(true); + execCMD(cmd, false); + while(pm3->waitForReadyRead(msec)) + ; + pm3->setRequiringOutput(false); + return pm3->getRequiredOutput(); +} + +bool MainWindow::MF_isKeyValid(const QString key) +{ + if(key.length() != 12) + return false; + for(int i = 0; i < 12; i++) + { + if(!((key[i] >= '0' && key[i] <= '9') || (key[i] >= 'A' && key[i] <= 'F'))) + return false; + } + return true; +} // *********************************************** diff --git a/mainwindow.h b/mainwindow.h index c9241aa..1d9cf0a 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -22,6 +22,8 @@ public: MainWindow(QWidget *parent = nullptr); ~MainWindow(); + bool MF_isKeyValid(const QString key); + QString execCMDWithOutput(QString cmd, int msec=2000); public slots: void refresh(); void setStatusBar(QLabel* target,const QString & text); @@ -55,6 +57,8 @@ private slots: void on_MF_Attack_listButton_clicked(); + void on_MF_RW_readAllButton_clicked(); + private: Ui::MainWindow *ui; PM3Process* pm3; diff --git a/mainwindow.ui b/mainwindow.ui index 4deb05c..25d4a20 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -161,7 +161,7 @@ 0 - 40 + 30 @@ -180,7 +180,7 @@ 0 - 40 + 30 @@ -199,7 +199,7 @@ 0 - 40 + 30 @@ -218,7 +218,7 @@ 0 - 40 + 30 @@ -237,7 +237,7 @@ 0 - 40 + 30 @@ -293,7 +293,7 @@ 0 - 40 + 30 @@ -312,7 +312,7 @@ 0 - 40 + 30 @@ -337,7 +337,7 @@ 0 - 40 + 30 @@ -362,7 +362,7 @@ 0 - 40 + 30 @@ -499,7 +499,7 @@ 0 - 40 + 30 @@ -518,7 +518,7 @@ 0 - 40 + 30 @@ -543,7 +543,7 @@ 0 - 40 + 30 @@ -568,7 +568,7 @@ 0 - 40 + 30 @@ -678,7 +678,7 @@ 0 - 40 + 30 @@ -697,7 +697,7 @@ 0 - 40 + 30 @@ -716,7 +716,7 @@ 0 - 40 + 30 @@ -735,7 +735,7 @@ 0 - 40 + 30 diff --git a/pm3process.cpp b/pm3process.cpp index 52ce4b2..0a498cf 100644 --- a/pm3process.cpp +++ b/pm3process.cpp @@ -53,3 +53,4 @@ bool PM3Process::waitForReadyRead(int msecs) { return QProcess::waitForReadyRead(msecs); } + diff --git a/pm3process.h b/pm3process.h index c3e1563..6184548 100644 --- a/pm3process.h +++ b/pm3process.h @@ -17,7 +17,7 @@ public: QByteArray readLine(qint64 maxlen = 0); void setRequiringOutput(bool st); QString getRequiredOutput(); - bool waitForReadyRead(int msecs = 3000); + bool waitForReadyRead(int msecs = 2000); private: bool isRequiringOutput; QString* requiredOutput;