Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions src/common/pm3process.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "pm3process.h"

PM3Process::PM3Process(QThread* thread, QObject* parent): QProcess(parent)
PM3Process::PM3Process(QThread* thread, QObject* parent): QProcess(parent), serialPort(new QSerialPort(this))
{
moveToThread(thread);
setProcessChannelMode(PM3Process::MergedChannels);
Expand All @@ -12,7 +12,7 @@ PM3Process::PM3Process(QThread* thread, QObject* parent): QProcess(parent)
serialListener->setTimerType(Qt::VeryCoarseTimer);
connect(serialListener, &QTimer::timeout, this, &PM3Process::onTimeout);
connect(this, &PM3Process::readyRead, this, &PM3Process::onReadyRead);
portInfo = nullptr;
serialPort = nullptr;

qRegisterMetaType<QProcess::ProcessError>("QProcess::ProcessError");
}
Expand Down Expand Up @@ -100,17 +100,23 @@ void PM3Process::setSerialListener(const QString& name, bool state)
if(state)
{
currPort = name;
portInfo = new QSerialPortInfo(name);
serialListener->start();
qDebug() << serialListener->thread();
serialPort->setPortName(name); // Set the port name
if(!serialPort->open(QIODevice::ReadWrite))
{
qDebug() << "Failed to open serial port:" << name;
}
else
{
serialListener->start();
qDebug() << serialListener->thread();
}
}
else
{
serialListener->stop();
if(portInfo != nullptr)
if(serialPort->isOpen())
{
delete portInfo;
portInfo = nullptr;
serialPort->close(); // Close the serial port
}
}
}
Expand All @@ -120,14 +126,9 @@ void PM3Process::setSerialListener(bool state)
setSerialListener(currPort, state);
}

void PM3Process::onTimeout() //when the proxmark3 client is unexpectedly terminated or the PM3 hardware is removed, the isBusy() will return false(only tested on Windows);
void PM3Process::onTimeout() //when the proxmark3 client is unexpectedly terminated or the PM3 hardware is removed, the isOpen() will return false
{
// isBusy() is a deprecated function because it will block the serial port when the port is not in use.
// However, the PM3 client is supposed to use the target serial port exclusively, so it should be fine
// isBusy() will always return false on Raspbian, in this case, check "Keep the client active" in the Settings panel.
//
// qDebug()<<portInfo->isBusy();
if(!portInfo->isBusy())
if(!serialPort->isOpen())
{
killPM3();
}
Expand Down
4 changes: 3 additions & 1 deletion src/common/pm3process.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,20 @@ public slots:
void setProcEnv(const QStringList* env);
void setWorkingDir(const QString& dir);
void killPM3();

private slots:
void onTimeout();
void onReadyRead();

private:
bool isRequiringOutput;
QString* requiredOutput; // It only works in this class now
void setRequiringOutput(bool st);// It only works in this class now
QTimer* serialListener;
QSerialPortInfo* portInfo;
QString currPath;
QString currPort = "";
QStringList currArgs;
QSerialPort* serialPort; // Declare serialPort as a member variable

signals:
void PM3StatedChanged(bool st, const QString& info = "");
Expand Down
36 changes: 28 additions & 8 deletions src/common/util.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include "util.h"
#include <QFile>
#include <QString>

Util::ClientType Util::clientType = CLIENTTYPE_OFFICIAL;

Expand All @@ -15,7 +17,6 @@ Util::Util(QObject *parent) : QObject(parent)
qRegisterMetaType<Util::ClientType>("Util::ClientType");
}


void Util::processOutput(const QString& output)
{
// qDebug() << "Util::processOutput:" << output;
Expand Down Expand Up @@ -114,14 +115,33 @@ bool Util::chooseLanguage(QSettings* guiSettings, QMainWindow* window)
// make sure the GUISettings is not in any group
QSettings* langSettings = new QSettings(":/i18n/languages.ini", QSettings::IniFormat);
QMap<QString, QString> langMap;
langSettings->setIniCodec("UTF-8");
langSettings->beginGroup("Languages");
QStringList langList = langSettings->allKeys();
for(int i = 0; i < langList.size(); i++)
langMap.insert(langSettings->value(langList[i]).toString(), langList[i]);
langMap.insert(tr("Load from external file"), "(ext)");
langSettings->endGroup();
QFile file(":/i18n/languages.ini");
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
qDebug() << "Failed to open languages.ini file.";
delete langSettings;
return false;
}
QByteArray data = file.readAll();
QString content = QString::fromUtf8(data);
QStringList lines = content.split('\n', Qt::SkipEmptyParts);
for (const QString& line : lines) {
if (line.startsWith("[Languages]")) {
while (!lines.isEmpty()) {
QString line = lines.takeFirst();
if (line.isEmpty() || line.startsWith("[")) break;
int index = line.indexOf('=');
if (index > 0) {
QString key = line.left(index).trimmed();
QString value = line.mid(index + 1).trimmed();
langMap.insert(value, key);
}
}
}
}
file.close();
delete langSettings;

langMap.insert(tr("Load from external file"), "(ext)");
bool isOk = false;
QString selectedText = QInputDialog::getItem(window, "", tr("Choose a language:"), langMap.keys(), 0, false, &isOk);
if(!isOk)
Expand Down
9 changes: 3 additions & 6 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <QSettings>
#include <QTranslator>
#include <QMessageBox>
#include <QTextCodec>
#include <QLocale>
#include <QDir>

int main(int argc, char *argv[])
Expand All @@ -20,12 +20,10 @@ int main(int argc, char *argv[])
}
delete pluginDir;

QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
QApplication a(argc, argv);

QSettings* settings = new QSettings("GUIsettings.ini", QSettings::IniFormat);
settings->setIniCodec("UTF-8");
QLocale::setDefault(QLocale::system());
settings->beginGroup("language");
QString languageFile = settings->value("extPath").toString();
QString languageName = settings->value("name").toString();
Expand Down Expand Up @@ -91,7 +89,6 @@ int main(int argc, char *argv[])
MainWindow w;
w.initUI();
w.show();

return a.exec();
}


12 changes: 6 additions & 6 deletions src/module/mifare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -865,11 +865,11 @@ void Mifare::data_syncWithDataWidget(bool syncAll, int block)
tmp = "";
if(dataList->at(i) != "")
{
tmp += dataList->at(i).midRef(0, 2);
tmp += dataList->at(i).mid(0, 2);
for(int j = 1; j < 16; j++)
{
tmp += " ";
tmp += dataList->at(i).midRef(j * 2, 2);
tmp += dataList->at(i).mid(j * 2, 2);
}
}
ui->MF_dataWidget->item(i, 2)->setText(tmp);
Expand All @@ -880,11 +880,11 @@ void Mifare::data_syncWithDataWidget(bool syncAll, int block)
tmp = "";
if(dataList->at(block) != "")
{
tmp += dataList->at(block).midRef(0, 2);
tmp += dataList->at(block).mid(0, 2);
for(int j = 1; j < 16; j++)
{
tmp += " ";
tmp += dataList->at(block).midRef(j * 2, 2);
tmp += dataList->at(block).mid(j * 2, 2);
}
}
ui->MF_dataWidget->item(block, 2)->setText(tmp);
Expand Down Expand Up @@ -1159,7 +1159,7 @@ bool Mifare::data_saveDataFile(const QString& filename, bool isBin)
{
for(int i = 0; i < cardType.block_size; i++)
{
buff += dataList->at(i);
buff += dataList->at(i).toUtf8();
buff += "\n";
}
}
Expand Down Expand Up @@ -1238,7 +1238,7 @@ void Mifare::data_key2Data()
if(dataList->at(getTrailerBlockId(i)) == "")
tmp += "FF078069"; // default control bytes
else
tmp += dataList->at(getTrailerBlockId(i)).midRef(12, 8);
tmp += dataList->at(getTrailerBlockId(i)).mid(12, 8);

if(data_isKeyValid(keyBList->at(i)))
tmp += keyBList->at(i);
Expand Down
37 changes: 23 additions & 14 deletions src/ui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,29 @@
MainWindow::MainWindow(QWidget *parent):
QMainWindow(parent)
, ui(new Ui::MainWindow)
, MFCardTypeBtnGroup(new QButtonGroup(this))
{
ui->setupUi(this);
dockAllWindows = new QAction(tr("Dock all windows"), this);
myInfo = new QAction("wh201906", this);
currVersion = new QAction(tr("Ver: ") + QApplication::applicationVersion().section('.', 0, -2), this); // ignore the 4th version number
checkUpdate = new QAction(tr("Check Update"), this);
connect(dockAllWindows, &QAction::triggered, [ = ]()
connect(dockAllWindows, &QAction::triggered, [this]()
{
for(int i = 0; i < dockList.size(); i++)
dockList[i]->setFloating(false);
});
connect(myInfo, &QAction::triggered, [ = ]()
connect(myInfo, &QAction::triggered, [this]()
{
QDesktopServices::openUrl(QUrl("https://github.com/wh201906"));
});
connect(checkUpdate, &QAction::triggered, [ = ]()
connect(checkUpdate, &QAction::triggered, [this]()
{
QDesktopServices::openUrl(QUrl("https://github.com/wh201906/Proxmark3GUI/releases"));
});
connect(MFCardTypeBtnGroup, &QButtonGroup::buttonToggled, this, &MainWindow::MF_onMFCardTypeChanged);

settings = new QSettings("GUIsettings.ini", QSettings::IniFormat);
settings->setIniCodec("UTF-8");

pm3Thread = new QThread(this);
connect(QApplication::instance(), &QApplication::aboutToQuit, pm3Thread, &QThread::quit);
Expand Down Expand Up @@ -101,6 +102,13 @@ void MainWindow::loadConfig()

void MainWindow::initUI() // will be called by main.app
{
// int numberOfButtons = 10; // No idea what this should be set to. Stupid Qwen.
// for (int i = 0; i < numberOfButtons; ++i) {
// QRadioButton* button = new QRadioButton("Button " + QString::number(i), this);
// MFCardTypeBtnGroup->addButton(button);
// button->setProperty("id", i); // Set the id property
// }

ui->retranslateUi(this);
uiInit();
signalInit();
Expand Down Expand Up @@ -451,22 +459,22 @@ void MainWindow::on_MF_keyWidget_resized(QObject* obj_addr, QEvent& event)
}
}

void MainWindow::MF_onMFCardTypeChanged(int id, bool st)
void MainWindow::MF_onMFCardTypeChanged(QAbstractButton* button, bool checked)
{
MFCardTypeBtnGroup->blockSignals(true);
qDebug() << id << MFCardTypeBtnGroup->checkedId();
if(!st)
qDebug() << button->property("id").toInt() << MFCardTypeBtnGroup->checkedId();
if (!checked)
{
int result;
if(id > MFCardTypeBtnGroup->checkedId()) // id is specified in uiInit() with a proper order, so I can compare the size by id.
if (button->property("id").toInt() > MFCardTypeBtnGroup->checkedId())
{
result = QMessageBox::question(this, tr("Info"), tr("Some of the data and key will be cleared.") + "\n" + tr("Continue?"), QMessageBox::Yes | QMessageBox::No);
}
else
{
result = QMessageBox::Yes;
}
if(result == QMessageBox::Yes)
if (result == QMessageBox::Yes)
{
qDebug() << "Yes";
mifare->setCardType(MFCardTypeBtnGroup->checkedId());
Expand All @@ -477,7 +485,7 @@ void MainWindow::MF_onMFCardTypeChanged(int id, bool st)
else
{
qDebug() << "No";
MFCardTypeBtnGroup->button(id)->setChecked(true);
button->setChecked(true);
}
}
MFCardTypeBtnGroup->blockSignals(false);
Expand Down Expand Up @@ -975,7 +983,7 @@ void MainWindow::on_MF_Sniff_loadButton_clicked() // use a tmp file to support c
qDebug() << filename;
if(filename != "")
{
QString tmpFile = "tmp" + QString::number(QDateTime::currentDateTimeUtc().toTime_t()) + defaultExtension;
QString tmpFile = "tmp" + QString::number(QDateTime::currentDateTimeUtc().toSecsSinceEpoch()) + defaultExtension;
if(QFile::copy(filename, clientTracePath.absolutePath() + "/" + tmpFile))
{
mifare->loadSniff(tmpFile);
Expand Down Expand Up @@ -1012,7 +1020,7 @@ void MainWindow::on_MF_Sniff_saveButton_clicked()
qDebug() << filename;
if(filename != "")
{
QString tmpFile = "tmp" + QString::number(QDateTime::currentDateTimeUtc().toTime_t()) + defaultExtension;
QString tmpFile = "tmp" + QString::number(QDateTime::currentDateTimeUtc().toSecsSinceEpoch()) + defaultExtension;
mifare->saveSniff(tmpFile);
for(int i = 0; i < 100; i++)
{
Expand Down Expand Up @@ -1130,7 +1138,8 @@ void MainWindow::uiInit()
MFCardTypeBtnGroup->addButton(ui->MF_Type_1kButton, 1);
MFCardTypeBtnGroup->addButton(ui->MF_Type_2kButton, 2);
MFCardTypeBtnGroup->addButton(ui->MF_Type_4kButton, 4);
connect(MFCardTypeBtnGroup, QOverload<int, bool>::of(&QButtonGroup::buttonToggled), this, &MainWindow::MF_onMFCardTypeChanged);
//connect(MFCardTypeBtnGroup, QOverload<int, bool>::of(&QButtonGroup::buttonToggled), this, &MainWindow::MF_onMFCardTypeChanged);
connect(MFCardTypeBtnGroup, &QButtonGroup::buttonToggled, this, &MainWindow::MF_onMFCardTypeChanged);

ui->MF_keyWidget->installEventFilter(this);
ui->MF_dataWidget->installEventFilter(this);
Expand Down Expand Up @@ -1442,7 +1451,7 @@ void MainWindow::loadClientPathList()
settings->endGroup();

ui->PM3_pathBox->clear();
for(const QString& clientPath : qAsConst(m_clientPathList))
for(const QString& clientPath : std::as_const(m_clientPathList))
ui->PM3_pathBox->addItem(clientPath);
}

Expand Down
Loading