pub mod elf;
pub mod mach;
pub mod pe;
use yara::{Compiler, MetadataValue};
use crate::errors::BinResult;
use crate::rules::UNIVERSAL_COMPILER_RULES;
pub type GenericMap = std::collections::BTreeMap<String, serde_json::Value>;
pub trait Analyze {
fn detect_compiler_runtime(&self, os_specific: &str, bytes: &[u8]) -> BinResult<String> {
let mut compiler = Compiler::new()?;
compiler.add_rules_str(UNIVERSAL_COMPILER_RULES)?;
compiler.add_rules_str(os_specific)?;
let rules = compiler.compile_rules()?;
let matches = rules.scan_mem(&bytes, 5)?;
if matches.is_empty() {
return Ok("N/A".to_string());
}
if let MetadataValue::String(name) = matches[0].metadatas[0].value {
Ok(name.to_string())
} else {
Ok("N/A".to_string())
}
}
fn run_compilation_checks(&self, bytes: &[u8]) -> BinResult<GenericMap>;
fn run_mitigation_checks(&self) -> GenericMap;
}