MCPcopy Create free account
hub / github.com/Vector35/binaryninja-api / Component

Class Component

python/component.py:13–335  ·  view source on GitHub ↗

Components are objects that can contain Functions and other Components. They can be queried for information about the functions contained within them. Components have a Guid, which persistent across saves and loads of the database, and should be used for retrieving components when

Source from the content-addressed store, hash-verified

11
12
13class Component:
14 """
15 Components are objects that can contain Functions and other Components.
16
17 They can be queried for information about the functions contained within them.
18
19 Components have a Guid, which persistent across saves and loads of the database, and should be
20 used for retrieving components when such is required and a reference to the Component cannot be held.
21
22 """
23 def __init__(self, handle=None):
24
25 assert handle is not None, "Cannot create component directly, run `bv.create_component?`"
26
27 self.handle = handle
28
29 self.guid = core.BNComponentGetGuid(self.handle)
30
31 def __eq__(self, other):
32 if not isinstance(other, Component):
33 return NotImplemented
34 return core.BNComponentsEqual(self.handle, other.handle)
35
36 def __ne__(self, other):
37 if not isinstance(other, Component):
38 return NotImplemented
39 return core.BNComponentsNotEqual(self.handle, other.handle)
40
41 def __repr__(self):
42 return f'<Component "{self.display_name}" "({self.guid[:8]}...")>'
43
44 def __del__(self):
45 if (hasattr(self, 'handle')):
46 core.BNFreeComponent(self.handle)
47
48 def __str__(self):
49 return self._sprawl_component(self)
50
51 def __hash__(self):
52 return hash(self.guid)
53
54 def _sprawl_component(self, c, depth=1, out=None):
55 """
56 Recursive quick function to print out the component&#x27;s tree of items
57
58 :param c: Current cycle&#x27;s component. On initial call, pass `self`
59 :param depth: Current tree depth.
60 :param out: Current text
61 :return:
62 """
63 _out = ([repr(c)] if not out else out.split('\n')) + [(' ' * depth + repr(f)) for f in c.functions]
64 _out += [' ' * (depth+1) + repr(i) for i in (c.get_referenced_data_variables() + c.get_referenced_types())]
65 for i in c.components:
66 _out.append(' ' * depth + repr(i))
67 _out = self._sprawl_component(i, depth+1, '\n'.join(_out)).split('\n')
68 return '\n'.join(_out)
69
70 def add_function(self, func: 'function.Function') -> bool:

Callers 2

parentMethod · 0.70
componentsMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected