diff --git a/Cargo.toml b/Cargo.toml index 8f42ce824..4ce26cc09 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,12 +9,16 @@ repository = "https://github.com/ReFirmLabs/binwalk" description = "Analyzes data for embedded file types" keywords = ["binwalk", "firmware", "analysis"] +[features] +default = [] +entropy-plot = ["dep:plotly", "dep:entropy"] + [dependencies] log = "0.4.22" base64 = "0.22.1" chrono = "0.4.38" walkdir = "2.5.0" -entropy = "0.4.2" +entropy = { version = "0.4.2", optional = true } colored = "3.0.0" termsize = "0.1" crc32-v2 = "0.0.5" @@ -34,7 +38,10 @@ clap = { version = "4.5.16", features = ["derive"] } xxhash-rust = { version = "0.8.12", features = ["xxh32"] } hex = "0.4.3" delink = { git = "https://github.com/devttys0/delink" } -plotly = { version = "0.13.1", features = ["kaleido", "kaleido_download"] } +plotly = { version = "0.14", features = [ + "kaleido", + "kaleido_download", +], optional = true } [dependencies.uuid] version = "1.17.0" diff --git a/src/display.rs b/src/display.rs index 211c26c9d..c9a6f589b 100644 --- a/src/display.rs +++ b/src/display.rs @@ -393,6 +393,7 @@ pub fn print_plain(quiet: bool, msg: &str) { } } +#[cfg(feature = "entropy-plot")] pub fn println_plain(quiet: bool, msg: &str) { if !quiet { println!("{msg}"); diff --git a/src/json.rs b/src/json.rs index 015c2fc5c..273e17d8c 100644 --- a/src/json.rs +++ b/src/json.rs @@ -7,6 +7,7 @@ use std::io::Write; use crate::binwalk::AnalysisResults; use crate::display; +#[cfg(feature = "entropy-plot")] use crate::entropy::FileEntropy; const STDOUT: &str = "-"; @@ -16,6 +17,7 @@ const JSON_LIST_SEP: &str = ",\n"; #[derive(Debug, Serialize, Deserialize)] pub enum JSONType { + #[cfg(feature = "entropy-plot")] Entropy(FileEntropy), Analysis(AnalysisResults), } diff --git a/src/main.rs b/src/main.rs index 6a885e180..1e3a4e952 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,6 +13,7 @@ mod binwalk; mod cliparser; mod common; mod display; +#[cfg(feature = "entropy-plot")] mod entropy; mod extractors; mod json; @@ -71,21 +72,30 @@ fn main() -> ExitCode { // If entropy analysis was requested, generate the entropy graph and return if cliargs.entropy { - display::print_plain(cliargs.quiet, "Calculating file entropy..."); - - if let Ok(entropy_results) = - entropy::plot(cliargs.file_name.unwrap(), cliargs.stdin, cliargs.png) + #[cfg(not(feature = "entropy-plot"))] { - // Log entropy results to JSON file, if requested - json_logger.log(json::JSONType::Entropy(entropy_results.clone())); - json_logger.close(); - - display::println_plain(cliargs.quiet, "done."); - } else { - panic!("Entropy analysis failed!"); + panic!( + "binwalk was built without the \"entropy-plot\" feature, entropy analysis isn't available" + ); } + #[cfg(feature = "entropy-plot")] + { + display::print_plain(cliargs.quiet, "Calculating file entropy..."); + + if let Ok(entropy_results) = + entropy::plot(cliargs.file_name.unwrap(), cliargs.stdin, cliargs.png) + { + // Log entropy results to JSON file, if requested + json_logger.log(json::JSONType::Entropy(entropy_results.clone())); + json_logger.close(); + + display::println_plain(cliargs.quiet, "done."); + } else { + panic!("Entropy analysis failed!"); + } - return ExitCode::SUCCESS; + return ExitCode::SUCCESS; + } } // If extraction or data carving was requested, we need to initialize the output directory