2019-03-23 11:23:05 +00:00
|
|
|
|
2017-10-09 09:38:57 +00:00
|
|
|
#include "DisassemblerGraphView.h"
|
2019-01-14 18:43:44 +00:00
|
|
|
#include "common/CutterSeekable.h"
|
2019-03-23 11:23:05 +00:00
|
|
|
#include "core/Cutter.h"
|
|
|
|
#include "common/Colors.h"
|
|
|
|
#include "common/Configuration.h"
|
|
|
|
#include "common/CachedFontMetrics.h"
|
|
|
|
#include "common/TempConfig.h"
|
|
|
|
#include "common/SyntaxHighlighter.h"
|
|
|
|
#include "common/BasicBlockHighlighter.h"
|
|
|
|
|
2019-05-23 16:22:31 +00:00
|
|
|
#include <QColorDialog>
|
2017-12-13 22:38:46 +00:00
|
|
|
#include <QPainter>
|
|
|
|
#include <QJsonObject>
|
|
|
|
#include <QJsonArray>
|
|
|
|
#include <QMouseEvent>
|
|
|
|
#include <QPropertyAnimation>
|
|
|
|
#include <QShortcut>
|
2017-12-19 16:59:39 +00:00
|
|
|
#include <QToolTip>
|
2018-02-01 14:15:16 +00:00
|
|
|
#include <QTextDocument>
|
2018-10-16 14:49:26 +00:00
|
|
|
#include <QTextEdit>
|
2018-02-14 09:33:34 +00:00
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QFile>
|
2018-07-01 11:47:15 +00:00
|
|
|
#include <QVBoxLayout>
|
2018-08-16 14:05:48 +00:00
|
|
|
#include <QRegularExpression>
|
2018-08-25 18:54:23 +00:00
|
|
|
#include <QStandardPaths>
|
2019-01-14 08:16:10 +00:00
|
|
|
#include <QClipboard>
|
|
|
|
#include <QApplication>
|
2017-10-09 09:38:57 +00:00
|
|
|
|
2019-03-23 11:23:05 +00:00
|
|
|
#include <cmath>
|
2017-10-09 09:38:57 +00:00
|
|
|
|
2019-07-19 19:21:12 +00:00
|
|
|
DisassemblerGraphView::DisassemblerGraphView(QWidget *parent, CutterSeekable* seekable, MainWindow* mainWindow)
|
2017-12-13 22:38:46 +00:00
|
|
|
: GraphView(parent),
|
|
|
|
mFontMetrics(nullptr),
|
2019-07-19 19:21:12 +00:00
|
|
|
blockMenu(new DisassemblyContextMenu(this, mainWindow)),
|
2019-04-18 10:10:18 +00:00
|
|
|
contextMenu(new QMenu(this)),
|
2019-06-18 13:02:41 +00:00
|
|
|
seekable(seekable)
|
2017-10-09 09:38:57 +00:00
|
|
|
{
|
2017-12-14 21:07:48 +00:00
|
|
|
highlight_token = nullptr;
|
2019-02-19 15:56:50 +00:00
|
|
|
auto *layout = new QVBoxLayout(this);
|
2017-12-13 22:38:46 +00:00
|
|
|
// Signals that require a refresh all
|
|
|
|
connect(Core(), SIGNAL(refreshAll()), this, SLOT(refreshView()));
|
|
|
|
connect(Core(), SIGNAL(commentsChanged()), this, SLOT(refreshView()));
|
2018-03-21 20:32:32 +00:00
|
|
|
connect(Core(), SIGNAL(functionRenamed(const QString &, const QString &)), this,
|
|
|
|
SLOT(refreshView()));
|
2017-12-13 22:38:46 +00:00
|
|
|
connect(Core(), SIGNAL(flagsChanged()), this, SLOT(refreshView()));
|
|
|
|
connect(Core(), SIGNAL(varsChanged()), this, SLOT(refreshView()));
|
|
|
|
connect(Core(), SIGNAL(instructionChanged(RVA)), this, SLOT(refreshView()));
|
2017-12-14 21:54:57 +00:00
|
|
|
connect(Core(), SIGNAL(functionsChanged()), this, SLOT(refreshView()));
|
2017-12-19 16:13:44 +00:00
|
|
|
connect(Core(), SIGNAL(graphOptionsChanged()), this, SLOT(refreshView()));
|
2018-01-31 09:17:06 +00:00
|
|
|
connect(Core(), SIGNAL(asmOptionsChanged()), this, SLOT(refreshView()));
|
2018-07-01 21:29:38 +00:00
|
|
|
connect(Core(), SIGNAL(refreshCodeViews()), this, SLOT(refreshView()));
|
2017-10-09 09:38:57 +00:00
|
|
|
|
2017-12-13 22:38:46 +00:00
|
|
|
connect(Config(), SIGNAL(colorsUpdated()), this, SLOT(colorsUpdatedSlot()));
|
|
|
|
connect(Config(), SIGNAL(fontsUpdated()), this, SLOT(fontsUpdatedSlot()));
|
2018-05-24 16:53:12 +00:00
|
|
|
connectSeekChanged(false);
|
2017-10-09 09:38:57 +00:00
|
|
|
|
2017-12-13 22:38:46 +00:00
|
|
|
// ESC for previous
|
|
|
|
QShortcut *shortcut_escape = new QShortcut(QKeySequence(Qt::Key_Escape), this);
|
|
|
|
shortcut_escape->setContext(Qt::WidgetShortcut);
|
2019-01-13 14:20:07 +00:00
|
|
|
connect(shortcut_escape, SIGNAL(activated()), seekable, SLOT(seekPrev()));
|
2017-10-09 09:38:57 +00:00
|
|
|
|
2017-12-13 22:57:36 +00:00
|
|
|
// Zoom shortcuts
|
2017-12-13 22:38:46 +00:00
|
|
|
QShortcut *shortcut_zoom_in = new QShortcut(QKeySequence(Qt::Key_Plus), this);
|
|
|
|
shortcut_zoom_in->setContext(Qt::WidgetShortcut);
|
2019-04-18 10:10:18 +00:00
|
|
|
connect(shortcut_zoom_in, &QShortcut::activated, this, std::bind(&DisassemblerGraphView::zoom, this,
|
|
|
|
QPointF(0.5, 0.5), 1));
|
2017-12-13 22:38:46 +00:00
|
|
|
QShortcut *shortcut_zoom_out = new QShortcut(QKeySequence(Qt::Key_Minus), this);
|
2017-12-13 22:57:36 +00:00
|
|
|
shortcut_zoom_out->setContext(Qt::WidgetShortcut);
|
2019-04-18 10:10:18 +00:00
|
|
|
connect(shortcut_zoom_out, &QShortcut::activated, this, std::bind(&DisassemblerGraphView::zoom,
|
|
|
|
this, QPointF(0.5, 0.5), -1));
|
2017-12-13 22:57:36 +00:00
|
|
|
QShortcut *shortcut_zoom_reset = new QShortcut(QKeySequence(Qt::Key_Equal), this);
|
|
|
|
shortcut_zoom_reset->setContext(Qt::WidgetShortcut);
|
|
|
|
connect(shortcut_zoom_reset, SIGNAL(activated()), this, SLOT(zoomReset()));
|
2017-10-09 09:38:57 +00:00
|
|
|
|
2017-12-13 22:57:36 +00:00
|
|
|
// Branch shortcuts
|
2017-12-13 22:38:46 +00:00
|
|
|
QShortcut *shortcut_take_true = new QShortcut(QKeySequence(Qt::Key_T), this);
|
|
|
|
shortcut_take_true->setContext(Qt::WidgetShortcut);
|
|
|
|
connect(shortcut_take_true, SIGNAL(activated()), this, SLOT(takeTrue()));
|
|
|
|
QShortcut *shortcut_take_false = new QShortcut(QKeySequence(Qt::Key_F), this);
|
|
|
|
shortcut_take_false->setContext(Qt::WidgetShortcut);
|
|
|
|
connect(shortcut_take_false, SIGNAL(activated()), this, SLOT(takeFalse()));
|
|
|
|
|
2017-12-14 21:07:48 +00:00
|
|
|
// Navigation shortcuts
|
|
|
|
QShortcut *shortcut_next_instr = new QShortcut(QKeySequence(Qt::Key_J), this);
|
|
|
|
shortcut_next_instr->setContext(Qt::WidgetShortcut);
|
|
|
|
connect(shortcut_next_instr, SIGNAL(activated()), this, SLOT(nextInstr()));
|
|
|
|
QShortcut *shortcut_prev_instr = new QShortcut(QKeySequence(Qt::Key_K), this);
|
|
|
|
shortcut_prev_instr->setContext(Qt::WidgetShortcut);
|
|
|
|
connect(shortcut_prev_instr, SIGNAL(activated()), this, SLOT(prevInstr()));
|
|
|
|
shortcuts.append(shortcut_escape);
|
|
|
|
shortcuts.append(shortcut_zoom_in);
|
|
|
|
shortcuts.append(shortcut_zoom_out);
|
|
|
|
shortcuts.append(shortcut_zoom_reset);
|
|
|
|
shortcuts.append(shortcut_next_instr);
|
|
|
|
shortcuts.append(shortcut_prev_instr);
|
|
|
|
|
2019-01-13 14:20:07 +00:00
|
|
|
// Export Graph menu
|
2018-02-14 09:33:34 +00:00
|
|
|
actionExportGraph.setText(tr("Export Graph"));
|
|
|
|
connect(&actionExportGraph, SIGNAL(triggered(bool)), this, SLOT(on_actionExportGraph_triggered()));
|
2018-05-25 14:30:59 +00:00
|
|
|
actionSyncOffset.setText(tr("Sync/unsync offset"));
|
2019-06-18 13:02:41 +00:00
|
|
|
connect(&actionSyncOffset, &QAction::triggered, seekable, &CutterSeekable::toggleSynchronization);
|
2019-04-18 10:10:18 +00:00
|
|
|
|
|
|
|
// Context menu that applies to everything
|
|
|
|
contextMenu->addAction(&actionExportGraph);
|
2019-08-03 13:10:44 +00:00
|
|
|
static const std::pair<QString, GraphView::Layout> LAYOUT_CONFIG[] = {
|
|
|
|
{tr("Grid narrow"), GraphView::Layout::GridNarrow}
|
|
|
|
,{tr("Grid medium"), GraphView::Layout::GridMedium}
|
|
|
|
,{tr("Grid wide"), GraphView::Layout::GridWide}
|
|
|
|
#ifdef CUTTER_ENABLE_GRAPHVIZ
|
|
|
|
,{tr("Graphviz polyline"), GraphView::Layout::GraphvizPolyline}
|
|
|
|
,{tr("Graphviz polyline LR"), GraphView::Layout::GraphvizPolylineLR}
|
|
|
|
,{tr("Graphviz ortho"), GraphView::Layout::GraphvizOrtho}
|
|
|
|
,{tr("Graphviz ortho LR"), GraphView::Layout::GraphvizOrthoLR}
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
auto layoutMenu = contextMenu->addMenu(tr("Layout"));
|
|
|
|
QActionGroup* layoutGroup = new QActionGroup(layoutMenu);
|
|
|
|
for (auto &item : LAYOUT_CONFIG) {
|
|
|
|
auto action = layoutGroup->addAction(item.first);
|
|
|
|
action->setCheckable(true);
|
|
|
|
GraphView::Layout layout = item.second;
|
|
|
|
connect(action, &QAction::triggered, this, [this, layout]() {
|
|
|
|
setGraphLayout(layout);
|
|
|
|
refreshView();
|
|
|
|
onSeekChanged(this->seekable->getOffset()); // try to keep the view on current block
|
|
|
|
});
|
|
|
|
if (layout == getGraphLayout()) {
|
|
|
|
action->setChecked(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
layoutMenu->addActions(layoutGroup->actions());
|
2019-04-18 10:10:18 +00:00
|
|
|
contextMenu->addSeparator();
|
|
|
|
contextMenu->addAction(&actionSyncOffset);
|
|
|
|
|
2019-05-23 16:22:31 +00:00
|
|
|
|
|
|
|
QAction *highlightBB = new QAction(this);
|
|
|
|
actionUnhighlight.setVisible(false);
|
|
|
|
|
|
|
|
highlightBB->setText(tr("Highlight block"));
|
|
|
|
connect(highlightBB, &QAction::triggered, this, [this]() {
|
|
|
|
auto bbh = Core()->getBBHighlighter();
|
|
|
|
RVA currBlockEntry = blockForAddress(this->seekable->getOffset())->entry;
|
|
|
|
|
|
|
|
QColor background = disassemblyBackgroundColor;
|
|
|
|
if (auto block = bbh->getBasicBlock(currBlockEntry)) {
|
|
|
|
background = block->color;
|
|
|
|
}
|
|
|
|
|
|
|
|
QColor c = QColorDialog::getColor(background, this, QString(),
|
|
|
|
QColorDialog::DontUseNativeDialog);
|
|
|
|
if (c.isValid()) {
|
|
|
|
bbh->highlight(currBlockEntry, c);
|
|
|
|
}
|
|
|
|
Config()->colorsUpdated();
|
|
|
|
});
|
|
|
|
|
|
|
|
actionUnhighlight.setText(tr("Unhighlight block"));
|
|
|
|
connect(&actionUnhighlight, &QAction::triggered, this, [this]() {
|
|
|
|
auto bbh = Core()->getBBHighlighter();
|
|
|
|
bbh->clear(blockForAddress(this->seekable->getOffset())->entry);
|
|
|
|
Config()->colorsUpdated();
|
|
|
|
});
|
|
|
|
|
|
|
|
blockMenu->addAction(highlightBB);
|
|
|
|
blockMenu->addAction(&actionUnhighlight);
|
|
|
|
|
|
|
|
|
2019-04-18 10:10:18 +00:00
|
|
|
// Include all actions from generic context menu in block specific menu
|
|
|
|
blockMenu->addSeparator();
|
|
|
|
blockMenu->addActions(contextMenu->actions());
|
|
|
|
|
|
|
|
|
2017-12-13 22:38:46 +00:00
|
|
|
initFont();
|
|
|
|
colorsUpdatedSlot();
|
2018-10-16 14:49:26 +00:00
|
|
|
|
2019-04-18 10:10:18 +00:00
|
|
|
connect(blockMenu, &DisassemblyContextMenu::copy, this, &DisassemblerGraphView::copySelection);
|
2019-01-14 08:16:10 +00:00
|
|
|
|
2019-02-13 07:37:05 +00:00
|
|
|
// Add header as widget to layout so it stretches to the layout width
|
2019-02-19 15:56:50 +00:00
|
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
|
|
|
layout->setAlignment(Qt::AlignTop);
|
2019-07-30 18:35:00 +00:00
|
|
|
|
|
|
|
this->scale_thickness_multiplier = true;
|
2017-10-09 09:38:57 +00:00
|
|
|
}
|
|
|
|
|
2018-05-25 14:30:59 +00:00
|
|
|
void DisassemblerGraphView::connectSeekChanged(bool disconn)
|
2018-05-24 16:53:12 +00:00
|
|
|
{
|
2018-05-25 14:30:59 +00:00
|
|
|
if (disconn) {
|
2019-01-13 14:20:07 +00:00
|
|
|
disconnect(seekable, &CutterSeekable::seekableSeekChanged, this,
|
2018-09-30 20:00:53 +00:00
|
|
|
&DisassemblerGraphView::onSeekChanged);
|
2018-05-24 16:53:12 +00:00
|
|
|
} else {
|
2019-02-06 13:42:03 +00:00
|
|
|
connect(seekable, &CutterSeekable::seekableSeekChanged, this,
|
|
|
|
&DisassemblerGraphView::onSeekChanged);
|
2018-05-24 16:53:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-14 21:07:48 +00:00
|
|
|
DisassemblerGraphView::~DisassemblerGraphView()
|
|
|
|
{
|
2018-03-21 20:32:32 +00:00
|
|
|
for (QShortcut *shortcut : shortcuts) {
|
2017-12-14 21:07:48 +00:00
|
|
|
delete shortcut;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-13 22:38:46 +00:00
|
|
|
void DisassemblerGraphView::refreshView()
|
2017-10-09 09:38:57 +00:00
|
|
|
{
|
2017-12-13 22:38:46 +00:00
|
|
|
initFont();
|
2017-10-09 09:38:57 +00:00
|
|
|
loadCurrentGraph();
|
2017-12-14 21:07:48 +00:00
|
|
|
viewport()->update();
|
2019-01-24 17:13:04 +00:00
|
|
|
emit viewRefreshed();
|
2017-10-09 09:38:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DisassemblerGraphView::loadCurrentGraph()
|
|
|
|
{
|
2018-02-01 14:15:16 +00:00
|
|
|
TempConfig tempConfig;
|
2019-02-14 21:47:39 +00:00
|
|
|
tempConfig.set("scr.color", COLOR_MODE_16M)
|
2019-03-26 19:40:41 +00:00
|
|
|
.set("asm.bb.line", false)
|
2018-03-21 20:32:32 +00:00
|
|
|
.set("asm.lines", false)
|
2018-05-24 06:21:12 +00:00
|
|
|
.set("asm.lines.fcn", false);
|
2018-12-24 12:22:46 +00:00
|
|
|
|
|
|
|
QJsonArray functions;
|
|
|
|
RAnalFunction *fcn = Core()->functionAt(seekable->getOffset());
|
|
|
|
if (fcn) {
|
2019-03-12 07:37:10 +00:00
|
|
|
currentFcnAddr = fcn->addr;
|
2018-12-24 12:22:46 +00:00
|
|
|
QJsonDocument functionsDoc = Core()->cmdj("agJ " + RAddressString(fcn->addr));
|
|
|
|
functions = functionsDoc.array();
|
|
|
|
}
|
2017-10-09 09:38:57 +00:00
|
|
|
|
2017-12-13 22:38:46 +00:00
|
|
|
disassembly_blocks.clear();
|
2017-12-14 21:07:48 +00:00
|
|
|
blocks.clear();
|
2017-12-13 22:38:46 +00:00
|
|
|
|
2018-08-16 14:05:48 +00:00
|
|
|
if (highlight_token) {
|
|
|
|
delete highlight_token;
|
|
|
|
highlight_token = nullptr;
|
|
|
|
}
|
|
|
|
|
2019-04-14 12:18:24 +00:00
|
|
|
emptyGraph = functions.isEmpty();
|
2018-07-01 11:47:15 +00:00
|
|
|
if (emptyGraph) {
|
2018-09-30 17:46:36 +00:00
|
|
|
// If there's no function to print, just add a message
|
2018-07-01 11:47:15 +00:00
|
|
|
if (!emptyText) {
|
|
|
|
emptyText = new QLabel(this);
|
|
|
|
emptyText->setText(tr("No function detected. Cannot display graph."));
|
|
|
|
emptyText->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
|
2019-02-19 15:56:50 +00:00
|
|
|
layout()->addWidget(emptyText);
|
|
|
|
layout()->setAlignment(emptyText, Qt::AlignHCenter);
|
2018-07-01 11:47:15 +00:00
|
|
|
}
|
|
|
|
emptyText->setVisible(true);
|
2018-07-24 07:02:35 +00:00
|
|
|
} else if (emptyText) {
|
2018-07-01 11:47:15 +00:00
|
|
|
emptyText->setVisible(false);
|
|
|
|
}
|
2018-09-30 17:46:36 +00:00
|
|
|
// Refresh global "empty graph" variable so other widget know there is nothing to show here
|
|
|
|
Core()->setGraphEmpty(emptyGraph);
|
2018-07-01 11:47:15 +00:00
|
|
|
|
2017-10-09 09:38:57 +00:00
|
|
|
QJsonValue funcRef = functions.first();
|
|
|
|
QJsonObject func = funcRef.toObject();
|
2017-11-21 17:48:01 +00:00
|
|
|
|
2018-05-25 14:30:59 +00:00
|
|
|
windowTitle = tr("Graph");
|
2017-11-21 17:48:01 +00:00
|
|
|
QString funcName = func["name"].toString().trimmed();
|
2018-07-01 11:47:15 +00:00
|
|
|
if (emptyGraph) {
|
|
|
|
windowTitle += " (Empty)";
|
|
|
|
} else if (!funcName.isEmpty()) {
|
2017-11-21 17:48:01 +00:00
|
|
|
windowTitle += " (" + funcName + ")";
|
|
|
|
}
|
2019-06-18 13:02:41 +00:00
|
|
|
emit nameChanged(windowTitle);
|
2017-10-09 09:38:57 +00:00
|
|
|
|
2017-12-13 22:38:46 +00:00
|
|
|
RVA entry = func["offset"].toVariant().toULongLong();
|
|
|
|
|
|
|
|
setEntry(entry);
|
2019-01-13 14:40:37 +00:00
|
|
|
for (const QJsonValueRef &value : func["blocks"].toArray()) {
|
2018-11-26 22:34:34 +00:00
|
|
|
QJsonObject block = value.toObject();
|
2017-12-13 22:38:46 +00:00
|
|
|
RVA block_entry = block["offset"].toVariant().toULongLong();
|
2018-02-01 14:15:16 +00:00
|
|
|
RVA block_size = block["size"].toVariant().toULongLong();
|
2017-12-13 22:38:46 +00:00
|
|
|
RVA block_fail = block["fail"].toVariant().toULongLong();
|
|
|
|
RVA block_jump = block["jump"].toVariant().toULongLong();
|
2017-10-09 09:38:57 +00:00
|
|
|
|
2017-12-13 22:38:46 +00:00
|
|
|
DisassemblyBlock db;
|
|
|
|
GraphBlock gb;
|
|
|
|
gb.entry = block_entry;
|
|
|
|
db.entry = block_entry;
|
|
|
|
db.true_path = RVA_INVALID;
|
|
|
|
db.false_path = RVA_INVALID;
|
2018-03-21 20:32:32 +00:00
|
|
|
if (block_fail) {
|
2017-12-13 22:38:46 +00:00
|
|
|
db.false_path = block_fail;
|
2019-04-07 11:34:53 +00:00
|
|
|
gb.edges.emplace_back(block_fail);
|
2017-10-09 09:38:57 +00:00
|
|
|
}
|
2018-03-21 20:32:32 +00:00
|
|
|
if (block_jump) {
|
|
|
|
if (block_fail) {
|
2017-12-13 22:38:46 +00:00
|
|
|
db.true_path = block_jump;
|
2017-10-12 12:14:33 +00:00
|
|
|
}
|
2019-04-07 11:34:53 +00:00
|
|
|
gb.edges.emplace_back(block_jump);
|
2017-10-09 09:38:57 +00:00
|
|
|
}
|
2018-09-20 11:27:24 +00:00
|
|
|
|
|
|
|
QJsonObject switchOp = block["switchop"].toObject();
|
|
|
|
if (!switchOp.isEmpty()) {
|
|
|
|
QJsonArray caseArray = switchOp["cases"].toArray();
|
|
|
|
for (QJsonValue caseOpValue : caseArray) {
|
|
|
|
QJsonObject caseOp = caseOpValue.toObject();
|
|
|
|
bool ok;
|
|
|
|
RVA caseJump = caseOp["jump"].toVariant().toULongLong(&ok);
|
|
|
|
if (!ok) {
|
|
|
|
continue;
|
|
|
|
}
|
2019-04-07 11:34:53 +00:00
|
|
|
gb.edges.emplace_back(caseJump);
|
2018-09-20 11:27:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-01 14:15:16 +00:00
|
|
|
QJsonArray opArray = block["ops"].toArray();
|
2018-03-21 20:32:32 +00:00
|
|
|
for (int opIndex = 0; opIndex < opArray.size(); opIndex++) {
|
2018-02-01 14:15:16 +00:00
|
|
|
QJsonObject op = opArray[opIndex].toObject();
|
2017-10-09 09:38:57 +00:00
|
|
|
Instr i;
|
2017-12-07 23:37:48 +00:00
|
|
|
i.addr = op["offset"].toVariant().toULongLong();
|
2018-01-31 09:17:06 +00:00
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
if (opIndex < opArray.size() - 1) {
|
2018-02-01 14:15:16 +00:00
|
|
|
// get instruction size from distance to next instruction ...
|
2018-03-21 20:32:32 +00:00
|
|
|
RVA nextOffset = opArray[opIndex + 1].toObject()["offset"].toVariant().toULongLong();
|
2018-02-01 14:15:16 +00:00
|
|
|
i.size = nextOffset - i.addr;
|
2018-03-21 20:32:32 +00:00
|
|
|
} else {
|
2018-02-01 14:15:16 +00:00
|
|
|
// or to the end of the block.
|
|
|
|
i.size = (block_entry + block_size) - i.addr;
|
2017-10-14 11:00:23 +00:00
|
|
|
}
|
2018-01-31 09:17:06 +00:00
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
QTextDocument textDoc;
|
2019-02-15 12:33:23 +00:00
|
|
|
textDoc.setHtml(CutterCore::ansiEscapeToHtml(op["text"].toString()));
|
2019-02-14 21:47:39 +00:00
|
|
|
|
2018-08-16 14:05:48 +00:00
|
|
|
i.plainText = textDoc.toPlainText();
|
2018-01-31 09:17:06 +00:00
|
|
|
|
2018-02-01 14:51:03 +00:00
|
|
|
RichTextPainter::List richText = RichTextPainter::fromTextDocument(textDoc);
|
|
|
|
//Colors::colorizeAssembly(richText, textDoc.toPlainText(), 0);
|
2018-01-31 09:17:06 +00:00
|
|
|
|
2017-12-19 16:59:39 +00:00
|
|
|
bool cropped;
|
2018-03-21 20:32:32 +00:00
|
|
|
int blockLength = Config()->getGraphBlockMaxChars() + Core()->getConfigb("asm.bytes") * 24 +
|
|
|
|
Core()->getConfigb("asm.emu") * 10;
|
2018-01-31 09:59:01 +00:00
|
|
|
i.text = Text(RichTextPainter::cropped(richText, blockLength, "...", &cropped));
|
2018-03-21 20:32:32 +00:00
|
|
|
if (cropped)
|
2017-12-19 16:59:39 +00:00
|
|
|
i.fullText = richText;
|
|
|
|
else
|
|
|
|
i.fullText = Text();
|
2017-12-13 22:38:46 +00:00
|
|
|
db.instrs.push_back(i);
|
2017-10-09 09:38:57 +00:00
|
|
|
}
|
2017-12-13 22:38:46 +00:00
|
|
|
disassembly_blocks[db.entry] = db;
|
|
|
|
prepareGraphNode(gb);
|
|
|
|
|
|
|
|
addBlock(gb);
|
2017-10-09 09:38:57 +00:00
|
|
|
}
|
2019-05-23 10:52:56 +00:00
|
|
|
cleanupEdges();
|
2017-12-13 22:38:46 +00:00
|
|
|
|
2019-01-13 14:40:37 +00:00
|
|
|
if (!func["blocks"].toArray().isEmpty()) {
|
2017-12-13 22:38:46 +00:00
|
|
|
computeGraph(entry);
|
|
|
|
}
|
|
|
|
}
|
2017-10-09 09:38:57 +00:00
|
|
|
|
2019-04-04 05:54:42 +00:00
|
|
|
DisassemblerGraphView::EdgeConfigurationMapping DisassemblerGraphView::getEdgeConfigurations()
|
|
|
|
{
|
|
|
|
EdgeConfigurationMapping result;
|
|
|
|
for (auto &block : blocks) {
|
|
|
|
for (const auto &edge : block.second.edges) {
|
|
|
|
result[ {block.first, edge.target}] = edgeConfiguration(block.second, &blocks[edge.target]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-12-13 22:38:46 +00:00
|
|
|
void DisassemblerGraphView::prepareGraphNode(GraphBlock &block)
|
2017-10-09 09:38:57 +00:00
|
|
|
{
|
2017-12-13 22:38:46 +00:00
|
|
|
DisassemblyBlock &db = disassembly_blocks[block.entry];
|
|
|
|
int width = 0;
|
|
|
|
int height = 0;
|
2018-03-21 20:32:32 +00:00
|
|
|
for (auto &line : db.header_text.lines) {
|
2017-12-13 22:38:46 +00:00
|
|
|
int lw = 0;
|
2018-03-21 20:32:32 +00:00
|
|
|
for (auto &part : line)
|
2017-12-13 22:38:46 +00:00
|
|
|
lw += mFontMetrics->width(part.text);
|
2018-03-21 20:32:32 +00:00
|
|
|
if (lw > width)
|
2017-12-13 22:38:46 +00:00
|
|
|
width = lw;
|
|
|
|
height += 1;
|
|
|
|
}
|
2018-03-21 20:32:32 +00:00
|
|
|
for (Instr &instr : db.instrs) {
|
|
|
|
for (auto &line : instr.text.lines) {
|
2017-12-13 22:38:46 +00:00
|
|
|
int lw = 0;
|
2018-03-21 20:32:32 +00:00
|
|
|
for (auto &part : line)
|
2017-12-13 22:38:46 +00:00
|
|
|
lw += mFontMetrics->width(part.text);
|
2018-03-21 20:32:32 +00:00
|
|
|
if (lw > width)
|
2017-12-13 22:38:46 +00:00
|
|
|
width = lw;
|
|
|
|
height += 1;
|
2017-10-09 09:38:57 +00:00
|
|
|
}
|
|
|
|
}
|
2019-01-13 14:40:37 +00:00
|
|
|
int extra = static_cast<int>(4 * charWidth + 4);
|
|
|
|
block.width = static_cast<int>(width + extra + charWidth);
|
2017-12-14 21:07:48 +00:00
|
|
|
block.height = (height * charHeight) + extra;
|
2017-10-09 09:38:57 +00:00
|
|
|
}
|
|
|
|
|
2019-05-23 10:52:56 +00:00
|
|
|
void DisassemblerGraphView::cleanupEdges()
|
|
|
|
{
|
|
|
|
for (auto &blockIt : blocks) {
|
|
|
|
auto &block = blockIt.second;
|
|
|
|
auto outIt = block.edges.begin();
|
|
|
|
std::unordered_set<ut64> seenEdges;
|
|
|
|
for (auto it = block.edges.begin(), end = block.edges.end(); it != end; ++it) {
|
|
|
|
// remove edges going to different functions
|
|
|
|
// and remove duplicate edges, common in switch statements
|
|
|
|
if (blocks.find(it->target) != blocks.end() &&
|
|
|
|
seenEdges.find(it->target) == seenEdges.end()) {
|
|
|
|
*outIt++ = *it;
|
|
|
|
seenEdges.insert(it->target);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
block.edges.erase(outIt, block.edges.end());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-13 22:38:46 +00:00
|
|
|
void DisassemblerGraphView::initFont()
|
2017-11-05 15:08:17 +00:00
|
|
|
{
|
2017-12-13 22:38:46 +00:00
|
|
|
setFont(Config()->getFont());
|
2017-12-14 21:07:48 +00:00
|
|
|
QFontMetricsF metrics(font());
|
|
|
|
baseline = int(metrics.ascent());
|
|
|
|
charWidth = metrics.width('X');
|
2019-01-13 14:40:37 +00:00
|
|
|
charHeight = static_cast<int>(metrics.height());
|
2017-12-14 21:07:48 +00:00
|
|
|
charOffset = 0;
|
2019-05-17 11:00:54 +00:00
|
|
|
mFontMetrics.reset(new CachedFontMetrics<qreal>(font()));
|
2017-11-05 15:08:17 +00:00
|
|
|
}
|
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
void DisassemblerGraphView::drawBlock(QPainter &p, GraphView::GraphBlock &block)
|
2017-10-09 09:38:57 +00:00
|
|
|
{
|
2019-04-14 12:18:24 +00:00
|
|
|
int blockX = block.x - getViewOffset().x();
|
|
|
|
int blockY = block.y - getViewOffset().y();
|
2019-02-16 17:17:11 +00:00
|
|
|
|
2019-05-19 10:27:15 +00:00
|
|
|
const qreal padding = 2 * charWidth;
|
|
|
|
|
2017-12-13 22:38:46 +00:00
|
|
|
p.setPen(Qt::black);
|
|
|
|
p.setBrush(Qt::gray);
|
2019-03-14 09:42:42 +00:00
|
|
|
p.setFont(Config()->getFont());
|
2019-02-16 17:17:11 +00:00
|
|
|
p.drawRect(blockX, blockY, block.width, block.height);
|
2017-10-09 09:38:57 +00:00
|
|
|
|
2018-08-12 16:20:16 +00:00
|
|
|
breakpoints = Core()->getBreakpointsAddresses();
|
2017-10-09 09:38:57 +00:00
|
|
|
|
2017-12-13 22:38:46 +00:00
|
|
|
// Render node
|
|
|
|
DisassemblyBlock &db = disassembly_blocks[block.entry];
|
|
|
|
bool block_selected = false;
|
2018-06-22 15:57:15 +00:00
|
|
|
bool PCInBlock = false;
|
2017-12-13 22:38:46 +00:00
|
|
|
RVA selected_instruction = RVA_INVALID;
|
2017-10-09 09:38:57 +00:00
|
|
|
|
2017-12-13 22:38:46 +00:00
|
|
|
// Figure out if the current block is selected
|
2018-06-22 15:57:15 +00:00
|
|
|
RVA addr = seekable->getOffset();
|
|
|
|
RVA PCAddr = Core()->getProgramCounterValue();
|
2018-03-21 20:32:32 +00:00
|
|
|
for (const Instr &instr : db.instrs) {
|
2019-05-19 10:27:15 +00:00
|
|
|
if (instr.contains(addr)) {
|
2017-12-13 22:38:46 +00:00
|
|
|
block_selected = true;
|
|
|
|
selected_instruction = instr.addr;
|
|
|
|
}
|
2019-05-19 10:27:15 +00:00
|
|
|
if (instr.contains(PCAddr)) {
|
2018-06-22 15:57:15 +00:00
|
|
|
PCInBlock = true;
|
|
|
|
}
|
2018-08-12 16:20:16 +00:00
|
|
|
|
2017-12-13 22:38:46 +00:00
|
|
|
// TODO: L219
|
|
|
|
}
|
2017-10-16 19:00:47 +00:00
|
|
|
|
2017-12-13 22:38:46 +00:00
|
|
|
p.setPen(QColor(0, 0, 0, 0));
|
2018-03-21 20:32:32 +00:00
|
|
|
if (db.terminal) {
|
2017-12-13 22:38:46 +00:00
|
|
|
p.setBrush(retShadowColor);
|
2018-03-21 20:32:32 +00:00
|
|
|
} else if (db.indirectcall) {
|
2017-12-13 22:38:46 +00:00
|
|
|
p.setBrush(indirectcallShadowColor);
|
|
|
|
} else {
|
2018-08-12 16:20:16 +00:00
|
|
|
p.setBrush(QColor(0, 0, 0, 100));
|
2017-12-13 22:38:46 +00:00
|
|
|
}
|
|
|
|
|
2018-08-12 16:20:16 +00:00
|
|
|
p.setPen(QPen(graphNodeColor, 1));
|
2017-12-13 22:38:46 +00:00
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
if (block_selected) {
|
2017-12-13 22:38:46 +00:00
|
|
|
p.setBrush(disassemblySelectedBackgroundColor);
|
|
|
|
} else {
|
|
|
|
p.setBrush(disassemblyBackgroundColor);
|
|
|
|
}
|
|
|
|
|
2019-02-19 18:56:59 +00:00
|
|
|
// Draw basic block background
|
2019-02-16 17:17:11 +00:00
|
|
|
p.drawRect(blockX, blockY,
|
2017-12-13 22:38:46 +00:00
|
|
|
block.width, block.height);
|
2019-02-19 18:56:59 +00:00
|
|
|
auto bb = Core()->getBBHighlighter()->getBasicBlock(block.entry);
|
|
|
|
if (bb) {
|
|
|
|
QColor color(bb->color);
|
|
|
|
p.setBrush(color);
|
|
|
|
p.drawRect(blockX, blockY,
|
|
|
|
block.width, block.height);
|
|
|
|
}
|
2017-12-13 22:38:46 +00:00
|
|
|
|
2019-05-19 10:27:15 +00:00
|
|
|
const int firstInstructionY = blockY + getInstructionOffset(db, 0).y();
|
|
|
|
|
2017-12-13 22:38:46 +00:00
|
|
|
// Draw different background for selected instruction
|
2018-03-21 20:32:32 +00:00
|
|
|
if (selected_instruction != RVA_INVALID) {
|
2019-05-19 10:27:15 +00:00
|
|
|
int y = firstInstructionY;
|
2018-11-26 22:34:34 +00:00
|
|
|
for (const Instr &instr : db.instrs) {
|
2018-07-18 10:15:10 +00:00
|
|
|
if (instr.addr > selected_instruction) {
|
|
|
|
break;
|
|
|
|
}
|
2017-12-13 22:38:46 +00:00
|
|
|
auto selected = instr.addr == selected_instruction;
|
2019-02-19 18:56:59 +00:00
|
|
|
if (selected) {
|
2019-02-16 17:17:11 +00:00
|
|
|
p.fillRect(QRect(static_cast<int>(blockX + charWidth), y,
|
2019-05-19 10:27:15 +00:00
|
|
|
static_cast<int>(block.width - (10 + padding)),
|
2017-12-14 21:07:48 +00:00
|
|
|
int(instr.text.lines.size()) * charHeight), disassemblySelectionColor);
|
2017-12-13 22:38:46 +00:00
|
|
|
}
|
2017-12-14 21:07:48 +00:00
|
|
|
y += int(instr.text.lines.size()) * charHeight;
|
2017-12-13 22:38:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-19 18:56:59 +00:00
|
|
|
// Highlight selected tokens
|
2018-08-16 14:05:48 +00:00
|
|
|
if (highlight_token != nullptr) {
|
2019-05-19 10:27:15 +00:00
|
|
|
int y = firstInstructionY;
|
2019-05-17 11:00:54 +00:00
|
|
|
qreal tokenWidth = mFontMetrics->width(highlight_token->content);
|
2018-08-16 14:05:48 +00:00
|
|
|
|
2018-11-26 22:34:34 +00:00
|
|
|
for (const Instr &instr : db.instrs) {
|
2018-08-16 14:05:48 +00:00
|
|
|
int pos = -1;
|
|
|
|
|
|
|
|
while ((pos = instr.plainText.indexOf(highlight_token->content, pos + 1)) != -1) {
|
|
|
|
int tokenEnd = pos + highlight_token->content.length();
|
|
|
|
|
2018-09-07 22:32:30 +00:00
|
|
|
if ((pos > 0 && instr.plainText[pos - 1].isLetterOrNumber())
|
2018-09-30 20:00:53 +00:00
|
|
|
|| (tokenEnd < instr.plainText.length() && instr.plainText[tokenEnd].isLetterOrNumber())) {
|
2018-08-16 14:05:48 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-05-17 11:00:54 +00:00
|
|
|
qreal widthBefore = mFontMetrics->width(instr.plainText.left(pos));
|
2019-05-19 10:27:15 +00:00
|
|
|
if (charWidth * 3 + widthBefore > block.width - (10 + padding)) {
|
2018-10-27 16:36:14 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-05-17 11:00:54 +00:00
|
|
|
qreal highlightWidth = tokenWidth;
|
2019-05-19 10:27:15 +00:00
|
|
|
if (charWidth * 3 + widthBefore + tokenWidth >= block.width - (10 + padding)) {
|
|
|
|
highlightWidth = block.width - widthBefore - (10 + 2 * padding);
|
2018-10-27 16:36:14 +00:00
|
|
|
}
|
|
|
|
|
2019-05-23 16:22:31 +00:00
|
|
|
QColor selectionColor = ConfigColor("wordHighlight");
|
2018-12-03 11:45:49 +00:00
|
|
|
|
2019-05-17 11:00:54 +00:00
|
|
|
p.fillRect(QRectF(blockX + charWidth * 3 + widthBefore, y, highlightWidth,
|
2018-12-03 11:45:49 +00:00
|
|
|
charHeight), selectionColor);
|
2018-08-16 14:05:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
y += int(instr.text.lines.size()) * charHeight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-19 18:56:59 +00:00
|
|
|
// Highlight program counter
|
2018-06-22 15:57:15 +00:00
|
|
|
if (PCInBlock) {
|
2019-05-19 10:27:15 +00:00
|
|
|
int y = firstInstructionY;
|
2018-11-26 22:34:34 +00:00
|
|
|
for (const Instr &instr : db.instrs) {
|
2018-07-18 10:15:10 +00:00
|
|
|
if (instr.addr > PCAddr) {
|
|
|
|
break;
|
|
|
|
}
|
2018-06-22 15:57:15 +00:00
|
|
|
auto PC = instr.addr == PCAddr;
|
|
|
|
if (PC) {
|
2019-02-16 17:17:11 +00:00
|
|
|
p.fillRect(QRect(static_cast<int>(blockX + charWidth), y,
|
2019-05-19 10:27:15 +00:00
|
|
|
static_cast<int>(block.width - (10 + padding)),
|
2018-06-22 15:57:15 +00:00
|
|
|
int(instr.text.lines.size()) * charHeight), PCSelectionColor);
|
|
|
|
}
|
|
|
|
y += int(instr.text.lines.size()) * charHeight;
|
|
|
|
}
|
|
|
|
}
|
2017-12-13 22:38:46 +00:00
|
|
|
|
2019-02-06 13:42:03 +00:00
|
|
|
qreal render_height = viewport()->size().height();
|
|
|
|
|
2019-04-21 16:30:57 +00:00
|
|
|
// Stop rendering text when it's too small
|
|
|
|
if (charHeight * getViewScale() * p.device()->devicePixelRatioF() < 4) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-13 22:38:46 +00:00
|
|
|
// Render node text
|
2019-05-19 10:27:15 +00:00
|
|
|
auto x = blockX + padding;
|
|
|
|
int y = blockY + getTextOffset(0).y();
|
2019-02-16 17:17:11 +00:00
|
|
|
qreal lineHeightRender = charHeight;
|
2018-03-21 20:32:32 +00:00
|
|
|
for (auto &line : db.header_text.lines) {
|
2019-02-16 17:17:11 +00:00
|
|
|
qreal lineYRender = y;
|
2019-04-14 12:18:24 +00:00
|
|
|
lineYRender *= getViewScale();
|
2019-02-06 13:42:03 +00:00
|
|
|
// Check if line does NOT intersects with view area
|
2019-02-16 17:17:11 +00:00
|
|
|
if (0 > lineYRender + lineHeightRender
|
|
|
|
|| render_height < lineYRender) {
|
2019-02-06 13:42:03 +00:00
|
|
|
y += charHeight;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-05-17 11:00:54 +00:00
|
|
|
RichTextPainter::paintRichText<qreal>(&p, x, y, block.width, charHeight, 0, line,
|
|
|
|
mFontMetrics.get());
|
2017-12-14 21:07:48 +00:00
|
|
|
y += charHeight;
|
2017-12-13 22:38:46 +00:00
|
|
|
}
|
2019-02-06 13:42:03 +00:00
|
|
|
|
2018-11-26 22:34:34 +00:00
|
|
|
for (const Instr &instr : db.instrs) {
|
2018-08-12 16:20:16 +00:00
|
|
|
if (Core()->isBreakpoint(breakpoints, instr.addr)) {
|
2019-02-16 17:17:11 +00:00
|
|
|
p.fillRect(QRect(static_cast<int>(blockX + charWidth), y,
|
2019-05-19 10:27:15 +00:00
|
|
|
static_cast<int>(block.width - (10 + padding)),
|
2018-08-12 16:20:16 +00:00
|
|
|
int(instr.text.lines.size()) * charHeight), ConfigColor("gui.breakpoint_background"));
|
|
|
|
if (instr.addr == selected_instruction) {
|
2019-02-16 17:17:11 +00:00
|
|
|
p.fillRect(QRect(static_cast<int>(blockX + charWidth), y,
|
2019-05-19 10:27:15 +00:00
|
|
|
static_cast<int>(block.width - (10 + padding)),
|
2018-08-12 16:20:16 +00:00
|
|
|
int(instr.text.lines.size()) * charHeight), disassemblySelectionColor);
|
|
|
|
}
|
|
|
|
}
|
2018-03-21 20:32:32 +00:00
|
|
|
for (auto &line : instr.text.lines) {
|
2019-02-16 17:17:11 +00:00
|
|
|
qreal lineYRender = y;
|
2019-04-14 12:18:24 +00:00
|
|
|
lineYRender *= getViewScale();
|
2019-02-16 17:17:11 +00:00
|
|
|
if (0 > lineYRender + lineHeightRender
|
|
|
|
|| render_height < lineYRender) {
|
2019-02-06 13:42:03 +00:00
|
|
|
y += charHeight;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-12-14 21:07:48 +00:00
|
|
|
int rectSize = qRound(charWidth);
|
2018-03-21 20:32:32 +00:00
|
|
|
if (rectSize % 2) {
|
2017-12-13 22:38:46 +00:00
|
|
|
rectSize++;
|
|
|
|
}
|
|
|
|
// Assume charWidth <= charHeight
|
|
|
|
// TODO: Breakpoint/Cip stuff
|
2019-01-13 14:40:37 +00:00
|
|
|
QRectF bpRect(x - rectSize / 3.0, y + (charHeight - rectSize) / 2.0, rectSize, rectSize);
|
|
|
|
Q_UNUSED(bpRect);
|
2017-12-13 22:38:46 +00:00
|
|
|
|
2019-05-17 11:00:54 +00:00
|
|
|
RichTextPainter::paintRichText<qreal>(&p, x + charWidth, y,
|
|
|
|
block.width - charWidth, charHeight, 0, line,
|
|
|
|
mFontMetrics.get());
|
2017-12-14 21:07:48 +00:00
|
|
|
y += charHeight;
|
2017-12-13 22:38:46 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2017-10-09 09:38:57 +00:00
|
|
|
}
|
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
GraphView::EdgeConfiguration DisassemblerGraphView::edgeConfiguration(GraphView::GraphBlock &from,
|
|
|
|
GraphView::GraphBlock *to)
|
2017-10-09 09:38:57 +00:00
|
|
|
{
|
2017-12-13 22:38:46 +00:00
|
|
|
EdgeConfiguration ec;
|
|
|
|
DisassemblyBlock &db = disassembly_blocks[from.entry];
|
2018-03-21 20:32:32 +00:00
|
|
|
if (to->entry == db.true_path) {
|
2017-12-13 22:38:46 +00:00
|
|
|
ec.color = brtrueColor;
|
2018-03-21 20:32:32 +00:00
|
|
|
} else if (to->entry == db.false_path) {
|
2017-12-13 22:38:46 +00:00
|
|
|
ec.color = brfalseColor;
|
2018-03-21 20:32:32 +00:00
|
|
|
} else {
|
2017-12-13 22:38:46 +00:00
|
|
|
ec.color = jmpColor;
|
|
|
|
}
|
|
|
|
ec.start_arrow = false;
|
|
|
|
ec.end_arrow = true;
|
2019-07-30 18:35:00 +00:00
|
|
|
if (from.entry == currentBlockAddress) {
|
|
|
|
ec.width_scale = 2.0;
|
|
|
|
} else if (to->entry == currentBlockAddress) {
|
|
|
|
ec.width_scale = 2.0;
|
|
|
|
}
|
2017-12-13 22:38:46 +00:00
|
|
|
return ec;
|
2017-10-09 09:38:57 +00:00
|
|
|
}
|
|
|
|
|
2018-05-24 16:53:12 +00:00
|
|
|
|
2017-12-19 16:59:39 +00:00
|
|
|
RVA DisassemblerGraphView::getAddrForMouseEvent(GraphBlock &block, QPoint *point)
|
2017-10-09 09:38:57 +00:00
|
|
|
{
|
2017-12-13 22:38:46 +00:00
|
|
|
DisassemblyBlock &db = disassembly_blocks[block.entry];
|
2017-12-14 21:07:48 +00:00
|
|
|
|
|
|
|
// Remove header and margin
|
2019-05-19 10:27:15 +00:00
|
|
|
int off_y = getInstructionOffset(db, 0).y();
|
2019-01-13 14:40:37 +00:00
|
|
|
|
2017-12-14 21:07:48 +00:00
|
|
|
// Get mouse coordinate over the actual text
|
|
|
|
int text_point_y = point->y() - off_y;
|
|
|
|
int mouse_row = text_point_y / charHeight;
|
|
|
|
|
2019-01-13 14:40:37 +00:00
|
|
|
int cur_row = static_cast<int>(db.header_text.lines.size());
|
2018-03-21 20:32:32 +00:00
|
|
|
if (mouse_row < cur_row) {
|
2017-12-13 22:38:46 +00:00
|
|
|
return db.entry;
|
|
|
|
}
|
|
|
|
|
2017-12-19 16:59:39 +00:00
|
|
|
Instr *instr = getInstrForMouseEvent(block, point);
|
2018-03-21 20:32:32 +00:00
|
|
|
if (instr) {
|
2017-12-19 16:59:39 +00:00
|
|
|
return instr->addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return RVA_INVALID;
|
|
|
|
}
|
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
DisassemblerGraphView::Instr *DisassemblerGraphView::getInstrForMouseEvent(
|
|
|
|
GraphView::GraphBlock &block, QPoint *point)
|
2017-12-19 16:59:39 +00:00
|
|
|
{
|
|
|
|
DisassemblyBlock &db = disassembly_blocks[block.entry];
|
|
|
|
|
|
|
|
// Remove header and margin
|
2019-05-19 10:27:15 +00:00
|
|
|
int off_y = getInstructionOffset(db, 0).y();
|
2019-01-13 14:40:37 +00:00
|
|
|
|
2017-12-19 16:59:39 +00:00
|
|
|
// Get mouse coordinate over the actual text
|
|
|
|
int text_point_y = point->y() - off_y;
|
|
|
|
int mouse_row = text_point_y / charHeight;
|
|
|
|
|
2019-01-13 14:40:37 +00:00
|
|
|
int cur_row = static_cast<int>(db.header_text.lines.size());
|
2017-12-19 16:59:39 +00:00
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
for (Instr &instr : db.instrs) {
|
|
|
|
if (mouse_row < cur_row + (int)instr.text.lines.size()) {
|
2017-12-19 16:59:39 +00:00
|
|
|
return &instr;
|
2017-12-13 22:38:46 +00:00
|
|
|
}
|
|
|
|
cur_row += instr.text.lines.size();
|
|
|
|
}
|
2017-10-09 09:38:57 +00:00
|
|
|
|
2017-12-19 16:59:39 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
2017-12-13 22:38:46 +00:00
|
|
|
|
2019-05-19 10:27:15 +00:00
|
|
|
QRectF DisassemblerGraphView::getInstrRect(GraphView::GraphBlock &block, RVA addr) const
|
|
|
|
{
|
|
|
|
auto blockIt = disassembly_blocks.find(block.entry);
|
|
|
|
if (blockIt == disassembly_blocks.end()) {
|
|
|
|
return QRectF();
|
|
|
|
}
|
|
|
|
auto &db = blockIt->second;
|
|
|
|
if (db.instrs.empty()) {
|
|
|
|
return QRectF();
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t sequenceAddr = db.instrs[0].addr;
|
|
|
|
size_t firstLineWithAddr = 0;
|
|
|
|
size_t currentLine = 0;
|
|
|
|
for (size_t i = 0; i < db.instrs.size(); i++) {
|
|
|
|
auto &instr = db.instrs[i];
|
|
|
|
if (instr.addr != sequenceAddr) {
|
|
|
|
sequenceAddr = instr.addr;
|
|
|
|
firstLineWithAddr = currentLine;
|
|
|
|
}
|
|
|
|
if (instr.contains(addr)) {
|
2019-08-03 10:18:05 +00:00
|
|
|
while (i < db.instrs.size() && db.instrs[i].addr == sequenceAddr) {
|
2019-05-19 10:27:15 +00:00
|
|
|
currentLine += db.instrs[i].text.lines.size();
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
QPointF topLeft = getInstructionOffset(db, static_cast<int>(firstLineWithAddr));
|
|
|
|
return QRectF(topLeft, QSizeF(block.width - 4 * charWidth,
|
2019-08-03 10:18:05 +00:00
|
|
|
charHeight * int(currentLine - firstLineWithAddr)));
|
2019-05-19 10:27:15 +00:00
|
|
|
}
|
|
|
|
currentLine += instr.text.lines.size();
|
|
|
|
}
|
|
|
|
return QRectF();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisassemblerGraphView::showInstruction(GraphView::GraphBlock &block, RVA addr)
|
|
|
|
{
|
|
|
|
QRectF rect = getInstrRect(block, addr);
|
|
|
|
rect.translate(block.x, block.y);
|
|
|
|
showRectangle(QRect(rect.x(), rect.y(), rect.width(), rect.height()), true);
|
|
|
|
}
|
|
|
|
|
2017-12-13 22:38:46 +00:00
|
|
|
// Public Slots
|
|
|
|
|
2017-10-09 09:38:57 +00:00
|
|
|
void DisassemblerGraphView::colorsUpdatedSlot()
|
|
|
|
{
|
2017-11-20 11:23:37 +00:00
|
|
|
disassemblyBackgroundColor = ConfigColor("gui.alt_background");
|
2018-05-02 06:02:24 +00:00
|
|
|
disassemblySelectedBackgroundColor = ConfigColor("gui.disass_selected");
|
2017-10-22 10:21:44 +00:00
|
|
|
mDisabledBreakpointColor = disassemblyBackgroundColor;
|
2017-10-15 07:14:05 +00:00
|
|
|
graphNodeColor = ConfigColor("gui.border");
|
2017-11-20 11:23:37 +00:00
|
|
|
backgroundColor = ConfigColor("gui.background");
|
2019-05-23 16:22:31 +00:00
|
|
|
disassemblySelectionColor = ConfigColor("lineHighlight");
|
2018-06-22 15:57:15 +00:00
|
|
|
PCSelectionColor = ConfigColor("highlightPC");
|
2017-10-15 07:14:05 +00:00
|
|
|
|
|
|
|
jmpColor = ConfigColor("graph.trufae");
|
|
|
|
brtrueColor = ConfigColor("graph.true");
|
|
|
|
brfalseColor = ConfigColor("graph.false");
|
2017-11-05 15:08:17 +00:00
|
|
|
|
|
|
|
mCommentColor = ConfigColor("comment");
|
2017-12-13 22:38:46 +00:00
|
|
|
initFont();
|
2017-11-21 14:33:15 +00:00
|
|
|
refreshView();
|
2017-10-09 09:38:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DisassemblerGraphView::fontsUpdatedSlot()
|
|
|
|
{
|
2017-12-14 21:07:48 +00:00
|
|
|
initFont();
|
2017-12-13 22:38:46 +00:00
|
|
|
refreshView();
|
2017-10-09 09:38:57 +00:00
|
|
|
}
|
|
|
|
|
2017-12-13 22:38:46 +00:00
|
|
|
DisassemblerGraphView::DisassemblyBlock *DisassemblerGraphView::blockForAddress(RVA addr)
|
2017-10-09 09:38:57 +00:00
|
|
|
{
|
2018-03-21 20:32:32 +00:00
|
|
|
for (auto &blockIt : disassembly_blocks) {
|
2017-12-13 22:38:46 +00:00
|
|
|
DisassemblyBlock &db = blockIt.second;
|
2018-11-26 22:34:34 +00:00
|
|
|
for (const Instr &i : db.instrs) {
|
2018-05-24 16:58:46 +00:00
|
|
|
if (i.addr == RVA_INVALID || i.size == RVA_INVALID) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-05-19 10:27:15 +00:00
|
|
|
if (i.contains(addr)) {
|
2017-12-13 22:38:46 +00:00
|
|
|
return &db;
|
|
|
|
}
|
|
|
|
}
|
2017-10-09 09:38:57 +00:00
|
|
|
}
|
2017-12-13 22:38:46 +00:00
|
|
|
return nullptr;
|
2017-10-09 09:38:57 +00:00
|
|
|
}
|
|
|
|
|
2017-12-13 22:38:46 +00:00
|
|
|
void DisassemblerGraphView::onSeekChanged(RVA addr)
|
2017-10-09 09:38:57 +00:00
|
|
|
{
|
2019-04-18 10:10:18 +00:00
|
|
|
blockMenu->setOffset(addr);
|
2018-05-24 16:53:12 +00:00
|
|
|
DisassemblyBlock *db = blockForAddress(addr);
|
2019-05-19 10:27:15 +00:00
|
|
|
bool switchFunction = false;
|
|
|
|
if (!db) {
|
|
|
|
// not in this function, try refreshing
|
|
|
|
refreshView();
|
|
|
|
db = blockForAddress(addr);
|
|
|
|
switchFunction = true;
|
|
|
|
}
|
2018-05-24 16:53:12 +00:00
|
|
|
if (db) {
|
|
|
|
// This is a local address! We animated to it.
|
|
|
|
transition_dont_seek = true;
|
2019-05-19 10:27:15 +00:00
|
|
|
showBlock(&blocks[db->entry], !switchFunction);
|
|
|
|
showInstruction(blocks[db->entry], addr);
|
2017-10-09 09:38:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-23 08:21:06 +00:00
|
|
|
void DisassemblerGraphView::zoom(QPointF mouseRelativePos, double velocity)
|
2017-10-09 09:38:57 +00:00
|
|
|
{
|
2019-03-23 08:21:06 +00:00
|
|
|
mouseRelativePos.rx() *= size().width();
|
|
|
|
mouseRelativePos.ry() *= size().height();
|
2019-04-14 12:18:24 +00:00
|
|
|
mouseRelativePos /= getViewScale();
|
2017-10-09 09:38:57 +00:00
|
|
|
|
2019-04-14 12:18:24 +00:00
|
|
|
auto globalMouse = mouseRelativePos + getViewOffset();
|
|
|
|
mouseRelativePos *= getViewScale();
|
|
|
|
qreal newScale = getViewScale() * std::pow(1.25, velocity);
|
2019-04-21 16:30:57 +00:00
|
|
|
newScale = std::max(newScale, 0.05);
|
2019-04-14 12:18:24 +00:00
|
|
|
mouseRelativePos /= newScale;
|
|
|
|
setViewScale(newScale);
|
2019-03-23 08:21:06 +00:00
|
|
|
|
|
|
|
// Adjusting offset, so that zooming will be approaching to the cursor.
|
2019-04-14 12:18:24 +00:00
|
|
|
setViewOffset(globalMouse.toPoint() - mouseRelativePos.toPoint());
|
2019-03-23 08:21:06 +00:00
|
|
|
|
2017-12-14 21:07:48 +00:00
|
|
|
viewport()->update();
|
2019-01-31 12:14:15 +00:00
|
|
|
emit viewZoomed();
|
2017-10-09 09:38:57 +00:00
|
|
|
}
|
|
|
|
|
2017-12-13 22:57:36 +00:00
|
|
|
void DisassemblerGraphView::zoomReset()
|
|
|
|
{
|
2019-04-14 12:18:24 +00:00
|
|
|
setViewScale(1.0);
|
2017-12-14 21:07:48 +00:00
|
|
|
viewport()->update();
|
2019-01-31 12:14:15 +00:00
|
|
|
emit viewZoomed();
|
2017-12-13 22:57:36 +00:00
|
|
|
}
|
|
|
|
|
2017-12-13 22:38:46 +00:00
|
|
|
void DisassemblerGraphView::takeTrue()
|
2017-10-09 09:38:57 +00:00
|
|
|
{
|
2018-05-25 14:30:59 +00:00
|
|
|
DisassemblyBlock *db = blockForAddress(seekable->getOffset());
|
2018-09-07 22:32:30 +00:00
|
|
|
if (!db) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
if (db->true_path != RVA_INVALID) {
|
2018-05-25 14:30:59 +00:00
|
|
|
seekable->seek(db->true_path);
|
2019-04-04 05:54:42 +00:00
|
|
|
} else if (!blocks[db->entry].edges.empty()) {
|
|
|
|
seekable->seek(blocks[db->entry].edges[0].target);
|
2017-12-13 22:38:46 +00:00
|
|
|
}
|
2017-10-09 09:38:57 +00:00
|
|
|
}
|
|
|
|
|
2017-12-13 22:38:46 +00:00
|
|
|
void DisassemblerGraphView::takeFalse()
|
2017-10-09 09:38:57 +00:00
|
|
|
{
|
2018-05-25 14:30:59 +00:00
|
|
|
DisassemblyBlock *db = blockForAddress(seekable->getOffset());
|
2018-09-07 22:32:30 +00:00
|
|
|
if (!db) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
if (db->false_path != RVA_INVALID) {
|
2018-05-25 14:30:59 +00:00
|
|
|
seekable->seek(db->false_path);
|
2019-04-04 05:54:42 +00:00
|
|
|
} else if (!blocks[db->entry].edges.empty()) {
|
|
|
|
seekable->seek(blocks[db->entry].edges[0].target);
|
2017-12-13 22:38:46 +00:00
|
|
|
}
|
2017-10-09 09:38:57 +00:00
|
|
|
}
|
|
|
|
|
2017-12-14 21:07:48 +00:00
|
|
|
void DisassemblerGraphView::seekInstruction(bool previous_instr)
|
|
|
|
{
|
2018-05-25 14:30:59 +00:00
|
|
|
RVA addr = seekable->getOffset();
|
2017-12-14 21:07:48 +00:00
|
|
|
DisassemblyBlock *db = blockForAddress(addr);
|
2018-03-21 20:32:32 +00:00
|
|
|
if (!db) {
|
2017-12-14 21:07:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
for (size_t i = 0; i < db->instrs.size(); i++) {
|
2017-12-14 21:07:48 +00:00
|
|
|
Instr &instr = db->instrs[i];
|
2019-05-19 10:27:15 +00:00
|
|
|
if (!instr.contains(addr)) {
|
2017-12-14 21:07:48 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-09-30 17:46:36 +00:00
|
|
|
// Found the instruction. Check if a next one exists
|
2018-03-21 20:32:32 +00:00
|
|
|
if (!previous_instr && (i < db->instrs.size() - 1)) {
|
2018-05-25 14:30:59 +00:00
|
|
|
seekable->seek(db->instrs[i + 1].addr);
|
2018-03-21 20:32:32 +00:00
|
|
|
} else if (previous_instr && (i > 0)) {
|
2019-05-19 10:27:15 +00:00
|
|
|
while (i > 0 && db->instrs[i].addr == addr) { // jump over 0 size instructions
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
seekable->seek(db->instrs[i].addr);
|
|
|
|
break;
|
2017-12-14 21:07:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisassemblerGraphView::nextInstr()
|
|
|
|
{
|
|
|
|
seekInstruction(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisassemblerGraphView::prevInstr()
|
|
|
|
{
|
|
|
|
seekInstruction(true);
|
|
|
|
}
|
|
|
|
|
2018-05-25 14:30:59 +00:00
|
|
|
void DisassemblerGraphView::seekLocal(RVA addr, bool update_viewport)
|
2017-10-09 09:38:57 +00:00
|
|
|
{
|
2019-03-02 08:07:05 +00:00
|
|
|
RVA curAddr = seekable->getOffset();
|
|
|
|
if (addr == curAddr) {
|
|
|
|
return;
|
|
|
|
}
|
2018-05-24 16:53:12 +00:00
|
|
|
connectSeekChanged(true);
|
2018-05-25 14:30:59 +00:00
|
|
|
seekable->seek(addr);
|
2018-05-24 16:53:12 +00:00
|
|
|
connectSeekChanged(false);
|
2018-03-21 20:32:32 +00:00
|
|
|
if (update_viewport) {
|
2017-12-14 21:07:48 +00:00
|
|
|
viewport()->update();
|
2017-12-13 22:38:46 +00:00
|
|
|
}
|
2017-10-09 09:38:57 +00:00
|
|
|
}
|
|
|
|
|
2019-01-14 08:16:10 +00:00
|
|
|
void DisassemblerGraphView::copySelection()
|
|
|
|
{
|
|
|
|
if (!highlight_token) return;
|
|
|
|
|
|
|
|
QClipboard *clipboard = QApplication::clipboard();
|
|
|
|
clipboard->setText(highlight_token->content);
|
|
|
|
}
|
|
|
|
|
2018-09-30 20:00:53 +00:00
|
|
|
DisassemblerGraphView::Token *DisassemblerGraphView::getToken(Instr *instr, int x)
|
2018-08-16 14:05:48 +00:00
|
|
|
{
|
2019-01-13 14:40:37 +00:00
|
|
|
x -= (int) (3 * charWidth); // Ignore left margin
|
2018-10-14 15:44:49 +00:00
|
|
|
if (x < 0) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2018-08-16 14:05:48 +00:00
|
|
|
|
2018-10-14 15:44:49 +00:00
|
|
|
int clickedCharPos = mFontMetrics->position(instr->plainText, x);
|
2018-08-16 14:05:48 +00:00
|
|
|
if (clickedCharPos > instr->plainText.length()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-01-13 14:40:37 +00:00
|
|
|
static const QRegularExpression tokenRegExp(R"(\b(?<!\.)([^\s]+)\b(?!\.))");
|
2018-08-16 14:05:48 +00:00
|
|
|
QRegularExpressionMatchIterator i = tokenRegExp.globalMatch(instr->plainText);
|
|
|
|
|
|
|
|
while (i.hasNext()) {
|
|
|
|
QRegularExpressionMatch match = i.next();
|
2018-09-07 22:32:30 +00:00
|
|
|
|
2018-08-16 14:05:48 +00:00
|
|
|
if (match.capturedStart() <= clickedCharPos && match.capturedEnd() > clickedCharPos) {
|
2019-01-13 14:40:37 +00:00
|
|
|
auto t = new Token;
|
2018-08-16 14:05:48 +00:00
|
|
|
t->start = match.capturedStart();
|
|
|
|
t->length = match.capturedLength();
|
|
|
|
t->content = match.captured();
|
|
|
|
t->instr = instr;
|
|
|
|
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-05-19 10:27:15 +00:00
|
|
|
QPoint DisassemblerGraphView::getTextOffset(int line) const
|
|
|
|
{
|
|
|
|
int padding = static_cast<int>(2 * charWidth);
|
|
|
|
return QPoint(padding, padding + line * charHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
QPoint DisassemblerGraphView::getInstructionOffset(const DisassemblyBlock &block, int line) const
|
|
|
|
{
|
|
|
|
return getTextOffset(line + static_cast<int>(block.header_text.lines.size()));
|
|
|
|
}
|
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
void DisassemblerGraphView::blockClicked(GraphView::GraphBlock &block, QMouseEvent *event,
|
|
|
|
QPoint pos)
|
2017-10-09 09:38:57 +00:00
|
|
|
{
|
2018-08-16 14:05:48 +00:00
|
|
|
Instr *instr = getInstrForMouseEvent(block, &pos);
|
|
|
|
if (!instr) {
|
2017-10-09 09:38:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-07-30 18:35:00 +00:00
|
|
|
currentBlockAddress = block.entry;
|
|
|
|
|
2018-08-16 14:05:48 +00:00
|
|
|
highlight_token = getToken(instr, pos.x());
|
|
|
|
|
|
|
|
RVA addr = instr->addr;
|
|
|
|
seekLocal(addr);
|
2017-10-09 09:38:57 +00:00
|
|
|
|
2019-04-18 10:10:18 +00:00
|
|
|
blockMenu->setOffset(addr);
|
|
|
|
blockMenu->setCanCopy(highlight_token);
|
2019-03-04 21:45:17 +00:00
|
|
|
if (highlight_token) {
|
2019-04-18 10:10:18 +00:00
|
|
|
blockMenu->setCurHighlightedWord(highlight_token->content);
|
2019-03-04 21:45:17 +00:00
|
|
|
}
|
2018-03-21 20:32:32 +00:00
|
|
|
if (event->button() == Qt::RightButton) {
|
2019-05-23 16:22:31 +00:00
|
|
|
actionUnhighlight.setVisible(Core()->getBBHighlighter()->getBasicBlock(block.entry));
|
2019-04-18 10:10:18 +00:00
|
|
|
event->accept();
|
|
|
|
blockMenu->exec(event->globalPos());
|
2017-10-09 09:38:57 +00:00
|
|
|
}
|
2019-03-23 06:20:19 +00:00
|
|
|
viewport()->update();
|
2017-10-09 09:38:57 +00:00
|
|
|
}
|
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
void DisassemblerGraphView::blockDoubleClicked(GraphView::GraphBlock &block, QMouseEvent *event,
|
|
|
|
QPoint pos)
|
2017-12-14 21:07:48 +00:00
|
|
|
{
|
2017-12-14 21:54:57 +00:00
|
|
|
Q_UNUSED(event);
|
2018-05-25 14:30:59 +00:00
|
|
|
|
2017-12-19 16:59:39 +00:00
|
|
|
RVA instr = getAddrForMouseEvent(block, &pos);
|
2018-03-21 20:32:32 +00:00
|
|
|
if (instr == RVA_INVALID) {
|
2017-12-14 21:07:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
QList<XrefDescription> refs = Core()->getXRefs(instr, false, false);
|
|
|
|
if (refs.length()) {
|
2018-05-25 14:30:59 +00:00
|
|
|
seekable->seek(refs.at(0).to);
|
2017-12-14 21:07:48 +00:00
|
|
|
}
|
|
|
|
if (refs.length() > 1) {
|
|
|
|
qWarning() << "Too many references here. Weird behaviour expected.";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
void DisassemblerGraphView::blockHelpEvent(GraphView::GraphBlock &block, QHelpEvent *event,
|
|
|
|
QPoint pos)
|
2017-12-19 16:59:39 +00:00
|
|
|
{
|
|
|
|
Instr *instr = getInstrForMouseEvent(block, &pos);
|
2018-03-21 20:32:32 +00:00
|
|
|
if (!instr || instr->fullText.lines.empty()) {
|
2017-12-19 16:59:39 +00:00
|
|
|
QToolTip::hideText();
|
|
|
|
event->ignore();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QToolTip::showText(event->globalPos(), instr->fullText.ToQString());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DisassemblerGraphView::helpEvent(QHelpEvent *event)
|
|
|
|
{
|
2018-03-21 20:32:32 +00:00
|
|
|
if (!GraphView::helpEvent(event)) {
|
2017-12-19 16:59:39 +00:00
|
|
|
QToolTip::hideText();
|
|
|
|
event->ignore();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-12-13 22:38:46 +00:00
|
|
|
void DisassemblerGraphView::blockTransitionedTo(GraphView::GraphBlock *to)
|
2017-10-09 09:38:57 +00:00
|
|
|
{
|
2019-07-30 18:35:00 +00:00
|
|
|
currentBlockAddress = to->entry;
|
2018-03-21 20:32:32 +00:00
|
|
|
if (transition_dont_seek) {
|
2017-12-13 22:38:46 +00:00
|
|
|
transition_dont_seek = false;
|
|
|
|
return;
|
2017-10-09 09:38:57 +00:00
|
|
|
}
|
2018-05-25 14:30:59 +00:00
|
|
|
seekLocal(to->entry);
|
2017-10-16 19:00:47 +00:00
|
|
|
}
|
2018-02-14 09:33:34 +00:00
|
|
|
|
2018-05-24 16:53:12 +00:00
|
|
|
|
2018-02-14 09:33:34 +00:00
|
|
|
void DisassemblerGraphView::on_actionExportGraph_triggered()
|
|
|
|
{
|
2018-08-25 18:54:23 +00:00
|
|
|
QStringList filters;
|
|
|
|
filters.append(tr("Graphiz dot (*.dot)"));
|
|
|
|
if (!QStandardPaths::findExecutable("dot").isEmpty()
|
|
|
|
|| !QStandardPaths::findExecutable("xdot").isEmpty()) {
|
|
|
|
filters.append(tr("GIF (*.gif)"));
|
|
|
|
filters.append(tr("PNG (*.png)"));
|
|
|
|
filters.append(tr("JPEG (*.jpg)"));
|
|
|
|
filters.append(tr("PostScript (*.ps)"));
|
|
|
|
filters.append(tr("SVG (*.svg)"));
|
|
|
|
filters.append(tr("JSON (*.json)"));
|
|
|
|
}
|
|
|
|
|
|
|
|
QFileDialog dialog(this, tr("Export Graph"));
|
|
|
|
dialog.setAcceptMode(QFileDialog::AcceptSave);
|
|
|
|
dialog.setFileMode(QFileDialog::AnyFile);
|
|
|
|
dialog.setNameFilters(filters);
|
|
|
|
dialog.selectFile("graph");
|
|
|
|
dialog.setDefaultSuffix("dot");
|
|
|
|
if (!dialog.exec())
|
|
|
|
return;
|
|
|
|
int startIdx = dialog.selectedNameFilter().lastIndexOf("*.") + 2;
|
|
|
|
int count = dialog.selectedNameFilter().length() - startIdx - 1;
|
|
|
|
QString format = dialog.selectedNameFilter().mid(startIdx, count);
|
|
|
|
QString fileName = dialog.selectedFiles()[0];
|
|
|
|
if (format != "dot") {
|
|
|
|
TempConfig tempConfig;
|
|
|
|
tempConfig.set("graph.gv.format", format);
|
|
|
|
qWarning() << Core()->cmd(QString("agfw \"%1\" @ $FB").arg(fileName));
|
|
|
|
return;
|
|
|
|
}
|
2018-02-14 09:33:34 +00:00
|
|
|
QFile file(fileName);
|
2018-03-21 20:32:32 +00:00
|
|
|
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
2018-02-14 09:33:34 +00:00
|
|
|
qWarning() << "Can't open file";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QTextStream fileOut(&file);
|
2018-07-24 07:01:34 +00:00
|
|
|
fileOut << Core()->cmd("agfd $FB");
|
2018-02-14 09:33:34 +00:00
|
|
|
}
|
2018-07-01 11:47:15 +00:00
|
|
|
|
2019-02-19 15:56:50 +00:00
|
|
|
void DisassemblerGraphView::mousePressEvent(QMouseEvent *event)
|
|
|
|
{
|
|
|
|
GraphView::mousePressEvent(event);
|
2019-04-18 10:10:18 +00:00
|
|
|
if (!event->isAccepted() && event->button() == Qt::RightButton) {
|
|
|
|
contextMenu->exec(event->globalPos());
|
|
|
|
event->accept();
|
|
|
|
}
|
2019-02-19 15:56:50 +00:00
|
|
|
emit graphMoved();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DisassemblerGraphView::mouseMoveEvent(QMouseEvent *event)
|
|
|
|
{
|
|
|
|
GraphView::mouseMoveEvent(event);
|
|
|
|
emit graphMoved();
|
|
|
|
}
|
|
|
|
|
2018-05-10 14:08:03 +00:00
|
|
|
void DisassemblerGraphView::wheelEvent(QWheelEvent *event)
|
|
|
|
{
|
|
|
|
// when CTRL is pressed, we zoom in/out with mouse wheel
|
|
|
|
if (Qt::ControlModifier == event->modifiers()) {
|
|
|
|
const QPoint numDegrees = event->angleDelta() / 8;
|
|
|
|
if (!numDegrees.isNull()) {
|
2019-03-23 08:21:06 +00:00
|
|
|
int numSteps = numDegrees.y() / 15;
|
|
|
|
|
|
|
|
QPointF relativeMousePos = event->pos();
|
|
|
|
relativeMousePos.rx() /= size().width();
|
|
|
|
relativeMousePos.ry() /= size().height();
|
|
|
|
|
|
|
|
zoom(relativeMousePos, numSteps);
|
2018-05-10 14:08:03 +00:00
|
|
|
}
|
|
|
|
event->accept();
|
|
|
|
} else {
|
|
|
|
// use mouse wheel for scrolling when CTRL is not pressed
|
|
|
|
GraphView::wheelEvent(event);
|
|
|
|
}
|
2019-02-19 15:56:50 +00:00
|
|
|
emit graphMoved();
|
2018-05-10 14:08:03 +00:00
|
|
|
}
|
2019-04-08 06:59:16 +00:00
|
|
|
|
2019-04-14 12:18:24 +00:00
|
|
|
void DisassemblerGraphView::resizeEvent(QResizeEvent *event)
|
|
|
|
{
|
|
|
|
GraphView::resizeEvent(event);
|
|
|
|
emit resized();
|
|
|
|
}
|
|
|
|
|
2019-04-08 06:59:16 +00:00
|
|
|
void DisassemblerGraphView::paintEvent(QPaintEvent *event)
|
|
|
|
{
|
|
|
|
// DisassemblerGraphView is always dirty
|
|
|
|
setCacheDirty();
|
|
|
|
GraphView::paintEvent(event);
|
|
|
|
}
|
2019-05-19 10:27:15 +00:00
|
|
|
|
|
|
|
bool DisassemblerGraphView::Instr::contains(ut64 addr) const
|
|
|
|
{
|
|
|
|
return this->addr <= addr && (addr - this->addr) < size;
|
|
|
|
}
|