forked from Vector35/binaryninja-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbndbimportdialog.h
126 lines (101 loc) · 3.08 KB
/
bndbimportdialog.h
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
#pragma once
#include <QStandardItemModel>
#include <QSortFilterProxyModel>
#include <QtWidgets/QDialog>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QTextEdit>
#include <QtWidgets/QSplitter>
#include <QtWidgets/QTextBrowser>
#include <QtWidgets/QTreeWidget>
#include <QtWidgets/QCheckBox>
#include <QtGui/QKeyEvent>
#include "binaryninjaapi.h"
#include "filter.h"
#include "uitypes.h"
constexpr int IndexRole = Qt::UserRole;
constexpr int ItemRole = Qt::UserRole + 1;
constexpr int LocationRole = Qt::UserRole + 2;
constexpr int IndexColumn = 0;
constexpr int NameColumn = 1;
constexpr int LocationColumn = 2;
class BndbImportFilterProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
protected:
bool filterAcceptsRow(int sourceRow, const QModelIndex& sourceParent) const override;
public:
BndbImportFilterProxyModel(QObject* parent = nullptr) : QSortFilterProxyModel(parent) {}
void updateFilter();
};
class BndbImportTreeView : public QTreeView
{
Q_OBJECT
public:
explicit BndbImportTreeView(QWidget *parent);
Q_SIGNALS:
void addressDoubleClicked(uint64_t address);
protected:
virtual void keyPressEvent(QKeyEvent* event) override;
};
/*!
\ingroup uiapi
*/
class BINARYNINJAUIAPI BndbImportDialog : public QDialog, public FilterTarget
{
Q_OBJECT
FilteredView* m_filteredView;
QWidget* m_filterWidget;
QStandardItemModel* m_model;
BndbImportFilterProxyModel* m_filterModel;
QLineEdit* m_fileEdit;
QPushButton* m_browseButton;
QWidget* m_resultsWidget;
BndbImportTreeView* m_typesTree;
QPushButton* m_importButton;
BinaryViewRef m_data;
std::string m_filePath;
struct SymbolAndType
{
SymbolAndType(SymbolRef name, TypeRef type): name(name), type(type) {}
SymbolRef name;
TypeRef type;
};
std::vector<BinaryNinja::QualifiedNameAndType> m_types;
std::vector<SymbolAndType> m_functions;
std::vector<SymbolAndType> m_functionsToImports;
std::vector<SymbolAndType> m_dataVariables;
enum ItemType {
TypeItem,
FunctionItem,
FunctionToImportItem,
DataVariableItem
};
BinaryViewRef m_incomingView;
LoggerRef m_logger;
protected Q_SLOTS:
void browseFile();
void updateButtons();
void previewTypes();
void importTypes();
protected:
virtual void keyPressEvent(QKeyEvent* event) override;
private:
bool loadTypes();
static bool isBuiltinType(const BinaryNinja::QualifiedName& name);
static bool inSymbolBlackList(const SymbolRef sym);
void applyFunctionTypes(const std::vector<SymbolAndType>& functions);
void applyFunctionTypesToImports(const std::vector<SymbolAndType>& functions);
void applyDataVariables(const std::vector<SymbolAndType>& dataVariables);
std::vector<SymbolRef> matchingSymbol(const SymbolRef& sym, std::vector<BNSymbolType> allowed, bool allowPrefix);
void navigateToItem(const QModelIndex& index);
public:
BndbImportDialog(QWidget* parent, BinaryViewRef view);
~BndbImportDialog() = default;
void setFilter(const std::string& filter) override;
void scrollToFirstItem() override;
void scrollToCurrentItem() override;
void selectFirstItem() override;
void activateFirstItem() override;
void closeFilter() override;
};