Fix saving/loading trace(sniff) files

Fix file extension for RRG repo
Fix overwriting existing file
Add support for RRG v4.16717(path in prefs)
master
wh201906 1 year ago
parent 0738aff2bf
commit 184a9ed5f2
No known key found for this signature in database

@ -104,7 +104,9 @@
"cmd": "hf mf darkside"
},
"save sniff": {
"cmd": "trace save -f <filename>"
"cmd": "trace save -f <filename>",
"path cmd":"prefs show",
"path pattern":"trace save path\\.+\\s*(.+)$"
},
"load sniff": {
"cmd": "trace load -f <filename>",

@ -1375,3 +1375,18 @@ quint16 Mifare::getTrailerBlockId(quint8 sectorId, qint8 cardTypeId)
// other cardTypeId: use current cardtype(include default -1)
return (cardType.blks[sectorId] + cardType.blk[sectorId] - 1);
}
QString Mifare::getTraceSavePath()
{
QVariantMap config = configMap["save sniff"].toMap();
QString pathCmd = config["path cmd"].toString();
QString patternText = config["path pattern"].toString();
QRegularExpression pattern = QRegularExpression(patternText, QRegularExpression::MultilineOption);
if(pathCmd.isEmpty() || patternText.isEmpty())
return QString();
QString result = util->execCMDWithOutput(pathCmd, 500);
QRegularExpressionMatch reMatch = pattern.match(result);
if(!reMatch.hasMatch())
return QString();
return reMatch.captured(1).trimmed();
}

@ -115,6 +115,7 @@ public:
QString data_getUID();
quint16 getTrailerBlockId(quint8 sectorId, qint8 cardTypeId = -1); // -1: use current cardtype
void setConfigMap(const QVariantMap& configMap);
QString getTraceSavePath();
public slots:
signals:

@ -956,18 +956,31 @@ void MainWindow::on_MF_Sniff_loadButton_clicked() // use a tmp file to support c
{
QString title = "";
QString filename = "";
QString defaultExtension;
QDir clientTracePath;
if(Util::getClientType() == Util::CLIENTTYPE_OFFICIAL)
defaultExtension = ".trc";
else if(Util::getClientType() == Util::CLIENTTYPE_ICEMAN)
defaultExtension = ".trace";
QString userTraceSavePath = mifare->getTraceSavePath();
if(userTraceSavePath.isEmpty())
clientTracePath = *clientWorkingDir;
else
clientTracePath = QDir(userTraceSavePath); // For v4.16717 and later
title = tr("Plz select the trace file:");
filename = QFileDialog::getOpenFileName(this, title, clientWorkingDir->absolutePath(), tr("Trace Files(*.trc)") + ";;" + tr("All Files(*.*)"));
filename = QFileDialog::getOpenFileName(this, title, clientTracePath.absolutePath(), tr("Trace Files") + "(*" + defaultExtension + ")" + ";;" + tr("All Files(*.*)"));
qDebug() << filename;
if(filename != "")
{
QString tmpFile = "tmp" + QString::number(QDateTime::currentDateTime().toTime_t()) + ".trc";
if(QFile::copy(filename, clientWorkingDir->absolutePath() + "/" + tmpFile))
QString tmpFile = "tmp" + QString::number(QDateTime::currentDateTimeUtc().toTime_t()) + defaultExtension;
if(QFile::copy(filename, clientTracePath.absolutePath() + "/" + tmpFile))
{
mifare->loadSniff(tmpFile);
util->delay(3000);
QFile::remove(clientWorkingDir->absolutePath() + "/" + tmpFile);
QFile::remove(clientTracePath.absolutePath() + "/" + tmpFile);
}
else
{
@ -980,25 +993,41 @@ void MainWindow::on_MF_Sniff_saveButton_clicked()
{
QString title = "";
QString filename = "";
QString defaultExtension;
QDir clientTracePath;
if(Util::getClientType() == Util::CLIENTTYPE_OFFICIAL)
defaultExtension = ".trc";
else if(Util::getClientType() == Util::CLIENTTYPE_ICEMAN)
defaultExtension = ".trace";
QString userTraceSavePath = mifare->getTraceSavePath();
if(userTraceSavePath.isEmpty())
clientTracePath = *clientWorkingDir;
else
clientTracePath = QDir(userTraceSavePath); // For v4.16717 and later
title = tr("Plz select the location to save trace file:");
filename = QFileDialog::getSaveFileName(this, title, clientWorkingDir->absolutePath(), tr("Trace Files(*.trc)"));
filename = QFileDialog::getSaveFileName(this, title, clientTracePath.absolutePath(), tr("Trace Files") + "(*" + defaultExtension + ")");
qDebug() << filename;
if(filename != "")
{
QString tmpFile = "tmp" + QString::number(QDateTime::currentDateTime().toTime_t()) + ".trc";
QString tmpFile = "tmp" + QString::number(QDateTime::currentDateTimeUtc().toTime_t()) + defaultExtension;
mifare->saveSniff(tmpFile);
for(int i = 0; i < 100; i++)
{
util->delay(100);
if(QFile::exists(clientWorkingDir->absolutePath() + "/" + tmpFile))
if(QFile::exists(clientTracePath.absolutePath() + "/" + tmpFile))
break;
}
if(!QFile::copy(clientWorkingDir->absolutePath() + "/" + tmpFile, filename))
// filename is not empty -> the user has chosen to overwrite the existing file
if(QFile::exists(filename))
QFile::remove(filename);
if(!QFile::copy(clientTracePath.absolutePath() + "/" + tmpFile, filename))
{
QMessageBox::information(this, tr("Info"), tr("Failed to save to") + "\n" + filename);
}
QFile::remove(clientWorkingDir->absolutePath() + "/" + tmpFile);
QFile::remove(clientTracePath.absolutePath() + "/" + tmpFile);
}
}

Loading…
Cancel
Save