From c97c55043935a1e244c1b9a9804c2dc6d0a773ef Mon Sep 17 00:00:00 2001 From: wh201906 Date: Sun, 26 Apr 2020 21:15:08 +0800 Subject: [PATCH] Support load data file and key file --- lang/en_US.ts | 191 ++++++++++++++++++++++++++-------------------- lang/zh_CN.ts | 191 ++++++++++++++++++++++++++-------------------- module/mifare.cpp | 97 +++++++++++++++++++++++ module/mifare.h | 10 ++- ui/mainwindow.cpp | 56 ++++++++++---- ui/mainwindow.h | 8 +- ui/mainwindow.ui | 9 +-- 7 files changed, 370 insertions(+), 192 deletions(-) diff --git a/lang/en_US.ts b/lang/en_US.ts index 729092e..80fd2cf 100644 --- a/lang/en_US.ts +++ b/lang/en_US.ts @@ -31,11 +31,6 @@ B - - - FFFFFFFFFFFF - - Target Block: @@ -82,11 +77,6 @@ Path: - - - E:\Documents\source\qt\pm3\win64\proxmark3 - - Refresh @@ -149,19 +139,19 @@ - + Load - + Save - + Data @@ -171,250 +161,283 @@ - + Attack - + Card Info - + Check Default - + Nested - + Hardnested - + Read/Write - + Block: - + Key: - - FFFFFFFFFFFF - - - - + Key Type: - + A - + B - + Normal(Require Password) - - + + Read Block - - + + Write Block - - - + + + Read All - - + + Write All - + Dump - + Restore - + Chinese Magic Card(Without Password) - + Lock UFUID Card - + About UID Card - + Set Parameter - + Wipe - - + + Simulate - + Load from data above - + Clear - - + + Sniff - + List Sniff Data - + RawCommand - - + + History: - + ClearHistory - + Send - + ClearOutput - - + + + + Info - + Plz choose a port first - + Connected - - - + + + Not Connected - + When Changeing card type, the data and keys in this app will be cleard. Continue? - + + Plz choose the data file: + + + + + Binary Data Files(*.bin *.dump);;Text Data Files(*.txt *.eml);;All Files(*.*) + + + + + + Failed to open + + + + + Plz choose the key file: + + + + + Binary Key Files(*.bin *.dump);;All Files(*.*) + + + + + Save data to + + + + + Bin Files(*.bin *.dump);;Text Files(*.txt *.eml) + + + + Idle - - + + Sec - + Blk - + KeyA - + KeyB - + HW Version: - + PM3: - + State: @@ -422,22 +445,22 @@ Continue? Mifare - - + + Success! - - - - + + + + Info - - + + Failed! diff --git a/lang/zh_CN.ts b/lang/zh_CN.ts index 1dddb58..eb7e8a3 100644 --- a/lang/zh_CN.ts +++ b/lang/zh_CN.ts @@ -35,11 +35,6 @@ B - - - FFFFFFFFFFFF - - Target Block: @@ -86,11 +81,6 @@ Path: 路径: - - - E:\Documents\source\qt\pm3\win64\proxmark3 - - Refresh @@ -153,19 +143,19 @@ - + Load 加载 - + Save 保存 - + Data @@ -175,250 +165,283 @@ - + Attack 破解 - + Card Info 读卡片信息 - + Check Default 验证默认密码 - + Nested Nested攻击 - + Hardnested Hardested攻击 - + Read/Write 读/写 - + Block: - + Key: - - FFFFFFFFFFFF - - - - + Key Type: Key类型: - + A - + B - + Normal(Require Password) 普通卡(需要密码) - - + + Read Block 读单个块 - - + + Write Block 写单个块 - - - + + + Read All 读所有块 - - + + Write All 写所有块 - + Dump Dump命令 - + Restore Restore命令 - + Chinese Magic Card(Without Password) UID卡(不需要密码) - + Lock UFUID Card 锁定UFUID卡 - + About UID Card 关于UID卡 - + Set Parameter 设置卡参数 - + Wipe 擦除 - - + + Simulate 模拟 - + Load from data above 从上方数据导入 - + Clear 清空 - - + + Sniff 嗅探 - + List Sniff Data 列出嗅探数据 - + RawCommand 原始命令 - - + + History: 命令历史: - + ClearHistory 清空历史 - + Send 发送 - + ClearOutput 清空输出 - - + + + + Info 信息 - + Plz choose a port first 请先选择端口 - + Connected 已连接 - - - + + + Not Connected 未连接 - + When Changeing card type, the data and keys in this app will be cleard. Continue? 更改卡容量后,窗口中的data和key会被清空\n要继续吗? - + + Plz choose the data file: + 请选择data文件: + + + + Binary Data Files(*.bin *.dump);;Text Data Files(*.txt *.eml);;All Files(*.*) + 二进制Data文件(*.bin *.dump);;文本Data文件(*.txt *.eml);;所有文件(*.*) + + + + + Failed to open + 打开失败: + + + + Plz choose the key file: + 请选择key文件: + + + + Binary Key Files(*.bin *.dump);;All Files(*.*) + 二进制Key文件(*.bin *.dump);;所有文件(*.*) + + + + Save data to + 保存数据至 + + + + Bin Files(*.bin *.dump);;Text Files(*.txt *.eml) + + + + Idle 空闲 - - + + Sec - + Blk - + KeyA - + KeyB - + HW Version: 固件版本: - + PM3: 连接状态: - + State: 运行状态: @@ -430,22 +453,22 @@ Continue? 信息: - - + + Success! 成功! - - - - + + + + Info 信息 - - + + Failed! 失败! diff --git a/module/mifare.cpp b/module/mifare.cpp index 6a75d04..2230dbe 100644 --- a/module/mifare.cpp +++ b/module/mifare.cpp @@ -422,6 +422,7 @@ void Mifare::data_syncWithDataWidget(bool syncAll, int block) { for(int i = 0; i < cardType.blocks; i++) { + tmp = ""; tmp += dataList->at(i).mid(0, 2); for(int j = 1; j < 16; j++) { @@ -545,3 +546,99 @@ void Mifare::setCardType(int type) data_clearData(); } } + +bool Mifare::data_loadDataFile(const QString& filename) +{ + QFile file(filename, this); + if(file.open(QIODevice::ReadOnly)) + { + QByteArray buff; + buff = file.read(8192); + bool isBin = false; + for(int i = 0; i < cardType.blocks * 16; i++) // Detect the file type + { +// 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')) + { + isBin = true; + break; + } + } + if(isBin) + { + char LByte, RByte; + char map[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; + for(int i = 0; i < cardType.blocks; i++) + { + QString tmp = ""; + for(int j = 0; j < 16; j++) + { + LByte = map[(unsigned char)buff[i * 16 + j] >> 4]; + RByte = map[(unsigned char)buff[i * 16 + j] & 0xF]; + tmp += LByte; + tmp += RByte; + } + qDebug() << tmp; + dataList->replace(i, tmp.toUpper()); + } + } + else + { + QString tmp = buff.left(cardType.blocks * 34); + QStringList tmpList = tmp.split("\r\n"); + for(int i = 0; i < cardType.blocks; i++) + { + dataList->replace(i, tmpList[i].toUpper()); + qDebug() << tmpList[i]; + } + } + file.close(); + data_syncWithDataWidget(); + return true; + } + else + { + return false; + } +} + +bool Mifare::data_loadKeyFile(const QString& filename) +{ + QFile file(filename, this); + if(file.open(QIODevice::ReadOnly)) + { + QByteArray buff; + buff = file.read(960); + bool isBin = true; + if(isBin) + { + char LByte, RByte; + char map[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; + for(int i = 0; i < cardType.sectors; i++) + { + QString tmp = ""; + for(int j = 0; j < 12; j++) + { + LByte = map[(unsigned char)buff[i * 12 + j] >> 4]; + RByte = map[(unsigned char)buff[i * 12 + j] & 0xF]; + tmp += LByte; + tmp += RByte; + } + qDebug() << tmp; + keyAList->replace(i, tmp.left(12).toUpper()); + keyBList->replace(i, tmp.right(12).toUpper()); + } + } + file.close(); + data_syncWithKeyWidget(); + return true; + } + else + { + return false; + } +} diff --git a/module/mifare.h b/module/mifare.h index ede29a6..6877c9b 100644 --- a/module/mifare.h +++ b/module/mifare.h @@ -93,6 +93,12 @@ public: void readC(); void wipeC(); void setParameterC(); + + QStringList* keyAList; + QStringList* keyBList; + QStringList* dataList; + bool data_loadDataFile(const QString &filename); + bool data_loadKeyFile(const QString &filename); public slots: signals: @@ -101,9 +107,7 @@ private: Ui::MainWindow *ui; Util* util; - QStringList* keyAList; - QStringList* keyBList; - QStringList* dataList; + QRegExp* dataPattern; QRegExp* chkKeyPattern; QRegExp* nestedKeyPattern; diff --git a/ui/mainwindow.cpp b/ui/mainwindow.cpp index 5e93ffa..8d46c8c 100644 --- a/ui/mainwindow.cpp +++ b/ui/mainwindow.cpp @@ -17,7 +17,6 @@ MainWindow::MainWindow(QWidget *parent) util = new Util(this); mifare = new Mifare(ui, util, this); - } MainWindow::~MainWindow() @@ -30,7 +29,7 @@ MainWindow::~MainWindow() delete pm3Thread; } -void MainWindow::initUI() +void MainWindow::initUI() // will be called by main.app { ui->retranslateUi(this); uiInit(); @@ -183,6 +182,47 @@ void MainWindow::MF_onTypeChanged(int id, bool st) typeBtnGroup->blockSignals(false); } +void MainWindow::on_MF_File_loadButton_clicked() +{ + QString title = ""; + QString filename = ""; + if(ui->MF_File_dataBox->isChecked()) + { + title = tr("Plz choose the data file:"); + filename = QFileDialog::getOpenFileName(this, title, "./", tr("Binary Data Files(*.bin *.dump);;Text Data Files(*.txt *.eml);;All Files(*.*)")); + qDebug() << filename; + if(filename != "") + { + if(!mifare->data_loadDataFile(filename)) + { + QMessageBox::information(this, tr("Info"), tr("Failed to open") + "\n" + filename); + } + } + } + else if(ui->MF_File_keyBox->isChecked()) + { + title = tr("Plz choose the key file:"); + filename = QFileDialog::getOpenFileName(this, title, "./", tr("Binary Key Files(*.bin *.dump);;All Files(*.*)")); + qDebug() << filename; + if(filename != "") + { + if(!mifare->data_loadKeyFile(filename)) + { + QMessageBox::information(this, tr("Info"), tr("Failed to open") + "\n" + filename); + } + } + } + +} + +void MainWindow::on_MF_File_saveButton_clicked() +{ + QString title = tr("Save data to"); + QString selectedType = ""; + QString filename = QFileDialog::getSaveFileName(this, title, "./", tr("Bin Files(*.bin *.dump);;Text Files(*.txt *.eml)"), &selectedType); + qDebug() << filename << selectedType; +} + void MainWindow::on_MF_Attack_infoButton_clicked() { mifare->info(); @@ -314,12 +354,6 @@ void MainWindow::uiInit() ui->MF_dataWidget->setColumnWidth(0, 35); ui->MF_dataWidget->setColumnWidth(1, 35); ui->MF_dataWidget->setColumnWidth(2, 400); -// for(int i = 0; i < 256; i++) -// { -// ui->MF_dataWidget->setItem(i, 0, new QTableWidgetItem()); -// ui->MF_dataWidget->setItem(i, 1, new QTableWidgetItem()); -// ui->MF_dataWidget->setItem(i, 2, new QTableWidgetItem()); -// } ui->MF_keyWidget->setColumnCount(3); ui->MF_keyWidget->setHorizontalHeaderItem(0, new QTableWidgetItem(tr("Sec"))); @@ -329,12 +363,6 @@ void MainWindow::uiInit() ui->MF_keyWidget->setColumnWidth(0, 35); ui->MF_keyWidget->setColumnWidth(1, 110); ui->MF_keyWidget->setColumnWidth(2, 110); -// for(int i = 0; i < 40; i++) -// { -// ui->MF_keyWidget->setItem(i, 0, new QTableWidgetItem()); -// ui->MF_keyWidget->setItem(i, 1, new QTableWidgetItem()); -// ui->MF_keyWidget->setItem(i, 2, new QTableWidgetItem()); -// } MF_widgetReset(); typeBtnGroup = new QButtonGroup(this); diff --git a/ui/mainwindow.h b/ui/mainwindow.h index 0aaf37d..d707eb0 100644 --- a/ui/mainwindow.h +++ b/ui/mainwindow.h @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -89,12 +90,17 @@ private slots: void on_MF_UID_writeBlockButton_clicked(); + void on_MF_File_loadButton_clicked(); + + void on_MF_File_saveButton_clicked(); + private: - Ui::MainWindow *ui; + Ui::MainWindow* ui; QButtonGroup* typeBtnGroup; QLabel* connectStatusBar; QLabel* programStatusBar; QLabel* PM3VersionBar; + void uiInit(); PM3Process* pm3; diff --git a/ui/mainwindow.ui b/ui/mainwindow.ui index 08f8714..63adddc 100644 --- a/ui/mainwindow.ui +++ b/ui/mainwindow.ui @@ -6,7 +6,7 @@ 0 0 - 800 + 820 770 @@ -323,7 +323,7 @@ - + Data @@ -333,13 +333,10 @@ - + Key - - true -