From 051b95c69d196954e218c4ba70c5ff6ebad155ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Fri, 9 Mar 2018 13:57:57 +0100 Subject: [PATCH] Make AnalThread interruptable (Fix #264) --- src/AnalThread.cpp | 18 ++++++++++++++++-- src/AnalThread.h | 5 +++++ src/dialogs/OptionsDialog.cpp | 16 +++++++++++++++- src/dialogs/OptionsDialog.h | 3 +++ 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/src/AnalThread.cpp b/src/AnalThread.cpp index 04498386..cf39d06e 100644 --- a/src/AnalThread.cpp +++ b/src/AnalThread.cpp @@ -9,7 +9,8 @@ AnalThread::AnalThread(OptionsDialog *parent) : QThread(parent), level(2), main(nullptr), - core(CutterCore::getInstance()) + core(CutterCore::getInstance()), + interrupted(false) { } @@ -31,6 +32,17 @@ void AnalThread::start(MainWindow *main, int level, QList advanced) QThread::start(); } +void AnalThread::interruptAndWait() +{ + interrupted = true; + + while(isRunning()) + { + r_cons_singleton()->breaked = true; + r_sys_usleep(10000); + } +} + // run() will be called when a thread starts void AnalThread::run() { @@ -40,6 +52,8 @@ void AnalThread::run() ut64 loadaddr = 0LL; ut64 mapaddr = 0LL; + interrupted = false; + // // Advanced Options // @@ -106,7 +120,7 @@ void AnalThread::run() } core->setBBSize(optionsDialog->getSelectedBBSize()); - + // use prj.simple as default as long as regular projects are broken core->setConfig("prj.simple", true); diff --git a/src/AnalThread.h b/src/AnalThread.h index 88704b56..253635b1 100644 --- a/src/AnalThread.h +++ b/src/AnalThread.h @@ -15,6 +15,9 @@ public: ~AnalThread(); void start(MainWindow *main, int level, QList advanced); + void interruptAndWait(); + + bool isInterrupted() { return interrupted; } protected: void run(); @@ -29,6 +32,8 @@ private: QList advanced; MainWindow *main; CutterCore *core; + + bool interrupted; }; #endif // ANALTHREAD_H diff --git a/src/dialogs/OptionsDialog.cpp b/src/dialogs/OptionsDialog.cpp index 02bff66c..87263000 100644 --- a/src/dialogs/OptionsDialog.cpp +++ b/src/dialogs/OptionsDialog.cpp @@ -262,6 +262,12 @@ void OptionsDialog::on_okButton_clicked() void OptionsDialog::anal_finished() { + if (analThread.isInterrupted()) + { + done(0); + return; + } + ui->statusLabel->setText(tr("Loading interface")); main->addOutput(tr(" > Analysis finished")); @@ -269,6 +275,15 @@ void OptionsDialog::anal_finished() done(0); } +void OptionsDialog::closeEvent(QCloseEvent *event) +{ + if (analThread.isRunning()) + { + analThread.interruptAndWait(); + } + event->accept(); +} + QString OptionsDialog::analysisDescription(int level) { //TODO: replace this with meaningful descriptions @@ -362,7 +377,6 @@ void OptionsDialog::on_pdbSelectButton_clicked() void OptionsDialog::reject() { - delete main; done(0); NewFileDialog *n = new NewFileDialog(nullptr); n->show(); diff --git a/src/dialogs/OptionsDialog.h b/src/dialogs/OptionsDialog.h index 5c943a3e..26a28242 100644 --- a/src/dialogs/OptionsDialog.h +++ b/src/dialogs/OptionsDialog.h @@ -40,6 +40,9 @@ private slots: void anal_finished(); +protected: + void closeEvent(QCloseEvent *event) override; + private: AnalThread analThread; MainWindow *main;