various: extract BotStat and error types into library crate
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I09cf5713683831154292cd59fdd2c7596a6a6964
This commit is contained in:
parent
ad6a992aa6
commit
83ae044fd3
4 changed files with 476 additions and 164 deletions
|
|
@ -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() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue