Rename something

pull/4/head
wh201906 4 years ago
parent 946d0acb01
commit 02b0c312a4

@ -54,7 +54,7 @@ void Mifare::chk()
int offset = 0; int offset = 0;
QString tmp, tmp2; QString tmp, tmp2;
for(int i = 0; i < cardType.sectors; i++) for(int i = 0; i < cardType.sector_size; i++)
{ {
offset = chkKeyPattern->indexIn(result, offset); offset = chkKeyPattern->indexIn(result, offset);
// offset = result.indexOf(*chkKeyPattern, offset); // offset = result.indexOf(*chkKeyPattern, offset);
@ -80,7 +80,7 @@ void Mifare::nested()
int offset = 0; int offset = 0;
QString tmp; QString tmp;
for(int i = 0; i < cardType.sectors; i++) for(int i = 0; i < cardType.sector_size; i++)
{ {
offset = nestedKeyPattern->indexIn(result, offset); offset = nestedKeyPattern->indexIn(result, offset);
// offset = result.indexOf(*nestedKeyPattern, offset); // offset = result.indexOf(*nestedKeyPattern, offset);
@ -96,7 +96,7 @@ void Mifare::nested()
void Mifare::hardnested() void Mifare::hardnested()
{ {
MF_Attack_hardnestedDialog dialog(cardType.blocks); MF_Attack_hardnestedDialog dialog(cardType.block_size);
connect(&dialog, &MF_Attack_hardnestedDialog::sendCMD, util, &Util::execCMD); connect(&dialog, &MF_Attack_hardnestedDialog::sendCMD, util, &Util::execCMD);
if(dialog.exec() == QDialog::Accepted) if(dialog.exec() == QDialog::Accepted)
ui->funcTab->setCurrentIndex(1); ui->funcTab->setCurrentIndex(1);
@ -236,86 +236,58 @@ void Mifare::read()
{ {
int blockId = ui->MF_RW_blockBox->currentText().toInt(); int blockId = ui->MF_RW_blockBox->currentText().toInt();
Mifare::KeyType keyType = (Mifare::KeyType)(ui->MF_RW_keyTypeBox->currentData().toInt()); Mifare::KeyType keyType = (Mifare::KeyType)(ui->MF_RW_keyTypeBox->currentData().toInt());
QString result = _readblk(blockId, keyType, ui->MF_RW_keyEdit->text()); QString result = _readblk(blockId, keyType, ui->MF_RW_keyEdit->text().toUpper());
if(result != "") if(result != "")
{ {
ui->MF_RW_dataEdit->setText(result); ui->MF_RW_dataEdit->setText(result);
} }
else else
{ {
ui->MF_RW_dataEdit->setText(tr("Failed")); ui->MF_RW_dataEdit->setText(tr("Failed!"));
} }
} }
void Mifare::readAll() void Mifare::readAll() // note:cannot handle some situations(special trailer block)
{ {
QStringList data;
QString result; QString result;
bool isKeyAValid; bool isKeyAValid;
bool isKeyBValid; bool isKeyBValid;
const int waitTime = 150; const int waitTime = 150;
QString tmp; QString tmp;
int offset = 0; for(int i = 0; i < cardType.sector_size; i++)
for(int i = 0; i < cardType.sectors; i++)
{ {
result = ""; result = "";
isKeyAValid = false; isKeyAValid = false;
isKeyBValid = false; isKeyBValid = false;
// check keys and read the first block of each sector // check keys and read the first block of each sector
if(data_isKeyValid(keyAList->at(i))) data = _readsec(i, Mifare::KEY_A, keyAList->at(i));
if(data.size() > 0)
{ {
result = util->execCMDWithOutput( isKeyAValid = true;
"hf mf rdsc " for(int j = 0; j < cardType.blk[i]; j++)
+ QString::number(i)
+ " A "
+ keyAList->at(i),
waitTime);
qDebug() << result;
offset = result.indexOf("isOk:01");
if(offset != -1)
{ {
isKeyAValid = true; dataList->replace(cardType.blks[i] + j, data[j]);
for(int j = 0; j < cardType.blk[i]; j++) data_syncWithDataWidget(false, cardType.blks[i] + j);
{
offset = dataPattern->indexIn(result, offset);
// offset = result.indexOf(*dataPattern, offset);
tmp = result.mid(offset, 47).toUpper();
offset += 47;
qDebug() << tmp;
tmp.replace(" ", "");
dataList->replace(cardType.blks[i] + j, tmp);
data_syncWithDataWidget(false, cardType.blks[i] + j);
}
} }
} }
if(data_isKeyValid(keyBList->at(i)))
data.clear();
data = _readsec(i, Mifare::KEY_B, keyBList->at(i));
if(data.size() > 0)
{ {
result = util->execCMDWithOutput( isKeyBValid = true;
"hf mf rdsc " for(int j = 0; j < cardType.blk[i]; j++)
+ QString::number(i)
+ " B "
+ keyBList->at(i),
waitTime);
qDebug() << result;
offset = result.indexOf("isOk:01");
if(offset != -1)
{ {
isKeyBValid = true; dataList->replace(cardType.blks[i] + j, data[j]);
for(int j = 0; j < cardType.blk[i]; j++) data_syncWithDataWidget(false, cardType.blks[i] + j);
{
offset = dataPattern->indexIn(result, offset);
// offset = result.indexOf(*dataPattern, offset);
tmp = result.mid(offset, 47).toUpper();
offset += 47;
qDebug() << tmp;
tmp.replace(" ", "");
dataList->replace(cardType.blks[i] + j, tmp);
data_syncWithDataWidget(false, cardType.blks[i] + j);
}
} }
} }
// check keys and read the first block of each sector
if(isKeyAValid || isKeyBValid) if(isKeyAValid || isKeyBValid)
{ {
@ -348,13 +320,8 @@ void Mifare::readAll()
{ {
QString tmpKey = QString tmpKey =
dataList->at(cardType.blks[i] + cardType.blk[i] - 1).right(12); dataList->at(cardType.blks[i] + cardType.blk[i] - 1).right(12);
result = util->execCMDWithOutput( result = _readblk(cardType.blks[i] + cardType.blk[i] - 1, Mifare::KEY_B, tmpKey);
"hf mf rdbl " if(result != "")
+ QString::number(cardType.blks[i] + cardType.blk[i] - 1)
+ " B "
+ tmpKey,
waitTime);
if(result.indexOf("isOk:01") != -1)
{ {
keyBList->replace(i, tmpKey); keyBList->replace(i, tmpKey);
data_syncWithKeyWidget(false, i, KEY_B); data_syncWithKeyWidget(false, i, KEY_B);
@ -394,7 +361,7 @@ void Mifare::writeAll()
{ {
const int waitTime = 300; const int waitTime = 300;
QString result; QString result;
for(int i = 0; i < cardType.sectors; i++) for(int i = 0; i < cardType.sector_size; i++)
{ {
for(int j = 0; j < cardType.blk[i]; j++) for(int j = 0; j < cardType.blk[i]; j++)
{ {
@ -459,7 +426,7 @@ void Mifare::readAllC()
QString tmp; QString tmp;
int offset = 0; int offset = 0;
for(int i = 0; i < cardType.sectors; i++) for(int i = 0; i < cardType.sector_size; i++)
{ {
result = util->execCMDWithOutput( result = util->execCMDWithOutput(
"hf mf cgetsc " "hf mf cgetsc "
@ -511,7 +478,7 @@ void Mifare::writeAllC()
{ {
const int waitTime = 150; const int waitTime = 150;
QString result; QString result;
for(int i = 0; i < cardType.sectors; i++) for(int i = 0; i < cardType.sector_size; i++)
{ {
for(int j = 0; j < cardType.blk[i]; j++) for(int j = 0; j < cardType.blk[i]; j++)
{ {
@ -581,7 +548,7 @@ void Mifare::writeAllE()
{ {
const int waitTime = 200; const int waitTime = 200;
QString result; QString result;
for(int i = 0; i < cardType.sectors; i++) for(int i = 0; i < cardType.sector_size; i++)
{ {
for(int j = 0; j < cardType.blk[i]; j++) for(int j = 0; j < cardType.blk[i]; j++)
{ {
@ -606,7 +573,7 @@ void Mifare::readAllE()
QString tmp; QString tmp;
int offset = 0; int offset = 0;
for(int i = 0; i < cardType.sectors; i++) for(int i = 0; i < cardType.sector_size; i++)
{ {
offset = 0; offset = 0;
for(int j = 0; j < cardType.blk[i]; j++) for(int j = 0; j < cardType.blk[i]; j++)
@ -670,7 +637,7 @@ void Mifare::data_syncWithDataWidget(bool syncAll, int block)
QString tmp; QString tmp;
if(syncAll) if(syncAll)
{ {
for(int i = 0; i < cardType.blocks; i++) for(int i = 0; i < cardType.block_size; i++)
{ {
tmp = ""; tmp = "";
if(dataList->at(i) != "") if(dataList->at(i) != "")
@ -705,7 +672,7 @@ void Mifare::data_syncWithKeyWidget(bool syncAll, int sector, KeyType keyType)
{ {
if(syncAll) if(syncAll)
{ {
for(int i = 0; i < cardType.sectors; i++) for(int i = 0; i < cardType.sector_size; i++)
{ {
ui->MF_keyWidget->item(i, 1)->setText(keyAList->at(i)); ui->MF_keyWidget->item(i, 1)->setText(keyAList->at(i));
ui->MF_keyWidget->item(i, 2)->setText(keyBList->at(i)); ui->MF_keyWidget->item(i, 2)->setText(keyBList->at(i));
@ -723,7 +690,7 @@ void Mifare::data_syncWithKeyWidget(bool syncAll, int sector, KeyType keyType)
void Mifare::data_clearData() void Mifare::data_clearData()
{ {
dataList->clear(); dataList->clear();
for(int i = 0; i < cardType.blocks; i++) for(int i = 0; i < cardType.block_size; i++)
dataList->append(""); dataList->append("");
} }
@ -731,7 +698,7 @@ void Mifare::data_clearKey()
{ {
keyAList->clear(); keyAList->clear();
keyBList->clear(); keyBList->clear();
for(int i = 0; i < cardType.sectors; i++) for(int i = 0; i < cardType.sector_size; i++)
{ {
keyAList->append(""); keyAList->append("");
keyBList->append(""); keyBList->append("");
@ -813,7 +780,7 @@ bool Mifare::data_loadDataFile(const QString &filename)
QByteArray buff; QByteArray buff;
buff = file.read(10000); 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.block_size * 16; i++) // Detect the file type
{ {
// qDebug() << (unsigned char)buff[i]; // qDebug() << (unsigned char)buff[i];
if(!((buff[i] >= 'A' && buff[i] <= 'F') || (buff[i] >= 'a' && buff[i] <= 'f') || (buff[i] >= '0' && buff[i] <= '9') || buff[i] == '\n' || buff[i] == '\r')) if(!((buff[i] >= 'A' && buff[i] <= 'F') || (buff[i] >= 'a' && buff[i] <= 'f') || (buff[i] >= '0' && buff[i] <= '9') || buff[i] == '\n' || buff[i] == '\r'))
@ -824,9 +791,9 @@ bool Mifare::data_loadDataFile(const QString &filename)
} }
if(isBin) if(isBin)
{ {
if(file.size() < cardType.blocks * 16) if(file.size() < cardType.block_size * 16)
return false; return false;
for(int i = 0; i < cardType.blocks; i++) for(int i = 0; i < cardType.block_size; i++)
{ {
QString tmp = bin2text(buff, i, 16); QString tmp = bin2text(buff, i, 16);
dataList->replace(i, tmp.toUpper()); dataList->replace(i, tmp.toUpper());
@ -834,9 +801,9 @@ bool Mifare::data_loadDataFile(const QString &filename)
} }
else else
{ {
QString tmp = buff.left(cardType.blocks * 34); QString tmp = buff.left(cardType.block_size * 34);
QStringList tmpList = tmp.split("\r\n"); QStringList tmpList = tmp.split("\r\n");
for(int i = 0; i < cardType.blocks; i++) for(int i = 0; i < cardType.block_size; i++)
{ {
dataList->replace(i, tmpList[i].toUpper()); dataList->replace(i, tmpList[i].toUpper());
qDebug() << tmpList[i]; qDebug() << tmpList[i];
@ -859,10 +826,10 @@ bool Mifare::data_loadKeyFile(const QString &filename)
{ {
QByteArray buff; QByteArray buff;
buff = file.read(10000); buff = file.read(10000);
bool isKey = file.size() <= cardType.sectors * 14; bool isKey = file.size() <= cardType.sector_size * 14;
if(isKey) if(isKey)
{ {
for(int i = 0; i < cardType.sectors; i++) for(int i = 0; i < cardType.sector_size; i++)
{ {
QString tmp = bin2text(buff, i, 12); QString tmp = bin2text(buff, i, 12);
keyAList->replace(i, tmp.left(12).toUpper()); keyAList->replace(i, tmp.left(12).toUpper());
@ -871,7 +838,7 @@ bool Mifare::data_loadKeyFile(const QString &filename)
} }
else else
{ {
for(int i = 0; i < cardType.sectors; i++) for(int i = 0; i < cardType.sector_size; i++)
{ {
int blk = cardType.blks[i] + cardType.blk[i] - 1; int blk = cardType.blks[i] + cardType.blk[i] - 1;
QString tmp = bin2text(buff, blk, 16); QString tmp = bin2text(buff, blk, 16);
@ -916,7 +883,7 @@ bool Mifare::data_saveDataFile(const QString &filename, bool isBin)
QChar tmp; QChar tmp;
if(isBin) if(isBin)
{ {
for(int i = 0; i < cardType.blocks; i++) for(int i = 0; i < cardType.block_size; i++)
{ {
for(int j = 0; j < 16; j++) for(int j = 0; j < 16; j++)
{ {
@ -935,7 +902,7 @@ bool Mifare::data_saveDataFile(const QString &filename, bool isBin)
} }
else else
{ {
for(int i = 0; i < cardType.blocks; i++) for(int i = 0; i < cardType.block_size; i++)
{ {
buff += dataList->at(i); buff += dataList->at(i);
buff += "\r\n"; buff += "\r\n";
@ -960,7 +927,7 @@ bool Mifare::data_saveKeyFile(const QString &filename, bool isBin)
QChar tmp; QChar tmp;
if(isBin) if(isBin)
{ {
for(int i = 0; i < cardType.sectors; i++) for(int i = 0; i < cardType.sector_size; i++)
{ {
for(int j = 0; j < 6; j++) for(int j = 0; j < 6; j++)
{ {
@ -1005,7 +972,7 @@ bool Mifare::data_saveKeyFile(const QString &filename, bool isBin)
void Mifare::data_key2Data() void Mifare::data_key2Data()
{ {
for(int i = 0; i < cardType.sectors; i++) for(int i = 0; i < cardType.sector_size; i++)
{ {
QString tmp = ""; QString tmp = "";
if(data_isKeyValid(keyAList->at(i))) if(data_isKeyValid(keyAList->at(i)))
@ -1030,7 +997,7 @@ void Mifare::data_key2Data()
void Mifare::data_data2Key() void Mifare::data_data2Key()
{ {
for(int i = 0; i < cardType.sectors; i++) for(int i = 0; i < cardType.sector_size; i++)
{ {
if(dataList->at(cardType.blks[i] + cardType.blk[i] - 1) == "") if(dataList->at(cardType.blks[i] + cardType.blk[i] - 1) == "")
{ {
@ -1061,7 +1028,7 @@ void Mifare::data_setKey(int sector, KeyType keyType, const QString &key)
void Mifare::data_fillKeys() void Mifare::data_fillKeys()
{ {
for(int i = 0; i < cardType.sectors; i++) for(int i = 0; i < cardType.sector_size; i++)
{ {
if(!data_isKeyValid(keyAList->at(i))) if(!data_isKeyValid(keyAList->at(i)))
{ {

@ -47,8 +47,8 @@ public:
struct CardType struct CardType
{ {
int type; int type;
int sectors; int sector_size;
int blocks; int block_size;
int blk[40]; int blk[40];
int blks[40]; int blks[40];
}; };

@ -211,11 +211,11 @@ void MainWindow::on_MF_selectAllBox_stateChanged(int arg1)
ui->MF_selectAllBox->setTristate(false); ui->MF_selectAllBox->setTristate(false);
ui->MF_selectAllBox->setCheckState(Qt::Checked); ui->MF_selectAllBox->setCheckState(Qt::Checked);
} }
for(int i = 0; i < mifare->cardType.blocks; i++) for(int i = 0; i < mifare->cardType.block_size; i++)
{ {
ui->MF_dataWidget->item(i, 1)->setCheckState(ui->MF_selectAllBox->checkState()); ui->MF_dataWidget->item(i, 1)->setCheckState(ui->MF_selectAllBox->checkState());
} }
for(int i = 0; i < mifare->cardType.sectors; i++) for(int i = 0; i < mifare->cardType.sector_size; i++)
{ {
ui->MF_dataWidget->item(mifare->cardType.blks[i], 0)->setCheckState(ui->MF_selectAllBox->checkState()); ui->MF_dataWidget->item(mifare->cardType.blks[i], 0)->setCheckState(ui->MF_selectAllBox->checkState());
} }
@ -262,7 +262,7 @@ void MainWindow::on_MF_dataWidget_itemChanged(QTableWidgetItem *item)
ui->MF_dataWidget->item(i + item->row(), 1)->setCheckState(item->checkState()); ui->MF_dataWidget->item(i + item->row(), 1)->setCheckState(item->checkState());
qDebug() << i << mifare->cardType.blk[item->row()] << i + item->row() << ui->MF_dataWidget->item(i + item->row(), 1)->text(); qDebug() << i << mifare->cardType.blk[item->row()] << i + item->row() << ui->MF_dataWidget->item(i + item->row(), 1)->text();
} }
for(int i = 0; i < mifare->cardType.sectors; i++) for(int i = 0; i < mifare->cardType.sector_size; i++)
{ {
if(ui->MF_dataWidget->item(mifare->cardType.blks[i], 0)->checkState() == Qt::Checked) if(ui->MF_dataWidget->item(mifare->cardType.blks[i], 0)->checkState() == Qt::Checked)
{ {
@ -273,7 +273,7 @@ void MainWindow::on_MF_dataWidget_itemChanged(QTableWidgetItem *item)
{ {
ui->MF_selectAllBox->setCheckState(Qt::Unchecked); ui->MF_selectAllBox->setCheckState(Qt::Unchecked);
} }
else if(selectedSectors == mifare->cardType.sectors) else if(selectedSectors == mifare->cardType.sector_size)
{ {
ui->MF_selectAllBox->setCheckState(Qt::Checked); ui->MF_selectAllBox->setCheckState(Qt::Checked);
} }
@ -287,7 +287,7 @@ void MainWindow::on_MF_dataWidget_itemChanged(QTableWidgetItem *item)
int selectedSubBlocks = 0; int selectedSubBlocks = 0;
int selectedBlocks = 0; int selectedBlocks = 0;
for(int i = 0; i < mifare->cardType.blocks; i++) for(int i = 0; i < mifare->cardType.block_size; i++)
{ {
if(ui->MF_dataWidget->item(i, 1)->checkState() == Qt::Checked) if(ui->MF_dataWidget->item(i, 1)->checkState() == Qt::Checked)
{ {
@ -305,7 +305,7 @@ void MainWindow::on_MF_dataWidget_itemChanged(QTableWidgetItem *item)
{ {
ui->MF_selectAllBox->setCheckState(Qt::Unchecked); ui->MF_selectAllBox->setCheckState(Qt::Unchecked);
} }
else if(selectedBlocks == mifare->cardType.blocks) else if(selectedBlocks == mifare->cardType.block_size)
{ {
ui->MF_selectAllBox->setCheckState(Qt::Checked); ui->MF_selectAllBox->setCheckState(Qt::Checked);
} }
@ -673,8 +673,8 @@ void MainWindow::on_MF_Sniff_listButton_clicked()
void MainWindow::MF_widgetReset() void MainWindow::MF_widgetReset()
{ {
int secs = mifare->cardType.sectors; int secs = mifare->cardType.sector_size;
int blks = mifare->cardType.blocks; int blks = mifare->cardType.block_size;
ui->MF_RW_blockBox->clear(); ui->MF_RW_blockBox->clear();
ui->MF_keyWidget->setRowCount(secs); ui->MF_keyWidget->setRowCount(secs);
ui->MF_dataWidget->setRowCount(blks); ui->MF_dataWidget->setRowCount(blks);

Loading…
Cancel
Save