1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
#pragma once
#include <QtGui/QPainter>
#include "binaryninjaapi.h"
#include "uicontext.h"
#include "action.h"
enum HexEditorHighlightMode
{
NoHighlight,
ColumnHighlight,
ByteValueHighlight
};
enum HexEditorColorMode
{
NoColorization,
AsciiColorization,
ModificationColorization
};
enum HexEditorHighlightContrast
{
NormalContrastHighlight,
MediumContrastHighlight,
HighContrastHighlight
};
struct BINARYNINJAUIAPI HexEditorHighlightState
{
HexEditorHighlightMode mode;
HexEditorColorMode color;
HexEditorHighlightContrast contrast;
void restoreSettings();
void saveSettings();
};
class BINARYNINJAUIAPI FontParameters
{
QWidget* m_owner;
QFont m_font, m_emojiFont;
int m_baseline, m_charWidth, m_charHeight, m_charOffset;
float m_fontScale;
bool m_customFont;
public:
FontParameters(QWidget* parent, float fontScale = 1.0f);
void update();
QFont& getFont() { return m_font; }
QFont& getEmojiFont() { return m_emojiFont; }
void setFont(const QFont& font);
void setEmojiFont(const QFont& emojiFont);
int getBaseline() const { return m_baseline; }
int getWidth() const { return m_charWidth; }
int getHeight() const { return m_charHeight; }
int getOffset() const { return m_charOffset; }
};
class BINARYNINJAUIAPI RenderContext
{
QWidget* m_owner;
FontParameters m_fontParams;
bool m_drawIndents;
public:
RenderContext(QWidget* parent, float fontScale = 1.0f);
void update();
FontParameters& getFontParamters() { return m_fontParams; }
int getFontWidth() const { return m_fontParams.getWidth(); }
int getFontHeight() const { return m_fontParams.getHeight(); }
void init(QPainter& p);
QColor getColorForHexDumpByte(
const HexEditorHighlightState& state, BNModificationStatus modification, uint8_t byte);
QColor getHighlightColor(BNHighlightColor color);
HighlightTokenState getTokenForDisassemblyLinePosition(
int64_t col, const std::vector<BinaryNinja::InstructionTextToken>& tokens);
HighlightTokenState getTokenForDisassemblyTokenIndex(
size_t tokenIndex, const std::vector<BinaryNinja::InstructionTextToken>& tokens);
HighlightTokenState getHighlightTokenForTextToken(const BinaryNinja::InstructionTextToken& token);
void drawText(QPainter& p, int x, int y, QColor color, const QString& text);
void drawUnderlinedText(QPainter& p, int x, int y, QColor color, const QString& text);
void drawSeparatorLine(QPainter& p, QColor top, QColor bottom, QColor line, const QRect& rect);
void drawInstructionHighlight(QPainter& p, const QRect& rect);
void drawLinearDisassemblyLineBackground(
QPainter& p, BNLinearDisassemblyLineType type, const QRect& rect, int gutterWidth);
void drawDisassemblyLine(QPainter& p, int left, int top,
const std::vector<BinaryNinja::InstructionTextToken>& tokens, HighlightTokenState& highlight,
bool highlightOnly = false);
void drawHexEditorLine(QPainter& p, int left, int top, const HexEditorHighlightState& highlight, BinaryViewRef view,
uint64_t lineStartAddr, size_t cols, size_t firstCol, size_t count, bool cursorVisible, bool cursorAscii,
size_t cursorPos, bool byteCursor);
QFont getFont() { return m_fontParams.getFont(); }
QFont getEmojiFont() { return m_fontParams.getEmojiFont(); }
void setFont(const QFont& font);
};
|