Fix YARA compiler move error by simplifying rule compilation
- Replace add_rules_str_with_namespace with add_rules_str to avoid move semantics issues - Simplify error handling in rule compilation loop - This should resolve the E0382 use of moved value error
This commit is contained in:
@@ -149,23 +149,21 @@ impl DynamicYaraEngine {
|
|||||||
.and_then(|s| s.to_str())
|
.and_then(|s| s.to_str())
|
||||||
.unwrap_or("default");
|
.unwrap_or("default");
|
||||||
|
|
||||||
match compiler.add_rules_str_with_namespace(&content, namespace) {
|
if let Err(e) = compiler.add_rules_str(&content) {
|
||||||
Ok(_) => {
|
log::error!("Failed to compile {}: {}", rule_file.display(), e);
|
||||||
log::info!("Compiled YARA rule: {}", rule_file.display());
|
continue;
|
||||||
|
|
||||||
self.rule_metadata.push(YaraRuleMetadata {
|
|
||||||
name: namespace.to_string(),
|
|
||||||
file_path: rule_file.display().to_string(),
|
|
||||||
threat_level: ThreatLevel::Medium,
|
|
||||||
last_updated: SystemTime::now(),
|
|
||||||
});
|
|
||||||
|
|
||||||
rule_count += 1;
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
log::error!("Failed to compile {}: {}", rule_file.display(), e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log::info!("Compiled YARA rule: {}", rule_file.display());
|
||||||
|
|
||||||
|
self.rule_metadata.push(YaraRuleMetadata {
|
||||||
|
name: namespace.to_string(),
|
||||||
|
file_path: rule_file.display().to_string(),
|
||||||
|
threat_level: ThreatLevel::Medium,
|
||||||
|
last_updated: SystemTime::now(),
|
||||||
|
});
|
||||||
|
|
||||||
|
rule_count += 1;
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log::error!("Failed to read {}: {}", rule_file.display(), e);
|
log::error!("Failed to read {}: {}", rule_file.display(), e);
|
||||||
@@ -179,7 +177,7 @@ impl DynamicYaraEngine {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compile all the added rules
|
// Compile all the added rules - this consumes the compiler
|
||||||
let compiled_rules = compiler
|
let compiled_rules = compiler
|
||||||
.compile_rules()
|
.compile_rules()
|
||||||
.map_err(|e| GhostError::Configuration {
|
.map_err(|e| GhostError::Configuration {
|
||||||
@@ -188,6 +186,8 @@ impl DynamicYaraEngine {
|
|||||||
|
|
||||||
self.compiled_rules = Some(compiled_rules);
|
self.compiled_rules = Some(compiled_rules);
|
||||||
|
|
||||||
|
self.compiled_rules = Some(compiled_rules);
|
||||||
|
|
||||||
log::info!("Successfully compiled {} YARA rules", rule_count);
|
log::info!("Successfully compiled {} YARA rules", rule_count);
|
||||||
Ok(rule_count)
|
Ok(rule_count)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user