Fix a bug

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.
This commit is contained in:
wh201906 2021-09-05 21:35:03 +08:00
parent 02a8fe03e3
commit 12a0837c50
5 changed files with 25 additions and 19 deletions

View file

@ -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);
@ -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);
}
@ -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
@ -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()

View file

@ -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)

View file

@ -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++)

View file

@ -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", "");
@ -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());
@ -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;

View file

@ -126,11 +126,11 @@ 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'
@ -138,7 +138,7 @@ void MainWindow::on_PM3_connectButton_clicked()
#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();