Support editing data and key manually

pull/2/head
wh201906 4 years ago
parent c74cdee924
commit 383eaff2a5

@ -417,28 +417,35 @@ void Mifare::restore()
void Mifare::data_syncWithDataWidget(bool syncAll, int block) 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.blocks; i++)
{ {
tmp = ""; tmp = "";
tmp += dataList->at(i).mid(0, 2); if(dataList->at(i) != "")
for(int j = 1; j < 16; j++)
{ {
tmp += " "; tmp += dataList->at(i).mid(0, 2);
tmp += dataList->at(i).mid(j * 2, 2); for(int j = 1; j < 16; j++)
{
tmp += " ";
tmp += dataList->at(i).mid(j * 2, 2);
}
} }
ui->MF_dataWidget->item(i, 2)->setText(tmp); ui->MF_dataWidget->item(i, 2)->setText(tmp);
} }
} }
else else
{ {
tmp += dataList->at(block).mid(0, 2); tmp = "";
for(int j = 1; j < 16; j++) if(dataList->at(block) != "")
{ {
tmp += " "; tmp += dataList->at(block).mid(0, 2);
tmp += dataList->at(block).mid(j * 2, 2); for(int j = 1; j < 16; j++)
{
tmp += " ";
tmp += dataList->at(block).mid(j * 2, 2);
}
} }
ui->MF_dataWidget->item(block, 2)->setText(tmp); ui->MF_dataWidget->item(block, 2)->setText(tmp);
} }
@ -659,13 +666,13 @@ bool Mifare::data_saveDataFile(const QString& filename, bool isBin)
unsigned char Byt[2]; unsigned char Byt[2];
for(int k = 0; k < 2; k++) for(int k = 0; k < 2; k++)
{ {
tmp = dataList->at(i).at(j*2+k).toUpper(); tmp = dataList->at(i).at(j * 2 + k).toUpper();
if(tmp >= '0' && tmp <= '9') if(tmp >= '0' && tmp <= '9')
Byt[k] = tmp.toLatin1() - '0'; Byt[k] = tmp.toLatin1() - '0';
else if(tmp >= 'A' && tmp <= 'F') else if(tmp >= 'A' && tmp <= 'F')
Byt[k] = tmp.toLatin1() - 'A' + 10; Byt[k] = tmp.toLatin1() - 'A' + 10;
} }
buff += (Byt[0] << 4)|Byt[1]; buff += (Byt[0] << 4) | Byt[1];
} }
} }
} }
@ -703,26 +710,26 @@ bool Mifare::data_saveKeyFile(const QString& filename, bool isBin)
unsigned char Byt[2]; unsigned char Byt[2];
for(int k = 0; k < 2; k++) for(int k = 0; k < 2; k++)
{ {
tmp = keyAList->at(i).at(j*2+k).toUpper(); tmp = keyAList->at(i).at(j * 2 + k).toUpper();
if(tmp >= '0' && tmp <= '9') if(tmp >= '0' && tmp <= '9')
Byt[k] = tmp.toLatin1() - '0'; Byt[k] = tmp.toLatin1() - '0';
else if(tmp >= 'A' && tmp <= 'F') else if(tmp >= 'A' && tmp <= 'F')
Byt[k] = tmp.toLatin1() - 'A' + 10; Byt[k] = tmp.toLatin1() - 'A' + 10;
} }
buff += (Byt[0] << 4)|Byt[1]; buff += (Byt[0] << 4) | Byt[1];
} }
for(int j = 0; j < 6; j++) for(int j = 0; j < 6; j++)
{ {
unsigned char Byt[2]; unsigned char Byt[2];
for(int k = 0; k < 2; k++) for(int k = 0; k < 2; k++)
{ {
tmp = keyBList->at(i).at(j*2+k).toUpper(); tmp = keyBList->at(i).at(j * 2 + k).toUpper();
if(tmp >= '0' && tmp <= '9') if(tmp >= '0' && tmp <= '9')
Byt[k] = tmp.toLatin1() - '0'; Byt[k] = tmp.toLatin1() - '0';
else if(tmp >= 'A' && tmp <= 'F') else if(tmp >= 'A' && tmp <= 'F')
Byt[k] = tmp.toLatin1() - 'A' + 10; Byt[k] = tmp.toLatin1() - 'A' + 10;
} }
buff += (Byt[0] << 4)|Byt[1]; buff += (Byt[0] << 4) | Byt[1];
} }
} }
} }
@ -782,3 +789,16 @@ void Mifare::data_data2Key()
data_syncWithKeyWidget(); data_syncWithKeyWidget();
} }
} }
void Mifare::data_setData(int block, const QString& data)
{
dataList->replace(block, data);
}
void Mifare::data_setKey(int sector, bool isKeyA, const QString& key)
{
if(isKeyA)
keyAList->replace(sector, key);
else
keyBList->replace(sector, key);
}

@ -101,6 +101,8 @@ public:
void data_key2Data(); void data_key2Data();
void data_data2Key(); void data_data2Key();
void data_setData(int block, const QString &data);
void data_setKey(int sector, bool isKeyA, const QString &key);
public slots: public slots:
signals: signals:

@ -192,6 +192,54 @@ void MainWindow::on_MF_key2DataBotton_clicked()
mifare->data_key2Data(); mifare->data_key2Data();
} }
void MainWindow::on_MF_dataWidget_itemChanged(QTableWidgetItem *item)
{
if(item->column() == 2)
{
QString data = item->text().replace(" ", "");
if(data == "" || mifare->data_isDataValid(data) == Mifare::DATA_NOSPACE)
{
mifare->data_setData(item->row(), data);
}
else
{
QMessageBox::information(this, tr("Info"), tr("Data must consists of 32 Hex symbols(Whitespace is allowed)"));
}
mifare->data_syncWithDataWidget(false, item->row());
}
}
void MainWindow::on_MF_keyWidget_itemChanged(QTableWidgetItem *item)
{
if(item->column() == 1)
{
QString key = item->text().replace(" ", "");
if(key == "" || mifare->data_isKeyValid(key))
{
mifare->data_setKey(item->row(), true, key);
}
else
{
QMessageBox::information(this, tr("Info"), tr("Key must consists of 12 Hex symbols(Whitespace is allowed)"));
}
mifare->data_syncWithKeyWidget(false, item->row(), true);
}
else if(item->column() == 2)
{
QString key = item->text().replace(" ", "");
if(key == "" || mifare->data_isKeyValid(key))
{
mifare->data_setKey(item->row(), false, key);
}
else
{
QMessageBox::information(this, tr("Info"), tr("Key must consists of 12 Hex symbols(Whitespace is allowed)"));
}
mifare->data_syncWithKeyWidget(false, item->row(), false);
}
}
void MainWindow::on_MF_File_loadButton_clicked() void MainWindow::on_MF_File_loadButton_clicked()
{ {
QString title = ""; QString title = "";
@ -261,6 +309,20 @@ void MainWindow::on_MF_File_saveButton_clicked()
qDebug() << filename << selectedType; qDebug() << filename << selectedType;
} }
void MainWindow::on_MF_File_clearButton_clicked()
{
if(ui->MF_File_keyBox->isChecked())
{
mifare->data_clearKey();
mifare->data_syncWithKeyWidget();
}
else if(ui->MF_File_dataBox->isChecked())
{
mifare->data_clearData();
mifare->data_syncWithDataWidget();
}
}
void MainWindow::on_MF_Attack_infoButton_clicked() void MainWindow::on_MF_Attack_infoButton_clicked()
{ {
mifare->info(); mifare->info();

@ -98,6 +98,12 @@ private slots:
void on_MF_key2DataBotton_clicked(); void on_MF_key2DataBotton_clicked();
void on_MF_dataWidget_itemChanged(QTableWidgetItem *item);
void on_MF_File_clearButton_clicked();
void on_MF_keyWidget_itemChanged(QTableWidgetItem *item);
private: private:
Ui::MainWindow* ui; Ui::MainWindow* ui;
QButtonGroup* typeBtnGroup; QButtonGroup* typeBtnGroup;

@ -6,14 +6,14 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>820</width> <width>859</width>
<height>770</height> <height>770</height>
</rect> </rect>
</property> </property>
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>800</width> <width>820</width>
<height>550</height> <height>770</height>
</size> </size>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -42,7 +42,7 @@
<item> <item>
<widget class="QLineEdit" name="PM3_pathEdit"> <widget class="QLineEdit" name="PM3_pathEdit">
<property name="text"> <property name="text">
<string notr="true">E:\Documents\source\qt\pm3\win64\proxmark3</string> <string notr="true">../pm3/win64/proxmark3</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -322,6 +322,19 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QPushButton" name="MF_File_clearButton">
<property name="minimumSize">
<size>
<width>40</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Clear</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QRadioButton" name="MF_File_dataBox"> <widget class="QRadioButton" name="MF_File_dataBox">
<property name="text"> <property name="text">

Loading…
Cancel
Save