Skip to content

Commit 2af5f74

Browse files
committed
Refactor strings view to support derived strings
1 parent b665c8c commit 2af5f74

File tree

3 files changed

+50
-12
lines changed

3 files changed

+50
-12
lines changed

ui/stringsview.h

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,36 @@
1818
\ingroup uiapi
1919
*/
2020

21+
class StringsListItem
22+
{
23+
std::variant<BNStringReference, BinaryNinja::DerivedString> m_contents;
24+
25+
public:
26+
StringsListItem(const BNStringReference& ref): m_contents(ref) {}
27+
StringsListItem(const BinaryNinja::DerivedString& str): m_contents(str) {}
28+
29+
bool IsStringReference() const { return std::holds_alternative<BNStringReference>(m_contents); }
30+
bool IsDerivedString() const { return std::holds_alternative<BinaryNinja::DerivedString>(m_contents); }
31+
std::optional<BNStringReference> GetStringReference() const;
32+
std::optional<BinaryNinja::DerivedString> GetDerivedString() const;
33+
34+
std::optional<uint64_t> GetStartAddress() const;
35+
BNDerivedStringLocationType GetLocationType() const;
36+
uint64_t GetDataLength() const;
37+
size_t GetCharacterLength() const;
38+
std::optional<BNStringType> GetStringType() const;
39+
QString GetStringTypeName() const;
40+
std::optional<BinaryNinja::StringRef> GetStringRef() const;
41+
42+
QString GetString(BinaryViewRef data, bool simplified) const;
43+
44+
std::optional<uint64_t> GetReferenceCount(const std::map<uint64_t, uint64_t>& refs,
45+
const std::map<BinaryNinja::DerivedString, uint64_t>& derivedRefs) const;
46+
47+
bool operator==(const StringsListItem& other) const;
48+
bool operator!=(const StringsListItem& other) const;
49+
};
50+
2151
/*!
2252
2353
\ingroup stringsview
@@ -28,15 +58,16 @@ class BINARYNINJAUIAPI StringsListModel : public QAbstractItemModel, public Bina
2858

2959
struct StringUpdateEvent
3060
{
31-
BNStringReference ref;
61+
StringsListItem item;
3262
bool added;
3363
};
3464

3565
QWidget* m_stringsList;
3666
BinaryViewRef m_data;
37-
std::vector<BNStringReference> m_allStrings;
38-
std::vector<BNStringReference> m_strings;
67+
std::vector<StringsListItem> m_allStrings;
68+
std::vector<StringsListItem> m_strings;
3969
std::map<uint64_t, uint64_t> m_refCounts;
70+
std::map<BinaryNinja::DerivedString, uint64_t> m_derivedRefCounts;
4071
std::string m_filter;
4172

4273
size_t m_filteredByOptions;
@@ -48,8 +79,8 @@ class BINARYNINJAUIAPI StringsListModel : public QAbstractItemModel, public Bina
4879
bool m_includeOnlyReferenced;
4980
bool m_includeOnlyFromCurrentFunction;
5081

51-
static bool stringComparison(const BNStringReference& a, const BNStringReference& b);
52-
bool matchString(const BNStringReference& stringRef);
82+
static bool stringComparison(const StringsListItem& a, const StringsListItem& b);
83+
bool matchString(const StringsListItem& item);
5384

5485
std::vector<StringUpdateEvent> getQueuedStringUpdates();
5586

@@ -74,8 +105,8 @@ class BINARYNINJAUIAPI StringsListModel : public QAbstractItemModel, public Bina
74105
virtual QVariant data(const QModelIndex& i, int role) const override;
75106
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
76107

77-
BNStringReference getStringAt(const QModelIndex& i);
78-
QModelIndex findString(const BNStringReference& ref);
108+
StringsListItem getStringAt(const QModelIndex& i);
109+
QModelIndex findString(const StringsListItem& item);
79110

80111
virtual void OnStringFound(BinaryNinja::BinaryView* data, BNStringType type, uint64_t offset, size_t len) override;
81112
virtual void OnStringRemoved(BinaryNinja::BinaryView* data, BNStringType type, uint64_t offset, size_t len) override;
@@ -147,15 +178,18 @@ class BINARYNINJAUIAPI StringsView : public QTableView, public View, public Filt
147178
StringsListModel* m_list;
148179
StringItemDelegate* m_itemDelegate;
149180

181+
bool m_selectionAddrValid = false;
150182
uint64_t m_selectionBegin, m_selectionEnd;
151183
uint64_t m_currentlySelectedDataAddress;
184+
std::optional<BinaryNinja::DerivedString> m_derivedString;
152185

153186
public:
154187
StringsView(BinaryViewRef data, StringsContainer* container);
155188

156189
virtual BinaryViewRef getData() override { return m_data; }
157190
virtual uint64_t getCurrentOffset() override;
158191
virtual BNAddressRange getSelectionOffsets() override;
192+
virtual SelectionInfoForXref getSelectionForXref() override;
159193
virtual void setSelectionOffsets(BNAddressRange range) override;
160194
virtual bool navigate(uint64_t offset) override;
161195

ui/uitypes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
// there are changes to the API that affect linking, including new functions,
77
// new types, modifications to existing functions or types, or new versions
88
// of the Qt libraries.
9-
#define BN_CURRENT_UI_ABI_VERSION 11
9+
#define BN_CURRENT_UI_ABI_VERSION 12
1010

1111
// Minimum ABI version that is supported for loading of plugins. Plugins that
1212
// are linked to an ABI version less than this will not be able to load and
1313
// will require rebuilding. The minimum version is increased when there are
1414
// incompatible changes that break binary compatibility, such as changes to
1515
// existing types or functions, or a new version of Qt.
16-
#define BN_MINIMUM_UI_ABI_VERSION 11
16+
#define BN_MINIMUM_UI_ABI_VERSION 12
1717

1818
#ifdef __GNUC__
1919
#ifdef BINARYNINJAUI_LIBRARY

ui/viewframe.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct BINARYNINJAUIAPI SelectionInfoForXref
3232
// Check these booleans before accessing the address/type/variable info,
3333
// since the invalid fields are not guaranteed to be initialized/zero-ed.
3434
// At any given time, at most one of these four should be true.
35-
bool addrValid, typeValid, typeFieldValid, localVarValid;
35+
bool addrValid, typeValid, typeFieldValid, localVarValid, derivedStringValid;
3636

3737
BNFunctionGraphType ilSource = InvalidILViewType;
3838

@@ -48,7 +48,9 @@ struct BINARYNINJAUIAPI SelectionInfoForXref
4848
FunctionRef func;
4949
ArchitectureRef arch;
5050

51-
SelectionInfoForXref() : addrValid(false), typeValid(false), typeFieldValid(false), localVarValid(false) { }
51+
BinaryNinja::DerivedString derivedString;
52+
53+
SelectionInfoForXref() : addrValid(false), typeValid(false), typeFieldValid(false), localVarValid(false), derivedStringValid(false) { }
5254

5355
bool operator==(const SelectionInfoForXref& other) const
5456
{
@@ -60,11 +62,13 @@ struct BINARYNINJAUIAPI SelectionInfoForXref
6062
return (type == other.type) && (offset == other.offset);
6163
else if (localVarValid && other.localVarValid)
6264
return (var == other.var) && (ilSource == other.ilSource);
65+
else if (derivedStringValid && other.derivedStringValid)
66+
return derivedString == other.derivedString;
6367
return false;
6468
}
6569

6670
bool operator!=(const SelectionInfoForXref& other) const { return !(*this == other); }
67-
bool isValid() const { return addrValid || typeValid || typeFieldValid || localVarValid; }
71+
bool isValid() const { return addrValid || typeValid || typeFieldValid || localVarValid || derivedStringValid; }
6872
};
6973

7074
/*!

0 commit comments

Comments
 (0)