mirror of
https://github.com/rizinorg/cutter.git
synced 2025-02-21 14:16:08 +00:00
Use InitialOptions right from the start
This commit is contained in:
parent
c2a0de2b31
commit
23e2d5fa9f
@ -101,7 +101,23 @@ CutterApplication::CutterApplication(int &argc, char **argv) : QApplication(argc
|
|||||||
|
|
||||||
mainWindow->displayNewFileDialog();
|
mainWindow->displayNewFileDialog();
|
||||||
} else { // filename specified as positional argument
|
} else { // filename specified as positional argument
|
||||||
mainWindow->openNewFile(args[0], analLevelSpecified ? analLevel : -1);
|
InitialOptions options;
|
||||||
|
options.filename = args[0];
|
||||||
|
if (analLevelSpecified) {
|
||||||
|
switch (analLevel) {
|
||||||
|
case 0:
|
||||||
|
default:
|
||||||
|
options.analCmd = {};
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
options.analCmd = { "aaa" };
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
options.analCmd = { "aaaa" };
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mainWindow->openNewFile(options, analLevelSpecified);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load plugins
|
// Load plugins
|
||||||
@ -130,7 +146,9 @@ bool CutterApplication::event(QEvent *e)
|
|||||||
QString fileName = openEvent->file();
|
QString fileName = openEvent->file();
|
||||||
m_FileAlreadyDropped = true;
|
m_FileAlreadyDropped = true;
|
||||||
mainWindow->closeNewFileDialog();
|
mainWindow->closeNewFileDialog();
|
||||||
mainWindow->openNewFile(fileName, -1);
|
InitialOptions options;
|
||||||
|
options.filename = fileName;
|
||||||
|
mainWindow->openNewFile(options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -312,25 +312,27 @@ void MainWindow::addExtraWidget(QDockWidget *extraDock)
|
|||||||
restoreExtraDock.restoreWidth(extraDock->widget());
|
restoreExtraDock.restoreWidth(extraDock->widget());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::openNewFile(const QString &fn, int analLevel, QList<QString> advancedOptions, const QString &shellcode)
|
void MainWindow::openNewFile(InitialOptions options, bool skipOptionsDialog)
|
||||||
{
|
{
|
||||||
setFilename(fn);
|
setFilename(options.filename);
|
||||||
|
|
||||||
/* Prompt to load filename.r2 script */
|
/* Prompt to load filename.r2 script */
|
||||||
QString script = QString("%1.r2").arg(this->filename);
|
if (options.script.isEmpty()) {
|
||||||
QString loadScript;
|
QString script = QString("%1.r2").arg(this->filename);
|
||||||
if (r_file_exists(script.toStdString().data())) {
|
QString loadScript;
|
||||||
QMessageBox mb;
|
if (r_file_exists(script.toStdString().data())) {
|
||||||
mb.setWindowTitle(tr("Script loading"));
|
QMessageBox mb;
|
||||||
mb.setText(tr("Do you want to load the '%1' script?").arg(script));
|
mb.setWindowTitle(tr("Script loading"));
|
||||||
mb.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
|
mb.setText(tr("Do you want to load the '%1' script?").arg(script));
|
||||||
if (mb.exec() == QMessageBox::Yes) {
|
mb.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
|
||||||
loadScript = script;
|
if (mb.exec() == QMessageBox::Yes) {
|
||||||
|
loadScript = script;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Show analysis options dialog */
|
/* Show analysis options dialog */
|
||||||
displayAnalysisOptionsDialog(analLevel, advancedOptions, loadScript, shellcode);
|
displayInitialOptionsDialog(options, skipOptionsDialog);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::openNewFileFailed()
|
void MainWindow::openNewFileFailed()
|
||||||
@ -361,16 +363,15 @@ void MainWindow::closeNewFileDialog()
|
|||||||
newFileDialog = nullptr;
|
newFileDialog = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::displayAnalysisOptionsDialog(int analLevel, QList<QString> advancedOptions, const QString &script, const QString &shellcode)
|
void MainWindow::displayInitialOptionsDialog(const InitialOptions &options, bool skipOptionsDialog)
|
||||||
{
|
{
|
||||||
InitialOptionsDialog *o = new InitialOptionsDialog(this);
|
auto o = new InitialOptionsDialog(this);
|
||||||
o->setAttribute(Qt::WA_DeleteOnClose);
|
o->setAttribute(Qt::WA_DeleteOnClose);
|
||||||
o->setInitialScript(script);
|
o->loadOptions(options);
|
||||||
o->setShellcode(shellcode);
|
|
||||||
o->show();
|
o->show();
|
||||||
|
|
||||||
if (analLevel >= 0) {
|
if (skipOptionsDialog) {
|
||||||
o->setupAndStartAnalysis(analLevel, advancedOptions);
|
o->setupAndStartAnalysis();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -929,7 +930,7 @@ void MainWindow::on_actionRefresh_Panels_triggered()
|
|||||||
|
|
||||||
void MainWindow::on_actionAnalyze_triggered()
|
void MainWindow::on_actionAnalyze_triggered()
|
||||||
{
|
{
|
||||||
displayAnalysisOptionsDialog(-1, QList<QString>(), nullptr);
|
// TODO: implement this, but do NOT open InitialOptionsDialog!!
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionImportPDB_triggered()
|
void MainWindow::on_actionImportPDB_triggered()
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
#include "widgets/PseudocodeWidget.h"
|
#include "widgets/PseudocodeWidget.h"
|
||||||
#include "dialogs/NewFileDialog.h"
|
#include "dialogs/NewFileDialog.h"
|
||||||
#include "utils/Configuration.h"
|
#include "utils/Configuration.h"
|
||||||
|
#include "utils/InitialOptions.h"
|
||||||
|
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
#include <QList>
|
#include <QList>
|
||||||
@ -67,11 +68,9 @@ public:
|
|||||||
explicit MainWindow(QWidget *parent = nullptr);
|
explicit MainWindow(QWidget *parent = nullptr);
|
||||||
~MainWindow();
|
~MainWindow();
|
||||||
|
|
||||||
void openNewFile(const QString &fn, int analLevel = -1,
|
void openNewFile(InitialOptions options = InitialOptions(), bool skipOptionsDialog = false);
|
||||||
QList<QString> advancedOptions = QList<QString>(), const QString &shellcode = QString());
|
|
||||||
void displayNewFileDialog();
|
void displayNewFileDialog();
|
||||||
void closeNewFileDialog();
|
void closeNewFileDialog();
|
||||||
void displayAnalysisOptionsDialog(int analLevel, QList<QString> advancedOptions, const QString &script, const QString &shellcode = QString());
|
|
||||||
void openProject(const QString &project_name);
|
void openProject(const QString &project_name);
|
||||||
|
|
||||||
void initUI();
|
void initUI();
|
||||||
@ -234,6 +233,8 @@ private:
|
|||||||
JupyterWidget *jupyterDock = nullptr;
|
JupyterWidget *jupyterDock = nullptr;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void displayInitialOptionsDialog(const InitialOptions &options = InitialOptions(), bool skipOptionsDialog = false);
|
||||||
|
|
||||||
void resetToDefaultLayout();
|
void resetToDefaultLayout();
|
||||||
void resetToZenLayout();
|
void resetToZenLayout();
|
||||||
void resetToDebugLayout();
|
void resetToDebugLayout();
|
||||||
|
@ -82,18 +82,41 @@ void InitialOptionsDialog::updateCPUComboBox()
|
|||||||
ui->cpuComboBox->lineEdit()->setText(currentText);
|
ui->cpuComboBox->lineEdit()->setText(currentText);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InitialOptionsDialog::setInitialScript(const QString &script)
|
void InitialOptionsDialog::loadOptions(const InitialOptions &options)
|
||||||
{
|
{
|
||||||
ui->scriptCheckBox->setChecked(!script.isEmpty());
|
if (options.analCmd.isEmpty()) {
|
||||||
ui->scriptLineEdit->setText(script);
|
|
||||||
if (!script.isEmpty()) {
|
|
||||||
ui->analSlider->setValue(0);
|
ui->analSlider->setValue(0);
|
||||||
|
} else if (options.analCmd == QList<QString>({ "aaa" })) {
|
||||||
|
ui->analSlider->setValue(1);
|
||||||
|
} else if (options.analCmd == QList<QString>({ "aaaa" })){
|
||||||
|
// TODO: These checks must always be in sync with getSelectedAdvancedAnalCmds(), which is dangerous
|
||||||
|
ui->aa_symbols->setChecked(options.analCmd.contains("aa"));
|
||||||
|
ui->aar_references->setChecked(options.analCmd.contains("aar"));
|
||||||
|
ui->aac_calls->setChecked(options.analCmd.contains("aac"));
|
||||||
|
ui->aab_basicblocks->setChecked(options.analCmd.contains("aab"));
|
||||||
|
ui->aan_rename->setChecked(options.analCmd.contains("aan"));
|
||||||
|
ui->aae_emulate->setChecked(options.analCmd.contains("aae"));
|
||||||
|
ui->aat_consecutive->setChecked(options.analCmd.contains("aat"));
|
||||||
|
ui->afta_typeargument->setChecked(options.analCmd.contains("afta"));
|
||||||
|
ui->aaT_aftertrap->setChecked(options.analCmd.contains("aaT"));
|
||||||
|
ui->aap_preludes->setChecked(options.analCmd.contains("aap"));
|
||||||
|
ui->jmptbl->setChecked(options.analCmd.contains("e! anal.jmptbl"));
|
||||||
|
ui->pushret->setChecked(options.analCmd.contains("e! anal.pushret"));
|
||||||
|
ui->hasnext->setChecked(options.analCmd.contains("e! anal.hasnext"));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void InitialOptionsDialog::setShellcode(const QString &shellcode)
|
if (!options.script.isEmpty()) {
|
||||||
{
|
ui->scriptCheckBox->setChecked(false);
|
||||||
this->shellcode = shellcode;
|
ui->scriptLineEdit->setText("");
|
||||||
|
ui->analSlider->setValue(0);
|
||||||
|
} else {
|
||||||
|
ui->scriptCheckBox->setChecked(true);
|
||||||
|
ui->scriptLineEdit->setText(options.script);
|
||||||
|
}
|
||||||
|
|
||||||
|
shellcode = options.shellcode;
|
||||||
|
|
||||||
|
// TODO: all other options should also be applied to the ui
|
||||||
}
|
}
|
||||||
|
|
||||||
QString InitialOptionsDialog::getSelectedArch()
|
QString InitialOptionsDialog::getSelectedArch()
|
||||||
@ -195,10 +218,8 @@ QList<QString> InitialOptionsDialog::getSelectedAdvancedAnalCmds()
|
|||||||
return advanced;
|
return advanced;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InitialOptionsDialog::setupAndStartAnalysis(int level, QList<QString> advanced)
|
void InitialOptionsDialog::setupAndStartAnalysis(/*int level, QList<QString> advanced*/)
|
||||||
{
|
{
|
||||||
ui->analSlider->setValue(level);
|
|
||||||
|
|
||||||
main->initUI();
|
main->initUI();
|
||||||
|
|
||||||
InitialOptions options;
|
InitialOptions options;
|
||||||
@ -233,6 +254,7 @@ void InitialOptionsDialog::setupAndStartAnalysis(int level, QList<QString> advan
|
|||||||
options.endian = getSelectedEndianness();
|
options.endian = getSelectedEndianness();
|
||||||
options.bbsize = getSelectedBBSize();
|
options.bbsize = getSelectedBBSize();
|
||||||
|
|
||||||
|
int level = ui->analSlider->value();
|
||||||
switch(level) {
|
switch(level) {
|
||||||
case 1:
|
case 1:
|
||||||
options.analCmd = { "aaa" };
|
options.analCmd = { "aaa" };
|
||||||
@ -241,7 +263,7 @@ void InitialOptionsDialog::setupAndStartAnalysis(int level, QList<QString> advan
|
|||||||
options.analCmd = { "aaaa" };
|
options.analCmd = { "aaaa" };
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
options.analCmd = advanced;
|
options.analCmd = getSelectedAdvancedAnalCmds();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
options.analCmd = {};
|
options.analCmd = {};
|
||||||
@ -276,7 +298,7 @@ void InitialOptionsDialog::setupAndStartAnalysis(int level, QList<QString> advan
|
|||||||
void InitialOptionsDialog::on_okButton_clicked()
|
void InitialOptionsDialog::on_okButton_clicked()
|
||||||
{
|
{
|
||||||
ui->okButton->setEnabled(false);
|
ui->okButton->setEnabled(false);
|
||||||
setupAndStartAnalysis(ui->analSlider->value(), getSelectedAdvancedAnalCmds());
|
setupAndStartAnalysis();
|
||||||
}
|
}
|
||||||
|
|
||||||
void InitialOptionsDialog::closeEvent(QCloseEvent *event)
|
void InitialOptionsDialog::closeEvent(QCloseEvent *event)
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include "Cutter.h"
|
#include "Cutter.h"
|
||||||
#include "AnalTask.h"
|
#include "AnalTask.h"
|
||||||
|
#include "utils/InitialOptions.h"
|
||||||
|
|
||||||
namespace Ui
|
namespace Ui
|
||||||
{
|
{
|
||||||
@ -26,7 +27,7 @@ public:
|
|||||||
|
|
||||||
QStringList asm_plugins;
|
QStringList asm_plugins;
|
||||||
|
|
||||||
void setupAndStartAnalysis(int level, QList<QString> advanced);
|
void setupAndStartAnalysis(/*int level, QList<QString> advanced*/);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_okButton_clicked();
|
void on_okButton_clicked();
|
||||||
@ -55,10 +56,6 @@ private:
|
|||||||
|
|
||||||
void updateCPUComboBox();
|
void updateCPUComboBox();
|
||||||
|
|
||||||
public:
|
|
||||||
void setInitialScript(const QString &script);
|
|
||||||
void setShellcode(const QString &shellcode);
|
|
||||||
|
|
||||||
QString getSelectedArch();
|
QString getSelectedArch();
|
||||||
QString getSelectedCPU();
|
QString getSelectedCPU();
|
||||||
int getSelectedBits();
|
int getSelectedBits();
|
||||||
@ -67,6 +64,9 @@ public:
|
|||||||
QString getSelectedOS();
|
QString getSelectedOS();
|
||||||
QList<QString> getSelectedAdvancedAnalCmds();
|
QList<QString> getSelectedAdvancedAnalCmds();
|
||||||
|
|
||||||
|
public:
|
||||||
|
void loadOptions(const InitialOptions &options);
|
||||||
|
|
||||||
void reject() override;
|
void reject() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -361,7 +361,9 @@ void NewFileDialog::loadFile(const QString &filename)
|
|||||||
ioFile = ui->ioPlugin->currentText() + "://";
|
ioFile = ui->ioPlugin->currentText() + "://";
|
||||||
}
|
}
|
||||||
ioFile += filename;
|
ioFile += filename;
|
||||||
main->openNewFile(ioFile);
|
InitialOptions options;
|
||||||
|
options.filename = ioFile;
|
||||||
|
main->openNewFile(options);
|
||||||
|
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
@ -377,8 +379,10 @@ void NewFileDialog::loadProject(const QString &project)
|
|||||||
void NewFileDialog::loadShellcode(const QString &shellcode, const int size)
|
void NewFileDialog::loadShellcode(const QString &shellcode, const int size)
|
||||||
{
|
{
|
||||||
MainWindow *main = new MainWindow();
|
MainWindow *main = new MainWindow();
|
||||||
QString ioFile = QString("malloc://%1").arg(size);
|
InitialOptions options;
|
||||||
main->openNewFile(ioFile, -1, QList<QString>(), shellcode);
|
options.filename = QString("malloc://%1").arg(size);
|
||||||
|
options.shellcode = shellcode;
|
||||||
|
main->openNewFile(options);
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user