From 24a6e1869bd4eb6e37922e3b30473f881e56682e Mon Sep 17 00:00:00 2001 From: wh201906 Date: Mon, 15 Feb 2021 23:46:05 +0800 Subject: [PATCH] Support hardnested(), darkside(), readblk(), readsec() in latest Iceman repo --- common/util.cpp | 8 ++++--- common/util.h | 6 +++--- lang/en_US.ts | 30 +++++++++++++------------- lang/zh_CN.ts | 34 ++++++++++++++--------------- module/mifare.cpp | 36 +++++++++++++++++++++++-------- ui/mf_attack_hardnesteddialog.cpp | 32 ++++++++++++++++++--------- ui/mf_attack_hardnesteddialog.h | 1 + 7 files changed, 90 insertions(+), 57 deletions(-) diff --git a/common/util.cpp b/common/util.cpp index 3443441..c620b97 100644 --- a/common/util.cpp +++ b/common/util.cpp @@ -1,11 +1,12 @@ #include "util.h" +Util::ClientType Util::clientType = CLIENTTYPE_OFFICIAL; + Util::Util(QObject *parent) : QObject(parent) { isRequiringOutput = false; requiredOutput = new QString(); timeStamp = QTime::currentTime(); - this->clientType = CLIENTTYPE_OFFICIAL; qRegisterMetaType("Util::ClientType"); } @@ -79,14 +80,15 @@ void Util::delay(unsigned int msec) while(QTime::currentTime() < timer) QApplication::processEvents(QEventLoop::AllEvents, 100); } + Util::ClientType Util::getClientType() { - return this->clientType; + return Util::clientType; } void Util::setClientType(Util::ClientType clientType) { - this->clientType = clientType; + Util::clientType = clientType; } void Util::setRunningState(bool st) diff --git a/common/util.h b/common/util.h index 3327330..fed751e 100644 --- a/common/util.h +++ b/common/util.h @@ -52,12 +52,12 @@ public: void execCMD(const QString& cmd); QString execCMDWithOutput(const QString& cmd, ReturnTrigger trigger = 10000); void delay(unsigned int msec); - ClientType getClientType(); + static ClientType getClientType(); static const int rawTabIndex = 1; static bool chooseLanguage(QSettings *guiSettings, QMainWindow *window); public slots: void processOutput(const QString& output); - void setClientType(Util::ClientType clientType); + static void setClientType(Util::ClientType clientType); void setRunningState(bool st); private: @@ -65,7 +65,7 @@ private: bool isRunning; QString* requiredOutput; QTime timeStamp; - ClientType clientType; + static ClientType clientType; signals: void refreshOutput(const QString& output); void write(QString data); // connected to PM3Process::write(QString data); diff --git a/lang/en_US.ts b/lang/en_US.ts index a9aff47..0df4a6c 100644 --- a/lang/en_US.ts +++ b/lang/en_US.ts @@ -989,56 +989,56 @@ or "-p <port> -f" Mifare - + Success! - - + - - - - + + + + + Info - + Plz provide at least one known key - - + + Failed! - + The Access Bits is invalid! It could make the whole sector blocked irreversibly! Continue to write? - + Successful! - + Failed to write to these blocks: - + Select them? - + Failed to read card. diff --git a/lang/zh_CN.ts b/lang/zh_CN.ts index 957f603..3ff7b4f 100644 --- a/lang/zh_CN.ts +++ b/lang/zh_CN.ts @@ -532,13 +532,13 @@ It could make the whole sector blocked irreversibly! Read One - 读取单个区 + 读取单个块 Write One - 写入单个区 + 写入单个块 @@ -997,34 +997,34 @@ or "-p <port> -f" Mifare - + Success! 成功! - - + - - - - + + + + + Info 信息 - + Plz provide at least one known key 请至少提供一个已知密码 - - + + Failed! 失败! - + The Access Bits is invalid! It could make the whole sector blocked irreversibly! Continue to write? @@ -1033,22 +1033,22 @@ Continue to write? 确定要写入吗? - + Successful! 成功! - + Failed to write to these blocks: 写入以下块失败: - + Select them? 选中这些块? - + Failed to read card. 读卡失败。 diff --git a/module/mifare.cpp b/module/mifare.cpp index 3acfb0f..95eab92 100644 --- a/module/mifare.cpp +++ b/module/mifare.cpp @@ -298,6 +298,7 @@ QString Mifare::_readblk(int blockId, KeyType keyType, const QString& key, Targe { QString data; QString result; + QRegularExpressionMatch currMatch; bool isTrailerBlock = (blockId < 128 && ((blockId + 1) % 4 == 0)) || ((blockId + 1) % 16 == 0); if(util->getClientType() == Util::CLIENTTYPE_OFFICIAL || util->getClientType() == Util::CLIENTTYPE_ICEMAN) @@ -317,9 +318,10 @@ QString Mifare::_readblk(int blockId, KeyType keyType, const QString& key, Targe + " " + key, waitTime); - if(result.indexOf("isOk:01") != -1) + currMatch = dataPattern->match(result); + if(currMatch.hasMatch()) { - data = dataPattern->match(result).captured().toUpper(); + data = currMatch.captured().toUpper(); data.remove(" "); // when the target block is a key block and the given key type is KeyA, try to check whether the KeyB is valid(by Access Bits) // if the given key type is KeyB, it will never get the KeyA from the key block @@ -347,15 +349,19 @@ QString Mifare::_readblk(int blockId, KeyType keyType, const QString& key, Targe "hf mf cgetblk " + QString::number(blockId), waitTime); - if(result.indexOf("Chinese magic") != -1) + currMatch = dataPattern->match(result); + if(currMatch.hasMatch()) { - data = dataPattern->match(result).captured().toUpper(); + data = currMatch.captured().toUpper(); data.remove(" "); } else data = ""; } - else if(targetType == TARGET_EMULATOR) + } + if(util->getClientType() == Util::CLIENTTYPE_OFFICIAL) + { + if(targetType == TARGET_EMULATOR) { result = util->execCMDWithOutput( "hf mf eget " @@ -365,6 +371,18 @@ QString Mifare::_readblk(int blockId, KeyType keyType, const QString& key, Targe data.remove(" "); } } + else if(util->getClientType() == Util::CLIENTTYPE_ICEMAN) + { + if(targetType == TARGET_EMULATOR) + { + result = util->execCMDWithOutput( + "hf mf egetblk " + + QString::number(blockId), + 150); + data = dataPattern->match(result).captured().toUpper(); + data.remove(" "); + } + } return data; } @@ -373,7 +391,7 @@ QStringList Mifare::_readsec(int sectorId, KeyType keyType, const QString& key, QStringList data; QString result, tmp; QRegularExpressionMatch reMatch; - int offset = -1; + int offset = -1; // for targetType == TARGET_EMULATOR for(int i = 0; i < cardType.blk[sectorId]; i++) { @@ -397,7 +415,7 @@ QStringList Mifare::_readsec(int sectorId, KeyType keyType, const QString& key, + " " + key, waitTime); - offset = result.indexOf("isOk:01"); + offset = result.indexOf("isOk:01"); // find successful flag } else if(targetType == TARGET_UID) { @@ -405,7 +423,7 @@ QStringList Mifare::_readsec(int sectorId, KeyType keyType, const QString& key, "hf mf cgetsc " + QString::number(sectorId), waitTime); - offset = result.indexOf("Chinese magic"); + offset = result.indexOf("error") == -1 ? 0 : -1; // find failed flag } if(offset != -1) { @@ -424,7 +442,7 @@ QStringList Mifare::_readsec(int sectorId, KeyType keyType, const QString& key, } // if failed, try to read them seperately. // (when one of the block cannot be read, the rdsc will return nothing, so you need to read the rest of blocks manually) - else if(targetType != TARGET_UID) // if the targetType is Chinese Magic Card, then the result implies the backdoor command is invalid. + else if(targetType == TARGET_UID || targetType == TARGET_EMULATOR) // if the targetType is Chinese Magic Card, then the result implies the backdoor command is invalid. { for(int i = 0; i < cardType.blk[sectorId]; i++) data[i] = _readblk(cardType.blks[sectorId] + i, keyType, key, targetType, waitTime); diff --git a/ui/mf_attack_hardnesteddialog.cpp b/ui/mf_attack_hardnesteddialog.cpp index 6896764..79b01c6 100644 --- a/ui/mf_attack_hardnesteddialog.cpp +++ b/ui/mf_attack_hardnesteddialog.cpp @@ -21,14 +21,26 @@ MF_Attack_hardnestedDialog::~MF_Attack_hardnestedDialog() void MF_Attack_hardnestedDialog::on_buttonBox_accepted() { - emit sendCMD("hf mf hardnested " - + ui->knownKeySectorBox->currentText() - + " " - + ui->knownKeyTypeBox->currentText() - + " " - + ui->knownKeyBox->text() - + " " - + ui->targetKeySectorBox->currentText() - + " " - + ui->targetKeyTypeBox->currentText()); + if(Util::getClientType() == Util::CLIENTTYPE_OFFICIAL) + emit sendCMD("hf mf hardnested " + + ui->knownKeySectorBox->currentText() + + " " + + ui->knownKeyTypeBox->currentText() + + " " + + ui->knownKeyBox->text() + + " " + + ui->targetKeySectorBox->currentText() + + " " + + ui->targetKeyTypeBox->currentText()); + else if(Util::getClientType() == Util::CLIENTTYPE_ICEMAN) // same format in v4.9237 + emit sendCMD("hf mf hardnested " + + ui->knownKeySectorBox->currentText() + + " " + + ui->knownKeyTypeBox->currentText() + + " " + + ui->knownKeyBox->text() + + " " + + ui->targetKeySectorBox->currentText() + + " " + + ui->targetKeyTypeBox->currentText()); } diff --git a/ui/mf_attack_hardnesteddialog.h b/ui/mf_attack_hardnesteddialog.h index d120b2a..785cb75 100644 --- a/ui/mf_attack_hardnesteddialog.h +++ b/ui/mf_attack_hardnesteddialog.h @@ -2,6 +2,7 @@ #define MF_ATTACK_HARDNESTEDDIALOG_H #include +#include "common/util.h" namespace Ui {