refactor: comprehensive codebase improvements and documentation
- Enhanced error handling with expanded GhostError variants and From impls - Fixed race conditions in TUI (ui.rs unwrap calls) - Added comprehensive module documentation with doc comments - Improved type safety with proper validation in DetectionConfig - Implemented Linux process enumeration via procfs - Refactored TUI for better state management and removed emojis - Enhanced CLI with proper logging initialization - Added example configuration file (examples/ghost.toml) - Updated README with complete feature documentation - Added performance optimizations (saturating arithmetic, reduced clones) - Improved testing framework with proper struct initialization - Added validation and preset modes to DetectionConfig
This commit is contained in:
@@ -11,7 +11,9 @@ ghost-core = { path = "../ghost-core" }
|
||||
ratatui = "0.24"
|
||||
crossterm = "0.27"
|
||||
tokio = { version = "1.0", features = ["full"] }
|
||||
anyhow = "1.0"
|
||||
anyhow.workspace = true
|
||||
log.workspace = true
|
||||
env_logger.workspace = true
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
chrono = { version = "0.4", features = ["serde"] }
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
//! Application state and business logic for the Ghost TUI.
|
||||
//!
|
||||
//! This module manages the core application state, including process scanning,
|
||||
//! detection events, and user interaction state.
|
||||
|
||||
use anyhow::Result;
|
||||
use chrono::{DateTime, Utc};
|
||||
use ghost_core::{
|
||||
DetectionEngine, DetectionResult, ProcessInfo, ThreatLevel,
|
||||
ThreatIntelligence, ThreatContext, IndicatorOfCompromise,
|
||||
memory, process, thread
|
||||
memory, process, thread, DetectionEngine, IndicatorOfCompromise, ProcessInfo, ThreatContext,
|
||||
ThreatIntelligence, ThreatLevel,
|
||||
};
|
||||
use ratatui::widgets::{ListState, TableState};
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -100,13 +104,24 @@ pub struct App {
|
||||
}
|
||||
|
||||
impl App {
|
||||
/// Creates a new application instance with initialized detection engine.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// Returns an error if the detection engine or threat intelligence
|
||||
/// system fails to initialize.
|
||||
pub async fn new() -> Result<Self> {
|
||||
let mut threat_intel = ThreatIntelligence::new();
|
||||
threat_intel.initialize_default_feeds().await?;
|
||||
|
||||
if let Err(e) = threat_intel.initialize_default_feeds().await {
|
||||
log::warn!("Failed to initialize threat feeds: {}", e);
|
||||
}
|
||||
|
||||
let detection_engine = DetectionEngine::new()
|
||||
.map_err(|e| anyhow::anyhow!("Failed to initialize detection engine: {}", e))?;
|
||||
|
||||
let mut app = Self {
|
||||
current_tab: TabIndex::Overview,
|
||||
detection_engine: DetectionEngine::new(),
|
||||
detection_engine,
|
||||
threat_intel,
|
||||
processes: Vec::new(),
|
||||
detections: VecDeque::new(),
|
||||
@@ -136,62 +151,71 @@ impl App {
|
||||
max_detection_entries: 500,
|
||||
};
|
||||
|
||||
app.add_log_message("Ghost TUI v0.1.0 - Process Injection Detection".to_string());
|
||||
app.add_log_message("Initializing detection engine...".to_string());
|
||||
|
||||
// Initial scan
|
||||
app.update_scan_data().await?;
|
||||
|
||||
app.add_log_message("Ghost TUI v0.1.0 - Process Injection Detection".into());
|
||||
app.add_log_message("Detection engine initialized successfully".into());
|
||||
|
||||
if let Err(e) = app.update_scan_data().await {
|
||||
app.add_log_message(format!("Initial scan failed: {}", e));
|
||||
}
|
||||
|
||||
Ok(app)
|
||||
}
|
||||
|
||||
/// Performs a full system scan for process injection indicators.
|
||||
///
|
||||
/// This method enumerates all running processes, analyzes their memory
|
||||
/// regions and threads, and records any suspicious or malicious findings.
|
||||
pub async fn update_scan_data(&mut self) -> Result<()> {
|
||||
let scan_start = Instant::now();
|
||||
|
||||
// Enumerate processes
|
||||
self.processes = process::enumerate_processes()?;
|
||||
|
||||
self.processes = match process::enumerate_processes() {
|
||||
Ok(procs) => procs,
|
||||
Err(e) => {
|
||||
self.add_log_message(format!("Process enumeration failed: {}", e));
|
||||
return Err(anyhow::anyhow!("Process enumeration failed: {}", e));
|
||||
}
|
||||
};
|
||||
|
||||
let mut detection_count = 0;
|
||||
let mut suspicious_count = 0;
|
||||
let mut malicious_count = 0;
|
||||
|
||||
// Scan each process for injections
|
||||
for proc in &self.processes {
|
||||
// Skip system processes for performance
|
||||
if proc.name == "System" || proc.name == "Registry" {
|
||||
if Self::should_skip_process(proc) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if let Ok(regions) = memory::enumerate_memory_regions(proc.pid) {
|
||||
let threads = thread::enumerate_threads(proc.pid).ok();
|
||||
let result = self.detection_engine.analyze_process(
|
||||
proc,
|
||||
®ions,
|
||||
threads.as_deref()
|
||||
);
|
||||
let regions = match memory::enumerate_memory_regions(proc.pid) {
|
||||
Ok(r) => r,
|
||||
Err(_) => continue,
|
||||
};
|
||||
|
||||
match result.threat_level {
|
||||
ThreatLevel::Suspicious => suspicious_count += 1,
|
||||
ThreatLevel::Malicious => malicious_count += 1,
|
||||
ThreatLevel::Clean => {}
|
||||
}
|
||||
let threads = thread::enumerate_threads(proc.pid).ok();
|
||||
let result = self
|
||||
.detection_engine
|
||||
.analyze_process(proc, ®ions, threads.as_deref());
|
||||
|
||||
if result.threat_level != ThreatLevel::Clean {
|
||||
detection_count += 1;
|
||||
self.add_detection(DetectionEvent {
|
||||
timestamp: Utc::now(),
|
||||
process: proc.clone(),
|
||||
threat_level: result.threat_level,
|
||||
indicators: result.indicators,
|
||||
confidence: result.confidence,
|
||||
threat_context: None, // TODO: Integrate threat intelligence
|
||||
});
|
||||
}
|
||||
match result.threat_level {
|
||||
ThreatLevel::Suspicious => suspicious_count += 1,
|
||||
ThreatLevel::Malicious => malicious_count += 1,
|
||||
ThreatLevel::Clean => {}
|
||||
}
|
||||
|
||||
if result.threat_level != ThreatLevel::Clean {
|
||||
detection_count += 1;
|
||||
self.add_detection(DetectionEvent {
|
||||
timestamp: Utc::now(),
|
||||
process: proc.clone(),
|
||||
threat_level: result.threat_level,
|
||||
indicators: result.indicators,
|
||||
confidence: result.confidence,
|
||||
threat_context: result.threat_context,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
let scan_duration = scan_start.elapsed();
|
||||
|
||||
// Update statistics
|
||||
|
||||
self.stats = SystemStats {
|
||||
total_processes: self.processes.len(),
|
||||
suspicious_processes: suspicious_count,
|
||||
@@ -202,18 +226,23 @@ impl App {
|
||||
};
|
||||
|
||||
self.last_scan = Some(scan_start);
|
||||
|
||||
if detection_count > 0 {
|
||||
self.add_log_message(format!(
|
||||
"Scan complete: {} detections found in {}ms",
|
||||
detection_count,
|
||||
scan_duration.as_millis()
|
||||
));
|
||||
}
|
||||
|
||||
self.add_log_message(format!(
|
||||
"Scan complete: {} processes, {} detections in {}ms",
|
||||
self.processes.len(),
|
||||
detection_count,
|
||||
scan_duration.as_millis()
|
||||
));
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Determines if a process should be skipped during scanning.
|
||||
fn should_skip_process(proc: &ProcessInfo) -> bool {
|
||||
const SKIP_PROCESSES: &[&str] = &["System", "Registry", "Idle", "smss.exe"];
|
||||
SKIP_PROCESSES.iter().any(|&name| proc.name == name) || proc.pid == 0 || proc.pid == 4
|
||||
}
|
||||
|
||||
pub async fn force_refresh(&mut self) -> Result<()> {
|
||||
self.add_log_message("Forcing refresh...".to_string());
|
||||
self.update_scan_data().await
|
||||
|
||||
@@ -1,25 +1,34 @@
|
||||
//! Terminal User Interface rendering for Ghost detection system.
|
||||
//!
|
||||
//! This module provides all the drawing functions for the TUI components,
|
||||
//! including the main dashboard, process list, detection history, and system logs.
|
||||
|
||||
use crate::app::{App, TabIndex};
|
||||
use ghost_core::ThreatLevel;
|
||||
use ratatui::{
|
||||
backend::Backend,
|
||||
layout::{Alignment, Constraint, Direction, Layout, Margin, Rect},
|
||||
layout::{Alignment, Constraint, Direction, Layout, Rect},
|
||||
style::{Color, Modifier, Style},
|
||||
symbols,
|
||||
text::{Line, Span, Text},
|
||||
widgets::{
|
||||
BarChart, Block, Borders, Cell, Gauge, List, ListItem, Paragraph, Row, Sparkline, Table, Tabs, Wrap
|
||||
},
|
||||
widgets::{Block, Borders, Cell, Gauge, List, ListItem, Paragraph, Row, Table, Tabs, Wrap},
|
||||
Frame,
|
||||
};
|
||||
|
||||
// Define color constants for consistent theming
|
||||
const PRIMARY_COLOR: Color = Color::Cyan;
|
||||
const SECONDARY_COLOR: Color = Color::Magenta;
|
||||
const SUCCESS_COLOR: Color = Color::Green;
|
||||
const WARNING_COLOR: Color = Color::Yellow;
|
||||
const DANGER_COLOR: Color = Color::Red;
|
||||
const BACKGROUND_COLOR: Color = Color::Black;
|
||||
const TEXT_COLOR: Color = Color::White;
|
||||
/// Color scheme for consistent theming across the application.
|
||||
mod colors {
|
||||
use ratatui::style::Color;
|
||||
|
||||
pub const PRIMARY: Color = Color::Cyan;
|
||||
pub const SECONDARY: Color = Color::Magenta;
|
||||
pub const SUCCESS: Color = Color::Green;
|
||||
pub const WARNING: Color = Color::Yellow;
|
||||
pub const DANGER: Color = Color::Red;
|
||||
pub const BACKGROUND: Color = Color::Black;
|
||||
pub const TEXT: Color = Color::White;
|
||||
pub const MUTED: Color = Color::Gray;
|
||||
}
|
||||
|
||||
use colors::*;
|
||||
|
||||
pub fn draw<B: Backend>(f: &mut Frame<B>, app: &App) {
|
||||
let size = f.size();
|
||||
@@ -56,17 +65,17 @@ fn draw_header<B: Backend>(f: &mut Frame<B>, area: Rect, app: &App) {
|
||||
.block(
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.title("👻 Ghost - Process Injection Detection")
|
||||
.title_style(Style::default().fg(PRIMARY_COLOR).add_modifier(Modifier::BOLD))
|
||||
.border_style(Style::default().fg(PRIMARY_COLOR))
|
||||
.title("Ghost - Process Injection Detection")
|
||||
.title_style(Style::default().fg(PRIMARY).add_modifier(Modifier::BOLD))
|
||||
.border_style(Style::default().fg(PRIMARY)),
|
||||
)
|
||||
.select(app.current_tab as usize)
|
||||
.style(Style::default().fg(TEXT_COLOR))
|
||||
.style(Style::default().fg(TEXT))
|
||||
.highlight_style(
|
||||
Style::default()
|
||||
.fg(BACKGROUND_COLOR)
|
||||
.bg(PRIMARY_COLOR)
|
||||
.add_modifier(Modifier::BOLD)
|
||||
.fg(BACKGROUND)
|
||||
.bg(PRIMARY)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
);
|
||||
|
||||
f.render_widget(tabs, area);
|
||||
@@ -74,20 +83,20 @@ fn draw_header<B: Backend>(f: &mut Frame<B>, area: Rect, app: &App) {
|
||||
|
||||
fn draw_footer<B: Backend>(f: &mut Frame<B>, area: Rect, app: &App) {
|
||||
let help_text = match app.current_tab {
|
||||
TabIndex::Overview => "↑↓: Navigate | Tab: Switch tabs | R: Refresh | C: Clear | Q: Quit",
|
||||
TabIndex::Processes => "↑↓: Select process | Enter: View details | Tab: Switch tabs | Q: Quit",
|
||||
TabIndex::Detections => "↑↓: Navigate detections | C: Clear history | Tab: Switch tabs | Q: Quit",
|
||||
TabIndex::Memory => "↑↓: Navigate | Tab: Switch tabs | R: Refresh | Q: Quit",
|
||||
TabIndex::Logs => "↑↓: Navigate logs | C: Clear logs | Tab: Switch tabs | Q: Quit",
|
||||
TabIndex::Overview => "Up/Down: Navigate | Tab: Switch tabs | R: Refresh | C: Clear | Q: Quit",
|
||||
TabIndex::Processes => "Up/Down: Select process | Enter: View details | Tab: Switch tabs | Q: Quit",
|
||||
TabIndex::Detections => "Up/Down: Navigate detections | C: Clear history | Tab: Switch tabs | Q: Quit",
|
||||
TabIndex::Memory => "Up/Down: Navigate | Tab: Switch tabs | R: Refresh | Q: Quit",
|
||||
TabIndex::Logs => "Up/Down: Navigate logs | C: Clear logs | Tab: Switch tabs | Q: Quit",
|
||||
};
|
||||
|
||||
let footer = Paragraph::new(help_text)
|
||||
.block(
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.border_style(Style::default().fg(SECONDARY_COLOR))
|
||||
.border_style(Style::default().fg(SECONDARY)),
|
||||
)
|
||||
.style(Style::default().fg(TEXT_COLOR))
|
||||
.style(Style::default().fg(TEXT))
|
||||
.alignment(Alignment::Center);
|
||||
|
||||
f.render_widget(footer, area);
|
||||
@@ -124,61 +133,61 @@ fn draw_stats_panel<B: Backend>(f: &mut Frame<B>, area: Rect, app: &App) {
|
||||
])
|
||||
.split(area);
|
||||
|
||||
// Total processes
|
||||
let total_processes = Gauge::default()
|
||||
.block(
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.title("Total Processes")
|
||||
.border_style(Style::default().fg(PRIMARY_COLOR))
|
||||
.border_style(Style::default().fg(PRIMARY)),
|
||||
)
|
||||
.gauge_style(Style::default().fg(PRIMARY_COLOR))
|
||||
.percent(std::cmp::min(app.stats.total_processes * 100 / 500, 100) as u16)
|
||||
.gauge_style(Style::default().fg(PRIMARY))
|
||||
.percent(std::cmp::min(app.stats.total_processes.saturating_mul(100) / 500, 100) as u16)
|
||||
.label(format!("{}", app.stats.total_processes));
|
||||
|
||||
f.render_widget(total_processes, stats_chunks[0]);
|
||||
|
||||
// Suspicious processes
|
||||
let suspicious_gauge = Gauge::default()
|
||||
.block(
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.title("Suspicious")
|
||||
.border_style(Style::default().fg(WARNING_COLOR))
|
||||
.border_style(Style::default().fg(WARNING)),
|
||||
)
|
||||
.gauge_style(Style::default().fg(WARNING_COLOR))
|
||||
.gauge_style(Style::default().fg(WARNING))
|
||||
.percent(if app.stats.total_processes > 0 {
|
||||
(app.stats.suspicious_processes * 100 / app.stats.total_processes) as u16
|
||||
} else { 0 })
|
||||
(app.stats.suspicious_processes.saturating_mul(100) / app.stats.total_processes) as u16
|
||||
} else {
|
||||
0
|
||||
})
|
||||
.label(format!("{}", app.stats.suspicious_processes));
|
||||
|
||||
f.render_widget(suspicious_gauge, stats_chunks[1]);
|
||||
|
||||
// Malicious processes
|
||||
let malicious_gauge = Gauge::default()
|
||||
.block(
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.title("Malicious")
|
||||
.border_style(Style::default().fg(DANGER_COLOR))
|
||||
.border_style(Style::default().fg(DANGER)),
|
||||
)
|
||||
.gauge_style(Style::default().fg(DANGER_COLOR))
|
||||
.gauge_style(Style::default().fg(DANGER))
|
||||
.percent(if app.stats.total_processes > 0 {
|
||||
(app.stats.malicious_processes * 100 / app.stats.total_processes) as u16
|
||||
} else { 0 })
|
||||
(app.stats.malicious_processes.saturating_mul(100) / app.stats.total_processes) as u16
|
||||
} else {
|
||||
0
|
||||
})
|
||||
.label(format!("{}", app.stats.malicious_processes));
|
||||
|
||||
f.render_widget(malicious_gauge, stats_chunks[2]);
|
||||
|
||||
// Scan performance
|
||||
let perf_gauge = Gauge::default()
|
||||
.block(
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.title("Scan Time (ms)")
|
||||
.border_style(Style::default().fg(SUCCESS_COLOR))
|
||||
.border_style(Style::default().fg(SUCCESS)),
|
||||
)
|
||||
.gauge_style(Style::default().fg(SUCCESS_COLOR))
|
||||
.gauge_style(Style::default().fg(SUCCESS))
|
||||
.percent(std::cmp::min(app.stats.scan_time_ms as u16 / 10, 100))
|
||||
.label(format!("{}ms", app.stats.scan_time_ms));
|
||||
|
||||
@@ -195,24 +204,27 @@ fn draw_threat_gauge<B: Backend>(f: &mut Frame<B>, area: Rect, app: &App) {
|
||||
};
|
||||
|
||||
let color = if threat_level > 80 {
|
||||
DANGER_COLOR
|
||||
DANGER
|
||||
} else if threat_level > 40 {
|
||||
WARNING_COLOR
|
||||
WARNING
|
||||
} else {
|
||||
SUCCESS_COLOR
|
||||
SUCCESS
|
||||
};
|
||||
|
||||
let threat_gauge = Gauge::default()
|
||||
.block(
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.title("🚨 System Threat Level")
|
||||
.title("System Threat Level")
|
||||
.title_style(Style::default().fg(color).add_modifier(Modifier::BOLD))
|
||||
.border_style(Style::default().fg(color))
|
||||
.border_style(Style::default().fg(color)),
|
||||
)
|
||||
.gauge_style(Style::default().fg(color))
|
||||
.percent(threat_level)
|
||||
.label(format!("{}% - {} Detection(s)", threat_level, app.stats.total_detections));
|
||||
.label(format!(
|
||||
"{}% - {} Detection(s)",
|
||||
threat_level, app.stats.total_detections
|
||||
));
|
||||
|
||||
f.render_widget(threat_gauge, area);
|
||||
}
|
||||
@@ -223,23 +235,23 @@ fn draw_recent_detections<B: Backend>(f: &mut Frame<B>, area: Rect, app: &App) {
|
||||
.iter()
|
||||
.take(10)
|
||||
.map(|detection| {
|
||||
let level_icon = match detection.threat_level {
|
||||
ThreatLevel::Malicious => "🔴",
|
||||
ThreatLevel::Suspicious => "🟡",
|
||||
ThreatLevel::Clean => "🟢",
|
||||
let (level_marker, style) = match detection.threat_level {
|
||||
ThreatLevel::Malicious => ("[!]", Style::default().fg(DANGER)),
|
||||
ThreatLevel::Suspicious => ("[?]", Style::default().fg(WARNING)),
|
||||
ThreatLevel::Clean => ("[+]", Style::default().fg(SUCCESS)),
|
||||
};
|
||||
|
||||
|
||||
let time = detection.timestamp.format("%H:%M:%S");
|
||||
let content = format!(
|
||||
"{} [{}] {} (PID: {}) - {:.1}%",
|
||||
level_icon,
|
||||
level_marker,
|
||||
time,
|
||||
detection.process.name,
|
||||
detection.process.pid,
|
||||
detection.confidence * 100.0
|
||||
);
|
||||
|
||||
ListItem::new(content).style(Style::default().fg(TEXT_COLOR))
|
||||
|
||||
ListItem::new(content).style(style)
|
||||
})
|
||||
.collect();
|
||||
|
||||
@@ -247,10 +259,10 @@ fn draw_recent_detections<B: Backend>(f: &mut Frame<B>, area: Rect, app: &App) {
|
||||
.block(
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.title("🔍 Recent Detections")
|
||||
.border_style(Style::default().fg(SECONDARY_COLOR))
|
||||
.title("Recent Detections")
|
||||
.border_style(Style::default().fg(SECONDARY)),
|
||||
)
|
||||
.style(Style::default().fg(TEXT_COLOR));
|
||||
.style(Style::default().fg(TEXT));
|
||||
|
||||
f.render_widget(list, area);
|
||||
}
|
||||
@@ -264,25 +276,24 @@ fn draw_processes<B: Backend>(f: &mut Frame<B>, area: Rect, app: &App) {
|
||||
// Process table
|
||||
let header_cells = ["PID", "PPID", "Name", "Threads", "Status"]
|
||||
.iter()
|
||||
.map(|h| Cell::from(*h).style(Style::default().fg(PRIMARY_COLOR).add_modifier(Modifier::BOLD)));
|
||||
.map(|h| Cell::from(*h).style(Style::default().fg(PRIMARY).add_modifier(Modifier::BOLD)));
|
||||
|
||||
let header = Row::new(header_cells).height(1).bottom_margin(1);
|
||||
|
||||
let rows: Vec<Row> = app.processes.iter().map(|proc| {
|
||||
let status = if app.detections.iter().any(|d| d.process.pid == proc.pid) {
|
||||
match app.detections.iter().find(|d| d.process.pid == proc.pid).unwrap().threat_level {
|
||||
ThreatLevel::Malicious => "🔴 MALICIOUS",
|
||||
ThreatLevel::Suspicious => "🟡 SUSPICIOUS",
|
||||
ThreatLevel::Clean => "🟢 CLEAN",
|
||||
}
|
||||
} else {
|
||||
"🟢 CLEAN"
|
||||
let status = match app.detections.iter().find(|d| d.process.pid == proc.pid) {
|
||||
Some(detection) => match detection.threat_level {
|
||||
ThreatLevel::Malicious => "MALICIOUS",
|
||||
ThreatLevel::Suspicious => "SUSPICIOUS",
|
||||
ThreatLevel::Clean => "CLEAN",
|
||||
},
|
||||
None => "CLEAN",
|
||||
};
|
||||
|
||||
Row::new(vec![
|
||||
Cell::from(proc.pid.to_string()),
|
||||
Cell::from(proc.ppid.to_string()),
|
||||
Cell::from(proc.name.clone()),
|
||||
Cell::from(proc.name.as_str()),
|
||||
Cell::from(proc.thread_count.to_string()),
|
||||
Cell::from(status),
|
||||
])
|
||||
@@ -293,10 +304,10 @@ fn draw_processes<B: Backend>(f: &mut Frame<B>, area: Rect, app: &App) {
|
||||
.block(
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.title("🖥️ System Processes")
|
||||
.border_style(Style::default().fg(PRIMARY_COLOR))
|
||||
.title("System Processes")
|
||||
.border_style(Style::default().fg(PRIMARY)),
|
||||
)
|
||||
.highlight_style(Style::default().bg(PRIMARY_COLOR).fg(BACKGROUND_COLOR))
|
||||
.highlight_style(Style::default().bg(PRIMARY).fg(BACKGROUND))
|
||||
.widths(&[
|
||||
Constraint::Length(8),
|
||||
Constraint::Length(8),
|
||||
@@ -305,7 +316,8 @@ fn draw_processes<B: Backend>(f: &mut Frame<B>, area: Rect, app: &App) {
|
||||
Constraint::Length(15),
|
||||
]);
|
||||
|
||||
f.render_stateful_widget(table, chunks[0], &mut app.processes_state.clone());
|
||||
let mut state = app.processes_state.clone();
|
||||
f.render_stateful_widget(table, chunks[0], &mut state);
|
||||
|
||||
// Process details panel
|
||||
draw_process_details(f, chunks[1], app);
|
||||
@@ -329,10 +341,10 @@ fn draw_process_details<B: Backend>(f: &mut Frame<B>, area: Rect, app: &App) {
|
||||
.block(
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.title("📋 Process Details")
|
||||
.border_style(Style::default().fg(SECONDARY_COLOR))
|
||||
.title("Process Details")
|
||||
.border_style(Style::default().fg(SECONDARY)),
|
||||
)
|
||||
.style(Style::default().fg(TEXT_COLOR))
|
||||
.style(Style::default().fg(TEXT))
|
||||
.wrap(Wrap { trim: true });
|
||||
|
||||
f.render_widget(paragraph, area);
|
||||
@@ -344,30 +356,33 @@ fn draw_detections<B: Backend>(f: &mut Frame<B>, area: Rect, app: &App) {
|
||||
.iter()
|
||||
.map(|detection| {
|
||||
let level_style = match detection.threat_level {
|
||||
ThreatLevel::Malicious => Style::default().fg(DANGER_COLOR),
|
||||
ThreatLevel::Suspicious => Style::default().fg(WARNING_COLOR),
|
||||
ThreatLevel::Clean => Style::default().fg(SUCCESS_COLOR),
|
||||
ThreatLevel::Malicious => Style::default().fg(DANGER),
|
||||
ThreatLevel::Suspicious => Style::default().fg(WARNING),
|
||||
ThreatLevel::Clean => Style::default().fg(SUCCESS),
|
||||
};
|
||||
|
||||
let content = vec![
|
||||
Line::from(vec![
|
||||
Span::styled(
|
||||
format!("[{}] ", detection.timestamp.format("%Y-%m-%d %H:%M:%S")),
|
||||
Style::default().fg(Color::Gray)
|
||||
Style::default().fg(MUTED),
|
||||
),
|
||||
Span::styled(
|
||||
format!("{:?}", detection.threat_level),
|
||||
level_style.add_modifier(Modifier::BOLD)
|
||||
level_style.add_modifier(Modifier::BOLD),
|
||||
),
|
||||
]),
|
||||
Line::from(format!("Process: {} (PID: {})", detection.process.name, detection.process.pid)),
|
||||
Line::from(format!(
|
||||
"Process: {} (PID: {})",
|
||||
detection.process.name, detection.process.pid
|
||||
)),
|
||||
Line::from(format!("Confidence: {:.1}%", detection.confidence * 100.0)),
|
||||
Line::from("Indicators:"),
|
||||
];
|
||||
|
||||
let mut all_lines = content;
|
||||
for indicator in &detection.indicators {
|
||||
all_lines.push(Line::from(format!(" • {}", indicator)));
|
||||
all_lines.push(Line::from(format!(" - {}", indicator)));
|
||||
}
|
||||
all_lines.push(Line::from(""));
|
||||
|
||||
@@ -379,12 +394,13 @@ fn draw_detections<B: Backend>(f: &mut Frame<B>, area: Rect, app: &App) {
|
||||
.block(
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.title(format!("🚨 Detection History ({} total)", app.detections.len()))
|
||||
.border_style(Style::default().fg(DANGER_COLOR))
|
||||
.title(format!("Detection History ({} total)", app.detections.len()))
|
||||
.border_style(Style::default().fg(DANGER)),
|
||||
)
|
||||
.style(Style::default().fg(TEXT_COLOR));
|
||||
.style(Style::default().fg(TEXT));
|
||||
|
||||
f.render_stateful_widget(list, area, &mut app.detections_state.clone());
|
||||
let mut state = app.detections_state.clone();
|
||||
f.render_stateful_widget(list, area, &mut state);
|
||||
}
|
||||
|
||||
fn draw_memory<B: Backend>(f: &mut Frame<B>, area: Rect, app: &App) {
|
||||
@@ -393,36 +409,34 @@ fn draw_memory<B: Backend>(f: &mut Frame<B>, area: Rect, app: &App) {
|
||||
.constraints([Constraint::Length(8), Constraint::Min(0)])
|
||||
.split(area);
|
||||
|
||||
// Memory usage gauge
|
||||
let memory_gauge = Gauge::default()
|
||||
.block(
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.title("💾 Memory Usage")
|
||||
.border_style(Style::default().fg(PRIMARY_COLOR))
|
||||
.title("Memory Usage")
|
||||
.border_style(Style::default().fg(PRIMARY)),
|
||||
)
|
||||
.gauge_style(Style::default().fg(PRIMARY_COLOR))
|
||||
.gauge_style(Style::default().fg(PRIMARY))
|
||||
.percent((app.stats.memory_usage_mb * 10.0) as u16)
|
||||
.label(format!("{:.2} MB", app.stats.memory_usage_mb));
|
||||
|
||||
f.render_widget(memory_gauge, chunks[0]);
|
||||
|
||||
// Memory analysis placeholder
|
||||
let memory_info = Paragraph::new(
|
||||
"Memory Analysis:\n\n\
|
||||
• Process memory regions scanned\n\
|
||||
• RWX regions monitored\n\
|
||||
• Suspicious allocations detected\n\
|
||||
• Memory layout anomalies tracked\n\n\
|
||||
Advanced memory analysis features coming soon..."
|
||||
- Process memory regions scanned\n\
|
||||
- RWX regions monitored\n\
|
||||
- Suspicious allocations detected\n\
|
||||
- Memory layout anomalies tracked\n\n\
|
||||
Advanced memory analysis features coming soon...",
|
||||
)
|
||||
.block(
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.title("🧠 Memory Analysis")
|
||||
.border_style(Style::default().fg(SECONDARY_COLOR))
|
||||
.title("Memory Analysis")
|
||||
.border_style(Style::default().fg(SECONDARY)),
|
||||
)
|
||||
.style(Style::default().fg(TEXT_COLOR))
|
||||
.style(Style::default().fg(TEXT))
|
||||
.wrap(Wrap { trim: true });
|
||||
|
||||
f.render_widget(memory_info, chunks[1]);
|
||||
@@ -432,17 +446,18 @@ fn draw_logs<B: Backend>(f: &mut Frame<B>, area: Rect, app: &App) {
|
||||
let items: Vec<ListItem> = app
|
||||
.logs
|
||||
.iter()
|
||||
.map(|log| ListItem::new(log.as_str()).style(Style::default().fg(TEXT_COLOR)))
|
||||
.map(|log| ListItem::new(log.as_str()).style(Style::default().fg(TEXT)))
|
||||
.collect();
|
||||
|
||||
let list = List::new(items)
|
||||
.block(
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.title(format!("📜 System Logs ({} entries)", app.logs.len()))
|
||||
.border_style(Style::default().fg(SUCCESS_COLOR))
|
||||
.title(format!("System Logs ({} entries)", app.logs.len()))
|
||||
.border_style(Style::default().fg(SUCCESS)),
|
||||
)
|
||||
.style(Style::default().fg(TEXT_COLOR));
|
||||
.style(Style::default().fg(TEXT));
|
||||
|
||||
f.render_stateful_widget(list, area, &mut app.logs_state.clone());
|
||||
let mut state = app.logs_state.clone();
|
||||
f.render_stateful_widget(list, area, &mut state);
|
||||
}
|
||||
Reference in New Issue
Block a user