-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from FuzzingLabs/feat/cfg
Implement Control-Flow Graph
- Loading branch information
Showing
14 changed files
with
284 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use sierra_analyzer_lib::sierra_program::SierraProgram; | ||
|
||
fn main() { | ||
let content = include_str!("../../examples/sierra/fib.sierra").to_string(); | ||
|
||
// Init a new SierraProgram with the .sierra file content | ||
let program = SierraProgram::new(content); | ||
|
||
// Decompile the Sierra programs | ||
let mut decompiler = program.decompiler(); | ||
decompiler.decompile(false); | ||
|
||
// Generate & print the dot graph | ||
let cfg = decompiler.generate_cfg(); | ||
println!("{}", cfg) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
pub struct GraphConfig; | ||
|
||
#[allow(dead_code)] | ||
impl GraphConfig { | ||
// Node attributes for CFG | ||
pub const CFG_NODE_ATTR_STYLE: &'static str = "filled, solid"; | ||
pub const CFG_NODE_ATTR_SHAPE: &'static str = "rect, plaintext"; | ||
pub const CFG_NODE_ATTR_COLOR: &'static str = "#9E9E9E"; | ||
pub const CFG_NODE_ATTR_FILLCOLOR: &'static str = "#F5F5F5"; | ||
pub const CFG_NODE_ATTR_FONTNAME: &'static str = "Helvetica,Arial,sans-serif"; | ||
pub const CFG_NODE_ATTR_MARGIN: &'static str = "0.2"; | ||
|
||
// Graph attributes for CFG | ||
pub const CFG_GRAPH_ATTR_OVERLAP: &'static str = "scale"; | ||
pub const CFG_GRAPH_ATTR_FONTNAME: &'static str = "Helvetica,Arial,sans-serif"; | ||
pub const CFG_GRAPH_ATTR_FONTSIZE: &'static str = "20"; | ||
pub const CFG_GRAPH_ATTR_LAYOUT: &'static str = "dot"; | ||
pub const CFG_GRAPH_ATTR_NEWRANK: &'static str = "true"; | ||
|
||
// Edge attributes for CFG | ||
pub const CFG_EDGE_ATTR_ARROWSIZE: &'static str = "0.5"; | ||
pub const CFG_EDGE_ATTR_FONTNAME: &'static str = "Helvetica,Arial,sans-serif"; | ||
pub const CFG_EDGE_ATTR_LABELDISTANCE: &'static str = "3"; | ||
pub const CFG_EDGE_ATTR_LABELFONTCOLOR: &'static str = "#00000080"; | ||
pub const CFG_EDGE_ATTR_PENWIDTH: &'static str = "2"; | ||
|
||
// Edge colors | ||
pub const EDGE_CONDITIONAL_TRUE_COLOR: &'static str = "#8BC34A"; | ||
pub const EDGE_CONDITIONAL_FALSE_COLOR: &'static str = "#C62828"; | ||
pub const EDGE_UNCONDITIONAL_COLOR: &'static str = "#0D47A1"; | ||
pub const EDGE_FALLTHROUGH_COLOR: &'static str = "#212121"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use graphviz_rust::cmd::Format; | ||
use graphviz_rust::dot_structures::*; | ||
use graphviz_rust::exec; | ||
use graphviz_rust::parse; | ||
use graphviz_rust::printer::PrinterContext; | ||
use std::fs::File; | ||
use std::io::{self, Write}; | ||
|
||
/// Converts a DOT graph provided as a string to SVG format and saves it to a file | ||
pub fn save_svg_graph_to_file(filename: &str, graph: String) -> io::Result<()> { | ||
// Parse the graph from the string input | ||
let parsed_graph: Graph = parse(&graph).unwrap(); | ||
|
||
// Generate SVG output | ||
let svg_data = exec( | ||
parsed_graph, | ||
&mut PrinterContext::default(), | ||
vec![Format::Svg.into()], | ||
)?; | ||
|
||
// Create the output file and write the SVG data to it | ||
let mut file = File::create(filename)?; | ||
file.write_all(&svg_data)?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod graph; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
mod config; | ||
mod decompiler; | ||
pub mod graph; | ||
pub mod sierra_program; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.