diff --git a/module/mifare.cpp b/module/mifare.cpp index 1817ad3..912e599 100644 --- a/module/mifare.cpp +++ b/module/mifare.cpp @@ -570,6 +570,17 @@ void Mifare::simulate() ui->funcTab->setCurrentIndex(1); } +void Mifare::loadSniff(const QString& file) +{ + util->execCMD("hf list mf -l " + file); + ui->funcTab->setCurrentIndex(1); +} + +void Mifare::saveSniff(const QString& file) +{ + util->execCMD("hf list mf -s " + file); + ui->funcTab->setCurrentIndex(1); +} void Mifare::data_syncWithDataWidget(bool syncAll, int block) { diff --git a/module/mifare.h b/module/mifare.h index 72c2c87..4d804b6 100644 --- a/module/mifare.h +++ b/module/mifare.h @@ -110,6 +110,8 @@ public: void readAllE(); void wipeE(); void simulate(); + void loadSniff(const QString& file); + void saveSniff(const QString& file); public slots: signals: diff --git a/ui/mainwindow.cpp b/ui/mainwindow.cpp index 21ec486..a396480 100644 --- a/ui/mainwindow.cpp +++ b/ui/mainwindow.cpp @@ -7,7 +7,7 @@ MainWindow::MainWindow(QWidget *parent): { ui->setupUi(this); // ui->MF_simGroupBox->setVisible(false); // developing... - ui->MF_sniffGroupBox->setVisible(false); // developing... +// ui->MF_sniffGroupBox->setVisible(false); // developing... myInfo = new QAction("wh201906", this); connect(myInfo, &QAction::triggered, [ = ]() { @@ -678,3 +678,46 @@ void MainWindow::on_MF_Sim_simButton_clicked() { mifare->simulate(); } + +void MainWindow::on_MF_Sniff_loadButton_clicked() // use a tmp file to support complicated path +{ + QString title = ""; + QString filename = ""; + + title = tr("Plz select the trace file:"); + filename = QFileDialog::getOpenFileName(this, title, "./", tr("Trace Files(*.trc);;All Files(*.*)")); + qDebug() << filename; + if(filename != "") + { + QString tmpFile = "tmp" + QString::number(QDateTime::currentDateTime().toTime_t()) + ".trc"; + if(QFile::copy(filename, "./" + tmpFile)) + { + mifare->loadSniff(tmpFile); + QFile::remove("./" + tmpFile); + } + else + { + QMessageBox::information(this, tr("Info"), tr("Failed to open") + "\n" + filename); + } + } +} + +void MainWindow::on_MF_Sniff_saveButton_clicked() +{ + QString title = ""; + QString filename = ""; + + title = tr("Plz select the location to save trace file:"); + filename = QFileDialog::getSaveFileName(this, title, "./", tr("Trace Files(*.trc)")); + qDebug() << filename; + if(filename != "") + { + QString tmpFile = "tmp" + QString::number(QDateTime::currentDateTime().toTime_t()) + ".trc"; + mifare->saveSniff(tmpFile); + if(!QFile::copy("./" + tmpFile, filename)) + { + QMessageBox::information(this, tr("Info"), tr("Failed to save to") + "\n" + filename); + } + } + +} diff --git a/ui/mainwindow.h b/ui/mainwindow.h index cc3928b..087fc5d 100644 --- a/ui/mainwindow.h +++ b/ui/mainwindow.h @@ -128,6 +128,10 @@ private slots: void on_MF_Sim_simButton_clicked(); + void on_MF_Sniff_loadButton_clicked(); + + void on_MF_Sniff_saveButton_clicked(); + private: Ui::MainWindow* ui; QButtonGroup* typeBtnGroup;