From 260b6973b031a709a988744eb59e7ad3fb6f0d11 Mon Sep 17 00:00:00 2001 From: James Dorgan Date: Tue, 24 Dec 2024 14:19:28 +0000 Subject: [PATCH] feat: improved logging --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/cli.rs | 15 +++++++++++++-- src/hunt.rs | 2 +- src/main.rs | 7 ++++--- 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fb85896a..abebcdfc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -258,7 +258,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chainsaw" -version = "2.10.3" +version = "2.10.4" dependencies = [ "aho-corasick", "anyhow", diff --git a/Cargo.toml b/Cargo.toml index 613e7516..40f75ef4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "chainsaw" -version = "2.10.3" +version = "2.10.4" repository = "https://github.com/WithSecureLabs/chainsaw" description = "Rapidly Search and Hunt Through Windows Forensic Artefacts" authors = ["James Dorgan ","Alex Kornitzer "] diff --git a/src/cli.rs b/src/cli.rs index 9ff0acb8..e0838d8e 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -34,7 +34,12 @@ const TICK_SETTINGS: (&str, u64) = ("⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏ ", 80); #[cfg(windows)] const TICK_SETTINGS: (&str, u64) = (r"-\|/-", 200); -pub fn init_progress_bar(size: u64, msg: String, verbose: bool) -> indicatif::ProgressBar { +pub fn init_progress_bar( + size: u64, + msg: String, + verbose: bool, + prefix: String, +) -> indicatif::ProgressBar { let pb = ProgressBar::new(size); if verbose { pb.set_draw_target(ProgressDrawTarget::hidden()); @@ -48,7 +53,13 @@ pub fn init_progress_bar(size: u64, msg: String, verbose: bool) -> indicatif::Pr } pb.set_style( ProgressStyle::default_bar() - .template("[+] {msg}: [{bar:40}] {pos}/{len} {spinner}") + .template( + format!( + "{{msg}}[+] {} [{{bar:40}}] {{pos}}/{{len}} {{spinner}} [{{elapsed_precise}}]", + prefix + ) + .as_str(), + ) .expect("could not set template") .tick_chars(TICK_SETTINGS.0) .progress_chars("=>-"), diff --git a/src/hunt.rs b/src/hunt.rs index bceaac08..cb05f066 100644 --- a/src/hunt.rs +++ b/src/hunt.rs @@ -793,7 +793,7 @@ impl Hunter { Err(e) => { if self.inner.skip_errors { cs_eyellowln!( - "[!] failed to parse document '{}' - {}\n", + "[!] failed to parse document '{}' - {} - use --skip-errors to continue...\n", file.display(), e ); diff --git a/src/main.rs b/src/main.rs index 790f4a86..f0c879f0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -723,12 +723,13 @@ fn run() -> Result<()> { let mut detections = vec![]; let pb = cli::init_progress_bar( files.len() as u64, - "Hunting".to_string(), + "".to_string(), args.verbose != 0, + "Hunting".to_string(), ); for file in &files { cs_debug!("[*] Hunting through file - {}", file.display()); - pb.tick(); + pb.set_message(format!("[+] Current Artifact: {}\n", file.display())); let cache = if cache { match tempfile::tempfile() { Ok(f) => Some(f), @@ -740,7 +741,7 @@ fn run() -> Result<()> { None }; let scratch = hunter.hunt(file, &cache).with_context(|| { - format!("Failed to hunt through file '{}'", file.to_string_lossy()) + format!("Failed to hunt through file '{}' (Use --skip-errors to continue processing)", file.to_string_lossy()) })?; hits += scratch.iter().map(|d| d.hits.len()).sum::(); documents += scratch.len();