Fixed weird widget priority behaviour and fix #514

This commit is contained in:
xarkes 2018-07-01 13:47:15 +02:00
parent 1e721ff32e
commit 22465615a4
3 changed files with 25 additions and 7 deletions

View File

@ -166,11 +166,6 @@ QString CutterCore::cmd(const QString &str)
r_mem_free(res); r_mem_free(res);
if (offset != core_->offset) { if (offset != core_->offset) {
emit seekChanged(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; return o;
} }

View File

@ -10,6 +10,7 @@
#include <QTextDocument> #include <QTextDocument>
#include <QFileDialog> #include <QFileDialog>
#include <QFile> #include <QFile>
#include <QVBoxLayout>
#include "Cutter.h" #include "Cutter.h"
#include "utils/Colors.h" #include "utils/Colors.h"
@ -157,6 +158,23 @@ void DisassemblerGraphView::loadCurrentGraph()
disassembly_blocks.clear(); disassembly_blocks.clear();
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; Analysis anal;
anal.ready = true; anal.ready = true;
@ -168,7 +186,9 @@ void DisassemblerGraphView::loadCurrentGraph()
windowTitle = tr("Graph"); windowTitle = tr("Graph");
QString funcName = func["name"].toString().trimmed(); QString funcName = func["name"].toString().trimmed();
if (!funcName.isEmpty()) { if (emptyGraph) {
windowTitle += " (Empty)";
} else if (!funcName.isEmpty()) {
windowTitle += " (" + funcName + ")"; windowTitle += " (" + funcName + ")";
} }
if (!seekable->getSyncWithCore()) { if (!seekable->getSyncWithCore()) {
@ -262,7 +282,6 @@ void DisassemblerGraphView::loadCurrentGraph()
} }
} }
void DisassemblerGraphView::prepareGraphNode(GraphBlock &block) void DisassemblerGraphView::prepareGraphNode(GraphBlock &block)
{ {
DisassemblyBlock &db = disassembly_blocks[block.entry]; DisassemblyBlock &db = disassembly_blocks[block.entry];
@ -714,6 +733,7 @@ void DisassemblerGraphView::on_actionExportGraph_triggered()
QTextStream fileOut(&file); QTextStream fileOut(&file);
fileOut << Core()->cmd("ag -"); fileOut << Core()->cmd("ag -");
} }
void DisassemblerGraphView::wheelEvent(QWheelEvent *event) void DisassemblerGraphView::wheelEvent(QWheelEvent *event)
{ {
// when CTRL is pressed, we zoom in/out with mouse wheel // when CTRL is pressed, we zoom in/out with mouse wheel

View File

@ -6,6 +6,7 @@
#include <QWidget> #include <QWidget>
#include <QPainter> #include <QPainter>
#include <QShortcut> #include <QShortcut>
#include <QLabel>
#include "widgets/GraphView.h" #include "widgets/GraphView.h"
#include "menus/DisassemblyContextMenu.h" #include "menus/DisassemblyContextMenu.h"
@ -222,6 +223,8 @@ private:
QAction actionExportGraph; QAction actionExportGraph;
QAction actionSyncOffset; QAction actionSyncOffset;
QLabel *emptyText = nullptr;
}; };
#endif // DISASSEMBLERGRAPHVIEW_H #endif // DISASSEMBLERGRAPHVIEW_H