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"
|
2018-05-25 14:30:59 +00:00
|
|
|
#include "CutterSeekableWidget.h"
|
2017-12-13 22:38:46 +00:00
|
|
|
|
2018-10-16 14:49:26 +00:00
|
|
|
class QTextEdit;
|
|
|
|
class SyntaxHighlighter;
|
|
|
|
|
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-03-21 20:32:32 +00:00
|
|
|
for (auto &line : lines) {
|
|
|
|
for (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
|
|
|
|
};
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
struct Function {
|
2017-12-13 22:38:46 +00:00
|
|
|
bool ready;
|
|
|
|
ut64 entry;
|
|
|
|
ut64 update_id;
|
|
|
|
std::vector<DisassemblyBlock> blocks;
|
|
|
|
};
|
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
struct Analysis {
|
2017-12-13 22:38:46 +00:00
|
|
|
ut64 entry = 0;
|
|
|
|
std::unordered_map<ut64, Function> functions;
|
|
|
|
bool ready = false;
|
|
|
|
ut64 update_id = 0;
|
|
|
|
QString status = "Analyzing...";
|
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
bool find_instr(ut64 addr, ut64 &func, ut64 &instr)
|
2017-12-13 22:38:46 +00:00
|
|
|
{
|
|
|
|
//TODO implement
|
|
|
|
Q_UNUSED(addr);
|
|
|
|
Q_UNUSED(func);
|
|
|
|
Q_UNUSED(instr);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
//dummy class
|
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
|
|
|
DisassemblerGraphView(QWidget *parent);
|
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;
|
2018-09-30 17:46:36 +00:00
|
|
|
bool isGraphEmpty();
|
2018-10-16 14:49:26 +00:00
|
|
|
QTextEdit *header = nullptr;
|
2017-12-13 22:38:46 +00:00
|
|
|
|
|
|
|
public slots:
|
|
|
|
void refreshView();
|
|
|
|
void colorsUpdatedSlot();
|
|
|
|
void fontsUpdatedSlot();
|
|
|
|
void onSeekChanged(RVA addr);
|
2018-05-25 14:30:59 +00:00
|
|
|
void toggleSync();
|
2017-12-13 22:38:46 +00:00
|
|
|
|
2018-05-10 14:08:03 +00:00
|
|
|
void zoomIn(QPoint mouse = QPoint(0, 0));
|
|
|
|
void zoomOut(QPoint mouse = QPoint(0, 0));
|
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
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void wheelEvent(QWheelEvent *event) override;
|
|
|
|
|
2017-12-13 22:38:46 +00:00
|
|
|
private slots:
|
|
|
|
void seekPrev();
|
|
|
|
|
2018-02-14 09:33:34 +00:00
|
|
|
void on_actionExportGraph_triggered();
|
|
|
|
|
2017-12-13 22:38:46 +00:00
|
|
|
private:
|
2017-12-14 21:07:48 +00:00
|
|
|
bool first_draw = true;
|
2017-12-13 22:38:46 +00:00
|
|
|
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
|
2018-03-21 20:32:32 +00:00
|
|
|
CachedFontMetrics *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
|
|
|
|
2018-03-21 20:32:32 +00:00
|
|
|
DisassemblyContextMenu *mMenu;
|
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);
|
2018-10-16 14:49:26 +00:00
|
|
|
void prepareHeader();
|
2018-09-30 20:00:53 +00:00
|
|
|
Token *getToken(Instr *instr, int x);
|
2017-12-19 16:59:39 +00:00
|
|
|
RVA getAddrForMouseEvent(GraphBlock &block, QPoint *point);
|
|
|
|
Instr *getInstrForMouseEvent(GraphBlock &block, QPoint *point);
|
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);
|
2018-05-25 14:30:59 +00:00
|
|
|
CutterSeekableWidget *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 disassemblyTracedColor;
|
|
|
|
QColor disassemblyTracedSelectionColor;
|
|
|
|
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;
|
2018-05-25 14:30:59 +00:00
|
|
|
QAction actionSyncOffset;
|
2018-07-01 11:47:15 +00:00
|
|
|
|
|
|
|
QLabel *emptyText = nullptr;
|
2018-10-16 14:49:26 +00:00
|
|
|
SyntaxHighlighter *highlighter = nullptr;
|
2017-12-13 22:38:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // DISASSEMBLERGRAPHVIEW_H
|