Move loading binary into thread ()

Reduce pressure on the main thread
This commit is contained in:
Tim Siebels 2017-09-29 00:04:57 +02:00 committed by xarkes
parent 5178046df2
commit 3ccafcaef3
5 changed files with 85 additions and 67 deletions

View File

@ -1,10 +1,14 @@
#include <QDebug> #include <QDebug>
#include "ui_optionsdialog.h"
#include "cutter.h" #include "cutter.h"
#include "analthread.h" #include "analthread.h"
#include "mainwindow.h"
#include "settings.h"
#include "optionsdialog.h"
AnalThread::AnalThread(QWidget *parent) : AnalThread::AnalThread(OptionsDialog *parent) :
QThread(parent), QThread(parent),
core(nullptr), main(nullptr),
level(2) level(2)
{ {
} }
@ -18,11 +22,11 @@ AnalThread::~AnalThread()
} }
} }
void AnalThread::start(CutterCore *core, int level, QList<QString> advanced) void AnalThread::start(MainWindow *main, int level, QList<QString> advanced)
{ {
this->core = core;
this->level = level; this->level = level;
this->advanced = advanced; this->advanced = advanced;
this->main = main;
QThread::start(); QThread::start();
} }
@ -30,6 +34,55 @@ void AnalThread::start(CutterCore *core, int level, QList<QString> advanced)
// run() will be called when a thread starts // run() will be called when a thread starts
void AnalThread::run() void AnalThread::run()
{ {
const auto optionsDialog = dynamic_cast<OptionsDialog *>(parent());
const auto ui = optionsDialog->ui;
int va = ui->vaCheckBox->isChecked();
ut64 loadaddr = 0LL;
ut64 mapaddr = 0LL;
//
// Advanced Options
//
main->core->setCPU(optionsDialog->getSelectedArch(), optionsDialog->getSelectedCPU(), optionsDialog->getSelectedBits());
bool rw = false;
bool load_bininfo = ui->binCheckBox->isChecked();
if (load_bininfo)
{
if (!va)
{
va = 2;
loadaddr = UT64_MAX;
r_config_set_i(main->core->core()->config, "bin.laddr", loadaddr);
mapaddr = 0;
}
}
else
{
va = false;
loadaddr = mapaddr = 0;
}
emit updateProgress(tr("Loading binary"));
// options dialog should show the list of archs inside the given fatbin
int binidx = 0; // index of subbin
main->core->loadFile(main->getFilename(), loadaddr, mapaddr, rw, va, binidx, load_bininfo);
emit updateProgress("Analysis in progress.");
QString os = optionsDialog->getSelectedOS();
if (!os.isNull())
{
main->core->cmd("e asm.os=" + os);
}
if (ui->pdbCheckBox->isChecked())
{
main->core->loadPDB(ui->pdbLineEdit->text());
}
//qDebug() << "Anal level: " << this->level; //qDebug() << "Anal level: " << this->level;
core->analyze(this->level, this->advanced); main->core->analyze(this->level, this->advanced);
} }

View File

@ -4,25 +4,30 @@
#include <QThread> #include <QThread>
class CutterCore; class CutterCore;
class MainWindow;
class OptionsDialog;
class AnalThread : public QThread class AnalThread : public QThread
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit AnalThread(QWidget *parent = 0); explicit AnalThread(OptionsDialog *parent = 0);
~AnalThread(); ~AnalThread();
void start(CutterCore *core, int level, QList<QString> advanced); void start(MainWindow *main, int level, QList<QString> advanced);
protected: protected:
void run(); void run();
using QThread::start; using QThread::start;
signals:
void updateProgress(QString str);
private: private:
CutterCore *core;
int level; int level;
QList<QString> advanced; QList<QString> advanced;
MainWindow *main;
}; };
#endif // ANALTHREAD_H #endif // ANALTHREAD_H

View File

@ -15,10 +15,10 @@
OptionsDialog::OptionsDialog(MainWindow *main): OptionsDialog::OptionsDialog(MainWindow *main):
QDialog(0), // parent may not be main QDialog(0), // parent may not be main
ui(new Ui::OptionsDialog),
analThread(this), analThread(this),
main(main), main(main),
defaultAnalLevel(1) defaultAnalLevel(1),
ui(new Ui::OptionsDialog)
{ {
ui->setupUi(this); ui->setupUi(this);
setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint)); setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint));
@ -139,9 +139,6 @@ void OptionsDialog::setupAndStartAnalysis(int level, QList<QString> advanced)
ui->statusLabel->setText(tr("Starting analysis")); ui->statusLabel->setText(tr("Starting analysis"));
//ui->progressBar->setValue(5); //ui->progressBar->setValue(5);
int va = ui->vaCheckBox->isChecked();
ut64 loadaddr = 0LL;
ut64 mapaddr = 0LL;
// Save options in settings // Save options in settings
Settings settings; Settings settings;
@ -156,58 +153,15 @@ void OptionsDialog::setupAndStartAnalysis(int level, QList<QString> advanced)
// Apply options set above in MainWindow // Apply options set above in MainWindow
main->applySettings(); main->applySettings();
//
// Advanced Options
//
main->core->setCPU(getSelectedArch(), getSelectedCPU(), getSelectedBits());
bool rw = false;
bool load_bininfo = ui->binCheckBox->isChecked();
if (load_bininfo)
{
if (!va)
{
va = 2;
loadaddr = UT64_MAX;
r_config_set_i(main->core->core()->config, "bin.laddr", loadaddr);
mapaddr = 0;
}
}
else
{
va = false;
loadaddr = mapaddr = 0;
}
//ui->progressBar->setValue(20);
ui->statusLabel->setText(tr("Loading binary"));
// options dialog should show the list of archs inside the given fatbin
int binidx = 0; // index of subbin
main->addOutput(tr(" > Loading file: ") + main->getFilename());
main->core->loadFile(main->getFilename(), loadaddr, mapaddr, rw, va, binidx, load_bininfo);
//ui->progressBar->setValue(40);
ui->statusLabel->setText(tr("Analysis in progress"));
QString os = getSelectedOS();
if (!os.isNull())
{
main->core->cmd("e asm.os=" + os);
}
if (ui->pdbCheckBox->isChecked())
{
main->core->loadPDB(ui->pdbLineEdit->text());
}
// Threads stuff // Threads stuff
// connect signal/slot // connect signal/slot
analThread.start(main->core, level, advanced); connect(&analThread, &AnalThread::updateProgress, this, &OptionsDialog::updateProgress);
analThread.start(main, level, advanced);
}
void OptionsDialog::updateProgress(const QString &status)
{
ui->statusLabel->setText(status);
} }
void OptionsDialog::on_closeButton_clicked() void OptionsDialog::on_closeButton_clicked()

View File

@ -25,6 +25,8 @@ public:
void setupAndStartAnalysis(int level, QList<QString> advanced); void setupAndStartAnalysis(int level, QList<QString> advanced);
public slots:
void updateProgress(const QString &str);
private slots: private slots:
void on_closeButton_clicked(); void on_closeButton_clicked();
void on_okButton_clicked(); void on_okButton_clicked();
@ -40,7 +42,6 @@ private slots:
void anal_finished(); void anal_finished();
private: private:
Ui::OptionsDialog *ui;
AnalThread analThread; AnalThread analThread;
MainWindow *main; MainWindow *main;
int defaultAnalLevel; int defaultAnalLevel;
@ -48,6 +49,8 @@ private:
QString analysisDescription(int level); QString analysisDescription(int level);
void updateCPUComboBox(); void updateCPUComboBox();
public:
Ui::OptionsDialog *ui;
QString getSelectedArch(); QString getSelectedArch();
QString getSelectedCPU(); QString getSelectedCPU();
int getSelectedBits(); int getSelectedBits();

View File

@ -997,6 +997,11 @@ color: rgb(0, 0, 0);</string>
<property name="enabled"> <property name="enabled">
<bool>true</bool> <bool>true</bool>
</property> </property>
<property name="font">
<font>
<kerning>true</kerning>
</font>
</property>
<property name="styleSheet"> <property name="styleSheet">
<string notr="true"/> <string notr="true"/>
</property> </property>
@ -1063,8 +1068,6 @@ color: rgb(0, 0, 0);</string>
</item> </item>
</layout> </layout>
</widget> </widget>
<resources> <resources/>
<include location="resources.qrc"/>
</resources>
<connections/> <connections/>
</ui> </ui>