main: add hash command

master
dece 4 years ago
parent 08cd2e4ec6
commit 026797d935

@ -52,11 +52,17 @@ fn main() {
.takes_value(true) .takes_value(true)
.required(false) .required(false)
.default_value(default_namefilepath))) .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(); .get_matches();
process::exit(match matches.subcommand() { process::exit(match matches.subcommand() {
("bhd", Some(s)) => { cmd_bhd(s) } ("bhd", Some(s)) => { cmd_bhd(s) }
("bhds", Some(s)) => { cmd_bhds(s) } ("bhds", Some(s)) => { cmd_bhds(s) }
("hash", Some(s)) => { cmd_hash(s) }
_ => { 0 } _ => { 0 }
}) })
} }
@ -113,6 +119,7 @@ fn cmd_bhds(args: &ArgMatches) -> i32 {
bhd_paths.sort(); bhd_paths.sort();
for bhd_path in bhd_paths { for bhd_path in bhd_paths {
println!("Extracting {:?}", bhd_path);
match unpackers::bhd::extract_bhd(bhd_path.to_str().unwrap(), &names, output_path) { match unpackers::bhd::extract_bhd(bhd_path.to_str().unwrap(), &names, output_path) {
Err(e) => { eprintln!("Failed to extract BHD: {:?}", e); return 1 } Err(e) => { eprintln!("Failed to extract BHD: {:?}", e); return 1 }
_ => {} _ => {}
@ -120,3 +127,9 @@ fn cmd_bhds(args: &ArgMatches) -> i32 {
} }
return 0 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
}

@ -6,7 +6,6 @@ use num_bigint::BigUint;
use num_traits::identities::Zero; use num_traits::identities::Zero;
/// Compute the weird hash for a string. Same mechanic since DeS. /// Compute the weird hash for a string. Same mechanic since DeS.
#[allow(dead_code)]
pub fn hash(s: &str) -> u32 { pub fn hash(s: &str) -> u32 {
let s = s.to_lowercase(); let s = s.to_lowercase();
let mut val = BigUint::zero(); let mut val = BigUint::zero();

Loading…
Cancel
Save