From a6a699d33cd84c648689e6608f025836b91e8d1e Mon Sep 17 00:00:00 2001
From: wh201906 <62299611+wh201906@users.noreply.github.com>
Date: Wed, 22 Apr 2020 16:00:56 +0800
Subject: [PATCH] Make execCmd() adapted to QThread
---
Proxmark3GUI.pro | 6 +++--
mainwindow.cpp | 19 +++++++-------
mainwindow.h | 3 ++-
mainwindow.ui | 64 ++++++++++++++++++++++++++++++++++++++----------
pm3process.cpp | 8 +++++-
pm3process.h | 1 +
util.cpp | 6 +++++
util.h | 16 ++++++++++++
8 files changed, 97 insertions(+), 26 deletions(-)
create mode 100644 util.cpp
create mode 100644 util.h
diff --git a/Proxmark3GUI.pro b/Proxmark3GUI.pro
index fb350ff..642c458 100644
--- a/Proxmark3GUI.pro
+++ b/Proxmark3GUI.pro
@@ -20,13 +20,15 @@ SOURCES += \
mainwindow.cpp \
mf_attack_hardnesteddialog.cpp \
mifare.cpp \
- pm3process.cpp
+ pm3process.cpp \
+ util.cpp
HEADERS += \
mainwindow.h \
mf_attack_hardnesteddialog.h \
mifare.h \
- pm3process.h
+ pm3process.h \
+ util.h
FORMS += \
mainwindow.ui \
diff --git a/mainwindow.cpp b/mainwindow.cpp
index ae5f08d..f68f91f 100644
--- a/mainwindow.cpp
+++ b/mainwindow.cpp
@@ -23,6 +23,7 @@ MainWindow::MainWindow(QWidget *parent)
MainWindow::~MainWindow()
{
delete ui;
+ emit killPM3();
pm3Thread->exit(0);
pm3Thread->wait(5000);
delete pm3;
@@ -62,7 +63,6 @@ void MainWindow::on_PM3_connectButton_clicked()
QMessageBox::information(NULL, "Info", "Plz choose a port first", QMessageBox::Ok);
else
{
- emit requiringOutput(true);
emit connectPM3(ui->PM3_pathEdit->text(), port);
}
}
@@ -95,11 +95,7 @@ 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())
- ui->Raw_CMDHistoryWidget->addItem(ui->Raw_CMDEdit->text());
- qDebug() << (ui->Raw_CMDEdit->text().toLocal8Bit());
- pm3->write((ui->Raw_CMDEdit->text() + "\r\n").toLocal8Bit());
- pm3->waitForBytesWritten(3000);
+ execCMD(ui->Raw_CMDEdit->text());
}
void MainWindow::on_Raw_clearOutputButton_clicked()
@@ -466,6 +462,8 @@ void MainWindow::signalInit()
connect(this,&MainWindow::connectPM3,pm3,&PM3Process::connectPM3);
connect(pm3, &PM3Process::PM3StatedChanged, this, &MainWindow::onPM3StateChanged);
connect(this,&MainWindow::killPM3,pm3,&PM3Process::kill);
+
+ connect(this,&MainWindow::write,pm3,&PM3Process::write);
}
void MainWindow::setStatusBar(QLabel* target, const QString & text)
@@ -481,15 +479,18 @@ void MainWindow::setStatusBar(QLabel* target, const QString & text)
void MainWindow::execCMD(QString cmd, bool gotoRawTab)
{
ui->Raw_CMDEdit->setText(cmd);
- on_Raw_sendCMDButton_clicked();
+ if(ui->Raw_CMDHistoryWidget->count() == 0 || ui->Raw_CMDHistoryWidget->item(ui->Raw_CMDHistoryWidget->count() - 1)->text() != cmd)
+ ui->Raw_CMDHistoryWidget->addItem(cmd);
+ qDebug() << cmd;
+ emit write(cmd + "\r\n");
if(gotoRawTab)
ui->funcTab->setCurrentIndex(1);
}
QString MainWindow::execCMDWithOutput(QString cmd, int msec)
{
- pm3->setRequiringOutput(true);
- execCMD(cmd, false);
+ emit requiringOutput(true);
+ execCMD(cmd);
while(pm3->waitForReadyRead(msec))
;
pm3->setRequiringOutput(false);
diff --git a/mainwindow.h b/mainwindow.h
index 22d200c..274fcdd 100644
--- a/mainwindow.h
+++ b/mainwindow.h
@@ -31,7 +31,7 @@ public:
public slots:
void refresh();
void setStatusBar(QLabel* target,const QString & text);
- void execCMD(QString cmd, bool gotoRawTab);
+ void execCMD(QString cmd, bool gotoRawTab=false);
void onPM3StateChanged(bool st, QString info);
private slots:
@@ -89,5 +89,6 @@ signals:
void connectPM3(const QString path, const QString port);
void killPM3();
void setSerialListener(const QString &name, bool state);
+ void write(QString data);
};
#endif // MAINWINDOW_H
diff --git a/mainwindow.ui b/mainwindow.ui
index 6f068e7..0b6dfe6 100644
--- a/mainwindow.ui
+++ b/mainwindow.ui
@@ -623,6 +623,44 @@
+ -
+
+
+
+ 0
+ 30
+
+
+
+
+ 16777215
+ 40
+
+
+
+ Lock UFUID Card
+
+
+
+ -
+
+
+
+ 0
+ 30
+
+
+
+
+ 16777215
+ 40
+
+
+
+ About UID Card
+
+
+
-
@@ -848,6 +886,19 @@
-
+
-
+
+
+ Qt::LeftToRight
+
+
+ History:
+
+
+ false
+
+
+
-
@@ -874,19 +925,6 @@
- -
-
-
- Qt::LeftToRight
-
-
- History:
-
-
- false
-
-
-
diff --git a/pm3process.cpp b/pm3process.cpp
index 89afea0..308862d 100644
--- a/pm3process.cpp
+++ b/pm3process.cpp
@@ -77,7 +77,7 @@ void PM3Process::setSerialListener(const QString& name,bool state)
}
}
-void PM3Process::onTimeout()
+void PM3Process::onTimeout() //when the proxmark3 client is unexpectedly terminated or the PM3 hardware is removed, the isBusy() will return false(tested on Windows);
{
qDebug()<isBusy();
if(!portInfo->isBusy())
@@ -92,3 +92,9 @@ void PM3Process::testThread()
{
qDebug()<<"PM3:"<
+
+class Util : public QObject
+{
+ Q_OBJECT
+public:
+ explicit Util(QObject *parent = nullptr);
+
+signals:
+
+};
+
+#endif // UTIL_H