From aa2b838026e020b459fb2ee5d73c13806d5c7e45 Mon Sep 17 00:00:00 2001 From: HoodedBlack Date: Thu, 15 Jun 2023 09:59:44 -0400 Subject: [PATCH 01/12] Update mainwindow.cpp Added functionality to allow user to easily see number of functions. --- src/mainwindow.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index a116a52..5fd8920 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -330,6 +330,15 @@ void MainWindow::displayFunctionData(){ // Populate function list in sidebar ui->functionList->addItems(disassemblyCore.getFunctionNames()); + //List the number of functions ObjGui picked up + int num = 0; + for(const auto& i : disassemblyCore.getFunctionNames()) { + num = num + 1; + } + std::string s = ("Functions ["+std::to_string(num)+"]"); + QString arg = QString::fromLocal8Bit(s.c_str()); + ui->functionListLabel->setText(arg); + // Display main function by default if it exists if (disassemblyCore.functionExists("main")) displayFunctionText("main"); From d1dc9b52cbee9b27a37d17bacaa32ff59cd014e9 Mon Sep 17 00:00:00 2001 From: HoodedBlack Date: Fri, 16 Jun 2023 09:24:55 -0400 Subject: [PATCH 02/12] Update mainwindow.cpp Added instruction count label --- src/mainwindow.cpp | 43 ++++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 5fd8920..3a504d1 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -196,9 +196,32 @@ void MainWindow::loadBinary(QString file){ ui->codeBrowser->setPlainText("File format not recognized."); ui->addressLabel->setText(""); ui->functionLabel->setText(""); + int num1 = 0; + std::string s1 = ("Instruction count: "+std::to_string(num1)); + QString arg1 = QString::fromLocal8Bit(s1.c_str()); + ui->fileInstructionCountlabel->setText(arg1); } else { // If all good, display disassembly data displayFunctionData(); + + //Display number of instructions detected + int num1 = 0; + for(const auto& i : disassemblyCore.getFunctionNames()) { + Function func = disassemblyCore.getFunction(i); + QByteArray functionData = func.getContents(); + QByteArray::iterator iteratorByte; + int count = 0; + for (iteratorByte = functionData.begin(); iteratorByte != functionData.end() ; iteratorByte++ ) { + QByteArray test1Byte(1,0); + test1Byte[0] = functionData.at(count++); + if(test1Byte.toHex() == "0a") { + num1 = num1 + 1; + } + } + } + std::string s1 = ("Instruction count: "+std::to_string(num1)); + QString arg1 = QString::fromLocal8Bit(s1.c_str()); + ui->fileInstructionCountlabel->setText(arg1); // Add initial location to history addToHistory(currentFunctionIndex, 0); @@ -215,6 +238,7 @@ void MainWindow::loadBinary(QString file){ setUpdatesEnabled(false); ui->fileFormatlabel->setText(disassemblyCore.getFileFormat(file)); + ui->symbolsBrowser->setPlainText(disassemblyCore.getSymbolsTable(file)); ui->relocationsBrowser->setPlainText(disassemblyCore.getRelocationEntries(file)); ui->headersBrowser->setPlainText(disassemblyCore.getHeaders(file)); @@ -323,22 +347,20 @@ void MainWindow::displayFunctionText(int functionIndex){ } } } - // Setup functionlist and display function data void MainWindow::displayFunctionData(){ if (disassemblyCore.disassemblyIsLoaded()){ // Populate function list in sidebar ui->functionList->addItems(disassemblyCore.getFunctionNames()); - //List the number of functions ObjGui picked up - int num = 0; - for(const auto& i : disassemblyCore.getFunctionNames()) { - num = num + 1; - } - std::string s = ("Functions ["+std::to_string(num)+"]"); - QString arg = QString::fromLocal8Bit(s.c_str()); - ui->functionListLabel->setText(arg); - + int num = 0; + for(const auto& i : disassemblyCore.getFunctionNames()) { + num = num + 1; + } + std::string s = ("Functions ["+std::to_string(num)+"]"); + QString arg = QString::fromLocal8Bit(s.c_str()); + ui->functionListLabel->setText(arg); + // Display main function by default if it exists if (disassemblyCore.functionExists("main")) displayFunctionText("main"); @@ -1220,4 +1242,3 @@ void MainWindow::on_actionFullscreen_triggered() MainWindow::showFullScreen(); } } - From 79f4d7dfd701a1eca9b8c2fb7deaa27aff7b8ba9 Mon Sep 17 00:00:00 2001 From: HoodedBlack Date: Fri, 16 Jun 2023 09:50:19 -0400 Subject: [PATCH 03/12] Update mainwindow.ui Added instruction count label to UI --- src/mainwindow.ui | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 4fba063..7808f6c 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -93,6 +93,28 @@ font-size: 11pt; 10 + + + + + + + + Qt::LeftToRight + + + + + + + + + Qt::AlignLeft|Qt::AlignTrailing|Qt::AlignVCenter + + + 10 + + From e9dc347203bc209fddadb6b119ca9ea56be9e4d7 Mon Sep 17 00:00:00 2001 From: HoodedBlack Date: Wed, 28 Jun 2023 14:24:06 -0400 Subject: [PATCH 04/12] Update mainwindow.cpp Improved instruction count accuracy. --- src/mainwindow.cpp | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 3a504d1..01a7a72 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -206,19 +206,21 @@ void MainWindow::loadBinary(QString file){ //Display number of instructions detected int num1 = 0; - for(const auto& i : disassemblyCore.getFunctionNames()) { - Function func = disassemblyCore.getFunction(i); - QByteArray functionData = func.getContents(); - QByteArray::iterator iteratorByte; - int count = 0; - for (iteratorByte = functionData.begin(); iteratorByte != functionData.end() ; iteratorByte++ ) { - QByteArray test1Byte(1,0); - test1Byte[0] = functionData.at(count++); - if(test1Byte.toHex() == "0a") { - num1 = num1 + 1; - } - } + ObjDumper dmp; + QStringList arg; + arg << "-d" << file; + QProcess *proc = new QProcess(); + proc->start(ui->customBinaryLineEdit->text(), arg); + proc->waitForFinished(); + QString result=proc->readAllStandardOutput(); + QRegularExpression re("[0-9a-fA-F]+:\t"); + QRegularExpressionMatchIterator i = re.globalMatch(result); + while(i.hasNext()) { + QRegularExpressionMatch match = i.next(); + (void)match; //Suppress -Wunused-parameter + num1=num1+1; } + //stops here std::string s1 = ("Instruction count: "+std::to_string(num1)); QString arg1 = QString::fromLocal8Bit(s1.c_str()); ui->fileInstructionCountlabel->setText(arg1); @@ -355,6 +357,7 @@ void MainWindow::displayFunctionData(){ int num = 0; for(const auto& i : disassemblyCore.getFunctionNames()) { + (void)i; //Suppress -Wunused-parameter num = num + 1; } std::string s = ("Functions ["+std::to_string(num)+"]"); @@ -1086,6 +1089,8 @@ void MainWindow::setMenuStyle(QString foregroundColor, QString backgroundColor, } void MainWindow::setNavbarStyle(QString foregroundColor, QString backgroundColor){ + (void)foregroundColor; //Suppress -Wunused-parameter + QString navBarStyle = "#navBar {background-color: " + backgroundColor + "; border-bottom: 1px solid #d4d4d4;}"; ui->navBar->setStyleSheet(navBarStyle); From a7350c9512b1f07fdcb20bfc6f20059108beca34 Mon Sep 17 00:00:00 2001 From: HoodedBlack Date: Fri, 30 Jun 2023 13:40:35 -0400 Subject: [PATCH 05/12] Update mainwindow.h --- src/mainwindow.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/mainwindow.h b/src/mainwindow.h index 4955955..dd507cb 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -28,6 +28,8 @@ private slots: void on_actionOpen_triggered(); + void on_actionDumpFile_triggered(); + void loadBinary(QString file); bool canDisassemble(QString file); From a8013ba467e655305f9bd70e49869a47132a6a32 Mon Sep 17 00:00:00 2001 From: HoodedBlack Date: Fri, 30 Jun 2023 13:41:01 -0400 Subject: [PATCH 06/12] Update mainwindow.ui --- src/mainwindow.ui | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 7808f6c..78ca372 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -1379,6 +1379,8 @@ color: rgb(85, 85, 85); + + @@ -1413,6 +1415,11 @@ color: rgb(85, 85, 85); Ctrl+O + + + Dump Info File + + Project From ceae718882305b654f0f963e6d32571d01b59628 Mon Sep 17 00:00:00 2001 From: HoodedBlack Date: Fri, 30 Jun 2023 13:43:00 -0400 Subject: [PATCH 07/12] Update mainwindow.cpp Added functionality to dump information file which outputs all information in the following format (.txt fle): [F's denote functions, I's denote instructions] F | function_name | 0xfunction_address I | instruction_mnemonic | 0xinstruction_address --- src/mainwindow.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 01a7a72..f52adc2 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -6,12 +6,15 @@ #include "QInputDialog" #include "QProgressDialog" #include "QFuture" +#include "QFile" +#include "QTextStream" #include "QtConcurrent/QtConcurrent" #include "QDebug" #include "resultsdialog.h" + MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) @@ -206,7 +209,6 @@ void MainWindow::loadBinary(QString file){ //Display number of instructions detected int num1 = 0; - ObjDumper dmp; QStringList arg; arg << "-d" << file; QProcess *proc = new QProcess(); @@ -275,6 +277,25 @@ void MainWindow::on_actionOpen_triggered() } +//Dump File +void MainWindow::on_actionDumpFile_triggered() +{ + QString filename = "objdumpOutput.txt"; + QFile file2(filename); + if(file2.open(QIODevice::ReadWrite | QIODevice::Truncate | QIODevice::Text)) { + QTextStream stream(&file2); + QStringList funcs = disassemblyCore.getFunctionNames(); + QVector baseOffsets = disassemblyCore.getBaseOffsets(); + for(const auto& func : funcs) { + Function currFunc = disassemblyCore.getFunction(func); + stream << "F|"+currFunc.getName()+"|"+currFunc.getAddress()< Date: Mon, 3 Jul 2023 12:54:44 -0400 Subject: [PATCH 08/12] Update mainwindow.cpp Finished binary info dump file feature --- src/mainwindow.cpp | 56 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index f52adc2..011c0f1 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -284,6 +284,8 @@ void MainWindow::on_actionDumpFile_triggered() QFile file2(filename); if(file2.open(QIODevice::ReadWrite | QIODevice::Truncate | QIODevice::Text)) { QTextStream stream(&file2); + + //dump functions QStringList funcs = disassemblyCore.getFunctionNames(); QVector baseOffsets = disassemblyCore.getBaseOffsets(); for(const auto& func : funcs) { @@ -291,6 +293,60 @@ void MainWindow::on_actionDumpFile_triggered() stream << "F|"+currFunc.getName()+"|"+currFunc.getAddress()<start(ui->customBinaryLineEdit->text(), arg); + proc->waitForFinished(); + QString result=proc->readAllStandardOutput(); + QString line; + QTextStream stream2(&result); + while (stream2.readLineInto(&line)) { + QString address; + QString nmeumonic; + QRegularExpression addressRegex("[\\s][a-fA-F0-9]+[:]"); + + QRegularExpressionMatch match = addressRegex.match(line); + if(match.hasMatch()) { + QString matched = match.captured(0); + address = matched.mid(1, (matched.length()-2)); + } else { + continue; + } + + + QRegularExpression nmeumonicRegex("[\\s]+\t(...)[.]*[a-z]*"); + QRegularExpressionMatch match2 = nmeumonicRegex.match(line); + if(match2.hasMatch()) { + nmeumonic = match2.captured(0).simplified(); + nmeumonic.remove("\t"); + /* + QRegularExpression nmeumonicRegex2("(...)[.]*[a-z]*"); + QRegularExpressionMatch match3 = nmeumonicRegex2.match(line2); + if(match3.hasMatch()) { + qDebug() << "MATCH 3 BEFORE: "< Date: Mon, 3 Jul 2023 12:55:11 -0400 Subject: [PATCH 09/12] Update disassemblycore.h --- src/disassemblycore.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/disassemblycore.h b/src/disassemblycore.h index 7c9a931..785c31e 100644 --- a/src/disassemblycore.h +++ b/src/disassemblycore.h @@ -18,6 +18,7 @@ class DisassemblyCore bool disassemblyIsLoaded(); void xrefStrings(); static QString extractAddress(const QByteArray& s); + QString getFileName(); QVector getBaseOffsets(); QString getObjdumpErrorMsg(QString file); QString getSymbolsTable(QString file); @@ -59,6 +60,7 @@ class DisassemblyCore Strings strings; QVector baseOffsets; bool fileLoaded; + QString fileName; ObjDumper objDumper; From f9d2ced01b1706d7a5d794e66c93edabba3e55ff Mon Sep 17 00:00:00 2001 From: HoodedBlack Date: Mon, 3 Jul 2023 12:55:46 -0400 Subject: [PATCH 10/12] Update disassemblycore.cpp --- src/disassemblycore.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/disassemblycore.cpp b/src/disassemblycore.cpp index f561d47..916a382 100644 --- a/src/disassemblycore.cpp +++ b/src/disassemblycore.cpp @@ -35,6 +35,15 @@ void DisassemblyCore::disassemble(QString file){ xrefStrings(); fileLoaded = true; + fileName = file; +} + +QString DisassemblyCore::getFileName() { + if(fileLoaded == true) { + return fileName; + } else { + return "NaN"; + } } bool DisassemblyCore::disassemblyIsLoaded(){ From ad3c81c7ae8838f1569af407ed945226dc4e1ce6 Mon Sep 17 00:00:00 2001 From: HoodedBlack Date: Wed, 5 Jul 2023 18:00:41 -0400 Subject: [PATCH 11/12] Update mainwindow.cpp bug fix --- src/mainwindow.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 011c0f1..893cd5d 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -290,7 +290,7 @@ void MainWindow::on_actionDumpFile_triggered() QVector baseOffsets = disassemblyCore.getBaseOffsets(); for(const auto& func : funcs) { Function currFunc = disassemblyCore.getFunction(func); - stream << "F|"+currFunc.getName()+"|"+currFunc.getAddress()< Date: Fri, 4 Aug 2023 22:11:20 -0400 Subject: [PATCH 12/12] Update objdumper.cpp Fixed bug with ARM instructions not displaying nmeumonic --- src/objdumper.cpp | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/objdumper.cpp b/src/objdumper.cpp index c80e2ac..ed3eede 100644 --- a/src/objdumper.cpp +++ b/src/objdumper.cpp @@ -17,6 +17,7 @@ ObjDumper::ObjDumper() insnwidth = 10; addressRegex.setPattern("[0-9a-f]+"); + hexBytesRegex.setPattern("[0-9a-f ]+"); } @@ -138,9 +139,8 @@ QVector ObjDumper::parseFunctionLine(QStringRef line){ } // Get hex - QByteArray hexBytes = line.mid(pos, insnwidth * 3).toLocal8Bit(); + QByteArray hexBytes = line.mid(pos, insnwidth * 4).toLocal8Bit(); row[1] = parseHexBytes(hexBytes); - pos += insnwidth * 3; // Skip whitespace @@ -157,6 +157,16 @@ QVector ObjDumper::parseFunctionLine(QStringRef line){ pos++; row[2] = opt; + QString temp2 = QString(row[2]); + if(temp2.contains("\t")) { + QByteArray temp3; + temp3 += temp2.split("\t")[1]; + row[2] = temp3; + } + if(temp2.size() == 1) { + QByteArray temp3; + row[2] = temp3; + } while (pos < line.length() && line.at(pos) == QChar(' ')){ pos++; @@ -199,16 +209,12 @@ QByteArray ObjDumper::parseAddress(QByteArray address){ } QByteArray ObjDumper::parseHexBytes(QByteArray byteString){ - QRegularExpressionMatch hexMatch = hexBytesRegex.match(byteString); - - if (hexMatch.hasMatch() && hexMatch.capturedLength(0) == byteString.length()) { - byteString.replace(" ", ""); - int paddingLength = (insnwidth * 2) - byteString.length(); - QString padding = ""; - padding.fill(' ', paddingLength); - byteString.append(padding); - - return byteString; + QString temp(byteString); + if (temp.contains("\t")) { + QStringList lst = temp.split("\t"); + QByteArray ba; + ba += lst[1]; + return ba; } else { return "";