diff --git a/src/cutter.cpp b/src/cutter.cpp index 3ff56bf3..212ecb76 100644 --- a/src/cutter.cpp +++ b/src/cutter.cpp @@ -327,19 +327,31 @@ void CutterCore::renameFunction(QString old_name, QString 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) { cmd("fr " + old_name + " " + new_name); emit flagsChanged(); } +void CutterCore::delFlag(RVA addr) +{ + cmd("f-@" + RAddressString(addr)); + emit flagsChanged(); +} + void CutterCore::setComment(RVA addr, const QString &cmt) { cmd("CCu base64:" + cmt.toLocal8Bit().toBase64() + " @ " + QString::number(addr)); emit commentsChanged(); } -void CutterCore::delComment(ut64 addr) +void CutterCore::delComment(RVA addr) { cmd("CC- @ " + QString::number(addr)); emit commentsChanged(); @@ -670,7 +682,7 @@ QString CutterCore::createFunctionAt(RVA addr, QString name) name.remove(QRegExp("[^a-zA-Z0-9_]")); QString command = "af " + name + " " + RAddressString(addr); QString ret = cmd(command); - emit refreshAll(); + emit functionsChanged(); return ret; } diff --git a/src/cutter.h b/src/cutter.h index 4ef4c02c..86e063c3 100644 --- a/src/cutter.h +++ b/src/cutter.h @@ -203,10 +203,12 @@ public: QJsonDocument cmdj(const QString &str); QStringList cmdList(const QString &str) { auto l = cmd(str).split("\n"); l.removeAll(""); return l; } void renameFunction(QString prev_name, QString new_name); + void delFunction(RVA addr); void renameFlag(QString old_name, QString new_name); + void delFlag(RVA addr); void setComment(RVA addr, const QString &cmt); - void delComment(ut64 addr); + void delComment(RVA addr); void setImmediateBase(const QString &r2BaseName, RVA offset = RVA_INVALID); @@ -333,6 +335,7 @@ signals: void functionRenamed(QString prev_name, QString new_name); void varsChanged(); + void functionsChanged(); void flagsChanged(); void commentsChanged(); void instructionChanged(RVA offset); diff --git a/src/menus/DisassemblyContextMenu.cpp b/src/menus/DisassemblyContextMenu.cpp index 6f34f023..8cce4c83 100644 --- a/src/menus/DisassemblyContextMenu.cpp +++ b/src/menus/DisassemblyContextMenu.cpp @@ -36,6 +36,10 @@ DisassemblyContextMenu::DisassemblyContextMenu(QWidget *parent) createAction(&actionRename, tr("Rename"), getRenameSequence(), SLOT(on_actionRename_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); setBaseMenuAction = addMenu(setBaseMenu); actionSetBaseBinary.setText(tr("Binary")); @@ -96,13 +100,17 @@ void DisassemblyContextMenu::aboutToShowSlot() bool immBase = keys.contains("val") || keys.contains("ptr"); setBaseMenuAction->setVisible(immBase); + actionCreateFunction.setVisible(true); + QString comment = Core()->cmd("CC." + RAddressString(offset)); if (comment.isNull() || comment.isEmpty()) { + actionDeleteComment.setVisible(false); actionAddComment.setText(tr("Add Comment")); } else { + actionDeleteComment.setVisible(true); actionAddComment.setText(tr("Edit Comment")); } @@ -113,7 +121,10 @@ void DisassemblyContextMenu::aboutToShowSlot() 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); - actionCreateFunction.setVisible(true); + + actionDeleteFlag.setVisible(f ? true : false); + actionDeleteFunction.setVisible(fcn ? true : false); + if (fcn) { actionCreateFunction.setVisible(false); @@ -160,8 +171,7 @@ QKeySequence DisassemblyContextMenu::getCopySequence() const QKeySequence DisassemblyContextMenu::getCommentSequence() const { -// return {";"}; - return {}; + return {";"}; } QKeySequence DisassemblyContextMenu::getAddFlagSequence() const @@ -342,6 +352,21 @@ void DisassemblyContextMenu::on_actionDisplayOptions_triggered() 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() { Core()->setImmediateBase("b", offset); diff --git a/src/menus/DisassemblyContextMenu.h b/src/menus/DisassemblyContextMenu.h index a9a84b14..2524a3ea 100644 --- a/src/menus/DisassemblyContextMenu.h +++ b/src/menus/DisassemblyContextMenu.h @@ -33,6 +33,10 @@ private slots: void on_actionXRefs_triggered(); void on_actionDisplayOptions_triggered(); + void on_actionDeleteComment_triggered(); + void on_actionDeleteFlag_triggered(); + void on_actionDeleteFunction_triggered(); + void on_actionSetBaseBinary_triggered(); void on_actionSetBaseOctal_triggered(); void on_actionSetBaseDecimal_triggered(); @@ -69,6 +73,10 @@ private: QAction actionXRefs; QAction actionDisplayOptions; + QAction actionDeleteComment; + QAction actionDeleteFlag; + QAction actionDeleteFunction; + QMenu *setBaseMenu; QAction *setBaseMenuAction; QAction actionSetBaseBinary; diff --git a/src/widgets/DisassemblyWidget.cpp b/src/widgets/DisassemblyWidget.cpp index e845ee7c..ba600104 100644 --- a/src/widgets/DisassemblyWidget.cpp +++ b/src/widgets/DisassemblyWidget.cpp @@ -82,6 +82,7 @@ DisassemblyWidget::DisassemblyWidget(QWidget *parent) 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(functionsChanged()), this, SLOT(refreshDisasm())); connect(Core(), SIGNAL(functionRenamed(QString, QString)), this, SLOT(refreshDisasm())); connect(Core(), SIGNAL(varsChanged()), this, SLOT(refreshDisasm())); connect(Core(), SIGNAL(asmOptionsChanged()), this, SLOT(refreshDisasm())); diff --git a/src/widgets/FunctionsWidget.cpp b/src/widgets/FunctionsWidget.cpp index 293adfa3..cc41a527 100644 --- a/src/widgets/FunctionsWidget.cpp +++ b/src/widgets/FunctionsWidget.cpp @@ -381,6 +381,7 @@ FunctionsWidget::FunctionsWidget(MainWindow *main, QWidget *parent) : connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(showTitleContextMenu(const QPoint &))); + connect(Core(), SIGNAL(functionsChanged()), this, SLOT(refreshTree())); connect(Core(), SIGNAL(refreshAll()), this, SLOT(refreshTree())); } diff --git a/src/widgets/VisualNavbar.cpp b/src/widgets/VisualNavbar.cpp index e3654718..48eec01a 100644 --- a/src/widgets/VisualNavbar.cpp +++ b/src/widgets/VisualNavbar.cpp @@ -40,6 +40,8 @@ VisualNavbar::VisualNavbar(MainWindow *main, QWidget *parent) : connect(Core(), SIGNAL(seekChanged(RVA)), this, SLOT(on_seekChanged(RVA))); 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); @@ -185,6 +187,25 @@ void VisualNavbar::fetchData() 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 functions = Core()->getAllFunctions(); for(auto function : functions) { diff --git a/src/widgets/VisualNavbar.h b/src/widgets/VisualNavbar.h index 9739a21c..4221b117 100644 --- a/src/widgets/VisualNavbar.h +++ b/src/widgets/VisualNavbar.h @@ -43,6 +43,8 @@ public slots: private slots: void fetchAndPaintData(); void fetchData(); + void updateMetadataAndPaint(); + void updateMetadata(); void fillData(); void drawCursor(); void on_seekChanged(RVA addr);