summaryrefslogtreecommitdiff
path: root/binaryview.cpp
diff options
context:
space:
mode:
authorkat <kat@vector35.com>2023-01-03 14:29:32 -0500
committerkat <kat@vector35.com>2023-02-20 13:23:31 -0500
commitfcfa33a14fc309984880b535b9f9b4fcfc316466 (patch)
tree0d2b1c62e9939d357a508a446f440541709625e4 /binaryview.cpp
parent982d90f20e400c7fe7b254eee31fe7eca4e11c2c (diff)
Allow DataVariables to be added to Components
Diffstat (limited to 'binaryview.cpp')
-rw-r--r--binaryview.cpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/binaryview.cpp b/binaryview.cpp
index 52fd3dd3..eeef5a74 100644
--- a/binaryview.cpp
+++ b/binaryview.cpp
@@ -376,6 +376,30 @@ void BinaryDataNotification::ComponentFunctionRemovedCallback(void* ctxt, BNBina
+void BinaryDataNotification::ComponentDataVariableAddedCallback(void* ctxt, BNBinaryView* data, BNComponent* bnComponent,
+ BNDataVariable* var)
+{
+ BinaryDataNotification* notify = (BinaryDataNotification*)ctxt;
+ Ref<BinaryView> view = new BinaryView(BNNewViewReference(data));
+ Ref<Component> component = new Component(BNNewComponentReference(bnComponent));
+ DataVariable varObj(var->address,
+ Confidence<Ref<Type>>(new Type(BNNewTypeReference(var->type)), var->typeConfidence), var->autoDiscovered);
+ notify->OnComponentDataVariableAdded(view, component, varObj);
+}
+
+
+void BinaryDataNotification::ComponentDataVariableRemovedCallback(void* ctxt, BNBinaryView* data,
+ BNComponent* bnComponent, BNDataVariable* var)
+{
+ BinaryDataNotification* notify = (BinaryDataNotification*)ctxt;
+ Ref<BinaryView> view = new BinaryView(BNNewViewReference(data));
+ Ref<Component> component = new Component(BNNewComponentReference(bnComponent));
+ DataVariable varObj(var->address,
+ Confidence<Ref<Type>>(new Type(BNNewTypeReference(var->type)), var->typeConfidence), var->autoDiscovered);
+ notify->OnComponentDataVariableRemoved(view, component, varObj);
+}
+
+
BinaryDataNotification::BinaryDataNotification()
{
m_callbacks.context = this;
@@ -415,6 +439,8 @@ BinaryDataNotification::BinaryDataNotification()
m_callbacks.componentMoved = ComponentMovedCallback;
m_callbacks.componentFunctionAdded = ComponentFunctionAddedCallback;
m_callbacks.componentFunctionRemoved = ComponentFunctionRemovedCallback;
+ m_callbacks.componentDataVariableAdded = ComponentDataVariableAddedCallback;
+ m_callbacks.componentDataVariableRemoved = ComponentDataVariableRemovedCallback;
}
@@ -3094,6 +3120,46 @@ bool BinaryView::RemoveComponent(std::string guid)
}
+std::vector<Ref<Component>> BinaryView::GetFunctionParentComponents(Ref<Function> function) const
+{
+ std::vector<Ref<Component>> components;
+
+ size_t count;
+ BNComponent** list = BNGetFunctionParentComponents(m_object, function->m_object, &count);
+
+ components.reserve(count);
+ for (size_t i = 0; i < count; i++)
+ {
+ Ref<Component> component = new Component(BNNewComponentReference(list[i]));
+ components.push_back(component);
+ }
+
+ BNFreeComponents(list, count);
+
+ return components;
+}
+
+
+std::vector<Ref<Component>> BinaryView::GetDataVariableParentComponents(DataVariable var) const
+{
+ std::vector<Ref<Component>> components;
+
+ size_t count;
+ BNComponent** list = BNGetDataVariableParentComponents(m_object, var.address, &count);
+
+ components.reserve(count);
+ for (size_t i = 0; i < count; i++)
+ {
+ Ref<Component> component = new Component(BNNewComponentReference(list[i]));
+ components.push_back(component);
+ }
+
+ BNFreeComponents(list, count);
+
+ return components;
+}
+
+
bool BinaryView::CanAssemble(Architecture* arch)
{
return BNCanAssemble(m_object, arch->GetObject());