use std::collections::HashMap;
use fuzzyhash::FuzzyHash;
use log::{debug, error, info, log_enabled, Level};
use serde::{Deserialize, Serialize};
use super::sig_generation::FuzzyFunc;
use crate::{functions_utils::search::Function, sig::sig_generation::hash_functions};
use indicatif::ProgressBar;
#[derive(Serialize, Deserialize)]
pub struct Symbol {
name: String,
rva: u32,
score: u32,
}
fn compare_sigs(from: &Vec<FuzzyFunc>, with: &HashMap<String, String>) -> Vec<Symbol> {
let mut symbols = vec![];
let bar = ProgressBar::new(from.len() as u64);
for f in from {
bar.inc(1);
for (f_name, hash) in with {
if let Ok(val) = FuzzyHash::compare(hash.to_owned(), f.hash.hash.to_string()) {
if val > 25 {
debug!(
"RVA {:08x} - val {} - {} ({} {})",
f.rva, val, &f_name, &f.hash.hash, &hash
);
symbols.push(Symbol {
name: f_name.clone(),
rva: f.rva,
score: val,
});
}
} else {
}
}
}
bar.finish();
symbols
}
pub fn compare(from: &Vec<FuzzyFunc>, with: &HashMap<String, String>) -> Vec<Symbol> {
compare_sigs(&from, &with)
}