fix: cargo formatting for ci/cd

This commit is contained in:
pandaadir05
2025-11-21 12:52:08 +02:00
parent 2bcfcac407
commit f0606d7835
5 changed files with 57 additions and 49 deletions

View File

@@ -293,9 +293,7 @@ impl LiveThreatFeeds {
indicator.get("type").and_then(|t| t.as_str()), indicator.get("type").and_then(|t| t.as_str()),
) { ) {
// Map OTX threat level to our scale // Map OTX threat level to our scale
let threat_level = indicator let threat_level = indicator.get("expiration").map(|_| 4).unwrap_or(3);
.get("expiration").map(|_| 4)
.unwrap_or(3);
iocs.push(CachedIOC { iocs.push(CachedIOC {
value: value.to_string(), value: value.to_string(),

View File

@@ -383,11 +383,7 @@ mod platform {
fn proc_pidpath(pid: c_int, buffer: *mut c_void, buffersize: u32) -> c_int; fn proc_pidpath(pid: c_int, buffer: *mut c_void, buffersize: u32) -> c_int;
} }
let ret = proc_pidpath( let ret = proc_pidpath(pid as c_int, buffer.as_mut_ptr() as *mut c_void, size);
pid as c_int,
buffer.as_mut_ptr() as *mut c_void,
size,
);
if ret > 0 { if ret > 0 {
let path_bytes = &buffer[..ret as usize]; let path_bytes = &buffer[..ret as usize];

View File

@@ -216,7 +216,8 @@ impl DynamicYaraEngine {
#[cfg(not(feature = "yara-scanning"))] #[cfg(not(feature = "yara-scanning"))]
pub fn compile_rules(&mut self) -> Result<usize, GhostError> { pub fn compile_rules(&mut self) -> Result<usize, GhostError> {
Err(GhostError::Configuration { Err(GhostError::Configuration {
message: "YARA scanning is not enabled. Build with --features yara-scanning to enable.".to_string(), message: "YARA scanning is not enabled. Build with --features yara-scanning to enable."
.to_string(),
}) })
} }
@@ -330,7 +331,8 @@ impl DynamicYaraEngine {
_memory_regions: &[MemoryRegion], _memory_regions: &[MemoryRegion],
) -> Result<YaraScanResult, GhostError> { ) -> Result<YaraScanResult, GhostError> {
Err(GhostError::Configuration { Err(GhostError::Configuration {
message: "YARA scanning is not enabled. Build with --features yara-scanning to enable.".to_string(), message: "YARA scanning is not enabled. Build with --features yara-scanning to enable."
.to_string(),
}) })
} }

View File

@@ -1,4 +1,4 @@
use ghost_core::{AnomalyDetector, ProcessInfo, MemoryRegion, MemoryProtection}; use ghost_core::{AnomalyDetector, MemoryProtection, MemoryRegion, ProcessInfo};
use std::path::PathBuf; use std::path::PathBuf;
#[test] #[test]
@@ -53,14 +53,12 @@ fn test_anomaly_analysis() {
thread_count: 5, thread_count: 5,
}; };
let regions = vec![ let regions = vec![MemoryRegion {
MemoryRegion { base_address: 0x1000,
base_address: 0x1000, size: 4096,
size: 4096, protection: MemoryProtection::ReadExecute,
protection: MemoryProtection::ReadExecute, region_type: "IMAGE".to_string(),
region_type: "IMAGE".to_string(), }];
},
];
let features = detector.extract_features(&process, &regions, None); let features = detector.extract_features(&process, &regions, None);
@@ -84,14 +82,12 @@ fn test_profile_persistence() {
thread_count: 5, thread_count: 5,
}; };
let regions = vec![ let regions = vec![MemoryRegion {
MemoryRegion { base_address: 0x1000,
base_address: 0x1000, size: 4096,
size: 4096, protection: MemoryProtection::ReadExecute,
protection: MemoryProtection::ReadExecute, region_type: "IMAGE".to_string(),
region_type: "IMAGE".to_string(), }];
},
];
for _ in 0..15 { for _ in 0..15 {
let features = detector.extract_features(&process, &regions, None); let features = detector.extract_features(&process, &regions, None);
@@ -101,11 +97,19 @@ fn test_profile_persistence() {
let temp_path = PathBuf::from("/tmp/ghost_test_profiles.json"); let temp_path = PathBuf::from("/tmp/ghost_test_profiles.json");
let save_result = detector.save_profiles(&temp_path); let save_result = detector.save_profiles(&temp_path);
assert!(save_result.is_ok(), "Failed to save profiles: {:?}", save_result.err()); assert!(
save_result.is_ok(),
"Failed to save profiles: {:?}",
save_result.err()
);
let mut detector2 = AnomalyDetector::new(); let mut detector2 = AnomalyDetector::new();
let load_result = detector2.load_profiles(&temp_path); let load_result = detector2.load_profiles(&temp_path);
assert!(load_result.is_ok(), "Failed to load profiles: {:?}", load_result.err()); assert!(
load_result.is_ok(),
"Failed to load profiles: {:?}",
load_result.err()
);
assert!(!detector2.get_all_profiles().is_empty()); assert!(!detector2.get_all_profiles().is_empty());
@@ -125,14 +129,12 @@ fn test_global_baseline_computation() {
thread_count: 5, thread_count: 5,
}; };
let regions = vec![ let regions = vec![MemoryRegion {
MemoryRegion { base_address: 0x1000,
base_address: 0x1000, size: 4096,
size: 4096, protection: MemoryProtection::ReadExecute,
protection: MemoryProtection::ReadExecute, region_type: "IMAGE".to_string(),
region_type: "IMAGE".to_string(), }];
},
];
for _ in 0..15 { for _ in 0..15 {
let features = detector.extract_features(&process, &regions, None); let features = detector.extract_features(&process, &regions, None);
@@ -157,14 +159,12 @@ fn test_profile_cleanup() {
thread_count: 5, thread_count: 5,
}; };
let regions = vec![ let regions = vec![MemoryRegion {
MemoryRegion { base_address: 0x1000,
base_address: 0x1000, size: 4096,
size: 4096, protection: MemoryProtection::ReadExecute,
protection: MemoryProtection::ReadExecute, region_type: "IMAGE".to_string(),
region_type: "IMAGE".to_string(), }];
},
];
for _ in 0..15 { for _ in 0..15 {
let features = detector.extract_features(&process, &regions, None); let features = detector.extract_features(&process, &regions, None);

View File

@@ -10,7 +10,10 @@ fn test_macos_process_enumeration() {
println!("Found {} processes", processes.len()); println!("Found {} processes", processes.len());
for proc in processes.iter().filter(|p| p.pid > 0).take(5) { for proc in processes.iter().filter(|p| p.pid > 0).take(5) {
println!("PID: {}, Name: {}, Path: {:?}", proc.pid, proc.name, proc.path); println!(
"PID: {}, Name: {}, Path: {:?}",
proc.pid, proc.name, proc.path
);
assert!(proc.pid > 0, "PID should be positive"); assert!(proc.pid > 0, "PID should be positive");
assert!(!proc.name.is_empty(), "Process name should not be empty"); assert!(!proc.name.is_empty(), "Process name should not be empty");
} }
@@ -19,12 +22,21 @@ fn test_macos_process_enumeration() {
let current_process = processes.iter().find(|p| p.pid == current_pid); let current_process = processes.iter().find(|p| p.pid == current_pid);
if let Some(proc) = current_process { if let Some(proc) = current_process {
println!("Current process found: PID={}, Name={}", proc.pid, proc.name); println!(
"Current process found: PID={}, Name={}",
proc.pid, proc.name
);
} else { } else {
println!("Current process (PID={}) not in list - this is OK for test processes", current_pid); println!(
"Current process (PID={}) not in list - this is OK for test processes",
current_pid
);
} }
assert!(processes.iter().any(|p| p.pid == 1), "Should at least find launchd (PID 1)"); assert!(
processes.iter().any(|p| p.pid == 1),
"Should at least find launchd (PID 1)"
);
} }
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]