-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathdebuggerinfowidget.h
More file actions
191 lines (142 loc) · 6.23 KB
/
debuggerinfowidget.h
File metadata and controls
191 lines (142 loc) · 6.23 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*
Copyright 2020-2025 Vector 35 Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#pragma once
#include <QAbstractItemModel>
#include <QItemSelectionModel>
#include <QModelIndex>
#include <QTableView>
#include <QStyledItemDelegate>
#include "inttypes.h"
#include "binaryninjaapi.h"
#include "viewframe.h"
#include "fontsettings.h"
#include "theme.h"
#include "render.h"
//#include "globalarea.h"
#include "debuggerapi.h"
using namespace BinaryNinjaDebuggerAPI;
using namespace BinaryNinja;
using namespace std;
enum ColumnHeaders
{
ExprColumn,
StorageColumn, // Moved to second position
ValueColumn,
HintColumn,
};
struct DebuggerInfoEntry
{
std::vector<InstructionTextToken> tokens;
intx::uint512 value;
std::string hints;
size_t instrIndex;
size_t operandIndex;
uint64_t address;
uint64_t storageAddress; // For stack entries, this will be the actual stack address
bool isStackEntry; // Flag to identify stack entries
DebuggerInfoEntry(const std::vector<InstructionTextToken>& t, intx::uint512 v, const std::string& h, size_t i, size_t o,
uint64_t a, uint64_t sa = 0, bool stack = false):
tokens(t), value(v), hints(h), instrIndex(i), operandIndex(o), address(a), storageAddress(sa), isStackEntry(stack)
{}
};
class DebuggerInfoEntryItemModel : public QAbstractTableModel
{
std::vector<DebuggerInfoEntry> m_infoEntries;
FileMetadataRef m_file;
std::vector<BinaryViewRef> m_views;
QSettings m_settings;
public:
DebuggerInfoEntryItemModel(QWidget* parent, BinaryViewRef data);
~DebuggerInfoEntryItemModel();
virtual QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override;
virtual QModelIndex parent(const QModelIndex& child) const override;
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const override;
virtual int columnCount(const QModelIndex& parent = QModelIndex()) const override;
virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
void updateRows(std::vector<DebuggerInfoEntry>& newRows);
virtual QVariant headerData(int column, Qt::Orientation orientation, int role) const override;
DebuggerInfoEntry getRow(int row) const;
};
class DebuggerInfoEntryItemDelegate : public QStyledItemDelegate
{
Q_OBJECT
QFont m_font;
int m_baseline, m_charWidth, m_charHeight, m_charOffset;
RenderContext m_render;
public:
DebuggerInfoEntryItemDelegate(QWidget* parent = nullptr);
void updateFonts();
QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& idx) const override;
virtual void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
};
class DebuggerInfoTable : public QTableView
{
Q_OBJECT;
DebuggerInfoEntryItemModel* m_model;
DebuggerInfoEntryItemDelegate* m_itemDelegate;
BinaryViewRef m_data;
DebuggerControllerRef m_debugger;
int m_stackEntryCount; // Number of stack entries to display
ViewLocation m_currentLocation; // Store current location for context menu updates
std::vector<DebuggerInfoEntry> getILInfoEntries(const ViewLocation& location);
std::vector<DebuggerInfoEntry> getInfoForLLIL(LowLevelILFunctionRef llil, const LowLevelILInstruction& instr);
std::vector<DebuggerInfoEntry> getInfoForLLILCalls(LowLevelILFunctionRef llil, const LowLevelILInstruction& instr);
std::vector<DebuggerInfoEntry> getInfoForLLILConditions(LowLevelILFunctionRef llil, const LowLevelILInstruction& instr);
std::vector<DebuggerInfoEntry> getInfoForMLIL(MediumLevelILFunctionRef mlil, const MediumLevelILInstruction& instr);
std::vector<DebuggerInfoEntry> getInfoForMLILCalls(MediumLevelILFunctionRef mlil, const MediumLevelILInstruction& instr);
std::vector<DebuggerInfoEntry> getInfoForMLILConditions(MediumLevelILFunctionRef mlil, const MediumLevelILInstruction& instr);
std::vector<DebuggerInfoEntry> getInfoForHLIL(HighLevelILFunctionRef hlil, const HighLevelILInstruction& instr);
std::vector<DebuggerInfoEntry> getInfoForHLILCalls(HighLevelILFunctionRef hlil, const HighLevelILInstruction& instr);
std::vector<DebuggerInfoEntry> getInfoForHLILConditions(HighLevelILFunctionRef hlil, const HighLevelILInstruction& instr);
std::vector<DebuggerInfoEntry> getStackInfo(const ViewLocation& location);
void updateColumnWidths();
protected:
virtual void contextMenuEvent(QContextMenuEvent* event) override;
private slots:
void onDoubleClicked(const QModelIndex& index);
void increaseStackEntries();
void decreaseStackEntries();
public:
DebuggerInfoTable(BinaryViewRef data);
void updateFonts();
void updateContents(const ViewLocation& location);
};
class DebugInfoSidebarWidget : public SidebarWidget
{
Q_OBJECT
DebuggerInfoTable* m_entryList;
QWidget* m_header;
BinaryViewRef m_data;
DebuggerControllerRef m_debugger;
// virtual void contextMenuEvent(QContextMenuEvent*) override;
virtual void notifyViewLocationChanged(View* /*view*/, const ViewLocation& /*viewLocation*/) override;
void itemDoubleClicked(const QModelIndex& index);
void scrollBarValueChanged(int value);
void scrollBarRangeChanged(int min, int max);
void resetToSelectedEntry(ProgressFunction progress);
public:
DebugInfoSidebarWidget(BinaryViewRef data);
~DebugInfoSidebarWidget();
void notifyFontChanged() override;
// QWidget* headerWidget() override { return m_header; }
};
class DebugInfoWidgetType : public SidebarWidgetType
{
public:
DebugInfoWidgetType();
SidebarWidget* createWidget(ViewFrame* frame, BinaryViewRef data) override;
SidebarWidgetLocation defaultLocation() const override { return SidebarWidgetLocation::RightBottom; }
SidebarContextSensitivity contextSensitivity() const override { return PerViewTypeSidebarContext; }
SidebarIconVisibility defaultIconVisibility() const override { return HideSidebarIconIfNoContent; }
SidebarContentClassifier* contentClassifier(ViewFrame*, BinaryViewRef) override;
};