Iceman support: info(), chk(), nested()

pull/4/head
wh201906 4 years ago
parent eb5fa7ec9a
commit d15b8e21fc

@ -26,10 +26,10 @@ void Util::execCMD(QString cmd)
emit write(cmd + "\r\n"); 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 currTime = QTime::currentTime();
QTime targetTime = QTime::currentTime().addMSecs(timeout); QTime targetTime = QTime::currentTime().addMSecs(waitTime);
isRequiringOutput = true; isRequiringOutput = true;
requiredOutput->clear(); requiredOutput->clear();
execCMD(cmd); execCMD(cmd);
@ -39,7 +39,7 @@ QString Util::execCMDWithOutput(QString cmd, unsigned long timeout)
if(timeStamp > currTime) if(timeStamp > currTime)
{ {
currTime = timeStamp; currTime = timeStamp;
targetTime = timeStamp.addMSecs(timeout); targetTime = timeStamp.addMSecs(waitTime);
} }
} }
isRequiringOutput = false; isRequiringOutput = false;

@ -25,7 +25,7 @@ public:
explicit Util(QObject *parent = nullptr); explicit Util(QObject *parent = nullptr);
void execCMD(QString cmd); 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); void delay(unsigned int msec);
ClientType getClientType(); ClientType getClientType();
public slots: public slots:

@ -102,31 +102,78 @@ void Mifare::chk()
} }
} }
data_syncWithKeyWidget(); data_syncWithKeyWidget();
} }
void Mifare::nested() 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 " "hf mf nested "
+ QString::number(cardType.type) + 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++) for(int i = 0; i < cardType.sector_size; i++)
{ {
// offset = nestedKeyPattern->indexIn(result, offset); reMatch = keyPattern_res->match(result, offset);
// offset = result.indexOf(*nestedKeyPattern, offset); offset = reMatch.capturedStart();
tmp = result.mid(offset, 47).toUpper(); if(reMatch.hasMatch())
offset += 47; {
if(tmp.at(23) == '1') data = reMatch.captured().toUpper();
keyAList->replace(i, tmp.mid(7, 12).trimmed()); offset += data.length();
if(tmp.at(44) == '1') QStringList cells = data.remove(" ").split("|");
keyBList->replace(i, tmp.mid(28, 12).trimmed()); if(cells.at(3) == "1")
{
keyAList->replace(i, cells.at(2));
}
if(cells.at(5) == "1")
{
keyBList->replace(i, cells.at(4));
}
}
} }
data_syncWithKeyWidget(); data_syncWithKeyWidget();
} }
void Mifare::hardnested() void Mifare::hardnested()
@ -288,7 +335,6 @@ void Mifare::readAll() // note:cannot handle some situations(special trailer blo
QString result; QString result;
bool isKeyAValid; bool isKeyAValid;
bool isKeyBValid; bool isKeyBValid;
const int waitTime = 150;
QString tmp; QString tmp;
for(int i = 0; i < cardType.sector_size; i++) for(int i = 0; i < cardType.sector_size; i++)

Loading…
Cancel
Save