Add _readblk() (not tested)

pull/4/head
wh201906 4 years ago
parent cd122b8959
commit a77985824c

@ -1,10 +1,11 @@
#include "util.h"
Util::Util(QObject *parent) : QObject(parent)
Util::Util(Util::ClientType clientType, QObject *parent) : QObject(parent)
{
isRequiringOutput = false;
requiredOutput = new QString();
timeStamp = QTime::currentTime();
this->clientType = clientType;
}
void Util::processOutput(QString output)
@ -50,3 +51,7 @@ void Util::delay(unsigned int msec)
while(QTime::currentTime() < timer)
QApplication::processEvents(QEventLoop::AllEvents, 100);
}
Util::ClientType Util::getClientType()
{
return this->clientType;
}

@ -13,11 +13,17 @@ class Util : public QObject
{
Q_OBJECT
public:
explicit Util(QObject *parent = nullptr);
enum ClientType
{
OFFICIAL,
ICEMAN,
};
explicit Util(Util::ClientType clientType, QObject *parent = nullptr);
void execCMD(QString cmd);
QString execCMDWithOutput(QString cmd, unsigned long timeout = 2000);
void delay(unsigned int msec);
ClientType getClientType();
public slots:
void processOutput(QString output);
@ -28,6 +34,7 @@ private:
signals:
void refreshOutput(const QString& output);
void write(QString data);
ClientType clientType;
};
#endif // UTIL_H

@ -114,6 +114,72 @@ void Mifare::list()
ui->funcTab->setCurrentIndex(1);
}
QString Mifare::_readblk(int blockId, KeyType keyType, QString& key, int waitTime)
{
QString data;
QString result;
if(util->getClientType() == Util::OFFICIAL)
{
result = util->execCMDWithOutput(
"hf mf rdbl "
+ QString::number(blockId)
+ " "
+ (char)keyType
+ " "
+ key,
waitTime);
if(result.indexOf("isOk:01") != -1)
{
result = result.mid(dataPattern->indexIn(result), 47).toUpper();
if((blockId < 128 && ((blockId + 1) % 4 == 0)) || ((blockId + 1) % 8 == 0)) // process key block
{
if(keyType == KEY_A)
{
for(int i = 0; i < 6; i++)
{
result = result.replace(i * 3, 2, key.mid(i * 2, 2));
}
data = result;
QString tmpKey = result.right(18).replace(" ", "");
result = util->execCMDWithOutput(
"hf mf rdbl "
+ QString::number(blockId)
+ " B "
+ tmpKey,
waitTime);
if(result.indexOf("isOk:01") == -1)
{
result = data;
result = result.replace(30, 17, "?? ?? ?? ?? ?? ??");
data = result;
}
}
else
{
for(int i = 0; i < 6; i++)
{
result = result.replace(
30 + i * 3,
2,
key.mid(i * 2, 2));
}
result = result.replace(0, 18, "?? ?? ?? ?? ?? ?? ");
data = result;
}
}
else
{
data = result;
}
}
else
{
data = "";
}
return data;
}
}
void Mifare::read()
{
int waitTime = 300;

@ -32,8 +32,8 @@ public:
enum KeyType
{
KEY_A,
KEY_B,
KEY_A = 'A',
KEY_B = 'B',
};
enum DataType
@ -134,6 +134,8 @@ private:
QRegExp* nestedKeyPattern;
QRegExp* UIDPattern;
QString bin2text(const QByteArray& buff, int start, int length);
QString _readblk(int blockId, KeyType keyType, QString &key, int waitTime);
};
#endif // MIFARE_H

Loading…
Cancel
Save