Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
1 change: 1 addition & 0 deletions src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
Expand Down
2 changes: 2 additions & 0 deletions src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "-";
Expand All @@ -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),
}
Expand Down
34 changes: 22 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ mod binwalk;
mod cliparser;
mod common;
mod display;
#[cfg(feature = "entropy-plot")]
mod entropy;
mod extractors;
mod json;
Expand Down Expand Up @@ -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
Expand Down
Loading