diff --git a/src/Cutter.cpp b/src/Cutter.cpp index 82d88ff4..66ca90f9 100644 --- a/src/Cutter.cpp +++ b/src/Cutter.cpp @@ -166,11 +166,6 @@ QString CutterCore::cmd(const QString &str) r_mem_free(res); if (offset != core_->offset) { emit seekChanged(core_->offset); - - // Switch from graph to disassembly if there is no function - if (this->cmd("afi.").trimmed().isEmpty() && memoryWidgetPriority == MemoryWidgetType::Graph) { - memoryWidgetPriority = MemoryWidgetType::Disassembly; - } } return o; } diff --git a/src/widgets/DisassemblerGraphView.cpp b/src/widgets/DisassemblerGraphView.cpp index 1087c155..b6feda15 100644 --- a/src/widgets/DisassemblerGraphView.cpp +++ b/src/widgets/DisassemblerGraphView.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include "Cutter.h" #include "utils/Colors.h" @@ -157,6 +158,23 @@ void DisassemblerGraphView::loadCurrentGraph() disassembly_blocks.clear(); blocks.clear(); + bool emptyGraph = functions.isEmpty(); + if (emptyGraph) { + // If there's no function to print, just move to disassembly and add a message + Core()->setMemoryWidgetPriority(CutterCore::MemoryWidgetType::Disassembly); + if (!emptyText) { + QVBoxLayout *layout = new QVBoxLayout(this); + emptyText = new QLabel(this); + emptyText->setText(tr("No function detected. Cannot display graph.")); + emptyText->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum); + layout->addWidget(emptyText); + layout->setAlignment(emptyText, Qt::AlignHCenter); + } + emptyText->setVisible(true); + } else { + emptyText->setVisible(false); + } + Analysis anal; anal.ready = true; @@ -168,7 +186,9 @@ void DisassemblerGraphView::loadCurrentGraph() windowTitle = tr("Graph"); QString funcName = func["name"].toString().trimmed(); - if (!funcName.isEmpty()) { + if (emptyGraph) { + windowTitle += " (Empty)"; + } else if (!funcName.isEmpty()) { windowTitle += " (" + funcName + ")"; } if (!seekable->getSyncWithCore()) { @@ -262,7 +282,6 @@ void DisassemblerGraphView::loadCurrentGraph() } } - void DisassemblerGraphView::prepareGraphNode(GraphBlock &block) { DisassemblyBlock &db = disassembly_blocks[block.entry]; @@ -714,6 +733,7 @@ void DisassemblerGraphView::on_actionExportGraph_triggered() QTextStream fileOut(&file); fileOut << Core()->cmd("ag -"); } + void DisassemblerGraphView::wheelEvent(QWheelEvent *event) { // when CTRL is pressed, we zoom in/out with mouse wheel diff --git a/src/widgets/DisassemblerGraphView.h b/src/widgets/DisassemblerGraphView.h index 04f0b497..ad1fca11 100644 --- a/src/widgets/DisassemblerGraphView.h +++ b/src/widgets/DisassemblerGraphView.h @@ -6,6 +6,7 @@ #include #include #include +#include #include "widgets/GraphView.h" #include "menus/DisassemblyContextMenu.h" @@ -222,6 +223,8 @@ private: QAction actionExportGraph; QAction actionSyncOffset; + + QLabel *emptyText = nullptr; }; #endif // DISASSEMBLERGRAPHVIEW_H