various: extract BotStat and error types into library crate

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I09cf5713683831154292cd59fdd2c7596a6a6964
This commit is contained in:
raf 2026-03-01 21:09:46 +03:00
commit 83ae044fd3
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
4 changed files with 476 additions and 164 deletions

View file

@ -90,6 +90,7 @@ pub struct MarkovGenerator {
}
impl MarkovGenerator {
#[must_use]
pub fn new(corpus_dir: &str) -> Self {
let mut chains = HashMap::new();
@ -101,28 +102,22 @@ impl MarkovGenerator {
// Load corpus files if they exist
let path = Path::new(corpus_dir);
if path.exists() && path.is_dir() {
if let Ok(entries) = fs::read_dir(path) {
for entry in entries {
if let Ok(entry) = entry {
let file_path = entry.path();
if let Some(file_name) = file_path.file_stem() {
if let Some(file_name_str) = file_name.to_str() {
if types.contains(&file_name_str) {
if let Ok(content) = fs::read_to_string(&file_path) {
let mut chain = Chain::new(DEFAULT_ORDER);
for line in content.lines() {
chain.add(line);
}
chains.insert(file_name_str.to_string(), chain);
if path.exists() && path.is_dir()
&& let Ok(entries) = fs::read_dir(path) {
for entry in entries.flatten() {
let file_path = entry.path();
if let Some(file_name) = file_path.file_stem()
&& let Some(file_name_str) = file_name.to_str()
&& types.contains(&file_name_str)
&& let Ok(content) = fs::read_to_string(&file_path) {
let mut chain = Chain::new(DEFAULT_ORDER);
for line in content.lines() {
chain.add(line);
}
chains.insert(file_name_str.to_string(), chain);
}
}
}
}
}
}
}
// If corpus files didn't exist, initialize with some default content
if chains["php_exploit"].start_states.is_empty() {