More friendly asm syntax changing

This commit is contained in:
xarkes 2017-09-02 10:17:48 +02:00
parent c07f486920
commit 2e79090a11
11 changed files with 70 additions and 73 deletions

View File

@ -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);

View File

@ -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<QString> 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();
}

View File

@ -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<QAction *> asmSyntaxes;
void openProject(const QString &project_name);
void openNewFile(const QString &fn, int anal_level, QList<QString> advanced);

View File

@ -204,6 +204,11 @@ border-top: 0px;
<property name="tabsOnTop" stdset="0">
<bool>false</bool>
</property>
<widget class="QMenu" name="menuAsm_syntax">
<property name="title">
<string>Asm syntax</string>
</property>
</widget>
<addaction name="actionRefresh_contents"/>
<addaction name="separator"/>
<addaction name="actionDefaut"/>
@ -218,6 +223,7 @@ border-top: 0px;
<addaction name="actionDisplay_Esil"/>
<addaction name="actionDisplay_Pseudocode"/>
<addaction name="actionDisplay_Offsets"/>
<addaction name="menuAsm_syntax"/>
</widget>
<widget class="QMenu" name="menuHelp">
<property name="title">

View File

@ -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<QString> 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<QString> advanced)
QString(),
bits);
bool rw = false;
bool load_bininfo = ui->binCheckBox->isChecked();
@ -143,7 +137,6 @@ void OptionsDialog::setupAndStartAnalysis(int level, QList<QString> advanced)
// Threads stuff
// connect signal/slot
analThread.start(main->core, level, advanced);
}

View File

@ -466,16 +466,13 @@ color: rgb(0, 0, 0);</string>
<property name="verticalSpacing">
<number>0</number>
</property>
<item row="13" column="0">
<widget class="QCheckBox" name="attCheckBox">
<property name="toolTip">
<string notr="true"/>
</property>
<property name="accessibleDescription">
<string notr="true"/>
</property>
<item row="11" column="0">
<widget class="QCheckBox" name="binCheckBox">
<property name="text">
<string notr="true">Use AT&amp;&amp;T syntax</string>
<string>Load bin information</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
@ -492,20 +489,20 @@ color: rgb(0, 0, 0);</string>
</property>
</widget>
</item>
<item row="11" column="0">
<widget class="QCheckBox" name="binCheckBox">
<item row="13" column="0">
<widget class="QCheckBox" name="spacyCheckBox">
<property name="text">
<string>Load bin information</string>
</property>
<property name="checked">
<bool>true</bool>
<string>Add space after calls</string>
</property>
</widget>
</item>
<item row="14" column="0">
<widget class="QCheckBox" name="spacyCheckBox">
<widget class="QCheckBox" name="bytesCheckBox">
<property name="text">
<string>Add space after calls</string>
<string>Display asm bytes</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
@ -528,16 +525,6 @@ color: rgb(0, 0, 0);</string>
<property name="leftMargin">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QCheckBox" name="bytesCheckBox">
<property name="text">
<string>Display asm bytes</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="descriptionCheckBox">
<property name="text">

View File

@ -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);

View File

@ -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); }

View File

@ -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");

View File

@ -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();

View File

@ -2149,7 +2149,7 @@ QToolTip {
<enum>QTabWidget::North</enum>
</property>
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<property name="usesScrollButtons">
<bool>true</bool>
@ -2852,14 +2852,6 @@ QToolTip {
<string>Switch case</string>
</property>
</action>
<action name="actionSyntax_AT_T_Intel">
<property name="text">
<string>Syntax ATT/Intel</string>
</property>
<property name="toolTip">
<string>Syntax ATT/Intel</string>
</property>
</action>
<action name="actionDisasCopy_All">
<property name="text">
<string>Copy all</string>