From 45b95ce7d3096d5c3390c15362e69d9124cf8f9a Mon Sep 17 00:00:00 2001 From: Adir Shitrit Date: Fri, 21 Nov 2025 00:41:25 +0200 Subject: [PATCH] fix: formatting the code for cicd --- ghost-core/src/detection.rs | 24 ++++++++++-------------- ghost-core/src/lib.rs | 3 +-- ghost-core/src/yara_engine.rs | 35 +++++++++++++---------------------- 3 files changed, 24 insertions(+), 38 deletions(-) diff --git a/ghost-core/src/detection.rs b/ghost-core/src/detection.rs index cc1c332..65c6a7e 100644 --- a/ghost-core/src/detection.rs +++ b/ghost-core/src/detection.rs @@ -262,20 +262,16 @@ impl DetectionEngine { // YARA rule scanning if let Some(yara_engine) = &self.yara_engine { - if let Ok(yara_result) = - tokio::runtime::Handle::try_current() - .and_then(|handle| { - handle.block_on(async { - yara_engine.scan_process(process, memory_regions).await - }) - }) - .or_else(|_| { - tokio::runtime::Runtime::new() - .unwrap() - .block_on(async { - yara_engine.scan_process(process, memory_regions).await - }) - }) + if let Ok(yara_result) = tokio::runtime::Handle::try_current() + .and_then(|handle| { + handle + .block_on(async { yara_engine.scan_process(process, memory_regions).await }) + }) + .or_else(|_| { + tokio::runtime::Runtime::new() + .unwrap() + .block_on(async { yara_engine.scan_process(process, memory_regions).await }) + }) { if !yara_result.matches.is_empty() { log::info!( diff --git a/ghost-core/src/lib.rs b/ghost-core/src/lib.rs index e1b0892..c20d3bf 100644 --- a/ghost-core/src/lib.rs +++ b/ghost-core/src/lib.rs @@ -110,6 +110,5 @@ pub use threat_intel::{ ThreatContext, ThreatIntelligence, }; pub use yara_engine::{ - DynamicYaraEngine, RuleMatch, ThreatLevel as YaraThreatLevel, YaraRuleMetadata, - YaraScanResult, + DynamicYaraEngine, RuleMatch, ThreatLevel as YaraThreatLevel, YaraRuleMetadata, YaraScanResult, }; diff --git a/ghost-core/src/yara_engine.rs b/ghost-core/src/yara_engine.rs index 9302e14..39af49e 100644 --- a/ghost-core/src/yara_engine.rs +++ b/ghost-core/src/yara_engine.rs @@ -154,11 +154,9 @@ impl DynamicYaraEngine { )); } - self.compiled_rules = Some( - compiler - .compile_rules() - .map_err(|e| GhostError::ConfigurationError(format!("Rule compilation failed: {}", e)))?, - ); + self.compiled_rules = Some(compiler.compile_rules().map_err(|e| { + GhostError::ConfigurationError(format!("Rule compilation failed: {}", e)) + })?); log::info!("Successfully compiled {} YARA rules", rule_count); Ok(rule_count) @@ -202,9 +200,10 @@ impl DynamicYaraEngine { ) -> Result { let start_time = SystemTime::now(); - let rules = self.compiled_rules.as_ref().ok_or_else(|| { - GhostError::ConfigurationError("YARA rules not compiled".to_string()) - })?; + let rules = self + .compiled_rules + .as_ref() + .ok_or_else(|| GhostError::ConfigurationError("YARA rules not compiled".to_string()))?; let mut all_matches = Vec::new(); let mut bytes_scanned = 0u64; @@ -322,10 +321,7 @@ impl DynamicYaraEngine { /// Read memory from a specific process and region #[cfg(target_os = "windows")] - fn read_process_memory( - pid: u32, - region: &MemoryRegion, - ) -> Result, GhostError> { + fn read_process_memory(pid: u32, region: &MemoryRegion) -> Result, GhostError> { use windows::Win32::Foundation::{CloseHandle, HANDLE}; use windows::Win32::System::Diagnostics::Debug::ReadProcessMemory; use windows::Win32::System::Threading::{OpenProcess, PROCESS_VM_READ}; @@ -360,16 +356,14 @@ impl DynamicYaraEngine { /// Read memory from a specific process and region (Linux implementation) #[cfg(target_os = "linux")] - fn read_process_memory( - pid: u32, - region: &MemoryRegion, - ) -> Result, GhostError> { + fn read_process_memory(pid: u32, region: &MemoryRegion) -> Result, GhostError> { use std::fs::File; use std::io::{Read, Seek, SeekFrom}; let mem_path = format!("/proc/{}/mem", pid); - let mut file = File::open(&mem_path) - .map_err(|e| GhostError::MemoryReadError(format!("Failed to open {}: {}", mem_path, e)))?; + let mut file = File::open(&mem_path).map_err(|e| { + GhostError::MemoryReadError(format!("Failed to open {}: {}", mem_path, e)) + })?; file.seek(SeekFrom::Start(region.base_address as u64)) .map_err(|e| GhostError::MemoryReadError(format!("Seek failed: {}", e)))?; @@ -383,10 +377,7 @@ impl DynamicYaraEngine { /// Read memory from a specific process and region (macOS implementation) #[cfg(target_os = "macos")] - fn read_process_memory( - _pid: u32, - _region: &MemoryRegion, - ) -> Result, GhostError> { + fn read_process_memory(_pid: u32, _region: &MemoryRegion) -> Result, GhostError> { Err(GhostError::NotImplemented( "Memory reading not implemented for macOS".to_string(), ))