mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-18 19:06:10 +00:00
Move loading binary into thread (#13)
Reduce pressure on the main thread
This commit is contained in:
parent
5178046df2
commit
3ccafcaef3
@ -1,10 +1,14 @@
|
||||
#include <QDebug>
|
||||
#include "ui_optionsdialog.h"
|
||||
#include "cutter.h"
|
||||
#include "analthread.h"
|
||||
#include "mainwindow.h"
|
||||
#include "settings.h"
|
||||
#include "optionsdialog.h"
|
||||
|
||||
AnalThread::AnalThread(QWidget *parent) :
|
||||
AnalThread::AnalThread(OptionsDialog *parent) :
|
||||
QThread(parent),
|
||||
core(nullptr),
|
||||
main(nullptr),
|
||||
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->advanced = advanced;
|
||||
this->main = main;
|
||||
|
||||
QThread::start();
|
||||
}
|
||||
@ -30,6 +34,55 @@ void AnalThread::start(CutterCore *core, int level, QList<QString> advanced)
|
||||
// run() will be called when a thread starts
|
||||
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;
|
||||
core->analyze(this->level, this->advanced);
|
||||
main->core->analyze(this->level, this->advanced);
|
||||
}
|
||||
|
@ -4,25 +4,30 @@
|
||||
#include <QThread>
|
||||
|
||||
class CutterCore;
|
||||
class MainWindow;
|
||||
class OptionsDialog;
|
||||
|
||||
class AnalThread : public QThread
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit AnalThread(QWidget *parent = 0);
|
||||
explicit AnalThread(OptionsDialog *parent = 0);
|
||||
~AnalThread();
|
||||
|
||||
void start(CutterCore *core, int level, QList<QString> advanced);
|
||||
void start(MainWindow *main, int level, QList<QString> advanced);
|
||||
|
||||
protected:
|
||||
void run();
|
||||
|
||||
using QThread::start;
|
||||
|
||||
signals:
|
||||
void updateProgress(QString str);
|
||||
|
||||
private:
|
||||
CutterCore *core;
|
||||
int level;
|
||||
QList<QString> advanced;
|
||||
MainWindow *main;
|
||||
};
|
||||
|
||||
#endif // ANALTHREAD_H
|
||||
|
@ -15,10 +15,10 @@
|
||||
|
||||
OptionsDialog::OptionsDialog(MainWindow *main):
|
||||
QDialog(0), // parent may not be main
|
||||
ui(new Ui::OptionsDialog),
|
||||
analThread(this),
|
||||
main(main),
|
||||
defaultAnalLevel(1)
|
||||
defaultAnalLevel(1),
|
||||
ui(new Ui::OptionsDialog)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint));
|
||||
@ -139,9 +139,6 @@ void OptionsDialog::setupAndStartAnalysis(int level, QList<QString> advanced)
|
||||
ui->statusLabel->setText(tr("Starting analysis"));
|
||||
//ui->progressBar->setValue(5);
|
||||
|
||||
int va = ui->vaCheckBox->isChecked();
|
||||
ut64 loadaddr = 0LL;
|
||||
ut64 mapaddr = 0LL;
|
||||
|
||||
// Save options in settings
|
||||
Settings settings;
|
||||
@ -156,58 +153,15 @@ void OptionsDialog::setupAndStartAnalysis(int level, QList<QString> advanced)
|
||||
// Apply options set above in MainWindow
|
||||
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
|
||||
// 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()
|
||||
|
@ -25,6 +25,8 @@ public:
|
||||
|
||||
void setupAndStartAnalysis(int level, QList<QString> advanced);
|
||||
|
||||
public slots:
|
||||
void updateProgress(const QString &str);
|
||||
private slots:
|
||||
void on_closeButton_clicked();
|
||||
void on_okButton_clicked();
|
||||
@ -40,7 +42,6 @@ private slots:
|
||||
void anal_finished();
|
||||
|
||||
private:
|
||||
Ui::OptionsDialog *ui;
|
||||
AnalThread analThread;
|
||||
MainWindow *main;
|
||||
int defaultAnalLevel;
|
||||
@ -48,6 +49,8 @@ private:
|
||||
QString analysisDescription(int level);
|
||||
|
||||
void updateCPUComboBox();
|
||||
public:
|
||||
Ui::OptionsDialog *ui;
|
||||
QString getSelectedArch();
|
||||
QString getSelectedCPU();
|
||||
int getSelectedBits();
|
||||
|
@ -997,6 +997,11 @@ color: rgb(0, 0, 0);</string>
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<kerning>true</kerning>
|
||||
</font>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
@ -1063,8 +1068,6 @@ color: rgb(0, 0, 0);</string>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="resources.qrc"/>
|
||||
</resources>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
Loading…
Reference in New Issue
Block a user