diff --git a/ghost-core/Cargo.toml b/ghost-core/Cargo.toml index 2ff608f..5b25ae1 100644 --- a/ghost-core/Cargo.toml +++ b/ghost-core/Cargo.toml @@ -32,6 +32,7 @@ windows = { version = "0.58", features = [ "Win32_System_ProcessStatus", "Win32_System_Memory", "Win32_System_LibraryLoader", + "Win32_System_Kernel", "Win32_Security", "Win32_UI_WindowsAndMessaging", ] } diff --git a/ghost-core/src/error.rs b/ghost-core/src/error.rs index b55e6b7..2fb66cf 100644 --- a/ghost-core/src/error.rs +++ b/ghost-core/src/error.rs @@ -16,6 +16,9 @@ pub enum GhostError { #[error("Memory enumeration failed: {reason}")] MemoryEnumeration { reason: String }, + #[error("Memory read error: {message}")] + MemoryRead { message: String }, + #[error("Thread enumeration failed: {reason}")] ThreadEnumeration { reason: String }, diff --git a/ghost-core/src/hooks.rs b/ghost-core/src/hooks.rs index 2ce3bbb..45eed50 100644 --- a/ghost-core/src/hooks.rs +++ b/ghost-core/src/hooks.rs @@ -404,7 +404,7 @@ mod platform { // Create memory reader closure let memory_reader = |pid: u32, addr: usize, size: usize| -> Result> { let handle = OpenProcess(PROCESS_VM_READ, false, pid).map_err(|e| { - GhostError::MemoryReadError(format!("OpenProcess failed: {}", e)) + GhostError::MemoryRead { message: format!("OpenProcess failed: {}", e) } })?; let mut buffer = vec![0u8; size]; @@ -424,9 +424,9 @@ mod platform { buffer.truncate(bytes_read); Ok(buffer) } else { - Err(GhostError::MemoryReadError( - "ReadProcessMemory failed".to_string(), - )) + Err(GhostError::MemoryRead { + message: "ReadProcessMemory failed".to_string(), + }) } }; diff --git a/ghost-core/src/pe_parser.rs b/ghost-core/src/pe_parser.rs index 4f726d8..bcedf30 100644 --- a/ghost-core/src/pe_parser.rs +++ b/ghost-core/src/pe_parser.rs @@ -289,11 +289,11 @@ fn parse_iat_from_disk(file_path: &str) -> Result> { use std::io::Read; let mut file = File::open(file_path) - .map_err(|e| GhostError::ConfigurationError(format!("Failed to open file: {}", e)))?; + .map_err(|e| GhostError::Configuration { message: format!("Failed to open file: {}", e) })?; let mut buffer = Vec::new(); file.read_to_end(&mut buffer) - .map_err(|e| GhostError::ConfigurationError(format!("Failed to read file: {}", e)))?; + .map_err(|e| GhostError::Configuration { message: format!("Failed to read file: {}", e) })?; parse_iat_from_buffer(&buffer) } @@ -301,11 +301,10 @@ fn parse_iat_from_disk(file_path: &str) -> Result> { /// Parse IAT from memory buffer #[cfg(windows)] fn parse_iat_from_buffer(buffer: &[u8]) -> Result> { - use std::mem; let reader = |_pid: u32, offset: usize, size: usize| -> Result> { if offset + size > buffer.len() { - return Err(GhostError::MemoryReadError("Buffer overflow".to_string())); + return Err(GhostError::MemoryRead { message: "Buffer overflow".to_string() }); } Ok(buffer[offset..offset + size].to_vec()) }; @@ -424,7 +423,7 @@ fn read_cstring( offset += 16; if offset > 512 { - return Err(GhostError::MemoryReadError("String too long".to_string())); + return Err(GhostError::MemoryRead { message: "String too long".to_string() }); } } } diff --git a/ghost-core/src/thread.rs b/ghost-core/src/thread.rs index 2816f8b..e967fa7 100644 --- a/ghost-core/src/thread.rs +++ b/ghost-core/src/thread.rs @@ -284,7 +284,6 @@ mod platform { pid: u32, memory_regions: &[crate::MemoryRegion], ) -> Result { - use windows::Win32::System::Diagnostics::Debug::ReadProcessMemory; use windows::Win32::System::Threading::{ GetThreadContext, OpenProcess, ResumeThread, SuspendThread, PROCESS_QUERY_INFORMATION, PROCESS_VM_READ, THREAD_GET_CONTEXT, THREAD_SUSPEND_RESUME, diff --git a/ghost-core/src/yara_engine.rs b/ghost-core/src/yara_engine.rs index ca57428..bc6b998 100644 --- a/ghost-core/src/yara_engine.rs +++ b/ghost-core/src/yara_engine.rs @@ -410,7 +410,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> { - use windows::Win32::Foundation::{CloseHandle, HANDLE}; + use windows::Win32::Foundation::CloseHandle; use windows::Win32::System::Diagnostics::Debug::ReadProcessMemory; use windows::Win32::System::Threading::{OpenProcess, PROCESS_VM_READ};