From f7834043bf37aa43c954e953342b83915c6a55fa Mon Sep 17 00:00:00 2001 From: br0kej Date: Tue, 20 Aug 2024 11:52:17 +0100 Subject: [PATCH] cargo fmt --- src/agfj.rs | 50 ++++++++++++++++++++++++++++++++----------------- src/bb.rs | 4 ++-- src/extract.rs | 7 ++++++- src/networkx.rs | 12 ++++++------ 4 files changed, 47 insertions(+), 26 deletions(-) diff --git a/src/agfj.rs b/src/agfj.rs index 97c022d..8d64697 100644 --- a/src/agfj.rs +++ b/src/agfj.rs @@ -1,7 +1,10 @@ use crate::bb::{ACFJBlock, FeatureType, TikNibFeaturesBB}; #[cfg(feature = "inference")] use crate::inference::InferenceJob; -use crate::networkx::{DGISNode, DisasmNode, DiscovreNode, EsilNode, GeminiNode, NetworkxDiGraph, NodeType, PseudoNode, TiknibNode}; +use crate::networkx::{ + DGISNode, DisasmNode, DiscovreNode, EsilNode, GeminiNode, NetworkxDiGraph, NodeType, + PseudoNode, TiknibNode, +}; use crate::utils::{average, check_or_create_dir, get_save_file_path}; use enum_as_inner::EnumAsInner; use itertools::Itertools; @@ -361,7 +364,13 @@ impl AGFJFunc { feature_type: FeatureType, architecture: &String, ) { - let full_output_path = get_save_file_path(path, output_path, None, Some(feature_type.to_string()), None); + let full_output_path = get_save_file_path( + path, + output_path, + None, + Some(feature_type.to_string()), + None, + ); check_or_create_dir(&full_output_path); let file_name = path.file_name().unwrap(); let binding = file_name.to_string_lossy().to_string(); @@ -392,7 +401,10 @@ impl AGFJFunc { | FeatureType::Gemini | FeatureType::DiscovRE | FeatureType::DGIS => StringOrF64::F64(Vec::new()), - FeatureType::Esil | FeatureType::Disasm | FeatureType::Pseudo | FeatureType::Pcode => StringOrF64::String(Vec::new()), + FeatureType::Esil + | FeatureType::Disasm + | FeatureType::Pseudo + | FeatureType::Pcode => StringOrF64::String(Vec::new()), FeatureType::ModelEmbedded | FeatureType::Encoded | FeatureType::Invalid => { info!("Invalid Feature Type. Skipping.."); return; @@ -437,7 +449,11 @@ impl AGFJFunc { _ => {} }; - debug!("Edge List Empty: {} Edge List Dims: {}", edge_list.is_empty(), edge_list.len()); + debug!( + "Edge List Empty: {} Edge List Dims: {}", + edge_list.is_empty(), + edge_list.len() + ); if !edge_list.is_empty() { let mut graph = Graph::::from_edges(&edge_list); @@ -460,7 +476,7 @@ impl AGFJFunc { &File::create(fname_string).expect("Failed to create writer"), &networkx_graph_inners, ) - .expect("Unable to write JSON"); + .expect("Unable to write JSON"); } else if feature_type == FeatureType::DGIS { let networkx_graph: NetworkxDiGraph = NetworkxDiGraph::::from(( @@ -476,7 +492,7 @@ impl AGFJFunc { &File::create(fname_string).expect("Failed to create writer"), &networkx_graph_inners, ) - .expect("Unable to write JSON"); + .expect("Unable to write JSON"); } else if feature_type == FeatureType::DiscovRE { let networkx_graph: NetworkxDiGraph = NetworkxDiGraph::::from(( @@ -492,7 +508,7 @@ impl AGFJFunc { &File::create(fname_string).expect("Failed to create writer"), &networkx_graph_inners, ) - .expect("Unable to write JSON"); + .expect("Unable to write JSON"); } else if feature_type == FeatureType::Tiknib { let networkx_graph: NetworkxDiGraph = NetworkxDiGraph::::from(( @@ -508,7 +524,7 @@ impl AGFJFunc { &File::create(fname_string).expect("Failed to create writer"), &networkx_graph_inners, ) - .expect("Unable to write JSON"); + .expect("Unable to write JSON"); } else if feature_type == FeatureType::Disasm { let networkx_graph: NetworkxDiGraph = NetworkxDiGraph::::from(( @@ -524,7 +540,7 @@ impl AGFJFunc { &File::create(fname_string).expect("Failed to create writer"), &networkx_graph_inners, ) - .expect("Unable to write JSON"); + .expect("Unable to write JSON"); } else if feature_type == FeatureType::Esil { let networkx_graph: NetworkxDiGraph = NetworkxDiGraph::::from(( @@ -540,7 +556,7 @@ impl AGFJFunc { &File::create(fname_string).expect("Failed to create writer"), &networkx_graph_inners, ) - .expect("Unable to write JSON"); + .expect("Unable to write JSON"); } else if feature_type == FeatureType::Pseudo { let networkx_graph: NetworkxDiGraph = NetworkxDiGraph::::from(( @@ -556,21 +572,21 @@ impl AGFJFunc { &File::create(fname_string).expect("Failed to create writer"), &networkx_graph_inners, ) - .expect("Unable to write JSON"); + .expect("Unable to write JSON"); } else { info!("Function {} has no edges. Skipping...", self.name) } } else { info!( - "Function {} has less than the minimum number of blocks. Skipping..", - self.name - ); + "Function {} has less than the minimum number of blocks. Skipping..", + self.name + ); } } else { info!( - "Function {} has already been processed. Skipping...", - self.name - ) + "Function {} has already been processed. Skipping...", + self.name + ) } } } diff --git a/src/bb.rs b/src/bb.rs index 232b01b..39ba083 100644 --- a/src/bb.rs +++ b/src/bb.rs @@ -26,7 +26,7 @@ pub enum FeatureType { Encoded, Invalid, Pcode, - Pseudo + Pseudo, } impl fmt::Display for FeatureType { @@ -42,7 +42,7 @@ impl fmt::Display for FeatureType { FeatureType::Encoded => "encoded", FeatureType::Invalid => "invalid", FeatureType::Pcode => "pcode", - FeatureType::Pseudo => "pseudo" + FeatureType::Pseudo => "pseudo", }; write!(f, "{}", feature_type_str) } diff --git a/src/extract.rs b/src/extract.rs index 3b4a9ef..d0a3733 100644 --- a/src/extract.rs +++ b/src/extract.rs @@ -903,7 +903,12 @@ impl FileToBeProcessed { debug!("Creating r2 handle without debugging"); R2PipeSpawnOptions { exepath: "radare2".to_owned(), - args: vec!["-e bin.cache=true", "-e log.level=1", "-2", "-e asm.pseudo=true"], + args: vec![ + "-e bin.cache=true", + "-e log.level=1", + "-2", + "-e asm.pseudo=true", + ], } }; diff --git a/src/networkx.rs b/src/networkx.rs index f758132..84b55b2 100644 --- a/src/networkx.rs +++ b/src/networkx.rs @@ -50,7 +50,7 @@ pub enum NodeType { Disasm(DisasmNode), Esil(EsilNode), PCode(PCodeNode), - Pseudo(PseudoNode) + Pseudo(PseudoNode), } #[derive(Debug, Clone, PartialEq, Hash, Serialize, Deserialize, EnumAsInner)] @@ -114,7 +114,7 @@ impl From<(i64, &Vec)> for EsilNode { #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct PseudoNode { pub id: i64, - pub features: Vec + pub features: Vec, } impl From<(i64, &Vec)> for PseudoNode { @@ -126,7 +126,6 @@ impl From<(i64, &Vec)> for PseudoNode { } } - #[derive(Copy, Default, Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct TiknibNode { pub id: i64, @@ -451,8 +450,10 @@ impl From<(&Graph, &Vec>, FeatureType)> for NetworkxDiG Some(NodeType::Disasm(DisasmNode::from((i as i64, node_vector)))) } FeatureType::Esil => Some(NodeType::Esil(EsilNode::from((i as i64, node_vector)))), - FeatureType::Pseudo => Some(NodeType::Pseudo(PseudoNode::from((i as i64, node_vector)))), - _ => todo!() + FeatureType::Pseudo => { + Some(NodeType::Pseudo(PseudoNode::from((i as i64, node_vector)))) + } + _ => todo!(), }; if let Some(node) = node { nodes.push(node); @@ -678,7 +679,6 @@ impl From> for NetworkxDiGraph { } } - #[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct PCodeNode { pub id: u64,