summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Taylor <alex@vector35.com>2025-03-04 08:43:00 -0500
committerAlexander Taylor <alex@vector35.com>2025-03-04 08:43:00 -0500
commit7125b1a3f07fd31acc15d1b24a9cf6917cd9c3fb (patch)
treebd7f25a169f87b0d9d85ad801917222068fb20e5
parentd9f829e739728a1a155e11cc21c7024ae4f78b21 (diff)
Add filtering to BNDB import dialog.
-rw-r--r--ui/bndbimportdialog.h60
1 files changed, 44 insertions, 16 deletions
diff --git a/ui/bndbimportdialog.h b/ui/bndbimportdialog.h
index 37b46f31..64030fbe 100644
--- a/ui/bndbimportdialog.h
+++ b/ui/bndbimportdialog.h
@@ -1,5 +1,7 @@
#pragma once
+#include <QStandardItemModel>
+#include <QSortFilterProxyModel>
#include <QtWidgets/QDialog>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QPushButton>
@@ -9,22 +11,37 @@
#include <QtWidgets/QTreeWidget>
#include <QtWidgets/QCheckBox>
#include <QtGui/QKeyEvent>
-
-#include "uitypes.h"
#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 BackgroundTreeWidget : public QTreeWidget
+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 BackgroundTreeWidget(QWidget *parent);
+ explicit BndbImportTreeView(QWidget *parent);
Q_SIGNALS:
void addressDoubleClicked(uint64_t address);
@@ -33,18 +50,23 @@ protected:
virtual void keyPressEvent(QKeyEvent* event) override;
};
+
/*!
\ingroup uiapi
*/
-class BINARYNINJAUIAPI BndbImportDialog : public QDialog
+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;
- QTreeWidget* m_typesTree;
- QPushButton* m_previewButton;
+ BndbImportTreeView* m_typesTree;
QPushButton* m_importButton;
BinaryViewRef m_data;
@@ -83,16 +105,22 @@ protected:
private:
bool loadTypes();
- bool isExistingType(const BinaryNinja::QualifiedName& name, bool function) const;
- bool isBuiltinType(const BinaryNinja::QualifiedName& name) const;
- 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(QTreeWidgetItem *item, int column);
- bool inSymbolBlackList(const SymbolRef sym);
-public:
+ 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;
};