|
|
@ -603,7 +603,7 @@ bool Mifare::data_loadDataFile(const QString& filename)
|
|
|
|
if(file.open(QIODevice::ReadOnly))
|
|
|
|
if(file.open(QIODevice::ReadOnly))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
QByteArray buff;
|
|
|
|
QByteArray buff;
|
|
|
|
buff = file.read(8192);
|
|
|
|
buff = file.read(10000);
|
|
|
|
bool isBin = false;
|
|
|
|
bool isBin = false;
|
|
|
|
for(int i = 0; i < cardType.blocks * 16; i++) // Detect the file type
|
|
|
|
for(int i = 0; i < cardType.blocks * 16; i++) // Detect the file type
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -620,19 +620,11 @@ bool Mifare::data_loadDataFile(const QString& filename)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(isBin)
|
|
|
|
if(isBin)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
char LByte, RByte;
|
|
|
|
if(file.size() < cardType.blocks * 16)
|
|
|
|
char map[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
|
|
|
|
return false;
|
|
|
|
for(int i = 0; i < cardType.blocks; i++)
|
|
|
|
for(int i = 0; i < cardType.blocks; i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
QString tmp = "";
|
|
|
|
QString tmp = bin2text(buff, i, 16);
|
|
|
|
for(int j = 0; j < 16; j++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
LByte = map[(unsigned char)buff[i * 16 + j] >> 4];
|
|
|
|
|
|
|
|
RByte = map[(unsigned char)buff[i * 16 + j] & 0xF];
|
|
|
|
|
|
|
|
tmp += LByte;
|
|
|
|
|
|
|
|
tmp += RByte;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
qDebug() << tmp;
|
|
|
|
|
|
|
|
dataList->replace(i, tmp.toUpper());
|
|
|
|
dataList->replace(i, tmp.toUpper());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -662,23 +654,23 @@ bool Mifare::data_loadKeyFile(const QString& filename)
|
|
|
|
if(file.open(QIODevice::ReadOnly))
|
|
|
|
if(file.open(QIODevice::ReadOnly))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
QByteArray buff;
|
|
|
|
QByteArray buff;
|
|
|
|
buff = file.read(960);
|
|
|
|
buff = file.read(10000);
|
|
|
|
bool isBin = true;
|
|
|
|
bool isKey = file.size() <= cardType.sectors * 14;
|
|
|
|
if(isBin)
|
|
|
|
if(isKey)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
char LByte, RByte;
|
|
|
|
|
|
|
|
char map[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
|
|
|
|
|
|
|
|
for(int i = 0; i < cardType.sectors; i++)
|
|
|
|
for(int i = 0; i < cardType.sectors; i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
QString tmp = "";
|
|
|
|
QString tmp = bin2text(buff, i, 12);
|
|
|
|
for(int j = 0; j < 12; j++)
|
|
|
|
keyAList->replace(i, tmp.left(12).toUpper());
|
|
|
|
{
|
|
|
|
keyBList->replace(i, tmp.right(12).toUpper());
|
|
|
|
LByte = map[(unsigned char)buff[i * 12 + j] >> 4];
|
|
|
|
}
|
|
|
|
RByte = map[(unsigned char)buff[i * 12 + j] & 0xF];
|
|
|
|
}
|
|
|
|
tmp += LByte;
|
|
|
|
else
|
|
|
|
tmp += RByte;
|
|
|
|
{
|
|
|
|
}
|
|
|
|
for(int i = 0; i < cardType.sectors; i++)
|
|
|
|
qDebug() << tmp;
|
|
|
|
{
|
|
|
|
|
|
|
|
int blk = cardType.blks[i] + cardType.blk[i] - 1;
|
|
|
|
|
|
|
|
QString tmp = bin2text(buff, blk, 16);
|
|
|
|
keyAList->replace(i, tmp.left(12).toUpper());
|
|
|
|
keyAList->replace(i, tmp.left(12).toUpper());
|
|
|
|
keyBList->replace(i, tmp.right(12).toUpper());
|
|
|
|
keyBList->replace(i, tmp.right(12).toUpper());
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -693,6 +685,22 @@ bool Mifare::data_loadKeyFile(const QString& filename)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QString Mifare::bin2text(const QByteArray& buff, int i, int length)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
QString ret = "";
|
|
|
|
|
|
|
|
char LByte, RByte;
|
|
|
|
|
|
|
|
char map[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
|
|
|
|
|
|
|
|
for(int j = 0; j < length; j++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
LByte = map[(unsigned char)buff[i * length + j] >> 4];
|
|
|
|
|
|
|
|
RByte = map[(unsigned char)buff[i * length + j] & 0xF];
|
|
|
|
|
|
|
|
ret += LByte;
|
|
|
|
|
|
|
|
ret += RByte;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
qDebug() << ret;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Mifare::data_saveDataFile(const QString& filename, bool isBin)
|
|
|
|
bool Mifare::data_saveDataFile(const QString& filename, bool isBin)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
QFile file(filename, this);
|
|
|
|
QFile file(filename, this);
|
|
|
|