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(){ 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; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index a116a52..893cd5d 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) @@ -196,9 +199,33 @@ 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; + 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); // Add initial location to history addToHistory(currentFunctionIndex, 0); @@ -215,6 +242,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)); @@ -249,6 +277,87 @@ 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); + + //dump functions + QStringList funcs = disassemblyCore.getFunctionNames(); + QVector baseOffsets = disassemblyCore.getBaseOffsets(); + for(const auto& func : funcs) { + Function currFunc = disassemblyCore.getFunction(func); + stream << "F|"+currFunc.getName().remove("@plt")+"|"+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"); + if(nmeumonic.contains(" ")) { + nmeumonic = nmeumonic.split(" ").at(0); + } + /* + QRegularExpression nmeumonicRegex2("(...)[.]*[a-z]*"); + QRegularExpressionMatch match3 = nmeumonicRegex2.match(line2); + if(match3.hasMatch()) { + qDebug() << "MATCH 3 BEFORE: "<functionList->addItems(disassemblyCore.getFunctionNames()); + 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)+"]"); + 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"); @@ -1055,6 +1172,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); @@ -1211,4 +1330,3 @@ void MainWindow::on_actionFullscreen_triggered() MainWindow::showFullScreen(); } } - 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); diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 4fba063..78ca372 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 + + @@ -1357,6 +1379,8 @@ color: rgb(85, 85, 85); + + @@ -1391,6 +1415,11 @@ color: rgb(85, 85, 85); Ctrl+O + + + Dump Info File + + Project 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 "";