From 6194f07bc57d940eb3d59b08a422958d75f0c8b4 Mon Sep 17 00:00:00 2001 From: Travis Finkenauer Date: Sun, 14 Apr 2024 17:20:13 -0700 Subject: [PATCH] cstool: upgrade deps --- Cargo.lock | 68 +++++++++++++++++--- cstool/Cargo.toml | 6 +- cstool/src/bin/cstool.rs | 134 +++++++++++++++++++-------------------- 3 files changed, 127 insertions(+), 81 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 846d0358..808136c6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -26,13 +26,19 @@ dependencies = [ "libc", ] +[[package]] +name = "anstyle" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc" + [[package]] name = "atty" version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ - "hermit-abi", + "hermit-abi 0.1.19", "libc", "winapi", ] @@ -112,9 +118,9 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" [[package]] name = "cc" -version = "1.0.92" +version = "1.0.94" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2678b2e3449475e95b0aa6f9b506a28e61b3dc8996592b983695e8ebb58a8b41" +checksum = "17f6e324229dc011159fcc089755d1e2e216a90d43a7dea6853ca740b84f35e7" [[package]] name = "cexpr" @@ -167,6 +173,31 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "clap" +version = "4.4.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e578d6ec4194633722ccf9544794b71b1385c3c027efe0c55db226fc880865c" +dependencies = [ + "clap_builder", +] + +[[package]] +name = "clap_builder" +version = "4.4.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4df4df40ec50c46000231c914968278b1eb05098cf8f1b3a518a95030e71d1c7" +dependencies = [ + "anstyle", + "clap_lex", +] + +[[package]] +name = "clap_lex" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1" + [[package]] name = "core-foundation-sys" version = "0.8.6" @@ -181,7 +212,7 @@ checksum = "b01d6de93b2b6c65e17c634a26653a29d107b3c98c607c765bf38d041531cd8f" dependencies = [ "atty", "cast", - "clap", + "clap 2.34.0", "criterion-plot", "csv", "itertools", @@ -239,7 +270,7 @@ name = "cstool" version = "0.1.0" dependencies = [ "capstone", - "clap", + "clap 4.4.18", "log", "stderrlog", ] @@ -302,6 +333,12 @@ dependencies = [ "libc", ] +[[package]] +name = "hermit-abi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" + [[package]] name = "home" version = "0.5.9" @@ -334,6 +371,17 @@ dependencies = [ "cc", ] +[[package]] +name = "is-terminal" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f23ff5ef2b80d608d61efee834934d862cd92461afc0560dedf493e4c033738b" +dependencies = [ + "hermit-abi 0.3.9", + "libc", + "windows-sys", +] + [[package]] name = "itertools" version = "0.10.5" @@ -493,9 +541,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.79" +version = "1.0.80" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" +checksum = "a56dea16b0a29e94408b9aa5e2940a4eedbd128a1ba20e8f7ae60fd3d465af0e" dependencies = [ "unicode-ident", ] @@ -641,12 +689,12 @@ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" [[package]] name = "stderrlog" -version = "0.5.4" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69a26bbf6de627d389164afa9783739b56746c6c72c4ed16539f4ff54170327b" +checksum = "61c910772f992ab17d32d6760e167d2353f4130ed50e796752689556af07dc6b" dependencies = [ - "atty", "chrono", + "is-terminal", "log", "termcolor", "thread_local", diff --git a/cstool/Cargo.toml b/cstool/Cargo.toml index 8d9caccb..d6ca43cd 100644 --- a/cstool/Cargo.toml +++ b/cstool/Cargo.toml @@ -8,12 +8,12 @@ edition = "2018" [dependencies] capstone = { path = "../capstone-rs", version = "0.12.0" } log = "0.4" -stderrlog = "0.5" +stderrlog = "0.6" [dependencies.clap] -version = "2.32" +version = "4.4.*" default-features = false -features = [] +features = ["error-context", "help", "std", "string", "usage"] [features] default = ["full"] diff --git a/cstool/src/bin/cstool.rs b/cstool/src/bin/cstool.rs index e3209562..469509f9 100644 --- a/cstool/src/bin/cstool.rs +++ b/cstool/src/bin/cstool.rs @@ -8,7 +8,10 @@ use std::process::exit; use std::str::FromStr; use capstone::{self, prelude::*, Arch, Endian, EnumList, ExtraMode, Mode}; -use clap::{App, Arg, ArgGroup}; +use clap::{ + builder::{PossibleValuesParser, Str}, + Arg, ArgAction, ArgGroup, Command, +}; use log::{debug, info}; const DEFAULT_CAPACITY: usize = 1024; @@ -143,120 +146,110 @@ Example: fn main() { // Lowercase arches - let _arches: Vec = Arch::variants() + let arches: Vec = Arch::variants() .iter() - .map(|x| format!("{}", x).to_lowercase()) + .map(|x| format!("{}", x).to_lowercase().into()) .collect(); - let arches: Vec<&str> = _arches.iter().map(|x| x.as_str()).collect(); // Lowercase modes - let _modes: Vec = Mode::variants() + let modes: Vec = Mode::variants() .iter() - .map(|x| format!("{}", x).to_lowercase()) + .map(|x| format!("{}", x).to_lowercase().into()) .collect(); - let modes: Vec<&str> = _modes.iter().map(|x| x.as_str()).collect(); // Lowercase extra modes - let _extra_modes: Vec = ExtraMode::variants() + let extra_modes: Vec = ExtraMode::variants() .iter() - .map(|x| format!("{}", x).to_lowercase()) + .map(|x| format!("{}", x).to_lowercase().into()) .collect(); - let extra_modes: Vec<&str> = _extra_modes.iter().map(|x| x.as_str()).collect(); - let matches = App::new("capstone-rs disassembler tool") + let matches = Command::new("capstone-rs disassembler tool") .about("Disassembles binary file") .after_help(AFTER_HELP) .arg( - Arg::with_name(FILE_ARG) - .short("f") + Arg::new(FILE_ARG) + .short('f') .long(FILE_ARG) .help("input file with binary instructions") - .takes_value(true), + .value_name("FILE"), ) .arg( - Arg::with_name(STDIN_ARG) - .short("s") + Arg::new(STDIN_ARG) + .short('s') .long(STDIN_ARG) .help("read binary instructions from stdin") - .takes_value(false), + .action(ArgAction::SetTrue), ) .arg( - Arg::with_name(CODE_ARG) - .short("c") + Arg::new(CODE_ARG) + .short('c') .long(CODE_ARG) - .help("instruction bytes (implies --hex)") - .takes_value(true), + .help("instruction bytes (implies --hex)"), ) .arg( - Arg::with_name(ADDRESS_ARG) - .short("r") + Arg::new(ADDRESS_ARG) + .short('r') .long("addr") - .help("address of code") - .takes_value(true), + .help("address of code"), ) .arg( - Arg::with_name(VERBOSE_ARG) - .short("v") - .multiple(true) - .help("Sets the level of verbosity"), + Arg::new(VERBOSE_ARG) + .short('v') + .help("Sets the level of verbosity") + .action(ArgAction::Count), ) .arg( - Arg::with_name(HEX_ARG) - .short("x") + Arg::new(HEX_ARG) + .short('x') .long(HEX_ARG) .help("Treat input has hex; only select characters that are [a-fA-F0-9]") - .takes_value(false), + .action(ArgAction::SetTrue), ) .arg( - Arg::with_name(DETAIL_ARG) - .short("d") + Arg::new(DETAIL_ARG) + .short('d') .long(DETAIL_ARG) .help("Print details about instructions") - .takes_value(false), + .action(ArgAction::SetTrue), ) .arg( - Arg::with_name(ARCH_ARG) - .short("a") + Arg::new(ARCH_ARG) + .short('a') .long(ARCH_ARG) .help("Architecture") - .takes_value(true) .required(true) - .possible_values(arches.as_slice()) - .case_insensitive(true), + .value_parser(PossibleValuesParser::new(arches)) + .ignore_case(true), ) .arg( - Arg::with_name(MODE_ARG) - .short("m") + Arg::new(MODE_ARG) + .short('m') .long(MODE_ARG) .help(MODE_ARG) - .takes_value(true) .required(true) - .possible_values(modes.as_slice()) - .case_insensitive(true), + .value_parser(PossibleValuesParser::new(modes)) + .ignore_case(true), ) .arg( - Arg::with_name(EXTRA_MODE_ARG) - .short("e") + Arg::new(EXTRA_MODE_ARG) + .short('e') .long(EXTRA_MODE_ARG) .help("Extra Mode") - .takes_value(true) .required(false) - .possible_values(extra_modes.as_slice()) - .case_insensitive(true) - .multiple(true), + .value_parser(PossibleValuesParser::new(extra_modes)) + .ignore_case(true), ) .arg( - Arg::with_name(ENDIAN_ARG) - .short("n") + Arg::new(ENDIAN_ARG) + .short('n') .long(ENDIAN_ARG) .help("Endianness") - .takes_value(true) .required(false) - .possible_values(&["little", "big"]) - .case_insensitive(true), + .value_parser(PossibleValuesParser::new(["little", "big"])) + .ignore_case(true), ) .group( - ArgGroup::with_name("input") + ArgGroup::new("input") .arg(FILE_ARG) .arg(STDIN_ARG) .arg(CODE_ARG) @@ -264,7 +257,7 @@ fn main() { ) .get_matches(); - let direct_input_bytes: Vec = if let Some(file_path) = matches.value_of(FILE_ARG) { + let direct_input_bytes: Vec = if let Some(file_path) = matches.get_one::(FILE_ARG) { let mut file = File::open(file_path).expect_exit(); let capacity = match file.metadata() { Err(_) => DEFAULT_CAPACITY, @@ -273,7 +266,7 @@ fn main() { let mut buf = Vec::with_capacity(capacity); file.read_to_end(&mut buf).expect_exit(); buf - } else if let Some(code) = matches.value_of(CODE_ARG) { + } else if let Some(code) = matches.get_one::(CODE_ARG) { code.as_bytes().to_vec() } else { let mut buf = Vec::with_capacity(DEFAULT_CAPACITY); @@ -283,35 +276,40 @@ fn main() { }; stderrlog::new() - .verbosity(matches.occurrences_of(VERBOSE_ARG) as usize) + .verbosity(matches.get_count(VERBOSE_ARG) as usize) .init() .unwrap(); - let is_hex = matches.is_present(HEX_ARG) || matches.is_present(CODE_ARG); + let is_hex = matches.get_flag(HEX_ARG) || matches.get_one::(CODE_ARG).is_some(); info!("is_hex = {:?}", is_hex); - let show_detail = matches.is_present(DETAIL_ARG); + let show_detail = matches.get_flag(DETAIL_ARG); info!("show_detail = {:?}", show_detail); - let arch: Arch = Arch::from_str(matches.value_of(ARCH_ARG).unwrap()).unwrap(); + let arch: Arch = Arch::from_str(matches.get_one::(ARCH_ARG).unwrap()).unwrap(); info!("Arch = {:?}", arch); - let mode: Mode = Mode::from_str(matches.value_of(MODE_ARG).unwrap()).unwrap(); + let mode: Mode = Mode::from_str(matches.get_one::(MODE_ARG).unwrap()).unwrap(); info!("Mode = {:?}", mode); - let extra_mode: Vec<_> = match matches.values_of(EXTRA_MODE_ARG) { + let extra_mode: Vec<_> = match matches.get_many::(EXTRA_MODE_ARG) { None => Vec::with_capacity(0), Some(x) => x.map(|x| ExtraMode::from_str(x).unwrap()).collect(), }; info!("ExtraMode = {:?}", extra_mode); let endian: Option = matches - .value_of(ENDIAN_ARG) + .get_one::(ENDIAN_ARG) .map(|x| Endian::from_str(x).expect_exit()); info!("Endian = {:?}", endian); - let address = - u64::from_str_radix(matches.value_of(ADDRESS_ARG).unwrap_or("1000"), 16).expect_exit(); + let address = u64::from_str_radix( + matches + .get_one::(ADDRESS_ARG) + .unwrap_or(&"1000".into()), + 16, + ) + .expect_exit(); info!("Address = 0x{:x}", address); let input_bytes = if is_hex {