mirror of
https://github.com/rizinorg/cutter.git
synced 2025-02-23 15:04:46 +00:00
Use QInputDialog in Disassembly context menu
This commit is contained in:
parent
447d2cfa20
commit
02ce60d1af
@ -3,7 +3,6 @@
|
|||||||
#include "dialogs/EditInstructionDialog.h"
|
#include "dialogs/EditInstructionDialog.h"
|
||||||
#include "dialogs/CommentsDialog.h"
|
#include "dialogs/CommentsDialog.h"
|
||||||
#include "dialogs/FlagDialog.h"
|
#include "dialogs/FlagDialog.h"
|
||||||
#include "dialogs/RenameDialog.h"
|
|
||||||
#include "dialogs/XrefsDialog.h"
|
#include "dialogs/XrefsDialog.h"
|
||||||
#include "dialogs/EditVariablesDialog.h"
|
#include "dialogs/EditVariablesDialog.h"
|
||||||
#include "dialogs/SetToDataDialog.h"
|
#include "dialogs/SetToDataDialog.h"
|
||||||
@ -19,6 +18,7 @@
|
|||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
#include <QInputDialog>
|
||||||
|
|
||||||
DisassemblyContextMenu::DisassemblyContextMenu(QWidget *parent, MainWindow *mainWindow)
|
DisassemblyContextMenu::DisassemblyContextMenu(QWidget *parent, MainWindow *mainWindow)
|
||||||
: QMenu(parent),
|
: QMenu(parent),
|
||||||
@ -770,12 +770,14 @@ void DisassemblyContextMenu::on_actionAddComment_triggered()
|
|||||||
|
|
||||||
void DisassemblyContextMenu::on_actionAnalyzeFunction_triggered()
|
void DisassemblyContextMenu::on_actionAnalyzeFunction_triggered()
|
||||||
{
|
{
|
||||||
RenameDialog dialog(mainWindow);
|
bool ok;
|
||||||
dialog.setWindowTitle(tr("Analyze function at %1").arg(RAddressString(offset)));
|
// Create dialog
|
||||||
dialog.setPlaceholderText(tr("Function name"));
|
QString functionName = QInputDialog::getText(this, tr("New function %1").arg(RAddressString(offset)),
|
||||||
if (dialog.exec()) {
|
tr("Function name:"), QLineEdit::Normal, QString(), &ok);
|
||||||
QString function_name = dialog.getName();
|
|
||||||
Core()->createFunctionAt(offset, function_name);
|
// If user accepted
|
||||||
|
if (ok && !functionName.isEmpty()) {
|
||||||
|
Core()->createFunctionAt(offset, functionName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -788,60 +790,60 @@ void DisassemblyContextMenu::on_actionAddFlag_triggered()
|
|||||||
void DisassemblyContextMenu::on_actionRename_triggered()
|
void DisassemblyContextMenu::on_actionRename_triggered()
|
||||||
{
|
{
|
||||||
RCore *core = Core()->core();
|
RCore *core = Core()->core();
|
||||||
|
bool ok;
|
||||||
RenameDialog dialog(mainWindow);
|
|
||||||
|
|
||||||
RAnalFunction *fcn = Core()->functionIn(offset);
|
RAnalFunction *fcn = Core()->functionIn(offset);
|
||||||
RFlagItem *f = r_flag_get_i(core->flags, offset);
|
RFlagItem *f = r_flag_get_i(core->flags, offset);
|
||||||
|
|
||||||
if (fcn) {
|
if (fcn) {
|
||||||
/* Rename function */
|
// Renaming a function
|
||||||
dialog.setWindowTitle(tr("Rename function %1").arg(fcn->name));
|
QString newName = QInputDialog::getText(this, tr("Rename function %2").arg(fcn->name),
|
||||||
dialog.setName(fcn->name);
|
tr("Function name:"), QLineEdit::Normal, fcn->name, &ok);
|
||||||
if (dialog.exec()) {
|
if (ok && !newName.isEmpty()) {
|
||||||
QString new_name = dialog.getName();
|
Core()->renameFunction(fcn->name, newName);
|
||||||
Core()->renameFunction(fcn->name, new_name);
|
|
||||||
}
|
}
|
||||||
} else if (f) {
|
} else if (f) {
|
||||||
/* Rename current flag */
|
// Renaming flag
|
||||||
dialog.setWindowTitle(tr("Rename flag %1").arg(f->name));
|
QString newName = QInputDialog::getText(this, tr("Rename flag %2").arg(f->name),
|
||||||
dialog.setName(f->name);
|
tr("Flag name:"), QLineEdit::Normal, f->name, &ok);
|
||||||
if (dialog.exec()) {
|
if (ok && !newName.isEmpty()) {
|
||||||
QString new_name = dialog.getName();
|
Core()->renameFlag(f->name, newName);
|
||||||
Core()->renameFlag(f->name, new_name);
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DisassemblyContextMenu::on_actionRenameUsedHere_triggered()
|
void DisassemblyContextMenu::on_actionRenameUsedHere_triggered()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
QString title;
|
||||||
|
QString inputValue;
|
||||||
|
QString oldName;
|
||||||
|
|
||||||
auto array = getThingUsedHere(offset);
|
auto array = getThingUsedHere(offset);
|
||||||
if (array.isEmpty()) {
|
if (array.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto thingUsedHere = array.first();
|
auto thingUsedHere = array.first();
|
||||||
|
|
||||||
RenameDialog dialog(mainWindow);
|
|
||||||
|
|
||||||
QString oldName;
|
|
||||||
auto type = thingUsedHere.type;
|
auto type = thingUsedHere.type;
|
||||||
|
|
||||||
if (type == ThingUsedHere::Type::Address) {
|
if (type == ThingUsedHere::Type::Address) {
|
||||||
RVA offset = thingUsedHere.offset;
|
RVA offset = thingUsedHere.offset;
|
||||||
dialog.setWindowTitle(tr("Add flag at %1").arg(RAddressString(offset)));
|
title = tr("Add flag at %1").arg(RAddressString(offset));
|
||||||
dialog.setName("label." + QString::number(offset, 16));
|
inputValue = "label." + QString::number(offset, 16);
|
||||||
} else {
|
} else {
|
||||||
oldName = thingUsedHere.name;
|
oldName = thingUsedHere.name;
|
||||||
dialog.setWindowTitle(tr("Rename %1").arg(oldName));
|
title = tr("Rename %1").arg(oldName);
|
||||||
dialog.setName(oldName);
|
inputValue = oldName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ok;
|
||||||
|
// Create dialog
|
||||||
|
QString newName = QInputDialog::getText(this, title,
|
||||||
|
tr("Name:"), QLineEdit::Normal, inputValue, &ok);
|
||||||
|
|
||||||
if (dialog.exec()) {
|
// If user accepted
|
||||||
QString newName = dialog.getName().trimmed();
|
if (ok && !newName.isEmpty()) {
|
||||||
if (!newName.isEmpty()) {
|
|
||||||
Core()->cmdRawAt(QString("an %1").arg(newName), offset);
|
Core()->cmdRawAt(QString("an %1").arg(newName), offset);
|
||||||
|
|
||||||
if (type == ThingUsedHere::Type::Address || type == ThingUsedHere::Type::Flag) {
|
if (type == ThingUsedHere::Type::Address || type == ThingUsedHere::Type::Flag) {
|
||||||
@ -853,7 +855,6 @@ void DisassemblyContextMenu::on_actionRenameUsedHere_triggered()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void DisassemblyContextMenu::on_actionSetFunctionVarTypes_triggered()
|
void DisassemblyContextMenu::on_actionSetFunctionVarTypes_triggered()
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user