Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
br0kej committed Aug 20, 2024
1 parent babe29c commit f783404
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 26 deletions.
50 changes: 33 additions & 17 deletions src/agfj.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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::<std::string::String, u32>::from_edges(&edge_list);

Expand All @@ -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<NodeType> =
NetworkxDiGraph::<NodeType>::from((
Expand All @@ -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<NodeType> =
NetworkxDiGraph::<NodeType>::from((
Expand All @@ -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<NodeType> =
NetworkxDiGraph::<NodeType>::from((
Expand All @@ -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<NodeType> =
NetworkxDiGraph::<NodeType>::from((
Expand All @@ -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<NodeType> =
NetworkxDiGraph::<NodeType>::from((
Expand All @@ -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<NodeType> =
NetworkxDiGraph::<NodeType>::from((
Expand All @@ -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
)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/bb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub enum FeatureType {
Encoded,
Invalid,
Pcode,
Pseudo
Pseudo,
}

impl fmt::Display for FeatureType {
Expand All @@ -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)
}
Expand Down
7 changes: 6 additions & 1 deletion src/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
}
};

Expand Down
12 changes: 6 additions & 6 deletions src/networkx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -114,7 +114,7 @@ impl From<(i64, &Vec<String>)> for EsilNode {
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PseudoNode {
pub id: i64,
pub features: Vec<String>
pub features: Vec<String>,
}

impl From<(i64, &Vec<String>)> for PseudoNode {
Expand All @@ -126,7 +126,6 @@ impl From<(i64, &Vec<String>)> for PseudoNode {
}
}


#[derive(Copy, Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct TiknibNode {
pub id: i64,
Expand Down Expand Up @@ -451,8 +450,10 @@ impl From<(&Graph<String, u32>, &Vec<Vec<String>>, 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);
Expand Down Expand Up @@ -678,7 +679,6 @@ impl From<NetworkxDiGraph<NodeType>> for NetworkxDiGraph<PseudoNode> {
}
}


#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct PCodeNode {
pub id: u64,
Expand Down

0 comments on commit f783404

Please sign in to comment.