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
|
//
// Created by kat on 8/15/24.
//
#include <binaryninjaapi.h>
#include <QStyledItemDelegate>
#include "uitypes.h"
#include "viewframe.h"
#include "animation.h"
#include "uicontext.h"
#include "filter.h"
#include "symboltable.h"
#ifndef BINARYNINJA_DSCTRIAGE_H
#define BINARYNINJA_DSCTRIAGE_H
class FilterableTableView : public QTableView, public FilterTarget {
Q_OBJECT
bool m_filterByHiding;
public:
explicit FilterableTableView(QWidget* parent = nullptr, bool filterByHiding = true)
: QTableView(parent), m_filterByHiding(filterByHiding) {
viewport()->installEventFilter(this);
}
~FilterableTableView() override = default;
void setFilter(const std::string& filter) override {
if (!m_filterByHiding)
{
emit filterTextChanged(QString::fromStdString(filter));
return;
}
QString qFilter = QString::fromStdString(filter);
for (int row = 0; row < model()->rowCount(); ++row) {
bool match = false;
for (int col = 0; col < model()->columnCount(); ++col) {
QModelIndex index = model()->index(row, col);
QString data = model()->data(index).toString();
if (data.contains(qFilter, Qt::CaseInsensitive)) {
match = true;
break;
}
}
setRowHidden(row, !match);
}
}
void scrollToFirstItem() override {
if (model()->rowCount() > 0) {
scrollTo(model()->index(0, 0));
}
}
void scrollToCurrentItem() override {
QModelIndex currentIndex = selectionModel()->currentIndex();
if (currentIndex.isValid()) {
scrollTo(currentIndex);
}
}
void selectFirstItem() override {
if (model()->rowCount() > 0) {
QModelIndex firstIndex = model()->index(0, 0);
selectionModel()->select(firstIndex, QItemSelectionModel::ClearAndSelect);
}
}
void activateFirstItem() override {
if (model()->rowCount() > 0) {
QModelIndex firstIndex = model()->index(0, 0);
setCurrentIndex(firstIndex);
emit activated(firstIndex);
}
}
bool eventFilter(QObject* obj, QEvent* event) override {
if (event->type() == QEvent::KeyPress) {
QKeyEvent* keyEvent = static_cast<QKeyEvent*>(event);
if (keyEvent->key() == Qt::Key_Escape) {
clearSelection();
return true;
}
if (keyEvent->key() == Qt::Key_Enter || keyEvent->key() == Qt::Key_Return) {
emit activated(currentIndex());
return true;
}
}
return QTableView::eventFilter(obj, event);
}
signals:
void filterTextChanged(const QString& text);
};
class DSCTriageView : public QWidget, public View, public UIContextNotification
{
BinaryViewRef m_data;
QVBoxLayout* m_layout;
SplitTabWidget* m_triageTabs;
DockableTabCollection* m_triageCollection;
QStandardItemModel* m_imageModel;
SymbolTableView* m_symbolTable;
QStandardItemModel* m_mappingModel;
QStandardItemModel* m_regionModel;
public:
DSCTriageView(QWidget* parent, BinaryViewRef data);
~DSCTriageView() override;
BinaryViewRef getData() override;
void setSelectionOffsets(BNAddressRange range) override {};
QFont getFont() override;
bool navigate(uint64_t offset) override;
uint64_t getCurrentOffset() override;
void OnAfterOpenFile(UIContext* context, FileContext* file, ViewFrame* frame) override;
void RefreshData();
void setImageLoaded(uint64_t imageHeaderAddr);
};
class DSCTriageViewType : public ViewType
{
public:
DSCTriageViewType();
int getPriority(BinaryViewRef data, const QString& filename) override;
QWidget* create(BinaryViewRef data, ViewFrame* viewFrame) override;
static void Register();
};
#endif // BINARYNINJA_DSCTRIAGE_H
|