Fix Trailer Decoder and add write feedback

pull/5/head
wh201906 4 years ago
parent d6beafe175
commit f8d2bbb206

@ -36,19 +36,19 @@ const Mifare::CardType Mifare::card_4k =
const Mifare::AccessType Mifare::dataCondition[8][4] =
{
{ACC_KEY_AB, ACC_KEY_AB, ACC_KEY_AB, ACC_KEY_AB},
{ACC_KEY_AB, ACC_NEVER, ACC_NEVER, ACC_NEVER},
{ACC_KEY_AB, ACC_KEY_B, ACC_NEVER, ACC_NEVER},
{ACC_KEY_AB, ACC_NEVER, ACC_NEVER, ACC_NEVER},
{ACC_KEY_AB, ACC_KEY_B, ACC_KEY_B, ACC_KEY_AB},
{ACC_KEY_AB, ACC_NEVER, ACC_NEVER, ACC_KEY_AB},
{ACC_KEY_B, ACC_KEY_B, ACC_NEVER, ACC_NEVER},
{ACC_KEY_B, ACC_NEVER, ACC_NEVER, ACC_NEVER},
{ACC_KEY_B, ACC_KEY_B, ACC_NEVER, ACC_NEVER},
{ACC_NEVER, ACC_NEVER, ACC_NEVER, ACC_NEVER},
};
const Mifare::AccessType Mifare::trailerReadCondition[8][3] =
{
{ACC_NEVER, ACC_KEY_A, ACC_KEY_A},
{ACC_NEVER, ACC_KEY_A, ACC_KEY_A},
{ACC_NEVER, ACC_KEY_AB, ACC_NEVER},
{ACC_NEVER, ACC_KEY_A, ACC_KEY_A},
{ACC_NEVER, ACC_KEY_AB, ACC_NEVER},
{ACC_NEVER, ACC_KEY_A, ACC_KEY_A},
{ACC_NEVER, ACC_KEY_AB, ACC_NEVER},
@ -58,12 +58,12 @@ const Mifare::AccessType Mifare::trailerReadCondition[8][3] =
const Mifare::AccessType Mifare::trailerWriteCondition[8][3] =
{
{ACC_KEY_A, ACC_NEVER, ACC_KEY_A},
{ACC_NEVER, ACC_NEVER, ACC_NEVER},
{ACC_KEY_B, ACC_NEVER, ACC_KEY_B},
{ACC_NEVER, ACC_NEVER, ACC_NEVER},
{ACC_NEVER, ACC_NEVER, ACC_NEVER},
{ACC_KEY_A, ACC_KEY_A, ACC_KEY_A},
{ACC_KEY_B, ACC_KEY_B, ACC_KEY_B},
{ACC_NEVER, ACC_KEY_B, ACC_NEVER},
{ACC_KEY_B, ACC_KEY_B, ACC_KEY_B},
{ACC_NEVER, ACC_NEVER, ACC_NEVER},
};
@ -597,7 +597,7 @@ void Mifare::writeOne(TargetType targetType)
}
}
QList<int> Mifare::writeSelected(TargetType targetType)
void Mifare::writeSelected(TargetType targetType)
{
QList<int> failedBlocks;
QList<int> selectedBlocks;
@ -630,7 +630,39 @@ QList<int> Mifare::writeSelected(TargetType targetType)
failedBlocks.append(item);
}
}
return failedBlocks;
if(failedBlocks.size() == 0)
QMessageBox::information(parent, tr("Info"), tr("Successful!"));
else
{
QString suffix = "";
int counter = 0;
for(int failedBlk : failedBlocks)
{
suffix += QString::number(failedBlk) + " ";
counter++;
counter %= 20;
if(counter == 0)
suffix += "\n";
}
QMessageBox::StandardButton res = QMessageBox::information(parent, tr("Info"), tr("Failed to write to these blocks:")
+ "\n"
+ suffix
+ "\n"
+ tr("Select them?"),
QMessageBox::Yes | QMessageBox::No);
if(res == QMessageBox::Yes)
{
for(int item : selectedBlocks)
{
ui->MF_dataWidget->item(item, 1)->setCheckState(Qt::Unchecked);
}
for(int failedBlk : failedBlocks)
{
ui->MF_dataWidget->item(failedBlk, 1)->setCheckState(Qt::Checked);
}
}
}
}
void Mifare::dump()

@ -73,7 +73,7 @@ public:
void readOne(TargetType targetType = TARGET_MIFARE);
void readSelected(TargetType targetType = TARGET_MIFARE);
void writeOne(TargetType targetType = TARGET_MIFARE);
QList<int> writeSelected(TargetType targetType = TARGET_MIFARE);
void writeSelected(TargetType targetType = TARGET_MIFARE);
void dump();
void restore();

@ -580,9 +580,8 @@ void MainWindow::on_MF_RW_writeBlockButton_clicked()
void MainWindow::on_MF_RW_writeSelectedButton_clicked()
{
QList<int> failedBlocks;
setState(false);
failedBlocks = mifare->writeSelected(Mifare::TARGET_MIFARE);
mifare->writeSelected(Mifare::TARGET_MIFARE);
setState(true);
}
@ -612,9 +611,8 @@ void MainWindow::on_MF_UID_readBlockButton_clicked()
void MainWindow::on_MF_UID_writeSelectedButton_clicked()
{
QList<int> failedBlocks;
setState(false);
failedBlocks = mifare->writeSelected(Mifare::TARGET_UID);
mifare->writeSelected(Mifare::TARGET_UID);
setState(true);
}
@ -672,9 +670,8 @@ void MainWindow::on_MF_Sim_readSelectedButton_clicked()
void MainWindow::on_MF_Sim_writeSelectedButton_clicked()
{
QList<int> failedBlocks;
setState(false);
failedBlocks = mifare->writeSelected(Mifare::TARGET_EMULATOR);
mifare->writeSelected(Mifare::TARGET_EMULATOR);
setState(true);
}

Loading…
Cancel
Save