diff --git a/src/iaitorcore.h b/src/iaitorcore.h index 8c690e51..06e51995 100644 --- a/src/iaitorcore.h +++ b/src/iaitorcore.h @@ -198,7 +198,8 @@ public: QString itoa(ut64 num, int rdx = 16); QString config(const QString &k, const QString &v = NULL); int config(const QString &k, int v); - int getConfig(const QString &k); + int getConfigi(const QString &k); + QString getConfig(const QString &k); QString assemble(const QString &code); QString disassemble(const QString &hex); QString disassembleSingleInstruction(RVA addr); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index f46fb515..a6fbc036 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -117,6 +117,7 @@ MainWindow::MainWindow(QWidget *parent) : MainWindow::~MainWindow() { + qDeleteAll(asmSyntaxes); delete ui; delete core; } @@ -180,6 +181,23 @@ void MainWindow::initUI() addToolBarBreak(Qt::TopToolBarArea); addToolBar(graphicsBar); + // Asm syntaxes + QList list = core->cmd("e asm.syntax =?").split("\n"); + QString checked = core->getConfig("asm.syntax"); + for (QString syntax : list) { + if (syntax == "") { + break; + } + QAction* action = new QAction(syntax); + action->setCheckable(true); + if (syntax == checked) { + action->setChecked(true); + } + connect(action, SIGNAL(triggered(bool)), this, SLOT(on_actionAsm_syntax_triggered())); + asmSyntaxes.append(action); + ui->menuAsm_syntax->addAction(action); + } + /* * Dock Widgets */ @@ -382,12 +400,6 @@ void MainWindow::applySettings() core->config("asm.cmtcol", "70"); } - // Show AT&T syntax - if (settings.getATnTSyntax()) - core->config("asm.syntax", "att"); - else - core->config("asm.syntax", "intel"); - // Show opcode description if (settings.getOpcodeDescription()) { @@ -1080,14 +1092,14 @@ void MainWindow::on_actionRefresh_contents_triggered() void MainWindow::on_actionDisplay_Esil_triggered() { - int esil = this->core->getConfig("asm.esil"); + int esil = this->core->getConfigi("asm.esil"); core->config("asm.esil", !esil); refreshVisibleDockWidgets(); } void MainWindow::on_actionDisplay_Pseudocode_triggered() { - int pseudo = this->core->getConfig("asm.pseudo"); + int pseudo = this->core->getConfigi("asm.pseudo"); core->config("asm.pseudo", !pseudo); refreshVisibleDockWidgets(); } @@ -1098,3 +1110,19 @@ void MainWindow::on_actionDisplay_Offsets_triggered() memoryDock->showOffsets(checked); refreshVisibleDockWidgets(); } + +void MainWindow::on_actionAsm_syntax_triggered() +{ + QObject* sender = QObject::sender(); + // Uncheck every other choices + for (QAction* action : asmSyntaxes) { + action->setChecked(false); + } + // Check selected choice + QAction* action = (QAction*) sender; + action->setChecked(true); + // Set r2 config + core->config("asm.syntax", action->text()); + // Refresh views + refreshVisibleDockWidgets(); +} diff --git a/src/mainwindow.h b/src/mainwindow.h index dae83baa..38bd65a4 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -180,6 +180,8 @@ private slots: void on_actionDisplay_Offsets_triggered(); + void on_actionAsm_syntax_triggered(); + private: QDockWidget *asmDock; QDockWidget *calcDock; @@ -214,6 +216,7 @@ private: RadareWebServer webserver; RVA cursor_address; + QList asmSyntaxes; void openProject(const QString &project_name); void openNewFile(const QString &fn, int anal_level, QList advanced); diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 410f0032..d58f499c 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -204,6 +204,11 @@ border-top: 0px; false + + + Asm syntax + + @@ -218,6 +223,7 @@ border-top: 0px; + diff --git a/src/optionsdialog.cpp b/src/optionsdialog.cpp index 6d892ec7..79544c9e 100644 --- a/src/optionsdialog.cpp +++ b/src/optionsdialog.cpp @@ -34,7 +34,6 @@ OptionsDialog::OptionsDialog(MainWindow *main): // Restore settings QSettings settings; ui->bytesCheckBox->setChecked(settings.value("bytes").toBool()); - ui->attCheckBox->setChecked(settings.value("syntax").toBool()); ui->descriptionCheckBox->setChecked(settings.value("describe").toBool()); ui->stackCheckBox->setChecked(settings.value("stackptr").toBool()); ui->ucaseCheckBox->setChecked(settings.value("ucase").toBool()); @@ -81,19 +80,16 @@ void OptionsDialog::setupAndStartAnalysis(int level, QList advanced) // Save options in settings Settings settings; settings.setAsmBytes(ui->bytesCheckBox->isChecked()); - settings.setATnTSyntax(ui->attCheckBox->isChecked()); settings.setOpcodeDescription(ui->descriptionCheckBox->isChecked()); settings.setStackPointer(ui->stackCheckBox->isChecked()); settings.setUppercaseDisas(ui->ucaseCheckBox->isChecked()); settings.setSpacy(ui->spacyCheckBox->isChecked()); - main->initUI(); // Apply options set above in MainWindow main->applySettings(); - // // Advanced Options // @@ -110,8 +106,6 @@ void OptionsDialog::setupAndStartAnalysis(int level, QList advanced) QString(), bits); - - bool rw = false; bool load_bininfo = ui->binCheckBox->isChecked(); @@ -143,7 +137,6 @@ void OptionsDialog::setupAndStartAnalysis(int level, QList advanced) // Threads stuff // connect signal/slot - analThread.start(main->core, level, advanced); } diff --git a/src/optionsdialog.ui b/src/optionsdialog.ui index 014229ab..0f184639 100644 --- a/src/optionsdialog.ui +++ b/src/optionsdialog.ui @@ -466,16 +466,13 @@ color: rgb(0, 0, 0); 0 - - - - - - - - + + - Use AT&&T syntax + Load bin information + + + true @@ -492,20 +489,20 @@ color: rgb(0, 0, 0); - - + + - Load bin information - - - true + Add space after calls - + - Add space after calls + Display asm bytes + + + true @@ -528,16 +525,6 @@ color: rgb(0, 0, 0); 0 - - - - Display asm bytes - - - true - - - diff --git a/src/qrcore.cpp b/src/qrcore.cpp index 2828344d..75b25429 100644 --- a/src/qrcore.cpp +++ b/src/qrcore.cpp @@ -507,13 +507,20 @@ int IaitoRCore::config(const QString &k, int v) return r_config_get_i(core_->config, key.constData()); } -int IaitoRCore::getConfig(const QString &k) +int IaitoRCore::getConfigi(const QString &k) { CORE_LOCK(); QByteArray key = k.toUtf8(); return r_config_get_i(core_->config, key.constData()); } +QString IaitoRCore::getConfig(const QString &k) +{ + CORE_LOCK(); + QByteArray key = k.toUtf8(); + return QString(r_config_get(core_->config, key.constData())); +} + void IaitoRCore::setOptions(QString key) { IAITONOTUSED(key); diff --git a/src/settings.h b/src/settings.h index 1ce6b77c..4685bb1c 100644 --- a/src/settings.h +++ b/src/settings.h @@ -13,9 +13,6 @@ public: bool getAsmBytes() const { return settings.value("bytes", false).toBool(); } void setAsmBytes(bool v) { settings.setValue("bytes", v); } - bool getATnTSyntax() const { return settings.value("syntax", false).toBool(); } - void setATnTSyntax(bool v) { settings.setValue("syntax", v); } - bool getOpcodeDescription() const { return settings.value("describe", false).toBool(); } void setOpcodeDescription(bool v) { settings.setValue("describe", v); } diff --git a/src/widgets/memorywidget.cpp b/src/widgets/memorywidget.cpp index 57ad7c2e..ba97d439 100644 --- a/src/widgets/memorywidget.cpp +++ b/src/widgets/memorywidget.cpp @@ -109,7 +109,6 @@ MemoryWidget::MemoryWidget(MainWindow *main) : hideSide->addAction(ui->actionRight_align_bytes); hideSide->addSeparator(); hideSide->addAction(ui->actionDisasSwitch_case); - hideSide->addAction(ui->actionSyntax_AT_T_Intel); hideSide->addAction(ui->actionSeparate_disasm_calls); hideSide->addAction(ui->actionShow_stack_pointer); ui->memSettingsButton_2->setMenu(memMenu); @@ -1040,7 +1039,6 @@ void MemoryWidget::showDisasContextMenu(const QPoint &pt) menu->addAction(ui->actionRight_align_bytes); menu->addSeparator(); menu->addAction(ui->actionDisasSwitch_case); - menu->addAction(ui->actionSyntax_AT_T_Intel); menu->addAction(ui->actionSeparate_disasm_calls); menu->addAction(ui->actionShow_stack_pointer); menu->addSeparator(); @@ -1238,20 +1236,6 @@ void MemoryWidget::on_actionDisasSwitch_case_triggered() this->refreshDisasm(); } -void MemoryWidget::on_actionSyntax_AT_T_Intel_triggered() -{ - QString syntax = this->main->core->cmd("e asm.syntax").trimmed(); - if (syntax == "intel") - { - this->main->core->config("asm.syntax", "att"); - } - else - { - this->main->core->config("asm.syntax", "intel"); - } - this->refreshDisasm(); -} - void MemoryWidget::on_actionSeparate_bytes_triggered() { this->main->core->cmd("e!asm.bytespace"); diff --git a/src/widgets/memorywidget.h b/src/widgets/memorywidget.h index 303c5f87..24b0929b 100644 --- a/src/widgets/memorywidget.h +++ b/src/widgets/memorywidget.h @@ -188,7 +188,6 @@ private slots: void on_previewToolButton_2_clicked(); void on_actionXRefs_triggered(); void on_actionDisasSwitch_case_triggered(); - void on_actionSyntax_AT_T_Intel_triggered(); void on_actionSeparate_bytes_triggered(); void on_actionRight_align_bytes_triggered(); void on_actionSeparate_disasm_calls_triggered(); diff --git a/src/widgets/memorywidget.ui b/src/widgets/memorywidget.ui index 2158f8e1..adef4368 100644 --- a/src/widgets/memorywidget.ui +++ b/src/widgets/memorywidget.ui @@ -2149,7 +2149,7 @@ QToolTip { QTabWidget::North - 0 + 1 true @@ -2852,14 +2852,6 @@ QToolTip { Switch case - - - Syntax ATT/Intel - - - Syntax ATT/Intel - - Copy all