Support encode Access Bits(in the Trailer Decoder)

This commit is contained in:
wh201906
2020-08-06 14:53:49 +08:00
parent 46b3912e82
commit 7dfabb60e9
5 changed files with 288 additions and 63 deletions
+33 -12
View File
@@ -295,19 +295,13 @@ QString Mifare::_readblk(int blockId, KeyType keyType, const QString& key, int w
{
data = dataPattern->match(result).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
// if the given key type is keyB, it will never get the keyA from the key block
// 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
if(isKeyBlock && keyType == KEY_A)
{
data.replace(0, 12, key);
QString tmpKey = data.right(12);
result = util->execCMDWithOutput(
"hf mf rdbl "
+ QString::number(blockId)
+ " B "
+ tmpKey,
waitTime);
if(result.indexOf("isOk:01") == -1)
QList<quint8> ACBits = data_getACBits(data.mid(12, 8));
if(ACBits[3] == 2 || ACBits[3] == 3 || ACBits[3] == 5 || ACBits[3] == 6 || ACBits[3] == 7) // in these cases, the KeyB cannot be read by KeyA
{
data.replace(20, 12, "????????????");
}
@@ -852,8 +846,7 @@ bool Mifare::data_isKeyValid(const QString &key)
return true;
}
Mifare::DataType
Mifare::data_isDataValid(QString data) // "?" will not been processd there
Mifare::DataType Mifare::data_isDataValid(const QString& data) // "?" will not been processd there
{
if(data.length() == 47)
{
@@ -1176,3 +1169,31 @@ void Mifare::data_fillKeys()
}
data_syncWithKeyWidget();
}
QList<quint8> Mifare::data_getACBits(const QString& text) //return empty QList if the text is invalid
{
QString input = text;
QList<quint8> result;
input.remove(" ");
if(input.length() < 6)
{
return result;
}
input = input.left(6);
quint32 val = input.toUInt(nullptr, 16);
quint8 halfBytes[6];
for(int i = 0; i < 6; i++)
{
halfBytes[i] = (val >> ((5 - i) * 4)) & 0xf;
}
qDebug() << val;
if((~halfBytes[0] & 0xf) == halfBytes[5] && (~halfBytes[1] & 0xf) == halfBytes[2] && (~halfBytes[3] & 0xf) == halfBytes[4])
{
for(int i = 0; i < 4; i++)
{
result.append((((halfBytes[4] >> i) & 1) << 2) | (((halfBytes[5] >> i) & 1) << 1) | (((halfBytes[2] >> i) & 1) << 0));
}
}
return result;
}
+3 -2
View File
@@ -72,8 +72,8 @@ public:
void data_clearData();
void data_clearKey();
bool data_isKeyValid(const QString& key);
Mifare::DataType data_isDataValid(QString data);
static bool data_isKeyValid(const QString& key);
static Mifare::DataType data_isDataValid(const QString& data);
void data_syncWithDataWidget(bool syncAll = true, int block = 0);
void data_syncWithKeyWidget(bool syncAll = true, int sector = 0, KeyType keyType = KEY_A);
@@ -107,6 +107,7 @@ public:
QString _readblk(int blockId, KeyType keyType, const QString &key, int waitTime = 300);
QStringList _readsec(int sectorId, KeyType keyType, const QString &key, int waitTime = 300);
static QList<quint8> data_getACBits(const QString &text);
public slots:
signals: