Skip to content

Commit

Permalink
Added concurrency for getting function and section lists, and replace…
Browse files Browse the repository at this point in the history
…d loading dialog with progress dialog
  • Loading branch information
jubal-R committed Sep 3, 2017
1 parent 75a0b36 commit ef7a01b
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 85 deletions.
1 change: 0 additions & 1 deletion src/ObjGui.pro
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ HEADERS += mainwindow.h \
dataStructures/strings.h

FORMS += mainwindow.ui \
loadingdialog.ui \
resultsdialog.ui

RESOURCES += \
Expand Down
2 changes: 1 addition & 1 deletion src/ObjGui.pro.user
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 3.5.1, 2017-09-02T09:37:31. -->
<!-- Written by QtCreator 3.5.1, 2017-09-02T22:20:58. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
Expand Down
63 changes: 0 additions & 63 deletions src/loadingdialog.ui

This file was deleted.

48 changes: 29 additions & 19 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#include "QScrollBar"
#include "QSettings"
#include "QInputDialog"
#include "QProgressDialog"
#include "QFuture"
#include "QtConcurrent/QtConcurrent"

#include "QDebug"

Expand All @@ -14,10 +17,8 @@
#include "highlighters/headerhighlighter.h"
#include "objdumper.h"
#include "dataStructures/strings.h"
#include "ui_loadingdialog.h"
#include "resultsdialog.h"

using namespace std;

Files files;
FunctionList functionList;
Expand Down Expand Up @@ -276,12 +277,28 @@ void MainWindow::loadBinary(QString file){
* Disassemble Binary and Display Values
*/

QProgressDialog progress("Loading Disassembly", "", 0, 4, this);
progress.setCancelButton(0);
progress.setWindowModality(Qt::WindowModal);
progress.setMinimumDuration(500);
progress.setValue(0);

// Get base offsets
baseOffsets = objDumper.getBaseOffset(file);

// Disassemble and get function list
// Disassemble, and get function and section lists
functionList.nukeList();
functionList = objDumper.getFunctionList(file, baseOffsets);
QFuture<FunctionList> futureFunctionList = QtConcurrent::run(&objDumper, &ObjDumper::getFunctionList, file, baseOffsets);
sectionList.nukeList();
QFuture<SectionList> futureSectionList = QtConcurrent::run(&objDumper, &ObjDumper::getSectionList, file);

while (!futureFunctionList.isFinished() || !futureSectionList.isFinished()){
qApp->processEvents();
}
functionList = futureFunctionList.result();
sectionList = futureSectionList.result();

progress.setValue(1);

// If functionlist is empty
if (functionList.isEmpty()){
Expand All @@ -306,9 +323,9 @@ void MainWindow::loadBinary(QString file){
ui->actionFind_Calls_to_Current_Location->setEnabled(true);
}

// Get section list and set hex values
sectionList.nukeList();
sectionList = objDumper.getSectionList(file);
progress.setValue(2);

// Set hex view values
int len = sectionList.getLength();
QByteArray addressStr;
QByteArray hexStr;
Expand All @@ -323,6 +340,8 @@ void MainWindow::loadBinary(QString file){
ui->hexAddressBrowser->setPlainText(addressStr);
ui->hexBrowser->setPlainText(hexStr);

progress.setValue(3);

// Set file format value in statusbar
ui->fileFormatlabel->setText(objDumper.getFileFormat(file));
ui->symbolsBrowser->setPlainText(objDumper.getSymbolsTable(file));
Expand All @@ -340,33 +359,24 @@ void MainWindow::loadBinary(QString file){

ui->tabWidget->setCurrentIndex(0);
ui->codeBrowser->setFocus();

progress.setValue(4);
}
}
}

// Disassemble
void MainWindow::on_actionOpen_triggered()
{
// Setup loading message dialog
QDialog* dialog = new QDialog(this, Qt::FramelessWindowHint);
Ui_Dialog loadingDialogUi;
loadingDialogUi.setupUi(dialog);
dialog->show();

// Prompt user for file
QString file = QFileDialog::getOpenFileName(this, tr("Open File"), files.getCurrentDirectory(), tr("All (*)"));

// Set and display loading message
loadingDialogUi.label->setText("Disassembling binary...");
qApp->processEvents();

// Update current directory and load file
if (file != ""){
files.setCurrentDirectory(file);
loadBinary(file);
}
// Delete loading dialog
delete dialog;

}

/*
Expand Down
2 changes: 1 addition & 1 deletion src/objdumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ QString ObjDumper::getDump(QString args, QString file){
}

// Parses disassembly and populates function list
FunctionList ObjDumper::getFunctionList(QString file, QVector<QString> baseOffsets){
extern FunctionList ObjDumper::getFunctionList(QString file, QVector<QString> baseOffsets){
FunctionList functionList;
QString dump = getDisassembly(file);

Expand Down

0 comments on commit ef7a01b

Please sign in to comment.