Fix regular Rename from DisassemblyContextMenu

This commit is contained in:
Florian Märkl 2017-12-03 21:23:02 +01:00
parent fab611f1b0
commit 10ce6e7e88
3 changed files with 47 additions and 50 deletions

View File

@ -330,6 +330,7 @@ void CutterCore::renameFunction(QString old_name, QString new_name)
void CutterCore::renameFlag(QString old_name, QString new_name) void CutterCore::renameFlag(QString old_name, QString new_name)
{ {
cmd("fr " + old_name + " " + new_name); cmd("fr " + old_name + " " + new_name);
emit flagsChanged();
} }
void CutterCore::setComment(RVA addr, const QString &cmt) void CutterCore::setComment(RVA addr, const QString &cmt)

View File

@ -155,6 +155,25 @@ void DisassemblyContextMenu::aboutToShowSlot()
actionCopy.setVisible(canCopy); actionCopy.setVisible(canCopy);
copySeparator->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 QKeySequence DisassemblyContextMenu::getCopySequence() const
@ -231,62 +250,38 @@ void DisassemblyContextMenu::on_actionAddFlag_triggered()
void DisassemblyContextMenu::on_actionRename_triggered() void DisassemblyContextMenu::on_actionRename_triggered()
{ {
ut64 tgt_addr = UT64_MAX;
RAnalOp op;
RCore *core = Core()->core(); RCore *core = Core()->core();
RenameDialog *dialog = new RenameDialog(this); RenameDialog *dialog = new RenameDialog(this);
r_anal_op(core->anal, &op, offset, core->block + offset - core->offset, 32); RAnalFunction *fcn = r_anal_get_fcn_at (core->anal, offset, R_ANAL_FCN_TYPE_NULL);
tgt_addr = op.jump != UT64_MAX ? op.jump : op.ptr; RFlagItem *f = r_flag_get_i (core->flags, offset);
if (op.var) { if (fcn)
RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, offset, 0); {
if (fcn) { /* Rename function */
RAnalVar *bar = r_anal_var_get_byname (core->anal, fcn, op.var->name); dialog->setWindowTitle(tr("Rename function %1").arg(fcn->name));
if (!bar) { dialog->setName(fcn->name);
bar = r_anal_var_get_byname (core->anal, fcn, op.var->name); if (dialog->exec())
if (!bar) { {
QString new_name = dialog->getName();
bar = r_anal_var_get_byname (core->anal, fcn, op.var->name); Core()->renameFunction(fcn->name, new_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);
}
} }
} }
r_anal_op_fini (&op); else if (f)
emit Core()->commentsChanged(); {
/* 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() void DisassemblyContextMenu::on_actionXRefs_triggered()

View File

@ -81,6 +81,7 @@ DisassemblyWidget::DisassemblyWidget(QWidget *parent)
connect(Core(), SIGNAL(seekChanged(RVA)), this, SLOT(on_seekChanged(RVA))); connect(Core(), SIGNAL(seekChanged(RVA)), this, SLOT(on_seekChanged(RVA)));
connect(Core(), SIGNAL(raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType)), this, SLOT(raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType))); connect(Core(), SIGNAL(raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType)), this, SLOT(raisePrioritizedMemoryWidget(CutterCore::MemoryWidgetType)));
connect(Core(), SIGNAL(commentsChanged()), this, SLOT(refreshDisasm())); connect(Core(), SIGNAL(commentsChanged()), this, SLOT(refreshDisasm()));
connect(Core(), SIGNAL(flagsChanged()), this, SLOT(refreshDisasm()));
connect(Core(), SIGNAL(asmOptionsChanged()), this, SLOT(refreshDisasm())); connect(Core(), SIGNAL(asmOptionsChanged()), this, SLOT(refreshDisasm()));
connect(Core(), &CutterCore::instructionChanged, this, [this](RVA offset) { connect(Core(), &CutterCore::instructionChanged, this, [this](RVA offset) {
if (offset >= topOffset && offset <= bottomOffset) if (offset >= topOffset && offset <= bottomOffset)