flowgraph module

binaryninja.flowgraph.CoreFlowGraph(handle)
binaryninja.flowgraph.FlowGraph([handle]) class FlowGraph implements a directed flow graph to be shown in the UI.
binaryninja.flowgraph.FlowGraphEdge(…)
binaryninja.flowgraph.FlowGraphLayoutRequest(graph)
binaryninja.flowgraph.FlowGraphNode(graph[, …])
binaryninja.flowgraph.range(*args) A Python2 and Python3 Compatible Range Generator
class CoreFlowGraph(handle)[source]

Bases: binaryninja.flowgraph.FlowGraph

update()[source]

update can be overridden by subclasses to allow a graph to be updated after it has been presented in the UI. This will automatically occur if the function referenced by the function property has been updated.

Return a new FlowGraph object with the new information if updates are desired. If the graph does not need updating, None can be returned to leave the graph in its current state.

Returns:Updated graph, or None
Return type:FlowGraph
class FlowGraph(handle=None)[source]

Bases: object

class FlowGraph implements a directed flow graph to be shown in the UI. This class allows plugins to create custom flow graphs and render them in the UI using the flow graph report API.

An example of creating a flow graph and presenting it in the UI:

>>> graph = FlowGraph()
>>> node_a = FlowGraphNode(graph)
>>> node_a.lines = ["Node A"]
>>> node_b = FlowGraphNode(graph)
>>> node_b.lines = ["Node B"]
>>> node_c = FlowGraphNode(graph)
>>> node_c.lines = ["Node C"]
>>> graph.append(node_a)
0
>>> graph.append(node_b)
1
>>> graph.append(node_c)
2
>>> node_a.add_outgoing_edge(BranchType.UnconditionalBranch, node_b)
>>> node_a.add_outgoing_edge(BranchType.UnconditionalBranch, node_c)
>>> show_graph_report("Custom Graph", graph)

Note

In the current implementation, only graphs that have a single start node where all other nodes are reachable from outgoing edges can be rendered correctly. This describes the natural limitations of a control flow graph, which is what the rendering logic was designed for. Graphs that have nodes that are only reachable from incoming edges, or graphs that have disjoint subgraphs will not render correctly. This will be fixed in a future version.

append(node)[source]

append adds a node to a flow graph.

Parameters:node (FlowGraphNode) – Node to add
Returns:Index of node
Return type:int
complete_layout()[source]

complete_layout can be overridden by subclasses and is called when a graph layout is completed.

finish_prepare_for_layout()[source]

finish_prepare_for_layout signals that preparations for rendering a graph are complete. This method should only be called by a prepare_for_layout reimplementation.

get_nodes_in_region(left, top, right, bottom)[source]
layout(callback=None)[source]

layout starts rendering a graph for display. Once a layout is complete, each node will contain coordinates and extents that can be used to render a graph with minimum additional computation. This function does not wait for the graph to be ready to display, but a callback can be provided to signal when the graph is ready.

Parameters:callback (callable()) – Function to be called when the graph is ready to display
Returns:Pending flow graph layout request object
Return type:FlowGraphLayoutRequest
layout_and_wait()[source]

layout_and_wait starts rendering a graph for display, and waits for the graph to be ready to display. After this function returns, each node will contain coordinates and extents that can be used to render a graph with minimum additional computation.

Do not use this API on the UI thread (use layout with a callback instead).

populate_nodes()[source]

prepare_for_layout can be overridden by subclasses to create nodes in a graph when a flow graph needs to be rendered. This will happen on a worker thread and will not block the UI.

prepare_for_layout()[source]

prepare_for_layout can be overridden by subclasses to handling preparations that must take place before a flow graph is rendered, such as waiting for a function to finish analysis. If this function is overridden, the finish_prepare_for_layout method must be called once preparations are completed.

show(title)[source]

show displays the graph in a new tab in the UI.

Parameters:title (str) – Title to show in the new tab
update()[source]

update can be overridden by subclasses to allow a graph to be updated after it has been presented in the UI. This will automatically occur if the function referenced by the function property has been updated.

Return a new FlowGraph object with the new information if updates are desired. If the graph does not need updating, None can be returned to leave the graph in its current state.

Returns:Updated graph, or None
Return type:FlowGraph
complete

Whether flow graph layout is complete (read-only)

function

Function for a flow graph

has_nodes

Whether the flow graph has at least one node (read-only)

height

Flow graph height (read-only)

horizontal_block_margin
il_function
is_il
is_low_level_il
is_medium_level_il
nodes

List of nodes in graph (read-only)

vertical_block_margin
width

Flow graph width (read-only)

class FlowGraphEdge(branch_type, source, target, points, back_edge)[source]

Bases: object

class FlowGraphLayoutRequest(graph, callback=None)[source]

Bases: object

abort()[source]
complete

Whether flow graph layout is complete (read-only)

graph

Flow graph that is being processed (read-only)

class FlowGraphNode(graph, handle=None)[source]

Bases: object

add_outgoing_edge(edge_type, target)[source]

add_outgoing_edge connects two flow graph nodes with an edge.

Parameters:
basic_block

Basic block associated with this part of the flow graph (read-only)

height

Flow graph block height (read-only)

highlight

Gets or sets the highlight color for the node

Example:
>>> g = FlowGraph()
>>> node = FlowGraphNode(g)
>>> node.highlight = HighlightStandardColor.BlueHighlightColor
>>> node.highlight
<color: blue>
lines

Flow graph block list of text lines

outgoing_edges

Flow graph block list of outgoing edges (read-only)

width

Flow graph block width (read-only)

x

Flow graph block X (read-only)

y

Flow graph block Y (read-only)