From 33732291e714fef319b1f0999a9f38cee379a065 Mon Sep 17 00:00:00 2001 From: xarkes Date: Thu, 14 Dec 2017 13:45:03 +0100 Subject: [PATCH] Added .r2 auto loading --- src/MainWindow.cpp | 16 ++++++++++++++++ src/cutter.cpp | 5 +++++ src/cutter.h | 2 ++ src/dialogs/OptionsDialog.cpp | 2 -- 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 76e5daee..85908b91 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -314,6 +314,22 @@ void MainWindow::openNewFile(const QString &fn, int anal_level, QList a { setFilename(fn); + /* Reset config */ + core->resetDefaultAsmOptions(); + + /* Prompt to load filename.r2 script */ + QString script = QString("%1.r2").arg(this->filename); + if (r_file_exists(script.toStdString().data())) { + QMessageBox mb; + mb.setWindowTitle(tr("Script loading")); + mb.setText(tr("Do you want to load the '%1' script?").arg(script)); + mb.setStandardButtons(QMessageBox::Yes | QMessageBox::No); + if (mb.exec() == QMessageBox::Yes) { + core->loadScript(script); + } + } + + /* Show analysis options dialog */ OptionsDialog *o = new OptionsDialog(this); o->setAttribute(Qt::WA_DeleteOnClose); o->show(); diff --git a/src/cutter.cpp b/src/cutter.cpp index 99c38892..5c02e0ab 100644 --- a/src/cutter.cpp +++ b/src/cutter.cpp @@ -1351,3 +1351,8 @@ QList CutterCore::disassembleLines(RVA offset, int lines) return r; } + +void CutterCore::loadScript(const QString &scriptname) +{ + r_core_cmd_file(core_, scriptname.toStdString().data()); +} diff --git a/src/cutter.h b/src/cutter.h index 2f825e8f..707545eb 100644 --- a/src/cutter.h +++ b/src/cutter.h @@ -333,6 +333,8 @@ public: void resetDefaultAsmOptions(); void saveDefaultAsmOptions(); + void loadScript(const QString &scriptname); + RCoreLocked core() const; /* fields */ diff --git a/src/dialogs/OptionsDialog.cpp b/src/dialogs/OptionsDialog.cpp index 32d867c7..bd812e3c 100644 --- a/src/dialogs/OptionsDialog.cpp +++ b/src/dialogs/OptionsDialog.cpp @@ -139,8 +139,6 @@ void OptionsDialog::setupAndStartAnalysis(int level, QList advanced) main->initUI(); - core->resetDefaultAsmOptions(); - // Timer for showing elapsed analysis time. analTimer.setInterval(1000); analTimer.setSingleShot(false);