Optimize the read logic and complete PM3 connection state

pull/2/head
wh201906 5 years ago
parent b540741b1a
commit 80a8db540f

@ -9,6 +9,7 @@ MainWindow::MainWindow(QWidget *parent)
pm3 = new PM3Process; pm3 = new PM3Process;
mifare = new Mifare; mifare = new Mifare;
connect(pm3, &PM3Process::readyRead, this, &MainWindow::refresh); connect(pm3, &PM3Process::readyRead, this, &MainWindow::refresh);
connect(pm3, &PM3Process::PM3disconnected, this, &MainWindow::onPM3disconnected);
connect(ui->Raw_CMDEdit, &QLineEdit::editingFinished, this, &MainWindow::sendMSG); connect(ui->Raw_CMDEdit, &QLineEdit::editingFinished, this, &MainWindow::sendMSG);
uiInit(); uiInit();
} }
@ -38,21 +39,31 @@ void MainWindow::on_PM3_connectButton_clicked()
else else
{ {
pm3->setRequiringOutput(true); pm3->setRequiringOutput(true);
qDebug() << pm3->start(ui->PM3_pathEdit->text(), port); if(pm3->start(ui->PM3_pathEdit->text(), port))
while(pm3->waitForReadyRead()) {
; while(pm3->waitForReadyRead())
QString result = pm3->getRequiredOutput(); ;
pm3->setRequiringOutput(false); QString result = pm3->getRequiredOutput();
result = result.mid(result.indexOf("os: ")); pm3->setRequiringOutput(false);
result = result.left(result.indexOf("\r\n")); result = result.mid(result.indexOf("os: "));
result = result.mid(3, result.lastIndexOf(" ") - 3); result = result.left(result.indexOf("\r\n"));
setStatusBar(PM3VersionBar, result); result = result.mid(3, result.lastIndexOf(" ") - 3);
setStatusBar(PM3VersionBar, result);
setStatusBar(connectStatusBar,"Connected");
}
} }
} }
void MainWindow::on_PM3_disconnectButton_clicked() void MainWindow::on_PM3_disconnectButton_clicked()
{ {
pm3->kill(); pm3->kill();
pm3->setSerialListener("",false);
onPM3disconnected();
}
void MainWindow::onPM3disconnected()
{
setStatusBar(connectStatusBar,"Not Connected");
} }
// ********************************************************* // *********************************************************
@ -108,6 +119,11 @@ void MainWindow::on_Raw_CMDHistoryWidget_itemDoubleClicked(QListWidgetItem *item
// ******************** mifare ******************** // ******************** mifare ********************
void MainWindow::on_MF_Attack_infoButton_clicked()
{
execCMD("hf 14a info", true);
}
void MainWindow::on_MF_Attack_chkButton_clicked() void MainWindow::on_MF_Attack_chkButton_clicked()
{ {
QString result = execCMDWithOutput("hf mf chk *1 ?"); QString result = execCMDWithOutput("hf mf chk *1 ?");
@ -252,6 +268,7 @@ void MainWindow::on_MF_RW_readAllButton_clicked()
} }
else else
{ {
result=ui->MF_dataWidget->item(4 * i + 3, 2)->text();
result = result.replace(30, 17, "?? ?? ?? ?? ?? ??"); result = result.replace(30, 17, "?? ?? ?? ?? ?? ??");
ui->MF_dataWidget->setItem(4 * i + 3, 2, new QTableWidgetItem(result)); ui->MF_dataWidget->setItem(4 * i + 3, 2, new QTableWidgetItem(result));
} }
@ -264,7 +281,7 @@ void MainWindow::on_MF_RW_readAllButton_clicked()
void MainWindow::on_MF_RW_readBlockButton_clicked() void MainWindow::on_MF_RW_readBlockButton_clicked()
{ {
QString result = execCMDWithOutput("hf mf rdbl " QString result = execCMDWithOutput("hf mf rdbl "
+ ui->MF_RW_blockBox->text() + ui->MF_RW_blockBox->currentText()
+ " " + " "
+ ui->MF_RW_keyTypeBox->currentText() + ui->MF_RW_keyTypeBox->currentText()
+ " " + " "
@ -272,7 +289,7 @@ void MainWindow::on_MF_RW_readBlockButton_clicked()
if(result.indexOf("isOk:01") != -1) if(result.indexOf("isOk:01") != -1)
{ {
result = result.mid(result.indexOf("isOk:01") + 13, 47).toUpper(); result = result.mid(result.indexOf("isOk:01") + 13, 47).toUpper();
if((ui->MF_RW_blockBox->text().toInt() + 1) % 4 == 0) if((ui->MF_RW_blockBox->currentText().toInt() + 1) % 4 == 0)
{ {
if(ui->MF_RW_keyTypeBox->currentText() == "A") if(ui->MF_RW_keyTypeBox->currentText() == "A")
{ {
@ -280,20 +297,37 @@ void MainWindow::on_MF_RW_readBlockButton_clicked()
{ {
result = result.replace(i * 3, 2, ui->MF_RW_keyEdit->text().mid(i * 2, 2)); result = result.replace(i * 3, 2, ui->MF_RW_keyEdit->text().mid(i * 2, 2));
} }
ui->MF_RW_dataEdit->setText(result);
QString tmpKey=result.right(18).replace(" ","");
result = execCMDWithOutput("hf mf rdbl "
+ ui->MF_RW_keyTypeBox->currentText()
+ " B "
+ tmpKey);
if(result.indexOf("isOk:01") == -1)
{
result= ui->MF_RW_dataEdit->text();
result = result.replace(30, 17, "?? ?? ?? ?? ?? ??");
ui->MF_RW_dataEdit->setText(result);
}
} }
else else
{ {
for(int i = 0; i < 6; i++)
{
result = result.replace(30 + i * 3, 2, ui->MF_RW_keyEdit->text().mid(i * 2, 2));
}
result = result.replace(0, 18, "?? ?? ?? ?? ?? ?? "); result = result.replace(0, 18, "?? ?? ?? ?? ?? ?? ");
ui->MF_RW_dataEdit->setText(result);
} }
} }
ui->MF_RW_dataEdit->setText(result);
} }
} }
void MainWindow::on_MF_RW_writeBlockButton_clicked() void MainWindow::on_MF_RW_writeBlockButton_clicked()
{ {
QString result = execCMDWithOutput("hf mf wrbl " QString result = execCMDWithOutput("hf mf wrbl "
+ ui->MF_RW_blockBox->text() + ui->MF_RW_blockBox->currentText()
+ " " + " "
+ ui->MF_RW_keyTypeBox->currentText() + ui->MF_RW_keyTypeBox->currentText()
+ " " + " "
@ -367,6 +401,12 @@ void MainWindow::uiInit()
ui->MF_keyWidget->setColumnWidth(1, 200); ui->MF_keyWidget->setColumnWidth(1, 200);
ui->MF_keyWidget->setColumnWidth(2, 200); ui->MF_keyWidget->setColumnWidth(2, 200);
for(int i=0;i<64;i++)
{
ui->MF_RW_blockBox->addItem(QString::number(i));
ui->MF_UID_blockBox->addItem(QString::number(i));
}
on_Raw_moreFuncCheckBox_stateChanged(0); on_Raw_moreFuncCheckBox_stateChanged(0);
on_PM3_refreshPortButton_clicked(); on_PM3_refreshPortButton_clicked();
} }
@ -374,7 +414,7 @@ void MainWindow::uiInit()
void MainWindow::setStatusBar(QLabel* target, const QString & text) void MainWindow::setStatusBar(QLabel* target, const QString & text)
{ {
if(target == PM3VersionBar) if(target == PM3VersionBar)
target->setText("Version:" + text); target->setText("HW Version:" + text);
else if(target == connectStatusBar) else if(target == connectStatusBar)
target->setText("Connecton State:" + text); target->setText("Connecton State:" + text);
else if(target == programStatusBar) else if(target == programStatusBar)
@ -411,3 +451,4 @@ bool MainWindow::MF_isKeyValid(const QString key)
return true; return true;
} }
// *********************************************** // ***********************************************

@ -28,6 +28,7 @@ public slots:
void refresh(); void refresh();
void setStatusBar(QLabel* target,const QString & text); void setStatusBar(QLabel* target,const QString & text);
void execCMD(QString cmd, bool gotoRawTab); void execCMD(QString cmd, bool gotoRawTab);
void onPM3disconnected();
private slots: private slots:
void on_PM3_connectButton_clicked(); void on_PM3_connectButton_clicked();
@ -63,6 +64,8 @@ private slots:
void on_MF_RW_writeBlockButton_clicked(); void on_MF_RW_writeBlockButton_clicked();
void on_MF_Attack_infoButton_clicked();
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
PM3Process* pm3; PM3Process* pm3;

@ -150,6 +150,19 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item>
<widget class="QPushButton" name="MF_Attack_infoButton">
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
</size>
</property>
<property name="text">
<string>Card Info</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QPushButton" name="MF_Attack_chkButton"> <widget class="QPushButton" name="MF_Attack_chkButton">
<property name="sizePolicy"> <property name="sizePolicy">
@ -401,9 +414,21 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QSpinBox" name="MF_RW_blockBox"> <widget class="QComboBox" name="MF_RW_blockBox">
<property name="maximum"> <property name="minimumSize">
<number>63</number> <size>
<width>40</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>40</width>
<height>16777215</height>
</size>
</property>
<property name="editable">
<bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
@ -430,6 +455,18 @@
</item> </item>
<item> <item>
<widget class="QComboBox" name="MF_RW_keyTypeBox"> <widget class="QComboBox" name="MF_RW_keyTypeBox">
<property name="minimumSize">
<size>
<width>35</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>35</width>
<height>16777215</height>
</size>
</property>
<item> <item>
<property name="text"> <property name="text">
<string>A</string> <string>A</string>
@ -611,9 +648,21 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QSpinBox" name="MF_UID_blockBox"> <widget class="QComboBox" name="MF_UID_blockBox">
<property name="maximum"> <property name="minimumSize">
<number>63</number> <size>
<width>40</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>40</width>
<height>16777215</height>
</size>
</property>
<property name="editable">
<bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>

@ -6,6 +6,12 @@ MF_Attack_hardnestedDialog::MF_Attack_hardnestedDialog(QWidget *parent) :
ui(new Ui::MF_Attack_hardnestedDialog) ui(new Ui::MF_Attack_hardnestedDialog)
{ {
ui->setupUi(this); ui->setupUi(this);
for(int i=0;i<64;i++)
{
ui->knownKeySectorBox->addItem(QString::number(i));
ui->targetKeySectorBox->addItem(QString::number(i));
}
} }
MF_Attack_hardnestedDialog::~MF_Attack_hardnestedDialog() MF_Attack_hardnestedDialog::~MF_Attack_hardnestedDialog()
@ -16,13 +22,13 @@ MF_Attack_hardnestedDialog::~MF_Attack_hardnestedDialog()
void MF_Attack_hardnestedDialog::on_buttonBox_accepted() void MF_Attack_hardnestedDialog::on_buttonBox_accepted()
{ {
emit sendCMD("hf mf hardnested " emit sendCMD("hf mf hardnested "
+ui->knownKeySectorBox->text() +ui->knownKeySectorBox->currentText()
+" " +" "
+ui->knownKeyTypeBox->currentText() +ui->knownKeyTypeBox->currentText()
+" " +" "
+ui->knownKeyBox->text() +ui->knownKeyBox->text()
+" " +" "
+ui->targetKeySectorBox->text() +ui->targetKeySectorBox->currentText()
+" " +" "
+ui->targetKeyTypeBox->currentText()); +ui->targetKeyTypeBox->currentText());
} }

@ -31,14 +31,38 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QSpinBox" name="knownKeySectorBox"> <widget class="QComboBox" name="knownKeySectorBox">
<property name="maximum"> <property name="minimumSize">
<number>63</number> <size>
<width>40</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>40</width>
<height>16777215</height>
</size>
</property>
<property name="editable">
<bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QComboBox" name="knownKeyTypeBox"> <widget class="QComboBox" name="knownKeyTypeBox">
<property name="minimumSize">
<size>
<width>35</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>35</width>
<height>16777215</height>
</size>
</property>
<item> <item>
<property name="text"> <property name="text">
<string>A</string> <string>A</string>
@ -77,14 +101,38 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QSpinBox" name="targetKeySectorBox"> <widget class="QComboBox" name="targetKeySectorBox">
<property name="maximum"> <property name="minimumSize">
<number>63</number> <size>
<width>40</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>40</width>
<height>16777215</height>
</size>
</property>
<property name="editable">
<bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QComboBox" name="targetKeyTypeBox"> <widget class="QComboBox" name="targetKeyTypeBox">
<property name="minimumSize">
<size>
<width>35</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>35</width>
<height>16777215</height>
</size>
</property>
<item> <item>
<property name="text"> <property name="text">
<string>A</string> <string>A</string>

@ -5,6 +5,10 @@ PM3Process::PM3Process(QObject* parent): QProcess(parent)
setProcessChannelMode(PM3Process::MergedChannels); setProcessChannelMode(PM3Process::MergedChannels);
isRequiringOutput=false; isRequiringOutput=false;
requiredOutput=new QString(); requiredOutput=new QString();
serialListener=new QTimer(this);
serialListener->setInterval(1000);
serialListener->setTimerType(Qt::VeryCoarseTimer);
connect(serialListener,&QTimer::timeout,this,&PM3Process::onTimeout);
} }
QStringList PM3Process::findPort() QStringList PM3Process::findPort()
@ -13,7 +17,9 @@ QStringList PM3Process::findPort()
QStringList retList; QStringList retList;
foreach(const QSerialPortInfo &info, QSerialPortInfo::availablePorts()) foreach(const QSerialPortInfo &info, QSerialPortInfo::availablePorts())
{ {
qDebug()<<info.isBusy()<<info.isNull()<<info.portName();
serial.setPort(info); serial.setPort(info);
if(serial.open(QIODevice::ReadWrite)) if(serial.open(QIODevice::ReadWrite))
{ {
retList<<info.portName(); retList<<info.portName();
@ -27,7 +33,15 @@ bool PM3Process::start(const QString path, const QString port)
{ {
// using "-f" option to make the client output flushed after every print. // using "-f" option to make the client output flushed after every print.
QProcess::start(path, QStringList()<<port<<"-f",QProcess::Unbuffered|QProcess::ReadWrite); QProcess::start(path, QStringList()<<port<<"-f",QProcess::Unbuffered|QProcess::ReadWrite);
return waitForStarted(); if(waitForStarted())
{
setSerialListener(port,true);
return true;
}
else
{
return false;
}
} }
void PM3Process::setRequiringOutput(bool st) void PM3Process::setRequiringOutput(bool st)
@ -54,3 +68,26 @@ bool PM3Process::waitForReadyRead(int msecs)
return QProcess::waitForReadyRead(msecs); return QProcess::waitForReadyRead(msecs);
} }
void PM3Process::setSerialListener(const QString& name,bool state)
{
if(state)
{
portInfo=new QSerialPortInfo(name);
serialListener->start();
}
else
{
serialListener->stop();
delete portInfo;
}
}
void PM3Process::onTimeout()
{
qDebug()<<portInfo->isBusy();
if(!portInfo->isBusy())
{
emit PM3disconnected();
setSerialListener("",false);
}
}

@ -4,6 +4,7 @@
#include <QProcess> #include <QProcess>
#include <QString> #include <QString>
#include <QDebug> #include <QDebug>
#include <QTimer>
#include <QtSerialPort/QSerialPortInfo> #include <QtSerialPort/QSerialPortInfo>
#include <QtSerialPort/QSerialPort> #include <QtSerialPort/QSerialPort>
@ -18,9 +19,16 @@ public:
void setRequiringOutput(bool st); void setRequiringOutput(bool st);
QString getRequiredOutput(); QString getRequiredOutput();
bool waitForReadyRead(int msecs = 2000); bool waitForReadyRead(int msecs = 2000);
void setSerialListener(const QString &name, bool state);
private slots:
void onTimeout();
private: private:
bool isRequiringOutput; bool isRequiringOutput;
QString* requiredOutput; QString* requiredOutput;
QTimer* serialListener;
QSerialPortInfo* portInfo;
signals:
void PM3disconnected();
}; };
#endif // PM3PROCESS_H #endif // PM3PROCESS_H

Loading…
Cancel
Save