Add _readblk() (not tested)

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

@ -1,10 +1,11 @@
#include "util.h" #include "util.h"
Util::Util(QObject *parent) : QObject(parent) Util::Util(Util::ClientType clientType, QObject *parent) : QObject(parent)
{ {
isRequiringOutput = false; isRequiringOutput = false;
requiredOutput = new QString(); requiredOutput = new QString();
timeStamp = QTime::currentTime(); timeStamp = QTime::currentTime();
this->clientType = clientType;
} }
void Util::processOutput(QString output) void Util::processOutput(QString output)
@ -31,7 +32,7 @@ QString Util::execCMDWithOutput(QString cmd, unsigned long timeout)
isRequiringOutput = true; isRequiringOutput = true;
requiredOutput->clear(); requiredOutput->clear();
execCMD(cmd); execCMD(cmd);
while( QTime::currentTime() < targetTime) while(QTime::currentTime() < targetTime)
{ {
QApplication::processEvents(); QApplication::processEvents();
if(timeStamp > currTime) if(timeStamp > currTime)
@ -47,6 +48,10 @@ QString Util::execCMDWithOutput(QString cmd, unsigned long timeout)
void Util::delay(unsigned int msec) void Util::delay(unsigned int msec)
{ {
QTime timer = QTime::currentTime().addMSecs(msec); QTime timer = QTime::currentTime().addMSecs(msec);
while( QTime::currentTime() < timer ) while(QTime::currentTime() < timer)
QApplication::processEvents(QEventLoop::AllEvents, 100); QApplication::processEvents(QEventLoop::AllEvents, 100);
} }
Util::ClientType Util::getClientType()
{
return this->clientType;
}

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

@ -114,6 +114,72 @@ void Mifare::list()
ui->funcTab->setCurrentIndex(1); 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() void Mifare::read()
{ {
int waitTime = 300; int waitTime = 300;

@ -32,8 +32,8 @@ public:
enum KeyType enum KeyType
{ {
KEY_A, KEY_A = 'A',
KEY_B, KEY_B = 'B',
}; };
enum DataType enum DataType
@ -87,7 +87,7 @@ public:
void data_clearData(); void data_clearData();
void data_clearKey(); void data_clearKey();
bool data_isKeyValid(const QString &key); bool data_isKeyValid(const QString& key);
Mifare::DataType data_isDataValid(QString data); Mifare::DataType data_isDataValid(QString data);
void data_syncWithDataWidget(bool syncAll = true, int block = 0); void data_syncWithDataWidget(bool syncAll = true, int block = 0);
void data_syncWithKeyWidget(bool syncAll = true, int sector = 0, KeyType keyType = KEY_A); void data_syncWithKeyWidget(bool syncAll = true, int sector = 0, KeyType keyType = KEY_A);
@ -102,15 +102,15 @@ public:
void wipeC(); void wipeC();
void setParameterC(); void setParameterC();
bool data_loadDataFile(const QString &filename); bool data_loadDataFile(const QString& filename);
bool data_loadKeyFile(const QString &filename); bool data_loadKeyFile(const QString& filename);
bool data_saveDataFile(const QString& filename, bool isBin); bool data_saveDataFile(const QString& filename, bool isBin);
bool data_saveKeyFile(const QString &filename, bool isBin); bool data_saveKeyFile(const QString& filename, bool isBin);
void data_key2Data(); void data_key2Data();
void data_data2Key(); void data_data2Key();
void data_setData(int block, const QString &data); void data_setData(int block, const QString& data);
void data_setKey(int sector, KeyType keyType, const QString &key); void data_setKey(int sector, KeyType keyType, const QString& key);
void lockC(); void lockC();
void writeAllE(); void writeAllE();
void readAllE(); void readAllE();
@ -133,7 +133,9 @@ private:
QRegExp* chkKeyPattern; QRegExp* chkKeyPattern;
QRegExp* nestedKeyPattern; QRegExp* nestedKeyPattern;
QRegExp* UIDPattern; QRegExp* UIDPattern;
QString bin2text(const QByteArray &buff, int start, int length); QString bin2text(const QByteArray& buff, int start, int length);
QString _readblk(int blockId, KeyType keyType, QString &key, int waitTime);
}; };
#endif // MIFARE_H #endif // MIFARE_H

Loading…
Cancel
Save