diff --git a/src/analthread.cpp b/src/analthread.cpp index e8acf09f..1dd5286a 100644 --- a/src/analthread.cpp +++ b/src/analthread.cpp @@ -1,10 +1,14 @@ #include +#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 advanced) +void AnalThread::start(MainWindow *main, int level, QList 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 advanced) // run() will be called when a thread starts void AnalThread::run() { + const auto optionsDialog = dynamic_cast(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); } diff --git a/src/analthread.h b/src/analthread.h index 14c9855f..18d840bc 100644 --- a/src/analthread.h +++ b/src/analthread.h @@ -4,25 +4,30 @@ #include 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 advanced); + void start(MainWindow *main, int level, QList advanced); protected: void run(); using QThread::start; +signals: + void updateProgress(QString str); + private: - CutterCore *core; int level; QList advanced; + MainWindow *main; }; #endif // ANALTHREAD_H diff --git a/src/optionsdialog.cpp b/src/optionsdialog.cpp index 17020cea..e349bccd 100644 --- a/src/optionsdialog.cpp +++ b/src/optionsdialog.cpp @@ -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 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 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() diff --git a/src/optionsdialog.h b/src/optionsdialog.h index 691d8399..9dffa734 100644 --- a/src/optionsdialog.h +++ b/src/optionsdialog.h @@ -25,6 +25,8 @@ public: void setupAndStartAnalysis(int level, QList 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(); diff --git a/src/optionsdialog.ui b/src/optionsdialog.ui index 2811ded3..272da2c9 100644 --- a/src/optionsdialog.ui +++ b/src/optionsdialog.ui @@ -997,6 +997,11 @@ color: rgb(0, 0, 0); true + + + true + + @@ -1063,8 +1068,6 @@ color: rgb(0, 0, 0); - - - +