DisassemblyContextMenu: Add delete flag/function/comment. (#206)

This commit is contained in:
Thomas (nezza-_-) Roth 2017-12-11 14:07:12 +01:00 committed by Maijin
parent 522881c569
commit 134c0ebb39
8 changed files with 79 additions and 6 deletions

View File

@ -327,19 +327,31 @@ void CutterCore::renameFunction(QString old_name, QString new_name)
emit functionRenamed(old_name, new_name); emit functionRenamed(old_name, new_name);
} }
void CutterCore::delFunction(RVA addr)
{
cmd("af- " + RAddressString(addr));
emit functionsChanged();
}
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(); emit flagsChanged();
} }
void CutterCore::delFlag(RVA addr)
{
cmd("f-@" + RAddressString(addr));
emit flagsChanged();
}
void CutterCore::setComment(RVA addr, const QString &cmt) void CutterCore::setComment(RVA addr, const QString &cmt)
{ {
cmd("CCu base64:" + cmt.toLocal8Bit().toBase64() + " @ " + QString::number(addr)); cmd("CCu base64:" + cmt.toLocal8Bit().toBase64() + " @ " + QString::number(addr));
emit commentsChanged(); emit commentsChanged();
} }
void CutterCore::delComment(ut64 addr) void CutterCore::delComment(RVA addr)
{ {
cmd("CC- @ " + QString::number(addr)); cmd("CC- @ " + QString::number(addr));
emit commentsChanged(); emit commentsChanged();
@ -670,7 +682,7 @@ QString CutterCore::createFunctionAt(RVA addr, QString name)
name.remove(QRegExp("[^a-zA-Z0-9_]")); name.remove(QRegExp("[^a-zA-Z0-9_]"));
QString command = "af " + name + " " + RAddressString(addr); QString command = "af " + name + " " + RAddressString(addr);
QString ret = cmd(command); QString ret = cmd(command);
emit refreshAll(); emit functionsChanged();
return ret; return ret;
} }

View File

@ -203,10 +203,12 @@ public:
QJsonDocument cmdj(const QString &str); QJsonDocument cmdj(const QString &str);
QStringList cmdList(const QString &str) { auto l = cmd(str).split("\n"); l.removeAll(""); return l; } QStringList cmdList(const QString &str) { auto l = cmd(str).split("\n"); l.removeAll(""); return l; }
void renameFunction(QString prev_name, QString new_name); void renameFunction(QString prev_name, QString new_name);
void delFunction(RVA addr);
void renameFlag(QString old_name, QString new_name); void renameFlag(QString old_name, QString new_name);
void delFlag(RVA addr);
void setComment(RVA addr, const QString &cmt); void setComment(RVA addr, const QString &cmt);
void delComment(ut64 addr); void delComment(RVA addr);
void setImmediateBase(const QString &r2BaseName, RVA offset = RVA_INVALID); void setImmediateBase(const QString &r2BaseName, RVA offset = RVA_INVALID);
@ -333,6 +335,7 @@ signals:
void functionRenamed(QString prev_name, QString new_name); void functionRenamed(QString prev_name, QString new_name);
void varsChanged(); void varsChanged();
void functionsChanged();
void flagsChanged(); void flagsChanged();
void commentsChanged(); void commentsChanged();
void instructionChanged(RVA offset); void instructionChanged(RVA offset);

View File

@ -36,6 +36,10 @@ DisassemblyContextMenu::DisassemblyContextMenu(QWidget *parent)
createAction(&actionRename, tr("Rename"), getRenameSequence(), SLOT(on_actionRename_triggered())); createAction(&actionRename, tr("Rename"), getRenameSequence(), SLOT(on_actionRename_triggered()));
createAction(&actionRenameUsedHere, "Rename Flag/Fcn/Var Used Here", getRenameUsedHereSequence(), SLOT(on_actionRenameUsedHere_triggered())); createAction(&actionRenameUsedHere, "Rename Flag/Fcn/Var Used Here", getRenameUsedHereSequence(), SLOT(on_actionRenameUsedHere_triggered()));
createAction(&actionDeleteComment, tr("Delete comment"), {}, SLOT(on_actionDeleteComment_triggered()));
createAction(&actionDeleteFlag, tr("Delete flag"), {}, SLOT(on_actionDeleteFlag_triggered()));
createAction(&actionDeleteFunction, tr("Delete function"), {}, SLOT(on_actionDeleteFunction_triggered()));
setBaseMenu = new QMenu(tr("Set Immediate Base to..."), this); setBaseMenu = new QMenu(tr("Set Immediate Base to..."), this);
setBaseMenuAction = addMenu(setBaseMenu); setBaseMenuAction = addMenu(setBaseMenu);
actionSetBaseBinary.setText(tr("Binary")); actionSetBaseBinary.setText(tr("Binary"));
@ -96,13 +100,17 @@ void DisassemblyContextMenu::aboutToShowSlot()
bool immBase = keys.contains("val") || keys.contains("ptr"); bool immBase = keys.contains("val") || keys.contains("ptr");
setBaseMenuAction->setVisible(immBase); setBaseMenuAction->setVisible(immBase);
actionCreateFunction.setVisible(true);
QString comment = Core()->cmd("CC." + RAddressString(offset)); QString comment = Core()->cmd("CC." + RAddressString(offset));
if (comment.isNull() || comment.isEmpty()) if (comment.isNull() || comment.isEmpty())
{ {
actionDeleteComment.setVisible(false);
actionAddComment.setText(tr("Add Comment")); actionAddComment.setText(tr("Add Comment"));
} }
else else
{ {
actionDeleteComment.setVisible(true);
actionAddComment.setText(tr("Edit Comment")); actionAddComment.setText(tr("Edit Comment"));
} }
@ -113,7 +121,10 @@ void DisassemblyContextMenu::aboutToShowSlot()
RCore *core = Core()->core(); RCore *core = Core()->core();
RAnalFunction *fcn = r_anal_get_fcn_at (core->anal, offset, R_ANAL_FCN_TYPE_NULL); RAnalFunction *fcn = r_anal_get_fcn_at (core->anal, offset, R_ANAL_FCN_TYPE_NULL);
RFlagItem *f = r_flag_get_i (core->flags, offset); RFlagItem *f = r_flag_get_i (core->flags, offset);
actionCreateFunction.setVisible(true);
actionDeleteFlag.setVisible(f ? true : false);
actionDeleteFunction.setVisible(fcn ? true : false);
if (fcn) if (fcn)
{ {
actionCreateFunction.setVisible(false); actionCreateFunction.setVisible(false);
@ -160,8 +171,7 @@ QKeySequence DisassemblyContextMenu::getCopySequence() const
QKeySequence DisassemblyContextMenu::getCommentSequence() const QKeySequence DisassemblyContextMenu::getCommentSequence() const
{ {
// return {";"}; return {";"};
return {};
} }
QKeySequence DisassemblyContextMenu::getAddFlagSequence() const QKeySequence DisassemblyContextMenu::getAddFlagSequence() const
@ -342,6 +352,21 @@ void DisassemblyContextMenu::on_actionDisplayOptions_triggered()
dialog->show(); dialog->show();
} }
void DisassemblyContextMenu::on_actionDeleteComment_triggered()
{
Core()->delComment(offset);
}
void DisassemblyContextMenu::on_actionDeleteFlag_triggered()
{
Core()->delFlag(offset);
}
void DisassemblyContextMenu::on_actionDeleteFunction_triggered()
{
Core()->delFunction(offset);
}
void DisassemblyContextMenu::on_actionSetBaseBinary_triggered() void DisassemblyContextMenu::on_actionSetBaseBinary_triggered()
{ {
Core()->setImmediateBase("b", offset); Core()->setImmediateBase("b", offset);

View File

@ -33,6 +33,10 @@ private slots:
void on_actionXRefs_triggered(); void on_actionXRefs_triggered();
void on_actionDisplayOptions_triggered(); void on_actionDisplayOptions_triggered();
void on_actionDeleteComment_triggered();
void on_actionDeleteFlag_triggered();
void on_actionDeleteFunction_triggered();
void on_actionSetBaseBinary_triggered(); void on_actionSetBaseBinary_triggered();
void on_actionSetBaseOctal_triggered(); void on_actionSetBaseOctal_triggered();
void on_actionSetBaseDecimal_triggered(); void on_actionSetBaseDecimal_triggered();
@ -69,6 +73,10 @@ private:
QAction actionXRefs; QAction actionXRefs;
QAction actionDisplayOptions; QAction actionDisplayOptions;
QAction actionDeleteComment;
QAction actionDeleteFlag;
QAction actionDeleteFunction;
QMenu *setBaseMenu; QMenu *setBaseMenu;
QAction *setBaseMenuAction; QAction *setBaseMenuAction;
QAction actionSetBaseBinary; QAction actionSetBaseBinary;

View File

@ -82,6 +82,7 @@ DisassemblyWidget::DisassemblyWidget(QWidget *parent)
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(flagsChanged()), this, SLOT(refreshDisasm()));
connect(Core(), SIGNAL(functionsChanged()), this, SLOT(refreshDisasm()));
connect(Core(), SIGNAL(functionRenamed(QString, QString)), this, SLOT(refreshDisasm())); connect(Core(), SIGNAL(functionRenamed(QString, QString)), this, SLOT(refreshDisasm()));
connect(Core(), SIGNAL(varsChanged()), this, SLOT(refreshDisasm())); connect(Core(), SIGNAL(varsChanged()), this, SLOT(refreshDisasm()));
connect(Core(), SIGNAL(asmOptionsChanged()), this, SLOT(refreshDisasm())); connect(Core(), SIGNAL(asmOptionsChanged()), this, SLOT(refreshDisasm()));

View File

@ -381,6 +381,7 @@ FunctionsWidget::FunctionsWidget(MainWindow *main, QWidget *parent) :
connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), connect(this, SIGNAL(customContextMenuRequested(const QPoint &)),
this, SLOT(showTitleContextMenu(const QPoint &))); this, SLOT(showTitleContextMenu(const QPoint &)));
connect(Core(), SIGNAL(functionsChanged()), this, SLOT(refreshTree()));
connect(Core(), SIGNAL(refreshAll()), this, SLOT(refreshTree())); connect(Core(), SIGNAL(refreshAll()), this, SLOT(refreshTree()));
} }

View File

@ -40,6 +40,8 @@ VisualNavbar::VisualNavbar(MainWindow *main, 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(refreshAll()), this, SLOT(fetchAndPaintData())); connect(Core(), SIGNAL(refreshAll()), this, SLOT(fetchAndPaintData()));
connect(Core(), SIGNAL(functionsChanged()), this, SLOT(updateMetadataAndPaint()));
connect(Core(), SIGNAL(flagsChanged()), this, SLOT(updateMetadataAndPaint()));
graphicsScene = new QGraphicsScene(this); graphicsScene = new QGraphicsScene(this);
@ -185,6 +187,25 @@ void VisualNavbar::fetchData()
totalMappedSize += mappedSegment.address_to - mappedSegment.address_from; totalMappedSize += mappedSegment.address_to - mappedSegment.address_from;
} }
updateMetadata();
}
void VisualNavbar::updateMetadataAndPaint()
{
qWarning() << "Update metadata & paint";
updateMetadata();
fillData();
}
void VisualNavbar::updateMetadata()
{
for(int i=0; i < mappedSegments.length(); i++)
{
mappedSegments[i].functions.clear();
mappedSegments[i].symbols.clear();
mappedSegments[i].strings.clear();
}
QList<FunctionDescription> functions = Core()->getAllFunctions(); QList<FunctionDescription> functions = Core()->getAllFunctions();
for(auto function : functions) for(auto function : functions)
{ {

View File

@ -43,6 +43,8 @@ public slots:
private slots: private slots:
void fetchAndPaintData(); void fetchAndPaintData();
void fetchData(); void fetchData();
void updateMetadataAndPaint();
void updateMetadata();
void fillData(); void fillData();
void drawCursor(); void drawCursor();
void on_seekChanged(RVA addr); void on_seekChanged(RVA addr);