|
|
|
@ -1,7 +1,6 @@
|
|
|
|
|
#include "mifare.h"
|
|
|
|
|
|
|
|
|
|
Mifare::Mifare(Ui::MainWindow *ui, Util *addr, QWidget *parent)
|
|
|
|
|
: QObject(parent)
|
|
|
|
|
Mifare::Mifare(Ui::MainWindow *ui, Util *addr, QWidget *parent): QObject(parent)
|
|
|
|
|
{
|
|
|
|
|
this->parent = parent;
|
|
|
|
|
util = addr;
|
|
|
|
@ -22,8 +21,7 @@ QString Mifare::info(bool isRequiringOutput)
|
|
|
|
|
if(isRequiringOutput)
|
|
|
|
|
{
|
|
|
|
|
QString result = util->execCMDWithOutput("hf 14a info", 500);
|
|
|
|
|
qDebug() << result
|
|
|
|
|
<< result.indexOf(QRegExp(ui->MF_RW_dataEdit->text()), 0);
|
|
|
|
|
qDebug() << result << result.indexOf(QRegExp(ui->MF_RW_dataEdit->text()), 0);
|
|
|
|
|
result.replace("UID :", "|");
|
|
|
|
|
result.replace("ATQA :", "|");
|
|
|
|
|
result.replace("SAK :", "|");
|
|
|
|
@ -48,7 +46,9 @@ QString Mifare::info(bool isRequiringOutput)
|
|
|
|
|
void Mifare::chk()
|
|
|
|
|
{
|
|
|
|
|
QString result = util->execCMDWithOutput(
|
|
|
|
|
"hf mf chk *" + QString::number(cardType.type) + " ?",
|
|
|
|
|
"hf mf chk *"
|
|
|
|
|
+ QString::number(cardType.type)
|
|
|
|
|
+ " ?",
|
|
|
|
|
1000 + cardType.type * 1000);
|
|
|
|
|
qDebug() << result;
|
|
|
|
|
|
|
|
|
@ -74,7 +74,9 @@ void Mifare::chk()
|
|
|
|
|
void Mifare::nested()
|
|
|
|
|
{
|
|
|
|
|
QString result = util->execCMDWithOutput(
|
|
|
|
|
"hf mf nested " + QString::number(cardType.type) + " *");
|
|
|
|
|
"hf mf nested "
|
|
|
|
|
+ QString::number(cardType.type)
|
|
|
|
|
+ " *");
|
|
|
|
|
|
|
|
|
|
int offset = 0;
|
|
|
|
|
QString tmp;
|
|
|
|
@ -117,27 +119,31 @@ void Mifare::read()
|
|
|
|
|
int waitTime = 300;
|
|
|
|
|
int currblk = ui->MF_RW_blockBox->currentText().toInt();
|
|
|
|
|
QString result = util->execCMDWithOutput(
|
|
|
|
|
"hf mf rdbl " + QString::number(currblk) + " " +
|
|
|
|
|
ui->MF_RW_keyTypeBox->currentText() + " " + ui->MF_RW_keyEdit->text(),
|
|
|
|
|
"hf mf rdbl "
|
|
|
|
|
+ QString::number(currblk)
|
|
|
|
|
+ " "
|
|
|
|
|
+ ui->MF_RW_keyTypeBox->currentText()
|
|
|
|
|
+ " "
|
|
|
|
|
+ ui->MF_RW_keyEdit->text(),
|
|
|
|
|
waitTime);
|
|
|
|
|
if(result.indexOf("isOk:01") != -1)
|
|
|
|
|
{
|
|
|
|
|
result = result.mid(dataPattern->indexIn(result), 47).toUpper();
|
|
|
|
|
if ((currblk < 128 && ((currblk + 1) % 4 == 0)) ||
|
|
|
|
|
((currblk + 1) % 8 == 0)) // process key block
|
|
|
|
|
if((currblk < 128 && ((currblk + 1) % 4 == 0)) || ((currblk + 1) % 8 == 0)) // process key block
|
|
|
|
|
{
|
|
|
|
|
if(ui->MF_RW_keyTypeBox->currentText() == "A")
|
|
|
|
|
{
|
|
|
|
|
for(int i = 0; i < 6; i++)
|
|
|
|
|
{
|
|
|
|
|
result =
|
|
|
|
|
result.replace(i * 3, 2, ui->MF_RW_keyEdit->text().mid(i * 2, 2));
|
|
|
|
|
result = result.replace(i * 3, 2, ui->MF_RW_keyEdit->text().mid(i * 2, 2));
|
|
|
|
|
}
|
|
|
|
|
ui->MF_RW_dataEdit->setText(result);
|
|
|
|
|
QString tmpKey = result.right(18).replace(" ", "");
|
|
|
|
|
result = util->execCMDWithOutput(
|
|
|
|
|
"hf mf rdbl " + ui->MF_RW_keyTypeBox->currentText() + " B " +
|
|
|
|
|
tmpKey,
|
|
|
|
|
"hf mf rdbl "
|
|
|
|
|
+ ui->MF_RW_keyTypeBox->currentText()
|
|
|
|
|
+ " B "
|
|
|
|
|
+ tmpKey,
|
|
|
|
|
waitTime);
|
|
|
|
|
if(result.indexOf("isOk:01") == -1)
|
|
|
|
|
{
|
|
|
|
@ -150,7 +156,9 @@ void Mifare::read()
|
|
|
|
|
{
|
|
|
|
|
for(int i = 0; i < 6; i++)
|
|
|
|
|
{
|
|
|
|
|
result = result.replace(30 + i * 3, 2,
|
|
|
|
|
result = result.replace(
|
|
|
|
|
30 + i * 3,
|
|
|
|
|
2,
|
|
|
|
|
ui->MF_RW_keyEdit->text().mid(i * 2, 2));
|
|
|
|
|
}
|
|
|
|
|
result = result.replace(0, 18, "?? ?? ?? ?? ?? ?? ");
|
|
|
|
@ -182,8 +190,11 @@ void Mifare::readAll()
|
|
|
|
|
// check keys and read the first block of each sector
|
|
|
|
|
if(data_isKeyValid(keyAList->at(i)))
|
|
|
|
|
{
|
|
|
|
|
result = util->execCMDWithOutput("hf mf rdsc " + QString::number(i) +
|
|
|
|
|
" A " + keyAList->at(i),
|
|
|
|
|
result = util->execCMDWithOutput(
|
|
|
|
|
"hf mf rdsc "
|
|
|
|
|
+ QString::number(i)
|
|
|
|
|
+ " A "
|
|
|
|
|
+ keyAList->at(i),
|
|
|
|
|
waitTime);
|
|
|
|
|
qDebug() << result;
|
|
|
|
|
offset = result.indexOf("isOk:01");
|
|
|
|
@ -205,8 +216,11 @@ void Mifare::readAll()
|
|
|
|
|
}
|
|
|
|
|
if(data_isKeyValid(keyBList->at(i)))
|
|
|
|
|
{
|
|
|
|
|
result = util->execCMDWithOutput("hf mf rdsc " + QString::number(i) +
|
|
|
|
|
" B " + keyBList->at(i),
|
|
|
|
|
result = util->execCMDWithOutput(
|
|
|
|
|
"hf mf rdsc "
|
|
|
|
|
+ QString::number(i)
|
|
|
|
|
+ " B "
|
|
|
|
|
+ keyBList->at(i),
|
|
|
|
|
waitTime);
|
|
|
|
|
qDebug() << result;
|
|
|
|
|
offset = result.indexOf("isOk:01");
|
|
|
|
@ -260,9 +274,10 @@ void Mifare::readAll()
|
|
|
|
|
QString tmpKey =
|
|
|
|
|
dataList->at(cardType.blks[i] + cardType.blk[i] - 1).right(12);
|
|
|
|
|
result = util->execCMDWithOutput(
|
|
|
|
|
"hf mf rdbl " +
|
|
|
|
|
QString::number(cardType.blks[i] + cardType.blk[i] - 1) +
|
|
|
|
|
" B " + tmpKey,
|
|
|
|
|
"hf mf rdbl "
|
|
|
|
|
+ QString::number(cardType.blks[i] + cardType.blk[i] - 1)
|
|
|
|
|
+ " B "
|
|
|
|
|
+ tmpKey,
|
|
|
|
|
waitTime);
|
|
|
|
|
if(result.indexOf("isOk:01") != -1)
|
|
|
|
|
{
|
|
|
|
@ -310,24 +325,29 @@ void Mifare::writeAll()
|
|
|
|
|
{
|
|
|
|
|
result = ""; // if the KeyA is invalid and the result is not empty, the
|
|
|
|
|
// KeyB will not be tested.
|
|
|
|
|
if (data_isDataValid(dataList->at(cardType.blks[i] + j)) !=
|
|
|
|
|
DATA_NOSPACE ||
|
|
|
|
|
dataList->at(cardType.blks[i] + j).contains('?'))
|
|
|
|
|
if(data_isDataValid(dataList->at(cardType.blks[i] + j)) != DATA_NOSPACE || dataList->at(cardType.blks[i] + j).contains('?'))
|
|
|
|
|
continue;
|
|
|
|
|
if(data_isKeyValid(keyAList->at(i)))
|
|
|
|
|
{
|
|
|
|
|
result = util->execCMDWithOutput(
|
|
|
|
|
"hf mf wrbl " + QString::number(cardType.blks[i] + j) + " A " +
|
|
|
|
|
keyAList->at(i) + " " + dataList->at(cardType.blks[i] + j),
|
|
|
|
|
"hf mf wrbl " +
|
|
|
|
|
QString::number(cardType.blks[i] + j)
|
|
|
|
|
+ " A "
|
|
|
|
|
+ keyAList->at(i)
|
|
|
|
|
+ " "
|
|
|
|
|
+ dataList->at(cardType.blks[i] + j),
|
|
|
|
|
waitTime);
|
|
|
|
|
}
|
|
|
|
|
qDebug() << i << j << result.indexOf("isOk:01")
|
|
|
|
|
<< data_isKeyValid(keyBList->at(i));
|
|
|
|
|
qDebug() << i << j << result.indexOf("isOk:01") << data_isKeyValid(keyBList->at(i));
|
|
|
|
|
if(result.indexOf("isOk:01") == -1 && data_isKeyValid(keyBList->at(i)))
|
|
|
|
|
{
|
|
|
|
|
result = util->execCMDWithOutput(
|
|
|
|
|
"hf mf wrbl " + QString::number(cardType.blks[i] + j) + " B " +
|
|
|
|
|
keyBList->at(i) + " " + dataList->at(cardType.blks[i] + j),
|
|
|
|
|
"hf mf wrbl "
|
|
|
|
|
+ QString::number(cardType.blks[i] + j)
|
|
|
|
|
+ " B "
|
|
|
|
|
+ keyBList->at(i)
|
|
|
|
|
+ " "
|
|
|
|
|
+ dataList->at(cardType.blks[i] + j),
|
|
|
|
|
waitTime);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -339,7 +359,9 @@ void Mifare::readC()
|
|
|
|
|
int waitTime = 300;
|
|
|
|
|
int currblk = ui->MF_RW_blockBox->currentText().toInt();
|
|
|
|
|
QString result = util->execCMDWithOutput(
|
|
|
|
|
"hf mf cgetblk " + QString::number(currblk), waitTime);
|
|
|
|
|
"hf mf cgetblk "
|
|
|
|
|
+ QString::number(currblk),
|
|
|
|
|
waitTime);
|
|
|
|
|
if(result.indexOf("No chinese") == -1)
|
|
|
|
|
{
|
|
|
|
|
result = result.mid(dataPattern->indexIn(result), 47).toUpper();
|
|
|
|
@ -356,7 +378,10 @@ void Mifare::readAllC()
|
|
|
|
|
int offset = 0;
|
|
|
|
|
for(int i = 0; i < cardType.sectors; i++)
|
|
|
|
|
{
|
|
|
|
|
result = util->execCMDWithOutput("hf mf cgetsc " + QString::number(i), waitTime);
|
|
|
|
|
result = util->execCMDWithOutput(
|
|
|
|
|
"hf mf cgetsc "
|
|
|
|
|
+ QString::number(i),
|
|
|
|
|
waitTime);
|
|
|
|
|
qDebug() << result;
|
|
|
|
|
if(result.indexOf("No chinese") == -1)
|
|
|
|
|
{
|
|
|
|
@ -372,10 +397,8 @@ void Mifare::readAllC()
|
|
|
|
|
dataList->replace(cardType.blks[i] + j, tmp);
|
|
|
|
|
data_syncWithDataWidget(false, cardType.blks[i] + j);
|
|
|
|
|
}
|
|
|
|
|
keyAList->replace(
|
|
|
|
|
i, dataList->at(cardType.blks[i] + cardType.blk[i] - 1).left(12));
|
|
|
|
|
keyBList->replace(
|
|
|
|
|
i, dataList->at(cardType.blks[i] + cardType.blk[i] - 1).right(12));
|
|
|
|
|
keyAList->replace(i, dataList->at(cardType.blks[i] + cardType.blk[i] - 1).left(12));
|
|
|
|
|
keyBList->replace(i, dataList->at(cardType.blks[i] + cardType.blk[i] - 1).right(12));
|
|
|
|
|
data_syncWithKeyWidget(false, i, true);
|
|
|
|
|
data_syncWithKeyWidget(false, i, false);
|
|
|
|
|
}
|
|
|
|
@ -386,8 +409,10 @@ void Mifare::writeC()
|
|
|
|
|
{
|
|
|
|
|
int waitTime = 150;
|
|
|
|
|
QString result = util->execCMDWithOutput(
|
|
|
|
|
"hf mf csetblk " + ui->MF_RW_blockBox->currentText() + " " +
|
|
|
|
|
ui->MF_RW_dataEdit->text().replace(" ", ""),
|
|
|
|
|
"hf mf csetblk "
|
|
|
|
|
+ ui->MF_RW_blockBox->currentText()
|
|
|
|
|
+ " "
|
|
|
|
|
+ ui->MF_RW_dataEdit->text().replace(" ", ""),
|
|
|
|
|
waitTime);
|
|
|
|
|
if(result.indexOf("No chinese") == -1)
|
|
|
|
|
{
|
|
|
|
@ -408,12 +433,13 @@ void Mifare::writeAllC()
|
|
|
|
|
for(int j = 0; j < cardType.blk[i]; j++)
|
|
|
|
|
{
|
|
|
|
|
result = "";
|
|
|
|
|
if (data_isDataValid(dataList->at(cardType.blks[i] + j)) != DATA_NOSPACE ||
|
|
|
|
|
dataList->at(cardType.blks[i] + j).contains('?'))
|
|
|
|
|
if(data_isDataValid(dataList->at(cardType.blks[i] + j)) != DATA_NOSPACE || dataList->at(cardType.blks[i] + j).contains('?'))
|
|
|
|
|
continue;
|
|
|
|
|
result = util->execCMDWithOutput(
|
|
|
|
|
"hf mf csetblk " + QString::number(cardType.blks[i] + j) + " " +
|
|
|
|
|
dataList->at(cardType.blks[i] + j),
|
|
|
|
|
"hf mf csetblk "
|
|
|
|
|
+ QString::number(cardType.blks[i] + j)
|
|
|
|
|
+ " "
|
|
|
|
|
+ dataList->at(cardType.blks[i] + j),
|
|
|
|
|
waitTime);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -421,7 +447,10 @@ void Mifare::writeAllC()
|
|
|
|
|
|
|
|
|
|
void Mifare::wipeC()
|
|
|
|
|
{
|
|
|
|
|
util->execCMD("hf mf cwipe " + QString::number(cardType.type) + " f");
|
|
|
|
|
util->execCMD(
|
|
|
|
|
"hf mf cwipe "
|
|
|
|
|
+ QString::number(cardType.type)
|
|
|
|
|
+ " f");
|
|
|
|
|
ui->funcTab->setCurrentIndex(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -436,8 +465,7 @@ void Mifare::setParameterC()
|
|
|
|
|
lis[0].replace(" ", "");
|
|
|
|
|
lis[1].replace(" ", "");
|
|
|
|
|
lis[2].replace(" ", "");
|
|
|
|
|
MF_UID_parameterDialog dialog(lis[0].toUpper(), lis[1].toUpper(),
|
|
|
|
|
lis[2].mid(0, 2).toUpper());
|
|
|
|
|
MF_UID_parameterDialog dialog(lis[0].toUpper(), lis[1].toUpper(), lis[2].mid(0, 2).toUpper());
|
|
|
|
|
connect(&dialog, &MF_UID_parameterDialog::sendCMD, util, &Util::execCMD);
|
|
|
|
|
if(dialog.exec() == QDialog::Accepted)
|
|
|
|
|
ui->funcTab->setCurrentIndex(1);
|
|
|
|
@ -450,8 +478,7 @@ void Mifare::lockC()
|
|
|
|
|
util->execCMD("hf 14a raw -pa 43");
|
|
|
|
|
util->execCMD("hf 14a raw -pa E0 00 39 F7");
|
|
|
|
|
util->execCMD("hf 14a raw -pa E1 00 E1 EE");
|
|
|
|
|
util->execCMD("hf 14a raw -pa 85 00 00 00 00 00 00 00 00 00 00 00 "
|
|
|
|
|
" 00 00 00 08 18 47");
|
|
|
|
|
util->execCMD("hf 14a raw -pa 85 00 00 00 00 00 00 00 00 00 00 00 00 00 00 08 18 47");
|
|
|
|
|
util->execCMD("hf 14a raw 52");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -467,7 +494,8 @@ void Mifare::writeAllE()
|
|
|
|
|
if(data_isDataValid(dataList->at(cardType.blks[i] + j)) != DATA_NOSPACE || dataList->at(cardType.blks[i] + j).contains('?'))
|
|
|
|
|
continue;
|
|
|
|
|
result = util->execCMDWithOutput(
|
|
|
|
|
"hf mf eset " + QString::number(cardType.blks[i] + j)
|
|
|
|
|
"hf mf eset "
|
|
|
|
|
+ QString::number(cardType.blks[i] + j)
|
|
|
|
|
+ " "
|
|
|
|
|
+ dataList->at(cardType.blks[i] + j),
|
|
|
|
|
waitTime);
|
|
|
|
@ -490,7 +518,10 @@ void Mifare::readAllE()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
qDebug() << "**********" ;
|
|
|
|
|
result = util->execCMDWithOutput("hf mf eget " + QString::number(cardType.blks[i] + j), waitTime);
|
|
|
|
|
result = util->execCMDWithOutput(
|
|
|
|
|
"hf mf eget "
|
|
|
|
|
+ QString::number(cardType.blks[i] + j),
|
|
|
|
|
waitTime);
|
|
|
|
|
qDebug() << result ;
|
|
|
|
|
|
|
|
|
|
offset = dataPattern->indexIn(result);
|
|
|
|
@ -905,10 +936,8 @@ void Mifare::data_data2Key()
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
keyAList->replace(
|
|
|
|
|
i, dataList->at(cardType.blks[i] + cardType.blk[i] - 1).left(12));
|
|
|
|
|
keyBList->replace(
|
|
|
|
|
i, dataList->at(cardType.blks[i] + cardType.blk[i] - 1).right(12));
|
|
|
|
|
keyAList->replace(i, dataList->at(cardType.blks[i] + cardType.blk[i] - 1).left(12));
|
|
|
|
|
keyBList->replace(i, dataList->at(cardType.blks[i] + cardType.blk[i] - 1).right(12));
|
|
|
|
|
}
|
|
|
|
|
data_syncWithKeyWidget();
|
|
|
|
|
}
|
|
|
|
|