From 3414d05821fcc80182612853dfcdaf3b6e1d7f9e Mon Sep 17 00:00:00 2001 From: pandaadir05 Date: Fri, 21 Nov 2025 02:01:52 +0200 Subject: [PATCH] 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 --- ghost-core/src/yara_engine.rs | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/ghost-core/src/yara_engine.rs b/ghost-core/src/yara_engine.rs index b79751f..4a37dc4 100644 --- a/ghost-core/src/yara_engine.rs +++ b/ghost-core/src/yara_engine.rs @@ -149,23 +149,21 @@ impl DynamicYaraEngine { .and_then(|s| s.to_str()) .unwrap_or("default"); - match compiler.add_rules_str_with_namespace(&content, namespace) { - Ok(_) => { - 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) => { - log::error!("Failed to compile {}: {}", rule_file.display(), e); - } + if let Err(e) = compiler.add_rules_str(&content) { + log::error!("Failed to compile {}: {}", rule_file.display(), e); + continue; } + + 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) => { 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 .compile_rules() .map_err(|e| GhostError::Configuration { @@ -188,6 +186,8 @@ impl DynamicYaraEngine { self.compiled_rules = Some(compiled_rules); + self.compiled_rules = Some(compiled_rules); + log::info!("Successfully compiled {} YARA rules", rule_count); Ok(rule_count) }