From e1849e593dfb4003019a46fbb52eb48c3c645080 Mon Sep 17 00:00:00 2001 From: Ilya Yegorov Date: Fri, 3 Nov 2023 17:17:15 +0300 Subject: [PATCH] [casr-java] Add source-dirs options (#173) --- casr/Cargo.toml | 2 +- casr/src/bin/casr-java.rs | 19 +++++++++++++------ docs/usage.md | 25 ++++++++++++------------- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/casr/Cargo.toml b/casr/Cargo.toml index 4213e775..da10af86 100644 --- a/casr/Cargo.toml +++ b/casr/Cargo.toml @@ -13,7 +13,7 @@ exclude = ["/tests"] [dependencies] shell-words = "1.1" anyhow = "1.0" -clap = { version = "4.2", features = ["wrap_help", "cargo"] } +clap = { version = "4.2", features = ["wrap_help", "cargo", "env"] } chrono = "0.4" goblin = "0.6" log = "0.4" diff --git a/casr/src/bin/casr-java.rs b/casr/src/bin/casr-java.rs index b5aa0658..c5361d99 100644 --- a/casr/src/bin/casr-java.rs +++ b/casr/src/bin/casr-java.rs @@ -45,6 +45,17 @@ fn main() -> Result<()> { .value_name("FILE") .help("Stdin file for program"), ) + .arg( + Arg::new("source-dirs") + .long("source-dirs") + .env("CASR_SOURCE_DIRS") + .action(ArgAction::Set) + .num_args(1..) + .value_delimiter(':') + .value_parser(clap::value_parser!(PathBuf)) + .value_name("DIR") + .help("Paths to directories with Java source files (list separated by ':' for env)"), + ) .arg( Arg::new("timeout") .short('t') @@ -151,12 +162,8 @@ fn main() -> Result<()> { report.crashline = crash_line.to_string(); if let CrashLine::Source(mut debug) = crash_line { // Modify DebugInfo to find sources - let source_dirs: Vec = if let Ok(sources) = std::env::var("CASR_SOURCE_DIRS") { - sources - .split(':') - .map(PathBuf::from) - .filter(|x| x.is_dir()) - .collect() + let source_dirs = if let Some(sources) = matches.get_many::("source-dirs") { + sources.collect() } else { Vec::new() }; diff --git a/docs/usage.md b/docs/usage.md index a7759fd6..f7f110bb 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -148,24 +148,23 @@ Create CASR reports (.casrep) from java reports [ARGS]... Add "-- " to run Options: - -o, --output Path to save report. Path can be a directory, then report name - is generated - --stdout Print CASR report to stdout - --stdin Stdin file for program - -t, --timeout Timeout (in seconds) for target execution, 0 value means that - timeout is disabled [default: 0] - --ignore File with regular expressions for functions and file paths that - should be ignored - -h, --help Print help - -V, --version Print version + -o, --output Path to save report. Path can be a directory, then report + name is generated + --stdout Print CASR report to stdout + --stdin Stdin file for program + --source-dirs ... Paths to directories with Java source files (list separated + by ':' for env) [env: CASR_SOURCE_DIRS=] + -t, --timeout Timeout (in seconds) for target execution, 0 value means + that timeout is disabled [default: 0] + --ignore File with regular expressions for functions and file paths + that should be ignored + -h, --help Print help + -V, --version Print version Run casr-java: $ casr-java -o java.casrep -- java casr/tests/casr_tests/java/Test1.java -You can specify paths to directories with Java source files via environment variable -`CASR_SOURCE_DIRS` (list separated by ':'). - ## casr-core Analyze coredump for security goals and provide detailed report with severity estimation