Edit Function Menu/Dialog (#528) (#765)

* button added, dialog todo

* WIP EditFunctionDialog

* dialog retrieving function parameters, but not yet setting them

* minor fixups, ok button not working

* wire everything up and add calling convention selection

* fixup Cutter.pro
This commit is contained in:
Paul 2018-10-22 02:16:56 -07:00 committed by Itay Cohen
parent 04148a6834
commit 899d64c6f8
6 changed files with 309 additions and 2 deletions

View File

@ -199,7 +199,8 @@ SOURCES += \
dialogs/SetToDataDialog.cpp \
dialogs/SetFunctionVarTypes.cpp \
widgets/ColorSchemePrefWidget.cpp \
common/ColorSchemeFileSaver.cpp
common/ColorSchemeFileSaver.cpp \
dialogs/EditFunctionDialog.cpp
HEADERS += \
Cutter.h \
@ -299,7 +300,8 @@ HEADERS += \
common/InitialOptions.h \
dialogs/SetFunctionVarTypes.h \
common/ColorSchemeFileSaver.h \
widgets/ColorSchemePrefWidget.h
widgets/ColorSchemePrefWidget.h \
dialogs/EditFunctionDialog.h
FORMS += \
dialogs/AboutDialog.ui \
@ -311,6 +313,7 @@ FORMS += \
dialogs/XrefsDialog.ui \
dialogs/NewfileDialog.ui \
dialogs/InitialOptionsDialog.ui \
dialogs/EditFunctionDialog.ui \
MainWindow.ui \
widgets/CommentsWidget.ui \
widgets/ConsoleWidget.ui \

View File

@ -0,0 +1,77 @@
#include "EditFunctionDialog.h"
#include "ui_EditFunctionDialog.h"
EditFunctionDialog::EditFunctionDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::EditFunctionDialog)
{
ui->setupUi(this);
setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint));
}
EditFunctionDialog::~EditFunctionDialog() {}
QString EditFunctionDialog::getNameText()
{
QString ret = ui->nameLineEdit->text();
return ret;
}
void EditFunctionDialog::setNameText(const QString &name)
{
ui->nameLineEdit->setText(name);
}
QString EditFunctionDialog::getStartAddrText()
{
QString ret = ui->startLineEdit->text();
return ret;
}
void EditFunctionDialog::setStartAddrText(const QString &startAddr)
{
ui->startLineEdit->setText(startAddr);
}
QString EditFunctionDialog::getEndAddrText()
{
QString ret = ui->endLineEdit->text();
return ret;
}
void EditFunctionDialog::setEndAddrText(const QString &endAddr)
{
ui->endLineEdit->setText(endAddr);
}
QString EditFunctionDialog::getStackSizeText()
{
QString ret = ui->stackSizeLineEdit->text();
return ret;
}
void EditFunctionDialog::setStackSizeText(const QString &stackSize)
{
ui->stackSizeLineEdit->setText(stackSize);
}
void EditFunctionDialog::setCallConList(const QStringList callConList) {
ui->callConComboBox->addItems(callConList);
}
void EditFunctionDialog::setCallConSelected(const QString selected) {
ui->callConComboBox->setCurrentText(selected);
}
QString EditFunctionDialog::getCallConSelected() {
return ui->callConComboBox->currentText();
}
void EditFunctionDialog::on_buttonBox_accepted()
{
}
void EditFunctionDialog::on_buttonBox_rejected()
{
close();
}

View File

@ -0,0 +1,39 @@
#ifndef EDITFUNCTIONDIALOG_H
#define EDITFUNCTIONDIALOG_H
#include <QDialog>
#include <memory>
namespace Ui {
class EditFunctionDialog;
}
class EditFunctionDialog : public QDialog
{
Q_OBJECT
public:
explicit EditFunctionDialog(QWidget *parent = nullptr);
~EditFunctionDialog();
QString getNameText();
void setNameText(const QString &name);
QString getStartAddrText();
void setStartAddrText(const QString &startAddr);
QString getEndAddrText();
void setEndAddrText(const QString &endAddr);
QString getStackSizeText();
void setStackSizeText(const QString &stackSize);
void setCallConList(const QStringList callConList);
void setCallConSelected(const QString selected);
QString getCallConSelected();
private slots:
void on_buttonBox_accepted();
void on_buttonBox_rejected();
private:
std::unique_ptr<Ui::EditFunctionDialog> ui;
};
#endif // EDITFUNCTIONDIALOG_H

View File

@ -0,0 +1,139 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>EditFunctionDialog</class>
<widget class="QDialog" name="EditFunctionDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>318</width>
<height>192</height>
</rect>
</property>
<property name="windowTitle">
<string>Edit Function</string>
</property>
<property name="toolTipDuration">
<number>0</number>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>2</number>
</property>
<property name="leftMargin">
<number>2</number>
</property>
<property name="topMargin">
<number>5</number>
</property>
<property name="rightMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<item>
<layout class="QFormLayout" name="formLayout">
<property name="topMargin">
<number>0</number>
</property>
<item row="2" column="0">
<widget class="QLabel" name="nameLabel">
<property name="text">
<string>Name of function</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="nameLineEdit"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="startLabel">
<property name="text">
<string>Start address</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="startLineEdit"/>
</item>
<item row="5" column="0">
<widget class="QLabel" name="endLabel">
<property name="text">
<string>End address</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QLineEdit" name="endLineEdit"/>
</item>
<item row="6" column="0">
<widget class="QLabel" name="stackSizeLabel">
<property name="text">
<string>Stack size</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QLineEdit" name="stackSizeLineEdit"/>
</item>
<item row="7" column="0">
<widget class="QLabel" name="callConLabel">
<property name="text">
<string>Calling convention</string>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QComboBox" name="callConComboBox"/>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>EditFunctionDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>158</x>
<y>142</y>
</hint>
<hint type="destinationlabel">
<x>158</x>
<y>78</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>EditFunctionDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>158</x>
<y>142</y>
</hint>
<hint type="destinationlabel">
<x>158</x>
<y>78</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -7,6 +7,7 @@
#include "dialogs/XrefsDialog.h"
#include "dialogs/SetFunctionVarTypes.h"
#include "dialogs/SetToDataDialog.h"
#include "dialogs/EditFunctionDialog.h"
#include <QtCore>
#include <QShortcut>
#include <QJsonArray>
@ -38,6 +39,10 @@ DisassemblyContextMenu::DisassemblyContextMenu(QWidget *parent)
SLOT(on_actionRename_triggered()), getRenameSequence());
addAction(&actionRename);
initAction(&actionEditFunction, tr("Edit function"),
SLOT(on_actionEditFunction_triggered()));
addAction(&actionEditFunction);
initAction(&actionRenameUsedHere, tr("Rename Flag/Fcn/Var Used Here"),
SLOT(on_actionRenameUsedHere_triggered()), getRenameUsedHereSequence());
addAction(&actionRenameUsedHere);
@ -60,6 +65,7 @@ DisassemblyContextMenu::DisassemblyContextMenu(QWidget *parent)
SLOT(on_actionAnalyzeFunction_triggered()));
addAction(&actionAnalyzeFunction);
addSetBaseMenu();
addSetBitsMenu();
@ -261,6 +267,8 @@ void DisassemblyContextMenu::aboutToShowSlot()
actionAnalyzeFunction.setVisible(false);
actionRename.setVisible(true);
actionRename.setText(tr("Rename function \"%1\"").arg(fcn->name));
actionEditFunction.setVisible(true);
actionEditFunction.setText(tr("Edit function \"%1\"").arg(fcn->name));
} else if (f) {
actionRename.setVisible(true);
actionRename.setText(tr("Rename flag \"%1\"").arg(f->name));
@ -681,6 +689,45 @@ void DisassemblyContextMenu::on_actionDeleteFunction_triggered()
Core()->delFunction(offset);
}
void DisassemblyContextMenu::on_actionEditFunction_triggered()
{
RCore *core = Core()->core();
EditFunctionDialog *dialog = new EditFunctionDialog(this);
RAnalFunction *fcn = r_anal_get_fcn_at (core->anal, offset, R_ANAL_FCN_TYPE_NULL);
dialog->setWindowTitle(tr("Edit function %1").arg(fcn->name));
dialog->setNameText(fcn->name);
QString startAddrText = "0x" + QString::number(fcn->addr, 16);
dialog->setStartAddrText(startAddrText);
QString endAddrText = "0x" + QString::number(fcn->addr + fcn->_size, 16);
dialog->setEndAddrText(endAddrText);
QString stackSizeText;
stackSizeText.sprintf("%d", fcn->stack);
dialog->setStackSizeText(stackSizeText);
QStringList callConList = Core()->cmd("afcl").split("\n");
callConList.removeLast();
dialog->setCallConList(callConList);
dialog->setCallConSelected(fcn->cc);
if (dialog->exec()) {
QString new_name = dialog->getNameText();
Core()->renameFunction(fcn->name, new_name);
QString new_start_addr = dialog->getStartAddrText();
fcn->addr = Core()->math(new_start_addr);
QString new_end_addr = dialog->getEndAddrText();
Core()->cmd("afu " + new_end_addr);
QString new_stack_size = dialog->getStackSizeText();
fcn->stack = int(Core()->math(new_stack_size));
Core()->cmd("afc " + dialog->getCallConSelected());
emit Core()->functionsChanged();
}
}
void DisassemblyContextMenu::setBase(QString base)
{
Core()->setImmediateBase(base, offset);

View File

@ -23,6 +23,7 @@ public slots:
private slots:
void aboutToShowSlot();
void on_actionEditFunction_triggered();
void on_actionEditInstruction_triggered();
void on_actionNopInstruction_triggered();
void on_actionJmpReverse_triggered();
@ -86,6 +87,7 @@ private:
QAction actionAddComment;
QAction actionAddFlag;
QAction actionAnalyzeFunction;
QAction actionEditFunction;
QAction actionRename;
QAction actionRenameUsedHere;
QAction actionSetFunctionVarTypes;