Support write selected blocks and fix a bug

pull/4/head
wh201906 4 years ago
parent 4dba7882e5
commit 41bbcd2c4a

@ -273,7 +273,7 @@ QString Mifare::_readblk(int blockId, KeyType keyType, const QString& key, int w
{
QString data;
QString result;
bool isKeyBlock = (blockId < 128 && ((blockId + 1) % 4 == 0)) || ((blockId + 1) % 8 == 0);
bool isKeyBlock = (blockId < 128 && ((blockId + 1) % 4 == 0)) || ((blockId + 1) % 16 == 0);
if(!data_isKeyValid(key))
{
@ -397,7 +397,7 @@ QStringList Mifare::_readsec(int sectorId, KeyType keyType, const QString& key,
return data;
}
void Mifare::read()
void Mifare::readOne()
{
int blockId = ui->MF_RW_blockBox->currentText().toInt();
Mifare::KeyType keyType = (Mifare::KeyType)(ui->MF_RW_keyTypeBox->currentData().toInt());
@ -424,7 +424,7 @@ void Mifare::readSelected(const QList<int>& selectedBlocks)
}
for(int item : selectedBlocks)
{
selectedSectors[item / 4] = true;
selectedSectors[data_b2s(item)] = true;
}
for(int i = 0; i < cardType.sector_size; i++)
@ -514,7 +514,7 @@ bool Mifare::_writeblk(int blockId, KeyType keyType, const QString& key, const Q
}
}
void Mifare::write()
void Mifare::writeOne()
{
int blockId = ui->MF_RW_blockBox->currentText().toInt();
Mifare::KeyType keyType = (Mifare::KeyType)(ui->MF_RW_keyTypeBox->currentData().toInt());
@ -529,22 +529,19 @@ void Mifare::write()
}
}
void Mifare::writeAll()
void Mifare::writeSelected(const QList<int>& selectedBlocks)
{
for(int i = 0; i < cardType.sector_size; i++)
{
for(int j = 0; j < cardType.blk[i]; j++)
for(int item : selectedBlocks)
{
bool result = false;
result = _writeblk(cardType.blks[i] + j, KEY_A, keyAList->at(i), dataList->at(cardType.blks[i] + j));
result = _writeblk(item, KEY_A, keyAList->at(data_b2s(item)), dataList->at(item));
if(!result)
{
result = _writeblk(cardType.blks[i] + j, KEY_B, keyBList->at(i), dataList->at(cardType.blks[i] + j));
result = _writeblk(item, KEY_B, keyBList->at(data_b2s(item)), dataList->at(item));
}
if(!result)
{
result = _writeblk(cardType.blks[i] + j, KEY_A, "FFFFFFFFFFFF", dataList->at(cardType.blks[i] + j));
}
result = _writeblk(item, KEY_A, "FFFFFFFFFFFF", dataList->at(item));
}
}
}
@ -1190,6 +1187,16 @@ void Mifare::data_fillKeys()
data_syncWithKeyWidget();
}
int Mifare::data_b2s(int block)
{
if(block >= 0 && block < 128)
return block / 4;
else if(block < 256)
return (block - 128) / 16 + 32;
else
return -1;
}
QList<quint8> Mifare::data_getACBits(const QString& text) //return empty QList if the text is invalid
{
QString input = text;

@ -24,10 +24,10 @@ public:
void sniff();
void snoop();
void list();
void read();
void readOne();
void readSelected(const QList<int>& selectedBlocks);
void write();
void writeAll();
void writeOne();
void writeSelected(const QList<int>& selectedBlocks);
void dump();
void restore();
@ -106,6 +106,7 @@ public:
void data_fillKeys();
static QList<quint8> data_getACBits(const QString &text);
static int data_b2s(int block);
public slots:
signals:

@ -263,7 +263,7 @@ void MainWindow::on_MF_dataWidget_itemChanged(QTableWidgetItem *item)
if(item->column() == 0)
{
int selectedSectors = 0;
for(int i = 0; i < mifare->cardType.blk[item->row() / 4]; i++)
for(int i = 0; i < mifare->cardType.blk[Mifare::data_b2s(item->row())]; i++)
{
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();
@ -300,9 +300,9 @@ void MainWindow::on_MF_dataWidget_itemChanged(QTableWidgetItem *item)
selectedBlocks++;
}
}
for(int i = 0; i < mifare->cardType.blk[item->row() / 4]; i++)
for(int i = 0; i < mifare->cardType.blk[Mifare::data_b2s(item->row())]; i++)
{
if(ui->MF_dataWidget->item(i + mifare->cardType.blks[item->row() / 4], 1)->checkState() == Qt::Checked)
if(ui->MF_dataWidget->item(i + mifare->cardType.blks[Mifare::data_b2s(item->row())], 1)->checkState() == Qt::Checked)
{
selectedSubBlocks++;
}
@ -321,15 +321,15 @@ void MainWindow::on_MF_dataWidget_itemChanged(QTableWidgetItem *item)
}
if(selectedSubBlocks == 0)
{
ui->MF_dataWidget->item(mifare->cardType.blks[item->row() / 4], 0)->setCheckState(Qt::Unchecked);
ui->MF_dataWidget->item(mifare->cardType.blks[Mifare::data_b2s(item->row())], 0)->setCheckState(Qt::Unchecked);
}
else if(selectedSubBlocks == mifare->cardType.blk[item->row() / 4])
else if(selectedSubBlocks == mifare->cardType.blk[Mifare::data_b2s(item->row())])
{
ui->MF_dataWidget->item(mifare->cardType.blks[item->row() / 4], 0)->setCheckState(Qt::Checked);
ui->MF_dataWidget->item(mifare->cardType.blks[Mifare::data_b2s(item->row())], 0)->setCheckState(Qt::Checked);
}
else
{
ui->MF_dataWidget->item(mifare->cardType.blks[item->row() / 4], 0)->setCheckState(Qt::PartiallyChecked);
ui->MF_dataWidget->item(mifare->cardType.blks[Mifare::data_b2s(item->row())], 0)->setCheckState(Qt::PartiallyChecked);
}
}
else if(item->column() == 2)
@ -502,21 +502,27 @@ void MainWindow::on_MF_RW_readSelectedButton_clicked()
void MainWindow::on_MF_RW_readBlockButton_clicked()
{
setState(false);
mifare->read();
mifare->readOne();
setState(true);
}
void MainWindow::on_MF_RW_writeBlockButton_clicked()
{
setState(false);
mifare->write();
mifare->writeOne();
setState(true);
}
void MainWindow::on_MF_RW_writeAllButton_clicked()
void MainWindow::on_MF_RW_writeSelectedButton_clicked()
{
setState(false);
mifare->writeAll();
QList<int> selectedBlocks;
for(int i = 0; i < mifare->cardType.block_size; i++)
{
if(ui->MF_dataWidget->item(i, 1)->checkState() == Qt::Checked)
selectedBlocks.append(i);
}
mifare->writeSelected(selectedBlocks);
setState(true);
}

@ -85,7 +85,7 @@ private slots:
void on_MF_Attack_infoButton_clicked();
void on_MF_RW_writeAllButton_clicked();
void on_MF_RW_writeSelectedButton_clicked();
void on_MF_RW_dumpButton_clicked();

@ -638,7 +638,7 @@
</widget>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="MF_RW_writeAllButton">
<widget class="QPushButton" name="MF_RW_writeSelectedButton">
<property name="text">
<string>Write Selected</string>
</property>

Loading…
Cancel
Save