Unverified Commit 8372c99a by Enkelmann Committed by GitHub

switch to clap from structopt (#354)

parent 00f223df
......@@ -8,8 +8,8 @@ on:
env:
CARGO_TERM_COLOR: always
GHIDRA_RELEASE_TAG: Ghidra_10.1_build
GHIDRA_VERSION: ghidra_10.1_PUBLIC_20211210
GHIDRA_RELEASE_TAG: Ghidra_10.1.5_build
GHIDRA_VERSION: ghidra_10.1.5_PUBLIC_20220726
jobs:
......
FROM rust:1.57 AS builder
FROM rust:1.63 AS builder
WORKDIR /cwe_checker
......
......@@ -52,7 +52,7 @@ The prebuilt Docker images on dockerhub are currently only x86-based.
### Local installation ###
The following dependencies must be installed in order to build and install the *cwe_checker* locally:
- [Rust](https://www.rust-lang.org) >= 1.57
- [Rust](https://www.rust-lang.org) >= 1.63
- [Ghidra](https://ghidra-sre.org/) >= 10.1.2
Run `make all GHIDRA_PATH=/path/to/ghidra_folder` (with the correct path to the local Ghidra installation inserted) to compile and install the cwe_checker.
......
......@@ -5,8 +5,8 @@ authors = ["Nils-Edvin Enkelmann <nils-edvin.enkelmann@fkie.fraunhofer.de>"]
edition = "2021"
[dependencies]
structopt = "0.3"
clap = { version = "4.0", features = ["derive"] }
cwe_checker_lib = { path = "../cwe_checker_lib" }
serde_json = "1.0"
directories = "4.0.1"
nix = "0.24.1"
\ No newline at end of file
nix = "0.25.0"
\ No newline at end of file
......@@ -3,6 +3,7 @@
extern crate cwe_checker_lib; // Needed for the docstring-link to work
use clap::Parser;
use cwe_checker_lib::analysis::graph;
use cwe_checker_lib::intermediate_representation::RuntimeMemoryImage;
use cwe_checker_lib::utils::binary::BareMetalConfig;
......@@ -15,76 +16,76 @@ use std::collections::{BTreeSet, HashSet};
use std::path::{Path, PathBuf};
use std::process::Command;
use std::thread;
use structopt::StructOpt;
#[derive(Debug, StructOpt)]
#[derive(Debug, Parser)]
#[command(version, about)]
/// Find vulnerable patterns in binary executables
struct CmdlineArgs {
/// The path to the binary.
#[structopt(required_unless("module-versions"), validator(check_file_existence))]
#[arg(required_unless_present("module_versions"), value_parser = check_file_existence)]
binary: Option<String>,
/// Path to a custom configuration file to use instead of the standard one.
#[structopt(long, short, validator(check_file_existence))]
#[arg(long, short, value_parser = check_file_existence)]
config: Option<String>,
/// Write the results to a file instead of stdout.
/// This only affects CWE warnings. Log messages are still printed to stdout.
#[structopt(long, short)]
#[arg(long, short)]
out: Option<String>,
/// Specify a specific set of checks to be run as a comma separated list, e.g. 'CWE332,CWE476,CWE782'.
///
/// Use the "--module-versions" command line option to get a list of all valid check names.
#[structopt(long, short)]
#[arg(long, short)]
partial: Option<String>,
/// Generate JSON output.
#[structopt(long, short)]
#[arg(long, short)]
json: bool,
/// Do not print log messages. This prevents polluting stdout for json output.
#[structopt(long, short)]
#[arg(long, short)]
quiet: bool,
/// Print additional debug log messages.
#[structopt(long, short, conflicts_with("quiet"))]
#[arg(long, short, conflicts_with("quiet"))]
verbose: bool,
/// Include various statistics in the log messages.
/// This can be helpful for assessing the analysis quality for the input binary.
#[structopt(long, conflicts_with("quiet"))]
#[arg(long, conflicts_with("quiet"))]
statistics: bool,
/// Path to a configuration file for analysis of bare metal binaries.
///
/// If this option is set then the input binary is treated as a bare metal binary regardless of its format.
#[structopt(long)]
#[arg(long, value_parser = check_file_existence)]
bare_metal_config: Option<String>,
/// Prints out the version numbers of all known modules.
#[structopt(long)]
#[arg(long)]
module_versions: bool,
/// Output for debugging purposes.
/// The current behavior of this flag is unstable and subject to change.
#[structopt(long, hidden = true)]
#[arg(long, hide(true))]
debug: bool,
}
fn main() {
let cmdline_args = CmdlineArgs::from_args();
let cmdline_args = CmdlineArgs::parse();
run_with_ghidra(&cmdline_args);
}
/// Check the existence of a file
fn check_file_existence(file_path: String) -> Result<(), String> {
/// Return `Ok(file_path)` only if `file_path` points to an existing file.
fn check_file_existence(file_path: &str) -> Result<String, String> {
if std::fs::metadata(&file_path)
.map_err(|err| format!("{}", err))?
.is_file()
{
Ok(())
Ok(file_path.to_string())
} else {
Err(format!("{} is not a file.", file_path))
}
......
......@@ -9,7 +9,7 @@ apint = "0.2"
regex = "1.5.5"
serde = {version = "1.0", features = ["derive", "rc"]}
serde_json = "1.0"
serde_yaml = "0.8"
serde_yaml = "0.9"
petgraph = { version = "0.6", features = ["default", "serde-1"] }
fnv = "1.0" # a faster hash function for small keys like integers
anyhow = "1.0" # for easy error types
......
......@@ -9,4 +9,4 @@ walkdir = "2"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
anyhow = "1.0" # for easy error types
structopt = "0.3"
clap = { version = "4.0", features = ["derive"] }
......@@ -2,24 +2,23 @@
//! It creates config files, copies the Ghida-Plugin and can search for a Ghidra installation at commonly used locations.
use anyhow::{anyhow, Result};
use clap::Parser;
use directories::{BaseDirs, ProjectDirs, UserDirs};
use serde::{Deserialize, Serialize};
use std::env;
use std::fs;
use std::path::{Path, PathBuf};
use structopt::StructOpt;
use walkdir::WalkDir;
#[derive(Debug, StructOpt)]
#[derive(Debug, Parser)]
/// Installs cwe_checker
struct CmdlineArgs {
#[structopt()]
/// Path to a ghidra installation.
///
/// If this option is set then the installation will use ghidra at this location.
ghidra_path: Option<String>,
#[structopt(long, short)]
#[arg(long, short)]
/// If true, cwe_checker will be uninstalled.
uninstall: bool,
}
......@@ -231,7 +230,7 @@ fn uninstall(conf_dir: &Path, data_dir: &Path) -> Result<()> {
fn main() -> Result<()> {
let cwe_checker_proj_dir = ProjectDirs::from("", "", "cwe_checker").unwrap();
let cmdline_args = CmdlineArgs::from_args();
let cmdline_args = CmdlineArgs::parse();
match cmdline_args.uninstall {
true => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment