use std::fs;
use std::process::ExitCode;
fn main() -> ExitCode {
let Some(path) = std::env::args().nth(1) else {
eprintln!("usage: sync <path-to-hashcat-example-hashes.md>");
eprintln!(" emits `mode<TAB>example` rows parsed from hashcat's example-hash table.");
return ExitCode::from(2);
};
let text = match fs::read_to_string(&path) {
Ok(t) => t,
Err(e) => {
eprintln!("error: cannot read {path}: {e}");
return ExitCode::from(2);
}
};
let mut count = 0usize;
for line in text.lines() {
let line = line.trim();
if !line.starts_with('|') {
continue;
}
let cells: Vec<&str> = line.trim_matches('|').split('|').map(str::trim).collect();
if cells.len() < 3 {
continue;
}
let Ok(mode) = cells[0].parse::<u32>() else {
continue;
};
let example = cells[2].trim_matches('`').trim();
if example.is_empty() {
continue;
}
println!("{mode}\t{example}");
count += 1;
}
eprintln!("parsed {count} example(s) from {path}");
ExitCode::SUCCESS
}