diff options
| author | kat <kat@vector35.com> | 2023-01-03 14:29:32 -0500 |
|---|---|---|
| committer | kat <kat@vector35.com> | 2023-02-20 13:23:31 -0500 |
| commit | fcfa33a14fc309984880b535b9f9b4fcfc316466 (patch) | |
| tree | 0d2b1c62e9939d357a508a446f440541709625e4 /python/binaryview.py | |
| parent | 982d90f20e400c7fe7b254eee31fe7eca4e11c2c (diff) | |
Allow DataVariables to be added to Components
Diffstat (limited to 'python/binaryview.py')
| -rw-r--r-- | python/binaryview.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/python/binaryview.py b/python/binaryview.py index 8005630b..0ca357a4 100644 --- a/python/binaryview.py +++ b/python/binaryview.py @@ -252,6 +252,12 @@ class BinaryDataNotification: func: '_function.Function'): pass + def component_data_var_added(self, view: 'BinaryView', _component: component.Component, var: 'DataVariable'): + pass + + def component_data_var_removed(self, view: 'BinaryView', _component: component.Component, var: 'DataVariable'): + pass + @@ -495,6 +501,8 @@ class BinaryDataNotificationCallbacks: self._cb.componentMoved = self._cb.componentMoved.__class__(self._component_moved) self._cb.componentFunctionAdded = self._cb.componentFunctionAdded.__class__(self._component_function_added) self._cb.componentFunctionRemoved = self._cb.componentFunctionRemoved.__class__(self._component_function_removed) + self._cb.componentDataVariableAdded = self._cb.componentDataVariableAdded.__class__(self._component_data_variable_added) + self._cb.componentDataVariableRemoved = self._cb.componentDataVariableRemoved.__class__(self._component_data_variable_removed) def _register(self) -> None: core.BNRegisterDataNotification(self._view.handle, self._cb) @@ -840,6 +848,26 @@ class BinaryDataNotificationCallbacks: except: log_error(traceback.format_exc()) + def _component_data_variable_added(self, ctxt, view: core.BNBinaryView, _component: core.BNComponent, + var: core.BNDataVariable): + try: + component_handle = core.BNNewComponentReference(_component) + assert component_handle is not None, "core.BNNewComponentReference returned None" + result = component.Component(component_handle) + self._notify.component_data_var_added(self._view, result, DataVariable.from_core_struct(var[0], self._view)) + except: + log_error(traceback.format_exc()) + + def _component_data_variable_removed(self, ctxt, view: core.BNBinaryView, _component: core.BNComponent, + var: core.BNDataVariable): + try: + component_handle = core.BNNewComponentReference(_component) + assert component_handle is not None, "core.BNNewComponentReference returned None" + result = component.Component(component_handle) + self._notify.component_data_var_removed(self._view, result, DataVariable.from_core_struct(var[0], self._view)) + except: + log_error(traceback.format_exc()) + @property def view(self) -> 'BinaryView': return self._view @@ -6189,6 +6217,31 @@ class BinaryView: raise TypeError("Removal is only supported with a Component or string representing its Guid") + def get_function_parent_components(self, function: 'function.Function') -> List['component.Component']: + _components = [] + count = ctypes.c_ulonglong(0) + bn_components = core.BNGetFunctionParentComponents(self.handle, function.handle, count) + try: + for i in range(count.value): + _components.append(component.Component(core.BNNewComponentReference(bn_components[i]))) + finally: + core.BNFreeComponents(bn_components, count.value) + return _components + + def get_data_variable_parent_components(self, data_variable: 'DataVariable') -> List['component.Component']: + _components = [] + count = ctypes.c_ulonglong(0) + bn_components = core.BNGetDataVariableParentComponents(self.handle, data_variable.address, count) + try: + for i in range(count.value): + _components.append(component.Component(core.BNNewComponentReference(bn_components[i]))) + finally: + core.BNFreeComponents(bn_components, count.value) + return _components + + def get_constant_data(self, addr: int) -> databuffer.DataBuffer: + return databuffer.DataBuffer(handle=core.BNGetConstantData(self.handle, addr)) + def get_strings(self, start: Optional[int] = None, length: Optional[int] = None) -> List['StringReference']: """ ``get_strings`` returns a list of strings defined in the binary in the optional virtual address range: |
