diff options
| author | Josh Ferrell <josh@vector35.com> | 2026-01-26 14:23:12 -0500 |
|---|---|---|
| committer | Josh Ferrell <josh@vector35.com> | 2026-02-06 17:53:45 -0500 |
| commit | 70bbb18a9444824a8ec2b9a7ff57fc848e017b6e (patch) | |
| tree | fe87c0976b75a7557986d1ac6bcc2409a839624c /examples/triage | |
| parent | 9b7604d13e8bd98c6998facb9326926ed96281b5 (diff) | |
Add regex and case sensitivity options to FilterEdit
Diffstat (limited to 'examples/triage')
| -rw-r--r-- | examples/triage/entry.cpp | 9 | ||||
| -rw-r--r-- | examples/triage/entry.h | 4 | ||||
| -rw-r--r-- | examples/triage/exports.cpp | 17 | ||||
| -rw-r--r-- | examples/triage/exports.h | 5 | ||||
| -rw-r--r-- | examples/triage/imports.cpp | 15 | ||||
| -rw-r--r-- | examples/triage/imports.h | 4 | ||||
| -rw-r--r-- | examples/triage/strings.cpp | 31 | ||||
| -rw-r--r-- | examples/triage/strings.h | 10 |
8 files changed, 60 insertions, 35 deletions
diff --git a/examples/triage/entry.cpp b/examples/triage/entry.cpp index addb5960..dfee4a2f 100644 --- a/examples/triage/entry.cpp +++ b/examples/triage/entry.cpp @@ -141,13 +141,14 @@ void GenericEntryModel::sort(int col, Qt::SortOrder order) } -void GenericEntryModel::setFilter(const std::string& filterText) +void GenericEntryModel::setFilter(const std::string& filterText, FilterOptions options) { beginResetModel(); m_entries.clear(); + bool caseSensitive = options.testFlag(FilterOption::CaseSensitiveOption); for (auto& entry : m_allEntries) { - if (FilteredView::match(entry->GetSymbol()->GetFullName(), filterText)) + if (FilteredView::match(entry->GetSymbol()->GetFullName(), filterText, caseSensitive)) m_entries.push_back(entry); } performSort(m_sortCol, m_sortOrder); @@ -250,9 +251,9 @@ void EntryTreeView::entryDoubleClicked(const QModelIndex& cur) } -void EntryTreeView::setFilter(const std::string& filterText) +void EntryTreeView::setFilter(const std::string& filterText, FilterOptions options) { - m_model->setFilter(filterText); + m_model->setFilter(filterText, options); } diff --git a/examples/triage/entry.h b/examples/triage/entry.h index a1396741..013e6793 100644 --- a/examples/triage/entry.h +++ b/examples/triage/entry.h @@ -24,7 +24,7 @@ class GenericEntryModel : public QAbstractItemModel virtual QModelIndex index(int row, int col, const QModelIndex& parent) const override; virtual QModelIndex parent(const QModelIndex& index) const override; virtual void sort(int col, Qt::SortOrder order) override; - void setFilter(const std::string& filterText); + void setFilter(const std::string& filterText, FilterOptions options); FunctionRef getEntry(const QModelIndex& index); }; @@ -46,7 +46,7 @@ class EntryTreeView : public QTreeView, public FilterTarget void copySelection(); bool canCopySelection() const; - virtual void setFilter(const std::string& filterText) override; + virtual void setFilter(const std::string& filterText, FilterOptions options) override; virtual void scrollToFirstItem() override; virtual void scrollToCurrentItem() override; virtual void ensureSelection() override; diff --git a/examples/triage/exports.cpp b/examples/triage/exports.cpp index 776044c5..976be45e 100644 --- a/examples/triage/exports.cpp +++ b/examples/triage/exports.cpp @@ -67,7 +67,7 @@ void GenericExportsModel::updateModel() } endResetModel(); - setFilter(m_filter); + setFilter(m_filter, m_filterOptions); } @@ -225,22 +225,26 @@ void GenericExportsModel::sort(int col, Qt::SortOrder order) } -void GenericExportsModel::setFilter(const std::string& filterText) +void GenericExportsModel::setFilter(const std::string& filterText, FilterOptions options) { m_filter = filterText; + m_filterOptions = options; beginResetModel(); m_entries.clear(); + + bool caseSensitive = options.testFlag(FilterOption::CaseSensitiveOption); for (auto& entry : m_allEntries) { - if (FilteredView::match(entry->GetFullName(), filterText)) + if (FilteredView::match(entry->GetFullName(), filterText, caseSensitive)) m_entries.push_back(entry); - else if (FilteredView::match(std::to_string(entry->GetOrdinal()), filterText)) + else if (FilteredView::match(std::to_string(entry->GetOrdinal()), filterText, caseSensitive)) m_entries.push_back(entry); } performSort(m_sortCol, m_sortOrder); endResetModel(); } + void GenericExportsModel::setNeedsUpdate(bool needed) { if (m_needsUpdate.exchange(needed) == needed) @@ -249,6 +253,7 @@ void GenericExportsModel::setNeedsUpdate(bool needed) updateTimer(needed); } + void GenericExportsModel::updateTimer(bool needsUpdate) { if (needsUpdate && !m_updateTimer->isActive()) @@ -427,9 +432,9 @@ void ExportsTreeView::exportDoubleClicked(const QModelIndex& cur) } -void ExportsTreeView::setFilter(const std::string& filterText) +void ExportsTreeView::setFilter(const std::string& filterText, FilterOptions options) { - m_model->setFilter(filterText); + m_model->setFilter(filterText, options); } diff --git a/examples/triage/exports.h b/examples/triage/exports.h index af0f4613..28c9d53a 100644 --- a/examples/triage/exports.h +++ b/examples/triage/exports.h @@ -13,6 +13,7 @@ class GenericExportsModel : public QAbstractItemModel, public BinaryNinja::Binar BinaryViewRef m_data; std::vector<SymbolRef> m_allEntries, m_entries; std::string m_filter; + FilterOptions m_filterOptions; QTimer* m_updateTimer; Qt::SortOrder m_sortOrder; int m_sortCol; @@ -46,7 +47,7 @@ signals: virtual QModelIndex index(int row, int col, const QModelIndex& parent) const override; virtual QModelIndex parent(const QModelIndex& index) const override; virtual void sort(int col, Qt::SortOrder order) override; - void setFilter(const std::string& filterText); + void setFilter(const std::string& filterText, FilterOptions options); void pauseUpdates(); void resumeUpdates(); @@ -79,7 +80,7 @@ class ExportsTreeView : public QTreeView, public FilterTarget void copySelection(); bool canCopySelection() const; - virtual void setFilter(const std::string& filterText) override; + virtual void setFilter(const std::string& filterText, FilterOptions options) override; virtual void scrollToFirstItem() override; virtual void scrollToCurrentItem() override; virtual void ensureSelection() override; diff --git a/examples/triage/imports.cpp b/examples/triage/imports.cpp index 19c6a62b..54b20bd2 100644 --- a/examples/triage/imports.cpp +++ b/examples/triage/imports.cpp @@ -205,19 +205,20 @@ void GenericImportsModel::sort(int col, Qt::SortOrder order) } -void GenericImportsModel::setFilter(const std::string& filterText) +void GenericImportsModel::setFilter(const std::string& filterText, FilterOptions options) { beginResetModel(); m_entries.clear(); + bool caseSensitive = options.testFlag(FilterOption::CaseSensitiveOption); for (auto& entry : m_allEntries) { - if (FilteredView::match(entry->GetFullName(), filterText)) + if (FilteredView::match(entry->GetFullName(), filterText, caseSensitive)) m_entries.push_back(entry); - else if (FilteredView::match(getNamespace(entry).toStdString(), filterText)) + else if (FilteredView::match(getNamespace(entry).toStdString(), filterText, caseSensitive)) m_entries.push_back(entry); - else if (FilteredView::match(std::to_string(entry->GetOrdinal()), filterText)) + else if (FilteredView::match(std::to_string(entry->GetOrdinal()), filterText, caseSensitive)) m_entries.push_back(entry); - else if (FilteredView::match(getLibrarySource(entry).toStdString(), filterText)) + else if (FilteredView::match(getLibrarySource(entry).toStdString(), filterText, caseSensitive)) m_entries.push_back(entry); } performSort(m_sortCol, m_sortOrder); @@ -325,9 +326,9 @@ void ImportsTreeView::importDoubleClicked(const QModelIndex& cur) } -void ImportsTreeView::setFilter(const std::string& filterText) +void ImportsTreeView::setFilter(const std::string& filterText, FilterOptions options) { - m_model->setFilter(filterText); + m_model->setFilter(filterText, options); } diff --git a/examples/triage/imports.h b/examples/triage/imports.h index 8a2441f7..dde9b06d 100644 --- a/examples/triage/imports.h +++ b/examples/triage/imports.h @@ -28,7 +28,7 @@ class GenericImportsModel : public QAbstractItemModel virtual QModelIndex index(int row, int col, const QModelIndex& parent) const override; virtual QModelIndex parent(const QModelIndex& index) const override; virtual void sort(int col, Qt::SortOrder order) override; - void setFilter(const std::string& filterText); + void setFilter(const std::string& filterText, FilterOptions options); SymbolRef getSymbol(const QModelIndex& index); @@ -55,7 +55,7 @@ class ImportsTreeView : public QTreeView, public FilterTarget void copySelection(); bool canCopySelection() const; - virtual void setFilter(const std::string& filterText) override; + virtual void setFilter(const std::string& filterText, FilterOptions options) override; virtual void scrollToFirstItem() override; virtual void scrollToCurrentItem() override; virtual void ensureSelection() override; diff --git a/examples/triage/strings.cpp b/examples/triage/strings.cpp index 32d9ff97..9ae176a0 100644 --- a/examples/triage/strings.cpp +++ b/examples/triage/strings.cpp @@ -115,16 +115,16 @@ QString GenericStringsModel::stringRefToQString(const BNStringReference& stringR BinaryNinja::DataBuffer stringBuffer = m_data->ReadBuffer(stringRef.start, stringRef.length); if (stringRef.type == BNStringType::Utf32String) - { + { char32_t* data = (char32_t*)stringBuffer.GetData(); qstr = QString::fromUcs4(data, stringRef.length / 4); - } + } else if (stringRef.type == BNStringType::Utf16String) { char16_t* data = (char16_t*)stringBuffer.GetData(); qstr = QString::fromUtf16(data, stringRef.length / 2); } - else + else { char* data = (char*)stringBuffer.GetData(); qstr = QString::fromUtf8(data, stringBuffer.GetLength()); @@ -159,7 +159,7 @@ void GenericStringsModel::performSort(int col, Qt::SortOrder order) return a.length > b.length; } else if (col == 2) - { + { QString s = stringRefToQString(a); QString s2 = stringRefToQString(b); @@ -188,18 +188,31 @@ void GenericStringsModel::applyFilter() m_entries.clear(); for (auto& entry : m_allEntries) { - auto s = stringRefToQString(entry).toStdString(); + auto s = stringRefToQString(entry); + + bool match; + if (m_filterOptions.testFlag(UseRegexOption)) + { + match = m_filterRegex.match(s).hasMatch(); + } + else + { + match = s.contains(m_filter, m_filterOptions.testFlag(CaseSensitiveOption) ? Qt::CaseSensitive : Qt::CaseInsensitive); + } - if (FilteredView::match(s, m_filter)) + if (match) m_entries.push_back(entry); } performSort(m_sortCol, m_sortOrder); } -void GenericStringsModel::setFilter(const std::string& filterText) +void GenericStringsModel::setFilter(const QString& filterText, FilterOptions options) { m_filter = filterText; + m_filterOptions = options; + bool caseSensitive = options.testFlag(CaseSensitiveOption); + m_filterRegex = QRegularExpression(filterText, caseSensitive ? QRegularExpression::NoPatternOption : QRegularExpression::CaseInsensitiveOption); beginResetModel(); applyFilter(); endResetModel(); @@ -412,9 +425,9 @@ void StringsTreeView::stringDoubleClicked(const QModelIndex& cur) } -void StringsTreeView::setFilter(const std::string& filterText) +void StringsTreeView::setFilter(const std::string& filterText, FilterOptions options) { - m_model->setFilter(filterText); + m_model->setFilter(QString::fromStdString(filterText), options); } diff --git a/examples/triage/strings.h b/examples/triage/strings.h index 31617f08..2a28c4f1 100644 --- a/examples/triage/strings.h +++ b/examples/triage/strings.h @@ -14,9 +14,12 @@ class GenericStringsModel : public QAbstractItemModel, public BinaryNinja::Binar std::vector<BNStringReference> m_allEntries, m_entries; int m_totalCols, m_sortCol; Qt::SortOrder m_sortOrder; - std::string m_filter; QTimer* m_updateTimer; + QString m_filter; + FilterOptions m_filterOptions; + QRegularExpression m_filterRegex; + // Read from arbitrary threads while processing notifications. std::atomic<bool> m_updatesPaused = false; // Read/written from arbitrary threads while processing notifications. @@ -46,7 +49,8 @@ signals: virtual QModelIndex index(int row, int col, const QModelIndex& parent) const override; virtual QModelIndex parent(const QModelIndex& index) const override; virtual void sort(int col, Qt::SortOrder order) override; - void setFilter(const std::string& filterText); + + void setFilter(const QString& filterText, FilterOptions options); void pauseUpdates(); void resumeUpdates(); @@ -81,7 +85,7 @@ class StringsTreeView : public QTreeView, public FilterTarget void copySelection(); bool canCopySelection() const; - virtual void setFilter(const std::string& filterText) override; + virtual void setFilter(const std::string& filterText, FilterOptions options) override; virtual void scrollToFirstItem() override; virtual void scrollToCurrentItem() override; virtual void ensureSelection() override; |
