From fcfa33a14fc309984880b535b9f9b4fcfc316466 Mon Sep 17 00:00:00 2001 From: kat Date: Tue, 3 Jan 2023 14:29:32 -0500 Subject: Allow DataVariables to be added to Components --- binaryview.cpp | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) (limited to 'binaryview.cpp') 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 view = new BinaryView(BNNewViewReference(data)); + Ref component = new Component(BNNewComponentReference(bnComponent)); + DataVariable varObj(var->address, + Confidence>(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 view = new BinaryView(BNNewViewReference(data)); + Ref component = new Component(BNNewComponentReference(bnComponent)); + DataVariable varObj(var->address, + Confidence>(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> BinaryView::GetFunctionParentComponents(Ref function) const +{ + std::vector> 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 = new Component(BNNewComponentReference(list[i])); + components.push_back(component); + } + + BNFreeComponents(list, count); + + return components; +} + + +std::vector> BinaryView::GetDataVariableParentComponents(DataVariable var) const +{ + std::vector> 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 = 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()); -- cgit v1.3.1