Skip to content

Commit

Permalink
Merge pull request #209 from WithSecureLabs/feat/logging_improvements
Browse files Browse the repository at this point in the history
feat: improved logging
  • Loading branch information
FranticTyping authored Dec 24, 2024
2 parents d936304 + 260b697 commit 8799abb
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>","Alex Kornitzer <[email protected]>"]
Expand Down
15 changes: 13 additions & 2 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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("=>-"),
Expand Down
2 changes: 1 addition & 1 deletion src/hunt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down
7 changes: 4 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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::<usize>();
documents += scratch.len();
Expand Down

0 comments on commit 8799abb

Please sign in to comment.