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

Class BasicBlock

python/basicblock.py:64–638  ·  view source on GitHub ↗

The ``class BasicBlock`` object is returned during analysis and should not be directly instantiated. Basic blocks contain a sequence of instructions that must execute in-order with no branches. We include calls in basic blocks, which technically violates that assumption, but you can mark funct

Source from the content-addressed store, hash-verified

62
63
64class BasicBlock:
65 """
66 The ``class BasicBlock`` object is returned during analysis and should not be directly instantiated.
67
68 Basic blocks contain a sequence of instructions that must execute in-order with no branches.
69 We include calls in basic blocks, which technically violates that assumption, but you can mark
70 functions as `func.can_return = False` if a given function should terminate basic blocks.
71 :Example:
72
73 >>> for func in bv.functions:
74 >>> for bb in func:
75 >>> # Any block-based analysis could start here
76 >>> for inst in bb:
77 >>> pass # Optionally do something here with instructions
78 """
79 def __init__(self, handle: core.BNBasicBlockHandle, view: Optional['binaryview.BinaryView'] = None):
80 self._view = view
81 _handle = core.BNBasicBlockHandle
82 self.handle: core.BNBasicBlockHandle = ctypes.cast(handle, _handle)
83 self._arch = None
84 self._func = None
85 self._instStarts: Optional[List[int]] = None
86 self._instLengths: Optional[List[int]] = None
87
88 def __del__(self):
89 if core is not None:
90 core.BNFreeBasicBlock(self.handle)
91
92 @classmethod
93 def _from_core_block(cls, block: core.BNBasicBlockHandle) -> Optional['BasicBlock']:
94 """From a BNBasicBlockHandle, get a BasicBlock or one of the IL subclasses (takes ref)"""
95 func_handle = core.BNGetBasicBlockFunction(block)
96 if not func_handle:
97 core.BNFreeBasicBlock(block)
98 return None
99
100 view = binaryview.BinaryView(handle=core.BNGetFunctionData(func_handle))
101 func = _function.Function(view, func_handle)
102
103 if core.BNIsLowLevelILBasicBlock(block):
104 return binaryninja.lowlevelil.LowLevelILBasicBlock(
105 block, binaryninja.lowlevelil.LowLevelILFunction(func.arch, core.BNGetBasicBlockLowLevelILFunction(block), func),
106 view
107 )
108 elif core.BNIsMediumLevelILBasicBlock(block):
109 mlil_func = binaryninja.mediumlevelil.MediumLevelILFunction(
110 func.arch, core.BNGetBasicBlockMediumLevelILFunction(block), func
111 )
112 return binaryninja.mediumlevelil.MediumLevelILBasicBlock(block, mlil_func, view)
113 elif core.BNIsHighLevelILBasicBlock(block):
114 hlil_func = binaryninja.highlevelil.HighLevelILFunction(func.arch, core.BNGetBasicBlockHighLevelILFunction(block), func)
115 return binaryninja.highlevelil.HighLevelILBasicBlock(block, hlil_func, view)
116 else:
117 return BasicBlock(block, view)
118
119 def __repr__(self):
120 arch = self.arch
121 if arch:

Callers 3

_from_core_blockMethod · 0.70
_create_instanceMethod · 0.70
source_blockMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected