summaryrefslogtreecommitdiff
path: root/binaryview.cpp
diff options
context:
space:
mode:
authorRusty Wagner <rusty.wagner@gmail.com>2025-10-13 19:35:01 -0400
committerRusty Wagner <rusty.wagner@gmail.com>2025-10-21 13:52:39 -0400
commit5d4fc5f1fb7a0c368d2a048a5d750564c970c9c9 (patch)
treecd740b4af25fe5184935fd67067025733f17b099 /binaryview.cpp
parentcae26921cf2b2e564f66e58b77a3963fe36f6d2d (diff)
Add derived strings and string recognizer API
Diffstat (limited to 'binaryview.cpp')
-rw-r--r--binaryview.cpp58
1 files changed, 57 insertions, 1 deletions
diff --git a/binaryview.cpp b/binaryview.cpp
index 292b11ac..3499f2ac 100644
--- a/binaryview.cpp
+++ b/binaryview.cpp
@@ -222,6 +222,22 @@ void BinaryDataNotification::StringRemovedCallback(
}
+void BinaryDataNotification::DerivedStringFoundCallback(void* ctxt, BNBinaryView* data, BNDerivedString* str)
+{
+ BinaryDataNotification* notify = (BinaryDataNotification*)ctxt;
+ Ref<BinaryView> view = new BinaryView(BNNewViewReference(data));
+ notify->OnDerivedStringFound(view, DerivedString::FromAPIObject(str, false));
+}
+
+
+void BinaryDataNotification::DerivedStringRemovedCallback(void* ctxt, BNBinaryView* data, BNDerivedString* str)
+{
+ BinaryDataNotification* notify = (BinaryDataNotification*)ctxt;
+ Ref<BinaryView> view = new BinaryView(BNNewViewReference(data));
+ notify->OnDerivedStringRemoved(view, DerivedString::FromAPIObject(str, false));
+}
+
+
void BinaryDataNotification::TypeDefinedCallback(void* ctxt, BNBinaryView* data, BNQualifiedName* name, BNType* type)
{
BinaryDataNotification* notify = (BinaryDataNotification*)ctxt;
@@ -556,6 +572,8 @@ BinaryDataNotification::BinaryDataNotification()
m_callbacks.symbolRemoved = SymbolRemovedCallback;
m_callbacks.stringFound = StringFoundCallback;
m_callbacks.stringRemoved = StringRemovedCallback;
+ m_callbacks.derivedStringFound = DerivedStringFoundCallback;
+ m_callbacks.derivedStringRemoved = DerivedStringRemovedCallback;
m_callbacks.typeDefined = TypeDefinedCallback;
m_callbacks.typeUndefined = TypeUndefinedCallback;
m_callbacks.typeReferenceChanged = TypeReferenceChangedCallback;
@@ -615,6 +633,8 @@ BinaryDataNotification::BinaryDataNotification(NotificationTypes notifications)
m_callbacks.symbolRemoved = (notifications & NotificationType::SymbolRemoved) ? SymbolRemovedCallback : nullptr;
m_callbacks.stringFound = (notifications & NotificationType::StringFound) ? StringFoundCallback : nullptr;
m_callbacks.stringRemoved = (notifications & NotificationType::StringRemoved) ? StringRemovedCallback : nullptr;
+ m_callbacks.derivedStringFound = (notifications & NotificationType::DerivedStringFound) ? DerivedStringFoundCallback : nullptr;
+ m_callbacks.derivedStringRemoved = (notifications & NotificationType::DerivedStringRemoved) ? DerivedStringRemovedCallback : nullptr;
m_callbacks.typeDefined = (notifications & NotificationType::TypeDefined) ? TypeDefinedCallback : nullptr;
m_callbacks.typeUndefined = (notifications & NotificationType::TypeUndefined) ? TypeUndefinedCallback : nullptr;
m_callbacks.typeReferenceChanged = (notifications & NotificationType::TypeReferenceChanged) ? TypeReferenceChangedCallback : nullptr;
@@ -670,7 +690,7 @@ StringRef::StringRef(const std::string& str)
StringRef::StringRef(const StringRef& other)
{
- m_ref = BNDuplicateStringRef(other.m_ref);
+ m_ref = other.m_ref ? BNDuplicateStringRef(other.m_ref) : nullptr;
}
@@ -4013,6 +4033,42 @@ vector<BNStringReference> BinaryView::GetStrings(uint64_t start, uint64_t len)
}
+vector<DerivedString> BinaryView::GetDerivedStrings()
+{
+ size_t count;
+ BNDerivedString* strings = BNGetDerivedStrings(m_object, &count);
+ vector<DerivedString> result;
+ for (size_t i = 0; i < count; i++)
+ result.push_back(DerivedString::FromAPIObject(&strings[i], false));
+ BNFreeDerivedStringList(strings, count);
+ return result;
+}
+
+
+vector<ReferenceSource> BinaryView::GetDerivedStringCodeReferences(
+ const DerivedString& str, std::optional<size_t> maxItems)
+{
+ BNDerivedString derivedStr = str.ToAPIObject(false);
+
+ size_t count;
+ BNReferenceSource* refs = BNGetDerivedStringCodeReferences(
+ m_object, &derivedStr, &count, maxItems.has_value(), maxItems.value_or(0));
+ vector<ReferenceSource> result;
+ result.reserve(count);
+ for (size_t i = 0; i < count; i++)
+ {
+ ReferenceSource src;
+ src.func = new Function(BNNewFunctionReference(refs[i].func));
+ src.arch = new CoreArchitecture(refs[i].arch);
+ src.addr = refs[i].addr;
+ result.push_back(src);
+ }
+
+ BNFreeCodeReferences(refs, count);
+ return result;
+}
+
+
// The caller of this function must hold a reference to the returned Ref<AnalysisCompletionEvent>.
// Otherwise, it can be freed before the callback is triggered, leading to a crash.
Ref<AnalysisCompletionEvent> BinaryView::AddAnalysisCompletionEvent(const function<void()>& callback)