Optimize ReadAll function(fill the KeyA and KeyB automatically)

pull/2/head
wh201906 5 years ago
parent fd009745f9
commit b540741b1a

@ -156,38 +156,45 @@ void MainWindow::on_MF_Attack_listButton_clicked()
void MainWindow::on_MF_RW_readAllButton_clicked() void MainWindow::on_MF_RW_readAllButton_clicked()
{ {
QString result; QString result;
int validkey; bool isKeyAValid;
const int waitTime=500; bool isKeyBValid;
const int waitTime = 500;
for(int i = 0; i < 16; i++) for(int i = 0; i < 16; i++)
{ {
QApplication::processEvents(); QApplication::processEvents();
result = ""; result = "";
validkey = -1; isKeyAValid=false;
if(ui->MF_keyWidget->item(i,1)!=nullptr && MF_isKeyValid(ui->MF_keyWidget->item(i, 1)->text())) isKeyBValid=false;
// check keys and read the first block of each sector
if(ui->MF_keyWidget->item(i, 1) != nullptr && MF_isKeyValid(ui->MF_keyWidget->item(i, 1)->text()))
{ {
result = execCMDWithOutput("hf mf rdbl " result = execCMDWithOutput("hf mf rdbl "
+ QString::number(4 * i) + QString::number(4 * i)
+ " A " + " A "
+ ui->MF_keyWidget->item(i, 1)->text(),waitTime); + ui->MF_keyWidget->item(i, 1)->text(), waitTime);
if(result.indexOf("isOk:01") != -1) if(result.indexOf("isOk:01") != -1)
{ {
validkey = 1; isKeyAValid=true;
ui->MF_dataWidget->setItem(4 * i, 2,new QTableWidgetItem(result.mid(result.indexOf("isOk:01")+13, 47).toUpper())); ui->MF_dataWidget->setItem(4 * i, 2, new QTableWidgetItem(result.mid(result.indexOf("isOk:01") + 13, 47).toUpper()));
} }
} }
if(validkey == -1 && ui->MF_keyWidget->item(i,2)!=nullptr && MF_isKeyValid(ui->MF_keyWidget->item(i, 2)->text())) QApplication::processEvents();
if(ui->MF_keyWidget->item(i, 2) != nullptr && MF_isKeyValid(ui->MF_keyWidget->item(i, 2)->text()))
{ {
result = execCMDWithOutput("hf mf rdbl " result = execCMDWithOutput("hf mf rdbl "
+ QString::number(4 * i) + QString::number(4 * i)
+ " B " + " B "
+ ui->MF_keyWidget->item(i, 2)->text(),waitTime); + ui->MF_keyWidget->item(i, 2)->text(), waitTime);
if(result.indexOf("isOk:01") != -1) if(result.indexOf("isOk:01") != -1)
{ {
validkey = 2; isKeyBValid=true;
ui->MF_dataWidget->setItem(4 * i, 2,new QTableWidgetItem(result.mid(result.indexOf("isOk:01")+13, 47).toUpper())); ui->MF_dataWidget->setItem(4 * i, 2, new QTableWidgetItem(result.mid(result.indexOf("isOk:01") + 13, 47).toUpper()));
} }
} }
if(validkey!=-1)
// read the rest blocks of a sector
if(isKeyAValid || isKeyBValid)
{ {
for(int j = 1; j < 4; j++) for(int j = 1; j < 4; j++)
{ {
@ -195,10 +202,59 @@ void MainWindow::on_MF_RW_readAllButton_clicked()
result = execCMDWithOutput("hf mf rdbl " result = execCMDWithOutput("hf mf rdbl "
+ QString::number(4 * i + j) + QString::number(4 * i + j)
+ " " + " "
+ (validkey==1?"A":"B") + (isKeyAValid ? "A" : "B")
+ " " + " "
+ ui->MF_keyWidget->item(i, validkey)->text(),waitTime); + ui->MF_keyWidget->item(i, (isKeyAValid ? 1 : 2))->text(), waitTime);
ui->MF_dataWidget->setItem(4 * i + j, 2,new QTableWidgetItem(result.mid(result.indexOf("isOk:01")+13, 47).toUpper())); result=result.mid(result.indexOf("isOk:01") + 13, 47).toUpper();
ui->MF_dataWidget->setItem(4 * i + j, 2, new QTableWidgetItem(result));
}
QApplication::processEvents();
// fill the MF_dataWidget with the known valid key
//
// check whether the MF_dataWidget contains the valid key,
// and fill MF_keyWidget(when you only have KeyA but the ReadBlock output contains the KeyB)
//
// the structure is not symmetric, since you cannot get KeyA from output
// this program will only process the provided KeyA(in MF_keyWidget)
result=ui->MF_dataWidget->item(4 * i + 3, 2)->text();
if(isKeyAValid)
{
for(int j = 0; j < 6; j++)
{
result = result.replace(j * 3, 2, ui->MF_keyWidget->item(i,1)->text().mid(j * 2, 2));
}
}
else
{
result = result.replace(0, 18, "?? ?? ?? ?? ?? ?? ");
}
ui->MF_dataWidget->setItem(4 * i + 3, 2, new QTableWidgetItem(result));
if(isKeyBValid)
{
for(int j = 0; j < 6; j++)
{
result = result.replace(30 + j * 3, 2, ui->MF_keyWidget->item(i,2)->text().mid(j * 2, 2));
ui->MF_dataWidget->setItem(4 * i + 3, 2, new QTableWidgetItem(result));
}
}
else
{
QString tmpKey=result.right(18).replace(" ","");
result = execCMDWithOutput("hf mf rdbl "
+ QString::number(4 * i + 3)
+ " B "
+ tmpKey, waitTime);
if(result.indexOf("isOk:01") != -1)
{
ui->MF_keyWidget->setItem(i, 2, new QTableWidgetItem(tmpKey));
}
else
{
result = result.replace(30, 17, "?? ?? ?? ?? ?? ??");
ui->MF_dataWidget->setItem(4 * i + 3, 2, new QTableWidgetItem(result));
}
} }
} }
} }
@ -215,7 +271,22 @@ void MainWindow::on_MF_RW_readBlockButton_clicked()
+ ui->MF_RW_keyEdit->text()); + ui->MF_RW_keyEdit->text());
if(result.indexOf("isOk:01") != -1) if(result.indexOf("isOk:01") != -1)
{ {
ui->MF_RW_dataEdit->setText(result.mid(result.indexOf("isOk:01")+13, 47).toUpper()); result = result.mid(result.indexOf("isOk:01") + 13, 47).toUpper();
if((ui->MF_RW_blockBox->text().toInt() + 1) % 4 == 0)
{
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));
}
}
else
{
result = result.replace(0, 18, "?? ?? ?? ?? ?? ?? ");
}
}
ui->MF_RW_dataEdit->setText(result);
} }
} }
@ -228,7 +299,7 @@ void MainWindow::on_MF_RW_writeBlockButton_clicked()
+ " " + " "
+ ui->MF_RW_keyEdit->text() + ui->MF_RW_keyEdit->text()
+ " " + " "
+ ui->MF_RW_dataEdit->text().replace(" ","")); + ui->MF_RW_dataEdit->text().replace(" ", ""));
if(result.indexOf("isOk:01") != -1) if(result.indexOf("isOk:01") != -1)
{ {

Loading…
Cancel
Save