From 026797d935b9a5940e66203bb19ded31c334fa8f Mon Sep 17 00:00:00 2001 From: dece Date: Thu, 16 Apr 2020 13:53:02 +0200 Subject: [PATCH] main: add hash command --- src/main.rs | 13 +++++++++++++ src/name_hashes.rs | 1 - 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 9b09f61..a516f78 100644 --- a/src/main.rs +++ b/src/main.rs @@ -52,11 +52,17 @@ fn main() { .takes_value(true) .required(false) .default_value(default_namefilepath))) + .subcommand(SubCommand::with_name("hash") + .about("Calculate hash for a string") + .arg(Arg::with_name("value") + .takes_value(true) + .required(true))) .get_matches(); process::exit(match matches.subcommand() { ("bhd", Some(s)) => { cmd_bhd(s) } ("bhds", Some(s)) => { cmd_bhds(s) } + ("hash", Some(s)) => { cmd_hash(s) } _ => { 0 } }) } @@ -113,6 +119,7 @@ fn cmd_bhds(args: &ArgMatches) -> i32 { bhd_paths.sort(); for bhd_path in bhd_paths { + println!("Extracting {:?}", bhd_path); match unpackers::bhd::extract_bhd(bhd_path.to_str().unwrap(), &names, output_path) { Err(e) => { eprintln!("Failed to extract BHD: {:?}", e); return 1 } _ => {} @@ -120,3 +127,9 @@ fn cmd_bhds(args: &ArgMatches) -> i32 { } return 0 } + +fn cmd_hash(args: &ArgMatches) -> i32 { + let value: &str = args.value_of("value").unwrap(); + println!("{}", name_hashes::hash_as_string(name_hashes::hash(&value))); + 0 +} diff --git a/src/name_hashes.rs b/src/name_hashes.rs index 79fa2b5..f937e89 100644 --- a/src/name_hashes.rs +++ b/src/name_hashes.rs @@ -6,7 +6,6 @@ use num_bigint::BigUint; use num_traits::identities::Zero; /// Compute the weird hash for a string. Same mechanic since DeS. -#[allow(dead_code)] pub fn hash(s: &str) -> u32 { let s = s.to_lowercase(); let mut val = BigUint::zero();