diff options
| author | KyleMiles <krm504@nyu.edu> | 2021-01-21 18:35:20 +0000 |
|---|---|---|
| committer | KyleMiles <krm504@nyu.edu> | 2021-01-21 19:07:07 +0000 |
| commit | 2fcacc55d5466a7d17bdc0b3ce988772aa6d0653 (patch) | |
| tree | 9d0f2ba19117843575936f2b93e0b6a578a84dc8 /rust/examples/flowgraph/src | |
| parent | a0da07c5c2860a5bd69921d38e438bbc1d43912f (diff) | |
cargo fmt and all my changes
Diffstat (limited to 'rust/examples/flowgraph/src')
| -rw-r--r-- | rust/examples/flowgraph/src/lib.rs | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/rust/examples/flowgraph/src/lib.rs b/rust/examples/flowgraph/src/lib.rs new file mode 100644 index 00000000..e0c47d9f --- /dev/null +++ b/rust/examples/flowgraph/src/lib.rs @@ -0,0 +1,52 @@ +use binaryninja::binaryview::{BinaryView, BinaryViewExt}; +use binaryninja::command::register; +use binaryninja::disassembly::{ + DisassemblyTextLine, InstructionTextToken, InstructionTextTokenType, +}; +use binaryninja::flowgraph::{ + BranchType, EdgePenStyle, EdgeStyle, FlowGraph, FlowGraphNode, ThemeColor, +}; + +fn test_graph(view: &BinaryView) { + let graph = FlowGraph::new(); + + let disassembly_lines_a = vec![DisassemblyTextLine::from(vec![ + InstructionTextToken::new(InstructionTextTokenType::TextToken, "Li"), + InstructionTextToken::new(InstructionTextTokenType::TextToken, "ne"), + InstructionTextToken::new(InstructionTextTokenType::TextToken, " 1"), + ])]; + + let node_a = FlowGraphNode::new(&graph); + node_a.set_disassembly_lines(&disassembly_lines_a); + + let node_b = FlowGraphNode::new(&graph); + let disassembly_lines_b = vec![DisassemblyTextLine::from(&vec!["Li", "ne", " 2"])]; + node_b.set_disassembly_lines(&disassembly_lines_b); + + let node_c = FlowGraphNode::new(&graph); + node_c.set_lines(vec!["Line 3", "Line 4", "Line 5"]); + + graph.append(&node_a); + graph.append(&node_b); + graph.append(&node_c); + + let edge = EdgeStyle::new(EdgePenStyle::DashDotDotLine, 2, ThemeColor::AddressColor); + node_a.add_outgoing_edge(BranchType::UserDefinedBranch, &node_b, &edge); + node_a.add_outgoing_edge( + BranchType::UnconditionalBranch, + &node_c, + &EdgeStyle::default(), + ); + + view.show_graph_report("Rust Graph Title", graph); +} + +#[no_mangle] +pub extern "C" fn UIPluginInit() -> bool { + register( + "Rust Graph Test Title", + "Rust Graph Test Description", + test_graph, + ); + true +} |
