Skip to content

Commit

Permalink
Fix a bug
Browse files Browse the repository at this point in the history
Trying to fix #22
Open client with QProcess::Text for proper newline character(s)
On Raspbian, the isBusy() function will always return false, even the serial port is actually connected.
  • Loading branch information
wh201906 committed Sep 5, 2021
1 parent 02a8fe0 commit 12a0837
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 19 deletions.
24 changes: 15 additions & 9 deletions common/pm3process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void PM3Process::connectPM3(const QString& path, const QStringList args)
currArgs = args;

// using "-f" option to make the client output flushed after every print.
start(path, args, QProcess::Unbuffered | QProcess::ReadWrite);
start(path, args, QProcess::Unbuffered | QProcess::ReadWrite | QProcess::Text);
if(waitForStarted(10000))
{
waitForReadyRead(10000);
Expand All @@ -36,11 +36,13 @@ void PM3Process::connectPM3(const QString& path, const QStringList args)
{
clientType = Util::CLIENTTYPE_ICEMAN;
setRequiringOutput(true);
write("hw version\r\n");
for(int i = 0; i < 10; i++)
write("hw version\n");
for(int i = 0; i < 50; i++)
{
waitForReadyRead(200);
result += *requiredOutput;
if(result.indexOf("os: ") != -1)
break;
}
setRequiringOutput(false);
}
Expand All @@ -52,8 +54,8 @@ void PM3Process::connectPM3(const QString& path, const QStringList args)
{
emit changeClientType(clientType);
result = result.mid(result.indexOf("os: "));
result = result.left(result.indexOf("\r\n"));
result = result.mid(3, result.lastIndexOf(" ") - 3);
result = result.left(result.indexOf("\n"));
result = result.mid(4, result.indexOf(" ", 4) - 4);
emit PM3StatedChanged(true, result);
}
else
Expand Down Expand Up @@ -105,11 +107,15 @@ void PM3Process::setSerialListener(bool 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);
{
// isBusy() is a deprecated function.
// It will always return false on Raspbian.
// SerialListener need to be removed.
//
// qDebug()<<portInfo->isBusy();
if(!portInfo->isBusy())
{
killPM3();
}
// if(!portInfo->isBusy())
// {
// killPM3();
// }
}

void PM3Process::testThread()
Expand Down
2 changes: 1 addition & 1 deletion common/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void Util::execCMD(const QString& cmd)
{
qDebug() << "executing: " << cmd;
if(isRunning)
emit write(cmd + "\r\n");
emit write(cmd + "\n");
}

QString Util::execCMDWithOutput(const QString& cmd, ReturnTrigger trigger)
Expand Down
4 changes: 2 additions & 2 deletions module/lf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ void LF::getConfig()
result = util->execCMDWithOutput("hw status", 400); // not all output from "hw status will be processed".
result = result.right(result.length() - result.indexOf("LF Sampling config"));
offset = result.indexOf("samples to skip");
offset = result.indexOf("\r\n", offset);
offset = result.indexOf("\n", offset);
result = result.mid(0, offset + 2);
qDebug() << "LF CONFIG GET\n" << result;
resultList = result.split("\r\n");
resultList = result.split("\n");
for(int i = 0; i < resultList.length(); i++)
{
for(int j = 0; j < symbolList.length(); j++)
Expand Down
6 changes: 3 additions & 3 deletions module/mifare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ void Mifare::setParameterC()
QMessageBox::information(parent, tr("Info"), tr("Failed to read card."));
else
{
result.replace("\r\n", "");
result.replace("\n", "");
result.replace(QRegularExpression("\\[.\\]"), "");
result.replace("UID", "");
result.replace("ATQA", "");
Expand Down Expand Up @@ -1071,7 +1071,7 @@ bool Mifare::data_loadDataFile(const QString& filename)
else
{
QString tmp = buff.left(cardType.block_size * 34);
QStringList tmpList = tmp.split("\r\n");
QStringList tmpList = tmp.split("\n");
for(int i = 0; i < cardType.block_size; i++)
{
dataList->replace(i, tmpList[i].toUpper());
Expand Down Expand Up @@ -1174,7 +1174,7 @@ bool Mifare::data_saveDataFile(const QString& filename, bool isBin)
for(int i = 0; i < cardType.block_size; i++)
{
buff += dataList->at(i);
buff += "\r\n";
buff += "\n";
}
}
bool ret = file.write(buff) != -1;
Expand Down
8 changes: 4 additions & 4 deletions ui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,19 @@ void MainWindow::on_PM3_connectButton_clicked()
// use the shell session to keep the environment then read it
#ifdef Q_OS_WIN
// cmd /c "<path>">>nul && set
envSetProcess.start("cmd");
envSetProcess.write(QString("\"" + envScriptPath.absoluteFilePath() + "\">>nul\r\n").toLatin1());
envSetProcess.start("cmd", {}, QProcess::Unbuffered | QProcess::ReadWrite | QProcess::Text);
envSetProcess.write(QString("\"" + envScriptPath.absoluteFilePath() + "\">>nul\n").toLatin1());
envSetProcess.waitForReadyRead(10000);
envSetProcess.readAll();
envSetProcess.write("set\r\n");
envSetProcess.write("set\n");
#else
// need implementation(or test if space works)
// sh -c '. "<path>">>/dev/null && env'
envSetProcess.start("sh -c \' . \"" + envScriptPath.absoluteFilePath() + "\">>/dev/null && env");
#endif
envSetProcess.waitForReadyRead(10000);
QString envSetResult = QString(envSetProcess.readAll());
clientEnv = envSetResult.split(QRegExp("[\r\n]{1,2}"), QString::SkipEmptyParts);
clientEnv = envSetResult.split("\n", QString::SkipEmptyParts);
if(clientEnv.size() > 2) // the first element is "set" and the last element is the current path
{
clientEnv.removeFirst();
Expand Down

0 comments on commit 12a0837

Please sign in to comment.