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:
......
......@@ -19,15 +19,6 @@ dependencies = [
]
[[package]]
name = "ansi_term"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
dependencies = [
"winapi",
]
[[package]]
name = "anyhow"
version = "1.0.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
......@@ -58,9 +49,9 @@ dependencies = [
[[package]]
name = "autocfg"
version = "1.0.1"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "bitflags"
......@@ -76,17 +67,39 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "clap"
version = "2.33.3"
version = "4.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002"
checksum = "30607dd93c420c6f1f80b544be522a0238a7db35e6a12968d28910983fee0df0"
dependencies = [
"ansi_term",
"atty",
"bitflags",
"clap_derive",
"clap_lex",
"once_cell",
"strsim",
"textwrap",
"unicode-width",
"vec_map",
"termcolor",
]
[[package]]
name = "clap_derive"
version = "4.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4a307492e1a34939f79d3b6b9650bd2b971513cd775436bf2b78defeb5af00b"
dependencies = [
"heck",
"proc-macro-error",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "clap_lex"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8"
dependencies = [
"os_str_bytes",
]
[[package]]
......@@ -130,11 +143,11 @@ dependencies = [
name = "cwe_checker"
version = "0.7.0-dev"
dependencies = [
"clap",
"cwe_checker_lib",
"directories",
"nix",
"serde_json",
"structopt",
]
[[package]]
......@@ -142,10 +155,10 @@ name = "cwe_checker_install"
version = "0.1.0"
dependencies = [
"anyhow",
"clap",
"directories",
"serde",
"serde_json",
"structopt",
"walkdir",
]
......@@ -203,12 +216,6 @@ dependencies = [
]
[[package]]
name = "dtoa"
version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56899898ce76aaf4a0f24d914c97ea6ed976d42fec6ad33fcbb0a1103e07b2b0"
[[package]]
name = "either"
version = "1.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
......@@ -265,18 +272,15 @@ dependencies = [
[[package]]
name = "hashbrown"
version = "0.11.2"
version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
[[package]]
name = "heck"
version = "0.3.3"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c"
dependencies = [
"unicode-segmentation",
]
checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9"
[[package]]
name = "hermit-abi"
......@@ -289,9 +293,9 @@ dependencies = [
[[package]]
name = "indexmap"
version = "1.7.0"
version = "1.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5"
checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e"
dependencies = [
"autocfg",
"hashbrown",
......@@ -313,6 +317,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4"
[[package]]
name = "itoa"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754"
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
......@@ -320,15 +330,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.126"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836"
[[package]]
name = "linked-hash-map"
version = "0.5.4"
version = "0.2.134"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fb9b38af92608140b86b693604b9ffcc5824240a484d1ecd4795bacb2fe88f3"
checksum = "329c933548736bc49fd575ee68c89e8be4d260064184389a5b77517cddd99ffb"
[[package]]
name = "log"
......@@ -362,17 +366,31 @@ dependencies = [
[[package]]
name = "nix"
version = "0.24.1"
version = "0.25.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f17df307904acd05aa8e32e97bb20f2a0df1728bbc2d771ae8f9a90463441e9"
checksum = "e322c04a9e3440c327fca7b6c8a63e6890a32fa2ad689db972425f07e0d22abb"
dependencies = [
"autocfg",
"bitflags",
"cfg-if",
"libc",
"memoffset",
"pin-utils",
]
[[package]]
name = "once_cell"
version = "1.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1"
[[package]]
name = "os_str_bytes"
version = "6.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ff7415e9ae3fff1225851df9e0d9e4e5479f947619774677a63572e55e80eff"
[[package]]
name = "paste"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
......@@ -400,6 +418,12 @@ dependencies = [
]
[[package]]
name = "pin-utils"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
[[package]]
name = "plain"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
......@@ -431,11 +455,11 @@ dependencies = [
[[package]]
name = "proc-macro2"
version = "1.0.29"
version = "1.0.46"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9f5105d4fdaab20335ca9565e106a5d9b82b6219b5ba735731124ac6711d23d"
checksum = "94e2ef8dbfc347b10c094890f778ee2e36ca9bb4262e86dc99cd217e35f3470b"
dependencies = [
"unicode-xid",
"unicode-ident",
]
[[package]]
......@@ -584,18 +608,18 @@ dependencies = [
[[package]]
name = "serde"
version = "1.0.130"
version = "1.0.145"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f12d06de37cf59146fbdecab66aa99f9fe4f78722e3607577a5375d66bd0c913"
checksum = "728eb6351430bccb993660dfffc5a72f91ccc1295abaa8ce19b27ebe4f75568b"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.130"
version = "1.0.145"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7bc1a1ab1961464eae040d96713baa5a724a8152c1222492465b54322ec508b"
checksum = "81fa1584d3d1bcacd84c277a0dfe21f5b0f6accf4a23d04d4c6d61f1af522b4c"
dependencies = [
"proc-macro2",
"quote",
......@@ -608,21 +632,22 @@ version = "1.0.68"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f690853975602e1bfe1ccbf50504d67174e3bcf340f23b5ea9992e0587a52d8"
dependencies = [
"itoa",
"itoa 0.4.8",
"ryu",
"serde",
]
[[package]]
name = "serde_yaml"
version = "0.8.21"
version = "0.9.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8c608a35705a5d3cdc9fbe403147647ff34b921f8e833e49306df898f9b20af"
checksum = "8613d593412a0deb7bbd8de9d908efff5a0cb9ccd8f62c641e7b2ed2f57291d1"
dependencies = [
"dtoa",
"indexmap",
"itoa 1.0.3",
"ryu",
"serde",
"yaml-rust",
"unsafe-libyaml",
]
[[package]]
......@@ -636,52 +661,28 @@ dependencies = [
[[package]]
name = "strsim"
version = "0.8.0"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
[[package]]
name = "structopt"
version = "0.3.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf9d950ef167e25e0bdb073cf1d68e9ad2795ac826f2f3f59647817cf23c0bfa"
dependencies = [
"clap",
"lazy_static",
"structopt-derive",
]
[[package]]
name = "structopt-derive"
version = "0.4.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "134d838a2c9943ac3125cf6df165eda53493451b719f3255b2a26b85f772d0ba"
dependencies = [
"heck",
"proc-macro-error",
"proc-macro2",
"quote",
"syn",
]
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "syn"
version = "1.0.77"
version = "1.0.101"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5239bc68e0fef57495900cfea4e8dc75596d9a319d7e16b1e0a440d24e6fe0a0"
checksum = "e90cde112c4b9690b8cbe810cba9ddd8bc1d7472e2cae317b69e9438c1cba7d2"
dependencies = [
"proc-macro2",
"quote",
"unicode-xid",
"unicode-ident",
]
[[package]]
name = "textwrap"
version = "0.11.0"
name = "termcolor"
version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755"
dependencies = [
"unicode-width",
"winapi-util",
]
[[package]]
......@@ -691,28 +692,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c"
[[package]]
name = "unicode-segmentation"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b"
[[package]]
name = "unicode-width"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973"
[[package]]
name = "unicode-xid"
version = "0.2.2"
name = "unicode-ident"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
checksum = "dcc811dc4066ac62f84f11307873c4850cb653bfa9b1719cee2bd2204a4bc5dd"
[[package]]
name = "vec_map"
version = "0.8.2"
name = "unsafe-libyaml"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
checksum = "c1e5fa573d8ac5f1a856f8d7be41d390ee973daf97c806b2c1a465e4e1406e68"
[[package]]
name = "version_check"
......@@ -767,12 +756,3 @@ name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "yaml-rust"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85"
dependencies = [
"linked-hash-map",
]
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