2017-12-13 22:38:46 +00:00
|
|
|
#ifndef DISASSEMBLERGRAPHVIEW_H
|
|
|
|
#define DISASSEMBLERGRAPHVIEW_H
|
|
|
|
|
|
|
|
// Based on the DisassemblerGraphView from x64dbg
|
|
|
|
|
|
|
|
#include <QWidget>
|
|
|
|
#include <QPainter>
|
2017-12-14 21:07:48 +00:00
|
|
|
#include <QShortcut>
|
2018-07-01 11:47:15 +00:00
|
|
|
#include <QLabel>
|
2017-12-13 22:38:46 +00:00
|
|
|
|
|
|
|
#include "widgets/GraphView.h"
|
|
|
|
#include "menus/DisassemblyContextMenu.h"
|
2018-10-17 07:55:53 +00:00
|
|
|
#include "common/RichTextPainter.h"
|
2019-01-14 18:43:44 +00:00
|
|
|
#include "common/CutterSeekable.h"
|
2017-12-13 22:38:46 +00:00
|
|
|
|
2018-10-16 14:49:26 +00:00
|
|
|
class QTextEdit;
|
2019-07-12 13:37:19 +00:00
|
|
|
class FallbackSyntaxHighlighter;
|
2018-10-16 14:49:26 +00:00
|
|
|
|
2017-12-13 22:38:46 +00:00
|
|
|
class DisassemblerGraphView : public GraphView
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
struct Text {
|
2017-12-13 22:38:46 +00:00
|
|
|
std::vector<RichTextPainter::List> lines;
|
|
|
|
|
|
|
|
Text() {}
|
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
Text(const QString &text, QColor color, QColor background)
|
2017-12-13 22:38:46 +00:00
|
|
|
{
|
|
|
|
RichTextPainter::List richText;
|
|
|
|
RichTextPainter::CustomRichText_t rt;
|
|
|
|
rt.highlight = false;
|
|
|
|
rt.text = text;
|
|
|
|
rt.textColor = color;
|
|
|
|
rt.textBackground = background;
|
|
|
|
rt.flags = rt.textBackground.alpha() ? RichTextPainter::FlagAll : RichTextPainter::FlagColor;
|
|
|
|
richText.push_back(rt);
|
|
|
|
lines.push_back(richText);
|
|
|
|
}
|
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
Text(const RichTextPainter::List &richText)
|
2017-12-13 22:38:46 +00:00
|
|
|
{
|
|
|
|
lines.push_back(richText);
|
|
|
|
}
|
|
|
|
|
|
|
|
QString ToQString() const
|
|
|
|
{
|
|
|
|
QString result;
|
2018-11-26 22:34:34 +00:00
|
|
|
for (const auto &line : lines) {
|
|
|
|
for (const auto &t : line) {
|
2017-12-13 22:38:46 +00:00
|
|
|
result += t.text;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
struct Instr {
|
2017-12-13 22:38:46 +00:00
|
|
|
ut64 addr = 0;
|
|
|
|
ut64 size = 0;
|
|
|
|
Text text;
|
2017-12-19 16:59:39 +00:00
|
|
|
Text fullText;
|
2018-08-16 14:05:48 +00:00
|
|
|
QString plainText;
|
2017-12-13 22:38:46 +00:00
|
|
|
std::vector<unsigned char> opcode; //instruction bytes
|
2019-05-19 10:27:15 +00:00
|
|
|
|
|
|
|
bool empty() const { return size == 0; }
|
|
|
|
bool contains(ut64 addr) const;
|
2017-12-13 22:38:46 +00:00
|
|
|
};
|
|
|
|
|
2018-08-16 14:05:48 +00:00
|
|
|
struct Token {
|
|
|
|
int start;
|
|
|
|
int length;
|
|
|
|
QString type;
|
2018-09-30 20:00:53 +00:00
|
|
|
Instr *instr;
|
2018-08-16 14:05:48 +00:00
|
|
|
QString name;
|
|
|
|
QString content;
|
|
|
|
};
|
2017-12-13 22:38:46 +00:00
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
struct DisassemblyBlock {
|
2017-12-13 22:38:46 +00:00
|
|
|
Text header_text;
|
|
|
|
std::vector<Instr> instrs;
|
|
|
|
ut64 entry = 0;
|
|
|
|
ut64 true_path = 0;
|
|
|
|
ut64 false_path = 0;
|
|
|
|
bool terminal = false;
|
|
|
|
bool indirectcall = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
2019-07-19 19:21:12 +00:00
|
|
|
DisassemblerGraphView(QWidget *parent, CutterSeekable* seekable, MainWindow* mainWindow);
|
2018-09-30 17:46:36 +00:00
|
|
|
~DisassemblerGraphView() override;
|
2017-12-13 22:38:46 +00:00
|
|
|
std::unordered_map<ut64, DisassemblyBlock> disassembly_blocks;
|
2018-03-21 20:32:32 +00:00
|
|
|
virtual void drawBlock(QPainter &p, GraphView::GraphBlock &block) override;
|
2017-12-13 22:38:46 +00:00
|
|
|
virtual void blockClicked(GraphView::GraphBlock &block, QMouseEvent *event, QPoint pos) override;
|
2018-03-21 20:32:32 +00:00
|
|
|
virtual void blockDoubleClicked(GraphView::GraphBlock &block, QMouseEvent *event,
|
|
|
|
QPoint pos) override;
|
2017-12-19 16:59:39 +00:00
|
|
|
virtual bool helpEvent(QHelpEvent *event) override;
|
|
|
|
virtual void blockHelpEvent(GraphView::GraphBlock &block, QHelpEvent *event, QPoint pos) override;
|
2018-03-21 20:32:32 +00:00
|
|
|
virtual GraphView::EdgeConfiguration edgeConfiguration(GraphView::GraphBlock &from,
|
|
|
|
GraphView::GraphBlock *to) override;
|
2017-12-13 22:38:46 +00:00
|
|
|
virtual void blockTransitionedTo(GraphView::GraphBlock *to) override;
|
|
|
|
|
|
|
|
void loadCurrentGraph();
|
2018-05-25 14:30:59 +00:00
|
|
|
QString windowTitle;
|
2017-12-13 22:38:46 +00:00
|
|
|
|
2019-01-24 17:13:04 +00:00
|
|
|
int getWidth() { return width; }
|
|
|
|
int getHeight() { return height; }
|
|
|
|
std::unordered_map<ut64, GraphBlock> getBlocks() { return blocks; }
|
2019-04-04 05:54:42 +00:00
|
|
|
using EdgeConfigurationMapping = std::map<std::pair<ut64, ut64>, EdgeConfiguration>;
|
|
|
|
EdgeConfigurationMapping getEdgeConfigurations();
|
2019-03-23 08:21:06 +00:00
|
|
|
|
2017-12-13 22:38:46 +00:00
|
|
|
public slots:
|
|
|
|
void refreshView();
|
|
|
|
void colorsUpdatedSlot();
|
|
|
|
void fontsUpdatedSlot();
|
|
|
|
void onSeekChanged(RVA addr);
|
2019-03-23 08:21:06 +00:00
|
|
|
void zoom(QPointF mouseRelativePos, double velocity);
|
2017-12-13 22:57:36 +00:00
|
|
|
void zoomReset();
|
2017-12-13 22:38:46 +00:00
|
|
|
|
|
|
|
void takeTrue();
|
|
|
|
void takeFalse();
|
2017-12-14 21:07:48 +00:00
|
|
|
|
|
|
|
void nextInstr();
|
|
|
|
void prevInstr();
|
2018-05-10 14:08:03 +00:00
|
|
|
|
2019-01-14 08:16:10 +00:00
|
|
|
void copySelection();
|
|
|
|
|
2018-05-10 14:08:03 +00:00
|
|
|
protected:
|
2019-02-19 15:56:50 +00:00
|
|
|
void mousePressEvent(QMouseEvent *event) override;
|
|
|
|
void mouseMoveEvent(QMouseEvent *event) override;
|
|
|
|
void wheelEvent(QWheelEvent *event) override;
|
2019-04-14 12:18:24 +00:00
|
|
|
void resizeEvent(QResizeEvent *event) override;
|
2018-05-10 14:08:03 +00:00
|
|
|
|
2019-04-08 06:59:16 +00:00
|
|
|
void paintEvent(QPaintEvent *event) override;
|
|
|
|
|
2017-12-13 22:38:46 +00:00
|
|
|
private slots:
|
2018-02-14 09:33:34 +00:00
|
|
|
void on_actionExportGraph_triggered();
|
|
|
|
|
2017-12-13 22:38:46 +00:00
|
|
|
private:
|
|
|
|
bool transition_dont_seek = false;
|
|
|
|
|
2018-08-16 14:05:48 +00:00
|
|
|
Token *highlight_token;
|
2017-12-13 22:38:46 +00:00
|
|
|
// Font data
|
2019-05-17 11:00:54 +00:00
|
|
|
std::unique_ptr<CachedFontMetrics<qreal>> mFontMetrics;
|
2017-12-13 22:38:46 +00:00
|
|
|
qreal charWidth;
|
2017-12-14 21:07:48 +00:00
|
|
|
int charHeight;
|
2017-12-13 22:38:46 +00:00
|
|
|
int charOffset;
|
|
|
|
int baseline;
|
2018-09-30 17:46:36 +00:00
|
|
|
bool emptyGraph;
|
2017-12-13 22:38:46 +00:00
|
|
|
|
2019-04-18 10:10:18 +00:00
|
|
|
DisassemblyContextMenu *blockMenu;
|
|
|
|
QMenu *contextMenu;
|
2017-12-13 22:38:46 +00:00
|
|
|
|
2018-05-24 16:53:12 +00:00
|
|
|
void connectSeekChanged(bool disconnect);
|
|
|
|
|
2017-12-13 22:38:46 +00:00
|
|
|
void initFont();
|
|
|
|
void prepareGraphNode(GraphBlock &block);
|
2019-05-23 10:52:56 +00:00
|
|
|
void cleanupEdges();
|
2018-09-30 20:00:53 +00:00
|
|
|
Token *getToken(Instr *instr, int x);
|
2019-05-19 10:27:15 +00:00
|
|
|
QPoint getTextOffset(int line) const;
|
|
|
|
QPoint getInstructionOffset(const DisassemblyBlock &block, int line) const;
|
2017-12-19 16:59:39 +00:00
|
|
|
RVA getAddrForMouseEvent(GraphBlock &block, QPoint *point);
|
|
|
|
Instr *getInstrForMouseEvent(GraphBlock &block, QPoint *point);
|
2019-05-19 10:27:15 +00:00
|
|
|
/**
|
|
|
|
* @brief Get instructions placement and size relative to block.
|
|
|
|
* Inefficient don't use this function when iterating over all instructions.
|
|
|
|
* @param block
|
|
|
|
* @param addr
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
QRectF getInstrRect(GraphView::GraphBlock &block, RVA addr) const;
|
|
|
|
void showInstruction(GraphView::GraphBlock &block, RVA addr);
|
2017-12-13 22:38:46 +00:00
|
|
|
DisassemblyBlock *blockForAddress(RVA addr);
|
2018-05-25 14:30:59 +00:00
|
|
|
void seekLocal(RVA addr, bool update_viewport = true);
|
2017-12-14 21:07:48 +00:00
|
|
|
void seekInstruction(bool previous_instr);
|
2019-01-13 14:20:07 +00:00
|
|
|
CutterSeekable *seekable = nullptr;
|
2018-03-21 20:32:32 +00:00
|
|
|
QList<QShortcut *> shortcuts;
|
2018-08-12 16:20:16 +00:00
|
|
|
QList<RVA> breakpoints;
|
2017-12-13 22:38:46 +00:00
|
|
|
|
|
|
|
QColor disassemblyBackgroundColor;
|
|
|
|
QColor disassemblySelectedBackgroundColor;
|
|
|
|
QColor disassemblySelectionColor;
|
2018-06-22 15:57:15 +00:00
|
|
|
QColor PCSelectionColor;
|
2017-12-13 22:38:46 +00:00
|
|
|
QColor jmpColor;
|
|
|
|
QColor brtrueColor;
|
|
|
|
QColor brfalseColor;
|
|
|
|
QColor retShadowColor;
|
|
|
|
QColor indirectcallShadowColor;
|
|
|
|
QColor mAutoCommentColor;
|
|
|
|
QColor mAutoCommentBackgroundColor;
|
|
|
|
QColor mCommentColor;
|
|
|
|
QColor mCommentBackgroundColor;
|
|
|
|
QColor mLabelColor;
|
|
|
|
QColor mLabelBackgroundColor;
|
|
|
|
QColor graphNodeColor;
|
|
|
|
QColor mAddressColor;
|
|
|
|
QColor mAddressBackgroundColor;
|
|
|
|
QColor mCipColor;
|
|
|
|
QColor mBreakpointColor;
|
|
|
|
QColor mDisabledBreakpointColor;
|
2018-02-14 09:33:34 +00:00
|
|
|
|
|
|
|
QAction actionExportGraph;
|
2019-05-23 16:22:31 +00:00
|
|
|
QAction actionUnhighlight;
|
2018-05-25 14:30:59 +00:00
|
|
|
QAction actionSyncOffset;
|
2018-07-01 11:47:15 +00:00
|
|
|
|
|
|
|
QLabel *emptyText = nullptr;
|
2019-01-24 17:13:04 +00:00
|
|
|
signals:
|
|
|
|
void viewRefreshed();
|
2019-01-31 12:14:15 +00:00
|
|
|
void viewZoomed();
|
2019-02-19 15:56:50 +00:00
|
|
|
void graphMoved();
|
2019-04-14 12:18:24 +00:00
|
|
|
void resized();
|
2019-06-18 13:02:41 +00:00
|
|
|
void nameChanged(const QString& name);
|
2019-04-14 12:18:24 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
bool isGraphEmpty() { return emptyGraph; }
|
2017-12-13 22:38:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // DISASSEMBLERGRAPHVIEW_H
|