diff --git a/Cargo.toml b/Cargo.toml index f88e33e..f4470a4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,2 +1,2 @@ [workspace] -members = ["cwe_checker_rs"] +members = ["cwe_checker_rs", "caller"] diff --git a/caller/Cargo.toml b/caller/Cargo.toml new file mode 100644 index 0000000..e1dae7a --- /dev/null +++ b/caller/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "cwe_checker" +version = "0.4.0-dev" +authors = ["Enkelmann <nils-edvin.enkelmann@fkie.fraunhofer.de>"] +edition = "2018" + +[dependencies] +structopt = "0.3" \ No newline at end of file diff --git a/caller/src/main.rs b/caller/src/main.rs new file mode 100644 index 0000000..d18d5fc --- /dev/null +++ b/caller/src/main.rs @@ -0,0 +1,74 @@ +use std::process::Command; +use structopt::StructOpt; + +#[derive(Debug, StructOpt)] +/// Find vulnerable patterns in binary executables +struct CmdlineArgs { + /// The path to the binary. + binary: String, + + /// Path to a custom configuration file to use instead of the standard one. + #[structopt(long, short)] + config: Option<String>, + + /// Write the results to a file. + #[structopt(long, short)] + out: Option<String>, + + /// Specify a specific set of checks to be run. + #[structopt(long, short)] + partial: Option<String>, + + /// Generate JSON output. + #[structopt(long, short)] + json: bool, + + /// Do not print log messages. This prevents polluting STDOUT for json output. + #[structopt(long, short)] + quiet: bool, + + /// Checks if there is a path from an input function to a CWE hit. + #[structopt(long)] + check_path: bool, + + /// Prints out the version numbers of all known modules. + #[structopt(long)] + module_versions: bool, +} + +fn main() { + let cmdline_args = CmdlineArgs::from_args(); + + if let Some(exit_code) = build_bap_command(&cmdline_args).status().unwrap().code() { + std::process::exit(exit_code); + } +} + +/// Build the BAP command corresponding to the given command line arguments. +fn build_bap_command(args: &CmdlineArgs) -> Command { + let mut command = Command::new("bap"); + command.arg(&args.binary); + command.arg("--pass=cwe-checker"); + if let Some(ref string) = args.config { + command.arg("--cwe-checker-config=".to_string() + string); + } + if let Some(ref string) = args.out { + command.arg("--cwe-checker-out=".to_string() + string); + } + if let Some(ref string) = args.partial { + command.arg("--cwe-checker-partial=".to_string() + string); + } + if args.json { + command.arg("--cwe-checker-json"); + } + if args.quiet { + command.arg("--cwe-checker-no-logging"); + } + if args.check_path { + command.arg("--cwe-checker-check-path"); + } + if args.module_versions { + command.arg("--cwe-checker-module-versions"); + } + command +} diff --git a/cwe_checker_rs/Cargo.toml b/cwe_checker_rs/Cargo.toml index 84db22f..813b991 100644 --- a/cwe_checker_rs/Cargo.toml +++ b/cwe_checker_rs/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cwe_checker_rs" -version = "0.1.0" +version = "0.4.0-dev" authors = ["Nils-Edvin Enkelmann <nils-edvin.enkelmann@fkie.fraunhofer.de>"] edition = "2018"