From 10ce6e7e88242418d00f68c8d0fa713bdc06bfe6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Sun, 3 Dec 2017 21:23:02 +0100 Subject: [PATCH] Fix regular Rename from DisassemblyContextMenu --- src/cutter.cpp | 1 + src/menus/DisassemblyContextMenu.cpp | 95 +++++++++++++--------------- src/widgets/DisassemblyWidget.cpp | 1 + 3 files changed, 47 insertions(+), 50 deletions(-) diff --git a/src/cutter.cpp b/src/cutter.cpp index 70a867f7..ca6354f5 100644 --- a/src/cutter.cpp +++ b/src/cutter.cpp @@ -330,6 +330,7 @@ void CutterCore::renameFunction(QString old_name, QString new_name) void CutterCore::renameFlag(QString old_name, QString new_name) { cmd("fr " + old_name + " " + new_name); + emit flagsChanged(); } void CutterCore::setComment(RVA addr, const QString &cmt) diff --git a/src/menus/DisassemblyContextMenu.cpp b/src/menus/DisassemblyContextMenu.cpp index d4e6b972..d75e6bcf 100644 --- a/src/menus/DisassemblyContextMenu.cpp +++ b/src/menus/DisassemblyContextMenu.cpp @@ -155,6 +155,25 @@ void DisassemblyContextMenu::aboutToShowSlot() actionCopy.setVisible(canCopy); copySeparator->setVisible(canCopy); + + + RCore *core = Core()->core(); + RAnalFunction *fcn = r_anal_get_fcn_at (core->anal, offset, R_ANAL_FCN_TYPE_NULL); + RFlagItem *f = r_flag_get_i (core->flags, offset); + if (fcn) + { + actionRename.setVisible(true); + actionRename.setText(tr("Rename function \"%1\"").arg(fcn->name)); + } + else if (f) + { + actionRename.setVisible(true); + actionRename.setText(tr("Rename flag \"%1\"").arg(f->name)); + } + else + { + actionRename.setVisible(false); + } } QKeySequence DisassemblyContextMenu::getCopySequence() const @@ -231,62 +250,38 @@ void DisassemblyContextMenu::on_actionAddFlag_triggered() void DisassemblyContextMenu::on_actionRename_triggered() { - ut64 tgt_addr = UT64_MAX; - RAnalOp op; RCore *core = Core()->core(); RenameDialog *dialog = new RenameDialog(this); - r_anal_op(core->anal, &op, offset, core->block + offset - core->offset, 32); - tgt_addr = op.jump != UT64_MAX ? op.jump : op.ptr; - if (op.var) { - RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, offset, 0); - if (fcn) { - RAnalVar *bar = r_anal_var_get_byname (core->anal, fcn, op.var->name); - if (!bar) { - bar = r_anal_var_get_byname (core->anal, fcn, op.var->name); - if (!bar) { - - bar = r_anal_var_get_byname (core->anal, fcn, op.var->name); - } - } - if (bar) { - dialog->setName(bar->name); - if (dialog->exec()) { - QString new_name = dialog->getName(); - r_anal_var_rename (core->anal, fcn->addr, bar->scope, - bar->kind, bar->name, new_name.toStdString().c_str()); - } - } - } - } else if (tgt_addr != UT64_MAX) { - RAnalFunction *fcn = r_anal_get_fcn_at (core->anal, tgt_addr, R_ANAL_FCN_TYPE_NULL); - RFlagItem *f = r_flag_get_i (core->flags, tgt_addr); - if (fcn) { - /* Rename function */ - dialog->setName(fcn->name); - if (dialog->exec()) { - QString new_name = dialog->getName(); - Core()->renameFunction(fcn->name, new_name); - } - } else if (f) { - /* Rename current flag */ - dialog->setName(f->name); - if (dialog->exec()) { - QString new_name = dialog->getName(); - Core()->renameFlag(f->name, new_name); - } - } else { - /* Create new flag */ - dialog->setName(""); - if (dialog->exec()) { - QString new_name = dialog->getName(); - Core()->addFlag(tgt_addr, new_name, 1); - } + RAnalFunction *fcn = r_anal_get_fcn_at (core->anal, offset, R_ANAL_FCN_TYPE_NULL); + RFlagItem *f = r_flag_get_i (core->flags, offset); + if (fcn) + { + /* Rename function */ + dialog->setWindowTitle(tr("Rename function %1").arg(fcn->name)); + dialog->setName(fcn->name); + if (dialog->exec()) + { + QString new_name = dialog->getName(); + Core()->renameFunction(fcn->name, new_name); } } - r_anal_op_fini (&op); - emit Core()->commentsChanged(); + else if (f) + { + /* Rename current flag */ + dialog->setWindowTitle(tr("Rename flag %1").arg(f->name)); + dialog->setName(f->name); + if (dialog->exec()) + { + QString new_name = dialog->getName(); + Core()->renameFlag(f->name, new_name); + } + } + else + { + return; + } } void DisassemblyContextMenu::on_actionXRefs_triggered() diff --git a/src/widgets/DisassemblyWidget.cpp b/src/widgets/DisassemblyWidget.cpp index 07baeab3..605763fc 100644 --- a/src/widgets/DisassemblyWidget.cpp +++ b/src/widgets/DisassemblyWidget.cpp @@ -81,6 +81,7 @@ DisassemblyWidget::DisassemblyWidget(QWidget *parent) connect(Core(), SIGNAL(seekChanged(RVA)), this, SLOT(on_seekChanged(RVA))); connect(Core(), SIGNAL(raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType)), this, SLOT(raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType))); connect(Core(), SIGNAL(commentsChanged()), this, SLOT(refreshDisasm())); + connect(Core(), SIGNAL(flagsChanged()), this, SLOT(refreshDisasm())); connect(Core(), SIGNAL(asmOptionsChanged()), this, SLOT(refreshDisasm())); connect(Core(), &CutterCore::instructionChanged, this, [this](RVA offset) { if (offset >= topOffset && offset <= bottomOffset)