Skip to content

Commit

Permalink
add handling of invalid parameter to evtxanalyze
Browse files Browse the repository at this point in the history
  • Loading branch information
janstarke committed Jul 29, 2024
1 parent ef12f43 commit f221893
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions src/bin/evtxanalyze/cli.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::{io::stdout, path::PathBuf};

use anyhow::bail;
use clap::{Parser, Subcommand, ValueEnum, ValueHint};
use dfir_toolkit::common::HasVerboseFlag;
use log::LevelFilter;
Expand Down Expand Up @@ -82,6 +83,20 @@ impl Cli {
evtx_files_dir,
session_id,
} => {
if !evtx_files_dir.exists() {
bail!(
"directory '{}' does not exist. Aborting now.",
evtx_files_dir.to_string_lossy()
)
}

if !evtx_files_dir.is_dir() {
bail!(
"'{}' is no directory. Aborting now.",
evtx_files_dir.to_string_lossy()
);
}

let sessions = SessionStore::import(evtx_files_dir, true)?;
match sessions.find_session(session_id) {
None => log::error!("no value found for session id {session_id}"),
Expand All @@ -105,6 +120,20 @@ impl Cli {
evtx_files_dir,
include_anonymous,
} => {
if !evtx_files_dir.exists() {
bail!(
"directory '{}' does not exist. Aborting now.",
evtx_files_dir.to_string_lossy()
)
}

if !evtx_files_dir.is_dir() {
bail!(
"'{}' is no directory. Aborting now.",
evtx_files_dir.to_string_lossy()
);
}

let sessions = SessionStore::import(evtx_files_dir, *include_anonymous)?;

let mut csv_writer = csv::Writer::from_writer(stdout());
Expand All @@ -119,9 +148,8 @@ impl Cli {
}
}


impl HasVerboseFlag for Cli {
fn log_level_filter(&self)-> LevelFilter {
fn log_level_filter(&self) -> LevelFilter {
self.verbose.log_level_filter()
}
}
}

0 comments on commit f221893

Please sign in to comment.