From d15b8e21fc7b1f4cedaa3e840a5c14ee0bc7197d Mon Sep 17 00:00:00 2001 From: wh201906 Date: Wed, 5 Aug 2020 23:55:14 +0800 Subject: [PATCH] Iceman support: info(), chk(), nested() --- common/util.cpp | 6 ++-- common/util.h | 2 +- module/mifare.cpp | 74 ++++++++++++++++++++++++++++++++++++++--------- 3 files changed, 64 insertions(+), 18 deletions(-) diff --git a/common/util.cpp b/common/util.cpp index 11f0a9f..3d73cc3 100644 --- a/common/util.cpp +++ b/common/util.cpp @@ -26,10 +26,10 @@ void Util::execCMD(QString cmd) emit write(cmd + "\r\n"); } -QString Util::execCMDWithOutput(QString cmd, unsigned long timeout) +QString Util::execCMDWithOutput(QString cmd, unsigned long waitTime) { QTime currTime = QTime::currentTime(); - QTime targetTime = QTime::currentTime().addMSecs(timeout); + QTime targetTime = QTime::currentTime().addMSecs(waitTime); isRequiringOutput = true; requiredOutput->clear(); execCMD(cmd); @@ -39,7 +39,7 @@ QString Util::execCMDWithOutput(QString cmd, unsigned long timeout) if(timeStamp > currTime) { currTime = timeStamp; - targetTime = timeStamp.addMSecs(timeout); + targetTime = timeStamp.addMSecs(waitTime); } } isRequiringOutput = false; diff --git a/common/util.h b/common/util.h index 27bee4a..adc9291 100644 --- a/common/util.h +++ b/common/util.h @@ -25,7 +25,7 @@ public: explicit Util(QObject *parent = nullptr); void execCMD(QString cmd); - QString execCMDWithOutput(QString cmd, unsigned long timeout = 2000); + QString execCMDWithOutput(QString cmd, unsigned long waitTime = 2000); void delay(unsigned int msec); ClientType getClientType(); public slots: diff --git a/module/mifare.cpp b/module/mifare.cpp index e9a0e94..0793dd9 100644 --- a/module/mifare.cpp +++ b/module/mifare.cpp @@ -102,31 +102,78 @@ void Mifare::chk() } } - data_syncWithKeyWidget(); } void Mifare::nested() { - QString result = util->execCMDWithOutput( + QRegularExpressionMatch reMatch; + QString result; + int offset = 0; + QString data; + if(util->getClientType() == Util::CLIENTTYPE_OFFICIAL) + { + result = util->execCMDWithOutput( + "hf mf nested " + + QString::number(cardType.type) + + " *", 10000); + } + else if(util->getClientType() == Util::CLIENTTYPE_ICEMAN) + { + QString knownKeyInfo = ""; + for(int i = 0; i < cardType.sector_size; i++) + { + if(data_isKeyValid(keyAList->at(i))) + { + knownKeyInfo = " " + QString::number(i * 4) + " A " + keyAList->at(i); + break; + } + } + if(knownKeyInfo == "") + { + for(int i = 0; i < cardType.sector_size; i++) + { + if(data_isKeyValid(keyBList->at(i))) + { + knownKeyInfo = " " + QString::number(i * 4) + " B " + keyBList->at(i); + break; + } + } + } + if(knownKeyInfo != "") + { + result = util->execCMDWithOutput( "hf mf nested " + QString::number(cardType.type) - + " *"); + + knownKeyInfo, 10000); + } + else + { + QMessageBox::information(parent, tr("Info"), tr("Plz provide at least one known key")); + } - int offset = 0; - QString tmp; + } for(int i = 0; i < cardType.sector_size; i++) { -// offset = nestedKeyPattern->indexIn(result, offset); -// offset = result.indexOf(*nestedKeyPattern, offset); - tmp = result.mid(offset, 47).toUpper(); - offset += 47; - if(tmp.at(23) == '1') - keyAList->replace(i, tmp.mid(7, 12).trimmed()); - if(tmp.at(44) == '1') - keyBList->replace(i, tmp.mid(28, 12).trimmed()); + reMatch = keyPattern_res->match(result, offset); + offset = reMatch.capturedStart(); + if(reMatch.hasMatch()) + { + data = reMatch.captured().toUpper(); + offset += data.length(); + QStringList cells = data.remove(" ").split("|"); + if(cells.at(3) == "1") + { + keyAList->replace(i, cells.at(2)); + } + if(cells.at(5) == "1") + { + keyBList->replace(i, cells.at(4)); + } + } } data_syncWithKeyWidget(); + } void Mifare::hardnested() @@ -288,7 +335,6 @@ void Mifare::readAll() // note:cannot handle some situations(special trailer blo QString result; bool isKeyAValid; bool isKeyBValid; - const int waitTime = 150; QString tmp; for(int i = 0; i < cardType.sector_size; i++)