flowgraph module¶

Class

Description

binaryninja.flowgraph.CoreFlowGraph

class FlowGraph implements a directed flow graph to be shown in the UI. This class allows…

binaryninja.flowgraph.EdgeStyle

binaryninja.flowgraph.FlowGraph

class FlowGraph implements a directed flow graph to be shown in the UI. This class allows…

binaryninja.flowgraph.FlowGraphEdge

binaryninja.flowgraph.FlowGraphLayout

binaryninja.flowgraph.FlowGraphLayoutRequest

binaryninja.flowgraph.FlowGraphNode

CoreFlowGraph¶

class CoreFlowGraph[source]¶

Bases: FlowGraph

__init__(handle)[source]¶
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

EdgeStyle¶

class EdgeStyle[source]¶

Bases: object

__init__(style: EdgePenStyle | None = None, width: int | None = None, theme_color: ThemeColor | None = None)[source]¶
Parameters:
static from_core_struct(edge_style)[source]¶

FlowGraph¶

class FlowGraph[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
>>> edge = EdgeStyle(EdgePenStyle.DashDotDotLine, 2, ThemeColor.AddressColor)
>>> node_a.add_outgoing_edge(BranchType.UserDefinedBranch, node_b, edge)
>>> 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.

__init__(handle: LP_BNCustomFlowGraph | None = None)[source]¶
Parameters:

handle (LP_BNCustomFlowGraph | None) –

add_render_layer(layer: RenderLayer)[source]¶

Add a Render Layer to be applied to this Flow Graph. Note that layers will be applied in the order in which they are added.

Parameters:

layer (RenderLayer) – Render Layer to add

append(node)[source]¶

append adds a node to a flow graph.

Note

After the graph has completed layout, this function has no effect.

Parameters:

node (FlowGraphNode) – Node to add

Returns:

Index of node

Return type:

int

clear()[source]¶

clear clears all the nodes in the graph

Note

After the graph has completed layout, this function has no effect.

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]¶
is_option_set(option)[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 (callback) – 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]¶

populate_nodes 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.

remove_render_layer(layer: RenderLayer)[source]¶

Remove a Render Layer from being applied to this Flow Graph

Parameters:

layer (RenderLayer) – Render Layer to remove

replace(index, node)[source]¶

replace replaces an existing node in the graph with a new node. Any existing edges referencing the old node will be updated to point to the new node.

Note

After the graph has completed layout, this function has no effect.

Parameters:
  • index – Index of the node to replace

  • node – New node with which to replace the old node

set_option(option, value=True)[source]¶
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

property allows_inline_instruction_editing¶

Set if flow graph should allow inline instruction editing (assembly only)

property allows_patching¶

Set if flow graph should allow modification of code from within the graph view

property complete¶

Whether flow graph layout is complete (read-only)

property function¶

Function for a flow graph

property has_nodes¶

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

property height¶

Flow graph height

property horizontal_block_margin¶
property il_function¶
property includes_user_comments¶

Set if flow graph includes comments made by the user

property is_addressable¶

Set if flow graph should make use of address information

property is_high_level_il¶
property is_il¶
property is_low_level_il¶
property is_medium_level_il¶
property is_workflow_graph¶

Set if flow graph should be treated as a workflow graph

property node_count: int¶

Number of nodes in graph (read-only)

property nodes¶

List of nodes in graph (read-only)

property render_layers: List[RenderLayer]¶

Get the list of Render Layers which will be applied to this Flow Graph, after it calls populate_nodes. :return: List of Render Layers

property shows_secondary_reg_highlighting¶

Set if flow graph should highlight associated registers in the UI

property uses_block_highlights¶

Set if flow graph uses the standard basic block highlighting settings

property uses_instruction_highlights¶

Set if flow graph uses the standard instruction highlighting settings

property vertical_block_margin¶
property view¶

Binary view for a flow graph

property width¶

Flow graph width

FlowGraphEdge¶

class FlowGraphEdge[source]¶

Bases: object

__init__(branch_type, source, target, points, back_edge, style)[source]¶

FlowGraphLayout¶

class FlowGraphLayout[source]¶

Bases: object

__init__(handle: BNCustomFlowGraphLayout | None = None)[source]¶
Parameters:

handle (BNCustomFlowGraphLayout | None) –

layout(graph: FlowGraph, nodes: List[FlowGraphNode]) bool[source]¶
Parameters:
Return type:

bool

register(name: str)[source]¶

Register a custom layout with the API

Parameters:

name (str) –

FlowGraphLayoutRequest¶

class FlowGraphLayoutRequest[source]¶

Bases: object

__init__(graph, callback=None)[source]¶
abort()[source]¶
property complete¶

Whether flow graph layout is complete (read-only)

property graph¶

Flow graph that is being processed (read-only)

FlowGraphNode¶

class FlowGraphNode[source]¶

Bases: object

__init__(graph=None, handle=None)[source]¶
add_outgoing_edge(edge_type, target, style=None)[source]¶

add_outgoing_edge connects two flow graph nodes with an edge.

Parameters:
  • edge_type (BranchType) – Type of edge to add

  • target (FlowGraphNode) – Target node object

  • style (EdgeStyle) – (optional) Styling for graph edge Branch Type must be set to UserDefinedBranch

is_valid_for_graph(graph)[source]¶
set_outgoing_edge_points(edge_num: int, points: List[Tuple[float, float]])[source]¶
Parameters:
set_visibility_region(x: int, y: int, w: int, h: int)[source]¶
Parameters:
  • x (int) –

  • y (int) –

  • w (int) –

  • h (int) –

property basic_block¶

Basic block associated with this part of the flow graph (well not automatically cause the node to render as a native basic block)

property graph¶
property height¶

Flow graph block height (read-only)

property highlight¶

Gets or sets the highlight color for the node

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

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

property lines¶

Flow graph block list of text lines

property outgoing_edges: List[FlowGraphEdge]¶

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

property width¶

Flow graph block width (read-only)

property x¶

Flow graph block X

property y¶

Flow graph block Y