Basic Block Model
In Ghidra you can get information about the control-flow between basic blocks using the BasicBlockModel.
from ghidra.program.model.block import BasicBlockModel
from ghidra.util.task import ConsoleTaskMonitor
blockModel = BasicBlockModel(currentProgram)
monitor = ConsoleTaskMonitor()
# ...
blocks = blockModel.getCodeBlocksContaining(func.getBody(), monitor)
while blocks.hasNext():
bb = blocks.next()
# ...
- Basic blocks are represented by
CodeBlockobjects - Edges are represented by
CodeBlockReferenceobjects that include information about theFlowTypeand destinations
A more complete example can be found in ghidra-graph-export