From 377f70aa399539ec27ed0cada1a4215fe2cd4ea9 Mon Sep 17 00:00:00 2001 From: mhvhm <1308784381@qq.com> Date: Sun, 25 Aug 2024 23:30:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E6=AD=A5=E5=AE=8C=E6=88=90can?= =?UTF-8?q?=E9=80=9A=E4=BF=A1=E8=A7=A3=E7=A0=81=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ComParseTool/ComParseTool.pro | 31 ++ ComParseTool/ComParseTool.pro.user | 557 +++++++++++++++++++++++++++++ ComParseTool/main.cpp | 11 + ComParseTool/mainwindow.cpp | 150 ++++++++ ComParseTool/mainwindow.h | 42 +++ ComParseTool/mainwindow.ui | 242 +++++++++++++ 6 files changed, 1033 insertions(+) create mode 100644 ComParseTool/ComParseTool.pro create mode 100644 ComParseTool/ComParseTool.pro.user create mode 100644 ComParseTool/main.cpp create mode 100644 ComParseTool/mainwindow.cpp create mode 100644 ComParseTool/mainwindow.h create mode 100644 ComParseTool/mainwindow.ui diff --git a/ComParseTool/ComParseTool.pro b/ComParseTool/ComParseTool.pro new file mode 100644 index 0000000..0086fd6 --- /dev/null +++ b/ComParseTool/ComParseTool.pro @@ -0,0 +1,31 @@ +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +CONFIG += c++11 + +# The following define makes your compiler emit warnings if you use +# any Qt feature that has been marked deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if it uses deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +SOURCES += \ + main.cpp \ + mainwindow.cpp + +HEADERS += \ + mainwindow.h + +FORMS += \ + mainwindow.ui + +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target diff --git a/ComParseTool/ComParseTool.pro.user b/ComParseTool/ComParseTool.pro.user new file mode 100644 index 0000000..51a3b94 --- /dev/null +++ b/ComParseTool/ComParseTool.pro.user @@ -0,0 +1,557 @@ + + + + + + EnvironmentId + {a9a6bae5-cd8f-4b74-ae55-1c4ea6a77b25} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt 5.14.2 MinGW 32-bit + Desktop Qt 5.14.2 MinGW 32-bit + qt.qt5.5142.win32_mingw73_kit + 0 + 0 + 0 + + E:/Project/QT_Projects/ComParseTool/build-ComParseTool-Desktop_Qt_5_14_2_MinGW_32_bit-Debug + + + true + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + + + E:/Project/QT_Projects/ComParseTool/build-ComParseTool-Desktop_Qt_5_14_2_MinGW_32_bit-Release + + + true + QtProjectManager.QMakeBuildStep + false + + false + false + true + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + + + E:/Project/QT_Projects/ComParseTool/build-ComParseTool-Desktop_Qt_5_14_2_MinGW_32_bit-Profile + + + true + QtProjectManager.QMakeBuildStep + true + + false + true + true + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + Qt4ProjectManager.Qt4BuildConfiguration + 0 + + 3 + + + 0 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + Qt4ProjectManager.Qt4RunConfiguration:E:/Project/QT_Projects/ComParseTool/ComParseTool/ComParseTool.pro + E:/Project/QT_Projects/ComParseTool/ComParseTool/ComParseTool.pro + + false + + false + true + true + false + false + true + + E:/Project/QT_Projects/ComParseTool/build-ComParseTool-Desktop_Qt_5_14_2_MinGW_32_bit-Debug + + 1 + + + + ProjectExplorer.Project.Target.1 + + Desktop Qt 5.14.2 MinGW 64-bit + Desktop Qt 5.14.2 MinGW 64-bit + qt.qt5.5142.win64_mingw73_kit + 0 + 0 + 0 + + E:/Project/QT_Projects/ComParseTool/build-ComParseTool-Desktop_Qt_5_14_2_MinGW_64_bit-Debug + + + true + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + + + E:/Project/QT_Projects/ComParseTool/build-ComParseTool-Desktop_Qt_5_14_2_MinGW_64_bit-Release + + + true + QtProjectManager.QMakeBuildStep + false + + false + false + true + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + + + E:/Project/QT_Projects/ComParseTool/build-ComParseTool-Desktop_Qt_5_14_2_MinGW_64_bit-Profile + + + true + QtProjectManager.QMakeBuildStep + true + + false + true + true + + + true + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + Qt4ProjectManager.Qt4BuildConfiguration + 0 + + 3 + + + 0 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + dwarf + + cpu-cycles + + + 250 + + -e + cpu-cycles + --call-graph + dwarf,4096 + -F + 250 + + -F + true + 4096 + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + kcachegrind + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + + ProjectExplorer.CustomExecutableRunConfiguration + + + false + + false + true + false + false + true + + + + 1 + + + + ProjectExplorer.Project.TargetCount + 2 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/ComParseTool/main.cpp b/ComParseTool/main.cpp new file mode 100644 index 0000000..fd3e533 --- /dev/null +++ b/ComParseTool/main.cpp @@ -0,0 +1,11 @@ +#include "mainwindow.h" + +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.show(); + return a.exec(); +} diff --git a/ComParseTool/mainwindow.cpp b/ComParseTool/mainwindow.cpp new file mode 100644 index 0000000..94ccc29 --- /dev/null +++ b/ComParseTool/mainwindow.cpp @@ -0,0 +1,150 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" + +typedef struct +{ + int len = 0; + uint8_t buf[8] = {0}; +}DATA_TYPEDEF; + +MainWindow::MainWindow(QWidget *parent) + : QMainWindow(parent) + , ui(new Ui::MainWindow) +{ + ui->setupUi(this); + + pQfile_ori = new QFile; + pQfile_key = new QFile; + + BindSlot(); // 绑定槽函数 +} + +MainWindow::~MainWindow() +{ + delete ui; +} + +// 绑定槽函数 +void MainWindow::BindSlot(void) +{ + connect(ui->pushButton_oriPath, &QPushButton::clicked, this, PushButton_Clicked_CatchFile_Callback); + connect(ui->pushButton_keyPath, &QPushButton::clicked, this, PushButton_Clicked_CatchFile_Callback); + + connect(ui->pushButton_parse, &QPushButton::clicked, this, PushButton_Clicked_Parse_clicked); +} + +// 打开资源管理器 +void MainWindow::OpenExplorerFile(bool isOriFileOpen) +{ + QString DesktopLocation = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); // 获取桌面路径 + QString filePath = QFileDialog::getOpenFileName(this, "选择源文件", DesktopLocation, "文本文件(*.txt)"); + if (filePath.isEmpty() != true) + { + ui->textEdit->clear(); + if (isOriFileOpen) + { + pQfile_ori->setFileName(filePath); + ui->lineEdit_oriPath->setText(filePath); + if (pQfile_ori->open(QIODevice::ReadWrite | QIODevice::Text)) // 打开成功 + { + qDebug() << "opened file [" << filePath << "]"; + + } + } + else + { + pQfile_key->setFileName(filePath); + ui->lineEdit_keyPath->setText(filePath); + if (pQfile_key->open(QIODevice::ReadWrite | QIODevice::Text)) // 打开成功 + { + qDebug() << "opened file [" << filePath << "]"; + QString str = pQfile_key->readLine(); // 获取一行 + + QByteArray byteArr = QByteArray::fromHex(str.toLatin1()); + memcpy(&key, byteArr.data(), 8); + } + } + } +} + +/* ******************************************************************** */ +// 文件浏览槽函数 +void MainWindow::PushButton_Clicked_CatchFile_Callback(void) +{ + QPushButton* btn = qobject_cast(sender()); + qDebug() << "***" << btn->objectName() << "Clicked_Callback ***"; + + if (btn == ui->pushButton_oriPath) + { + OpenExplorerFile(true); + } + else + { + OpenExplorerFile(false); + } +} + +void MainWindow::PushButton_Clicked_Parse_clicked() +{ + bool isFirstLine = true; + qDebug() << "*** \"pushButton_parse\" Clicked Callback ***"; + + if (!(pQfile_ori->isOpen() && pQfile_key->isOpen())) + { + QMessageBox msgBox; + msgBox.setText("请先选择源文件以及密钥文件"); + msgBox.setIcon(QMessageBox::Information); + msgBox.setWindowTitle("!WARNING!"); + msgBox.exec(); + return; + } + + QTextCodec* codec = QTextCodec::codecForName("GBK"); // 中文显示 + QByteArray byteArr = pQfile_ori->readLine(); // 读取一行 + QString context = codec->toUnicode(byteArr); + QString disp = context; + while (byteArr.isEmpty() != true) // 成功读取到数据 + { + if (isFirstLine == true) // 跳过第一行的解密 + { + isFirstLine = false; + } + else + { + int strFirstIndex = context.lastIndexOf("\t"); // 获取第一次遇到制表符的位置 + int strSecondIndex = 0; + if (strFirstIndex >= 1) + { + strSecondIndex = context.lastIndexOf("\t", strFirstIndex - 1); + if (strSecondIndex == -1) + { + break; // todo 需要调试 + } + } + // todo 将String转换为数组 + QByteArray ba = QByteArray::fromHex(context.mid(strSecondIndex + 1, strFirstIndex - strSecondIndex - 2).toLatin1()); + DATA_TYPEDEF bufData; + + bufData.len = ba.size(); + memcpy(&bufData.buf, ba.data(), bufData.len); + + disp.chop(1); // 删除最后一个字符 + disp += "【"; + + for (uint8_t i = 0; i < bufData.len; i++) + { + bufData.buf[i] ^= key[i]; + disp += QString("%1").arg(bufData.buf[i], 2, 16, QLatin1Char('0')) + " "; + } + disp += "】\r\n"; + } + + ui->textEdit->append(disp); + byteArr = pQfile_ori->readLine(); // 继续下一行的读取 + context = codec->toUnicode(byteArr); + disp = context; + } + QTextCursor cursor = ui->textEdit->textCursor(); + cursor.movePosition(QTextCursor::Start); + ui->textEdit->setTextCursor(cursor); +} diff --git a/ComParseTool/mainwindow.h b/ComParseTool/mainwindow.h new file mode 100644 index 0000000..847798c --- /dev/null +++ b/ComParseTool/mainwindow.h @@ -0,0 +1,42 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include + +#include +#include +#include +#include +#include +#include + + +QT_BEGIN_NAMESPACE +namespace Ui { class MainWindow; } +QT_END_NAMESPACE + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(QWidget *parent = nullptr); + ~MainWindow(); + + void BindSlot(void); + void OpenExplorerFile(bool isOriFileOpen); + +private slots: + void PushButton_Clicked_CatchFile_Callback(); + + void PushButton_Clicked_Parse_clicked(); + +private: + Ui::MainWindow *ui; + QFile *pQfile_ori; // 源文件的文件句柄 + QFile *pQfile_key; // 密钥文件的文件句柄 + + uint8_t key[8]; // 密钥 + uint8_t data[8]; // 数据 +}; +#endif // MAINWINDOW_H diff --git a/ComParseTool/mainwindow.ui b/ComParseTool/mainwindow.ui new file mode 100644 index 0000000..74f5e6e --- /dev/null +++ b/ComParseTool/mainwindow.ui @@ -0,0 +1,242 @@ + + + MainWindow + + + + 0 + 0 + 1106 + 718 + + + + MainWindow + + + + + + + Qt::Horizontal + + + QSizePolicy::Minimum + + + + 10 + 20 + + + + + + + + + + + + + + 0 + 25 + + + + font: 12pt "Adobe Arabic"; + + + 源文件路径(*.txt) + + + + + + + + 0 + 25 + + + + font: 12pt "Adobe Arabic"; + + + true + + + + + + + + 0 + 25 + + + + font: 12pt "Adobe Arabic"; + + + 浏览 + + + + + + + + + + + + 0 + 25 + + + + font: 12pt "Adobe Arabic"; + + + 密钥文件路径(*.txt) + + + + + + + + 0 + 25 + + + + font: 12pt "Adobe Arabic"; + + + true + + + + + + + + 0 + 25 + + + + font: 12pt "Adobe Arabic"; + + + 浏览 + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 160 + 50 + + + + font: 75 16pt "Adobe Arabic"; +background-color: rgb(91, 255, 88); + + + 解密 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + 1100 + 400 + + + + QTextEdit::NoWrap + + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Minimum + + + + 10 + 20 + + + + + + + + + + 0 + 0 + 1106 + 21 + + + + + 说明 + + + + + + + + +