Fix Windows compilation errors
- Added Win32_System_Kernel feature for CONTEXT structure support
- Added MemoryRead error variant to GhostError enum
- Fixed all MemoryReadError -> MemoryRead { message } conversions
- Fixed all ConfigurationError -> Configuration { message } conversions
- Added missing HashMap import in pe_parser.rs
- Removed unused imports (ReadProcessMemory, HANDLE, std::mem)
- Prefixed unused variables with underscore (_file_header, _suspicious_start_patterns)
This fixes all Windows build errors on CI/CD.
This commit is contained in:
@@ -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",
|
||||
] }
|
||||
|
||||
@@ -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 },
|
||||
|
||||
|
||||
@@ -404,7 +404,7 @@ mod platform {
|
||||
// Create memory reader closure
|
||||
let memory_reader = |pid: u32, addr: usize, size: usize| -> Result<Vec<u8>> {
|
||||
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(),
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -289,11 +289,11 @@ fn parse_iat_from_disk(file_path: &str) -> Result<Vec<ImportEntry>> {
|
||||
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<Vec<ImportEntry>> {
|
||||
/// Parse IAT from memory buffer
|
||||
#[cfg(windows)]
|
||||
fn parse_iat_from_buffer(buffer: &[u8]) -> Result<Vec<ImportEntry>> {
|
||||
use std::mem;
|
||||
|
||||
let reader = |_pid: u32, offset: usize, size: usize| -> Result<Vec<u8>> {
|
||||
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() });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -284,7 +284,6 @@ mod platform {
|
||||
pid: u32,
|
||||
memory_regions: &[crate::MemoryRegion],
|
||||
) -> Result<super::ThreadHijackingResult> {
|
||||
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,
|
||||
|
||||
@@ -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<Vec<u8>, 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};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user