Skip to content

Commit

Permalink
A small patch
Browse files Browse the repository at this point in the history
Support specifying client working directory
Clean all compile warnings
  • Loading branch information
wh201906 committed Feb 16, 2021
1 parent 7f96c06 commit aa6b939
Show file tree
Hide file tree
Showing 13 changed files with 312 additions and 197 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Great thanks to him.
+ Support configuring environment variables by script
(Useful when the client requires specific environment variables)
+ All functions are compatible with Iceman/RRG repo(tested on v4.9237)
+ Support specifying client working directory
+ Fix some bugs

### V0.1.3
Expand Down
1 change: 1 addition & 0 deletions README/doc/README_zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ release页面中有含客户端的GUI。这个GUI也可以搭配你自己的客
+ 可通过外部脚本配置环境变量
(在客户端需要配置环境变量时很有用)
+ 全功能兼容冰人版(在v4.9237上测试通过)
+ 支持指定客户端工作路径
+ 修复部分bug

### V0.1.3
Expand Down
14 changes: 12 additions & 2 deletions common/pm3process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ void PM3Process::connectPM3(const QString& path, const QString& port, const QStr
result = result.left(result.indexOf("\r\n"));
result = result.mid(3, result.lastIndexOf(" ") - 3);
emit PM3StatedChanged(true, result);
setSerialListener(port, true);

// if the arguments don't contain <port>, then disable the port listener
// useful when using offline sniff
if(args.indexOf(port) != -1)
setSerialListener(port, true);
}
else
kill();
Expand Down Expand Up @@ -132,5 +136,11 @@ void PM3Process::setProcEnv(const QStringList* env)
{
// qDebug() << "passed Env List" << *env;
this->setEnvironment(*env);
// qDebug() << "final Env List" << processEnvironment().toStringList();
// qDebug() << "final Env List" << processEnvironment().toStringList();
}

void PM3Process::setWorkingDir(const QString& dir)
{
// the working directory cannot be the default, or the client will failed to load the dll
this->setWorkingDirectory(dir);
}
2 changes: 2 additions & 0 deletions common/pm3process.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <QtSerialPort/QSerialPortInfo>
#include <QtSerialPort/QSerialPort>
#include <QProcessEnvironment>
#include <QDir>

#include "util.h"

Expand All @@ -27,6 +28,7 @@ public slots:
qint64 write(QString data);
void reconnectPM3();
void setProcEnv(const QStringList* env);
void setWorkingDir(const QString& dir);
private slots:
void onTimeout();
void onReadyRead();
Expand Down
205 changes: 111 additions & 94 deletions lang/en_US.ts

Large diffs are not rendered by default.

Binary file modified lang/zh_CN.qm
Binary file not shown.
206 changes: 112 additions & 94 deletions lang/zh_CN.ts

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions module/mifare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,14 @@ QString Mifare::info(bool isRequiringOutput)
end = result.indexOf("\n", end);
return result.mid(begin, end - begin + 1);
}
else
return "";
}
else
{
util->execCMD("hf 14a info");
ui->funcTab->setCurrentIndex(Util::rawTabIndex);
return "";
}
}
return "";
}

void Mifare::chk()
Expand Down Expand Up @@ -629,6 +627,7 @@ bool Mifare::_writeblk(int blockId, KeyType keyType, const QString& key, const Q
return true;
}
}
return false;
}

void Mifare::writeOne(TargetType targetType)
Expand Down
20 changes: 20 additions & 0 deletions ui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ MainWindow::MainWindow(QWidget *parent):
pm3 = new PM3Process(pm3Thread);
pm3Thread->start();
pm3state = false;
clientWorkingDir = new QDir;

util = new Util(this);
mifare = new Mifare(ui, util, this);
Expand Down Expand Up @@ -94,6 +95,7 @@ void MainWindow::on_PM3_connectButton_clicked()
{
QStringList args = ui->Set_Client_startArgsEdit->text().replace("<port>", port).split(' ');
saveClientPath(ui->PM3_pathEdit->text());

QProcess envSetProcess;
QFileInfo envScriptPath(ui->Set_Client_envScriptEdit->text());
if(envScriptPath.exists())
Expand All @@ -113,6 +115,15 @@ void MainWindow::on_PM3_connectButton_clicked()
else
clientEnv.clear();
emit setProcEnv(&clientEnv);

clientWorkingDir->setPath(QApplication::applicationDirPath());
qDebug() << clientWorkingDir->absolutePath();
clientWorkingDir->mkpath(ui->Set_Client_workingDirEdit->text());
qDebug() << clientWorkingDir->absolutePath();
clientWorkingDir->cd(ui->Set_Client_workingDirEdit->text());
qDebug() << clientWorkingDir->absolutePath();
emit setWorkingDir(clientWorkingDir->absolutePath());

emit connectPM3(ui->PM3_pathEdit->text(), port, args);
}
}
Expand Down Expand Up @@ -976,6 +987,7 @@ void MainWindow::uiInit()

settings->beginGroup("Client_Env");
ui->Set_Client_envScriptEdit->setText(settings->value("scriptPath").toString());
ui->Set_Client_workingDirEdit->setText(settings->value("workingDir", "../data").toString());
settings->endGroup();

ui->MF_RW_keyTypeBox->addItem("A", Mifare::KEY_A);
Expand All @@ -996,6 +1008,7 @@ void MainWindow::signalInit()
connect(pm3, &PM3Process::PM3StatedChanged, util, &Util::setRunningState);
connect(this, &MainWindow::killPM3, pm3, &PM3Process::kill);
connect(this, &MainWindow::setProcEnv, pm3, &PM3Process::setProcEnv);
connect(this, &MainWindow::setWorkingDir, pm3, &PM3Process::setWorkingDir);

connect(util, &Util::write, pm3, &PM3Process::write);

Expand Down Expand Up @@ -1160,3 +1173,10 @@ void MainWindow::on_Set_Client_envScriptEdit_editingFinished()
settings->setValue("scriptPath", ui->Set_Client_envScriptEdit->text());
settings->endGroup();
}

void MainWindow::on_Set_Client_saveWorkingDirButton_clicked()
{
settings->beginGroup("Client_Env");
settings->setValue("workingDir", ui->Set_Client_workingDirEdit->text());
settings->endGroup();
}
4 changes: 4 additions & 0 deletions ui/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ private slots:

void on_Set_Client_envScriptEdit_editingFinished();

void on_Set_Client_saveWorkingDirButton_clicked();

private:
Ui::MainWindow* ui;
QButtonGroup* MFCardTypeBtnGroup;
Expand All @@ -199,6 +201,7 @@ private slots:
QTimer* portSearchTimer;
QStringList portList;
QStringList clientEnv;
QDir* clientWorkingDir;

Mifare* mifare;
Util* util;
Expand All @@ -217,5 +220,6 @@ private slots:
void killPM3();
void setSerialListener(const QString& name, bool state);
void setProcEnv(const QStringList *env);
void setWorkingDir(const QString& dir);
};
#endif // MAINWINDOW_H
47 changes: 45 additions & 2 deletions ui/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
</sizepolicy>
</property>
<property name="currentIndex">
<number>0</number>
<number>4</number>
</property>
<widget class="QWidget" name="mifareTab">
<attribute name="title">
Expand Down Expand Up @@ -1538,7 +1538,7 @@
<attribute name="title">
<string>Settings</string>
</attribute>
<layout class="QHBoxLayout" name="horizontalLayout_15">
<layout class="QHBoxLayout" name="horizontalLayout_18">
<item>
<layout class="QVBoxLayout" name="verticalLayout_12">
<item>
Expand Down Expand Up @@ -1573,6 +1573,49 @@ then put the path of the script there</string>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_19">
<property name="text">
<string>Client working directory:</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_15">
<item>
<widget class="QLineEdit" name="Set_Client_workingDirEdit">
<property name="text">
<string>../data</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="Set_Client_saveWorkingDirButton">
<property name="text">
<string>Save</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="label_20">
<property name="text">
<string>Note:
On Windows, the client working directory should not be identical to the path of GUI, otherwise the client will use the wrong .dll file.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
Expand Down
2 changes: 1 addition & 1 deletion ui/mf_trailerdecoderdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void MF_trailerDecoderDialog::setTableItem(QTableWidget* widget, int row, int co
widget->item(row, column)->setText(text);
}

void MF_trailerDecoderDialog::on_boxChanged(int arg1)
void MF_trailerDecoderDialog::on_boxChanged()
{
quint8 ACBits[4];
ACBits[0] = ui->C0Box->value();
Expand Down
2 changes: 1 addition & 1 deletion ui/mf_trailerdecoderdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private slots:

void on_blockSizeChanged(int id, bool st);

void on_boxChanged(int arg1);
void on_boxChanged();
private:
Ui::MF_trailerDecoderDialog *ui;
QRegularExpressionValidator* validator;
Expand Down

0 comments on commit aa6b939

Please sign in to comment.