Skip to content

Ghidrust provides a hyper fast, AI native reverse engineering platform built in Rust, inspired by Ghidra. Includes experimental GPU kernels to rapidly decompile large files, a decryption suite, and network monitor for packet to binary reverse engineering.

Add `ghidrust-agent` as a dependency in `Cargo.lock`. Refactor `grok_binary_path` function for improved readability by using `find` method. Update `BottomTab` enum to use `Default` trait and add tests for default behavior and state management in `GrokPaneState`. Introduce new functions for rendering pseudo-C snippets and loading skill documentation in the GUI. Enhance session management and UI interactions for Grok Build installation.

oofz0a82b926ee83
diff --git a/Cargo.lock b/Cargo.lock
index ad501d9..f55b88a 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1377,6 +1377,7 @@ version = "0.1.0"
dependencies = [
"eframe",
"egui",
+ "ghidrust-agent",
"ghidrust-core",
"ghidrust-decomp",
"ghidrust-types",
diff --git a/crates/ghidrust-agent/src/installer.rs b/crates/ghidrust-agent/src/installer.rs
index 75921f2..4177b1b 100644
--- a/crates/ghidrust-agent/src/installer.rs
+++ b/crates/ghidrust-agent/src/installer.rs
@@ -94,12 +94,7 @@ pub fn grok_binary_path() -> Option<PathBuf> {
candidates.push(PathBuf::from(&userprofile).join(".grok").join("bin").join(exe_name));
candidates.push(PathBuf::from(&userprofile).join("AppData").join("Local").join("Programs").join("grok").join(exe_name));
}
- for c in candidates {
- if c.is_file() {
- return Some(c);
- }
- }
- None
+ candidates.into_iter().find(|c| c.is_file())
}
#[cfg(test)]
diff --git a/crates/ghidrust-gui/src/agent_pane.rs b/crates/ghidrust-gui/src/agent_pane.rs
index 9bbf9d3..ac7d68d 100644
--- a/crates/ghidrust-gui/src/agent_pane.rs
+++ b/crates/ghidrust-gui/src/agent_pane.rs
@@ -20,20 +20,15 @@ use ghidrust_agent::{
use std::path::{Path, PathBuf};
/// Which tab of the bottom dock is currently active.
-#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum BottomTab {
/// The Grok Build agent console (default primary tab per user spec).
+ #[default]
Grok,
/// The plain analyzer / script Console (existing behavior).
Console,
}
-impl Default for BottomTab {
- fn default() -> Self {
- BottomTab::Grok
- }
-}
-
/// One transcript entry the pane renders.
#[derive(Debug, Clone)]
pub enum TranscriptEntry {
@@ -383,3 +378,76 @@ pub fn spawn_install_grok() -> String {
),
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn default_tab_is_grok() {
+ assert_eq!(BottomTab::default(), BottomTab::Grok);
+ }
+
+ #[test]
+ fn pane_state_defaults_to_read_only() {
+ let s = GrokPaneState::new();
+ assert_eq!(s.mode, AgentMode::ReadOnly);
+ assert_eq!(s.tab, BottomTab::Grok);
+ assert!(s.transcript.is_empty());
+ assert!(s.session.is_none());
+ }
+
+ #[test]
+ fn assistant_deltas_coalesce_into_one_bubble() {
+ let mut s = GrokPaneState::new();
+ s.ingest_events(vec![
+ AgentEvent::AssistantDelta { text: "hel".into() },
+ AgentEvent::AssistantDelta { text: "lo".into() },
+ AgentEvent::AssistantDelta { text: " world".into() },
+ ]);
+ assert_eq!(s.transcript.len(), 1);
+ match &s.transcript[0] {
+ TranscriptEntry::Assistant { markdown } => assert_eq!(markdown, "hello world"),
+ _ => panic!("expected assistant bubble"),
+ }
+ }
+
+ #[test]
+ fn tool_call_finished_binds_to_pending_start() {
+ let mut s = GrokPaneState::new();
+ s.ingest_events(vec![
+ AgentEvent::ToolCallStarted {
+ id: "c1".into(),
+ name: "analyze".into(),
+ args_json: "{}".into(),
+ },
+ AgentEvent::ToolCallFinished {
+ id: "c1".into(),
+ ok: true,
+ summary: "42 fns".into(),
+ },
+ ]);
+ assert_eq!(s.transcript.len(), 1);
+ match &s.transcript[0] {
+ TranscriptEntry::ToolCall {
+ id, done: Some(res), ..
+ } => {
+ assert_eq!(id, "c1");
+ assert!(res.ok);
+ assert!(res.summary.contains("42"));
+ }
+ _ => panic!("expected finished tool card"),
+ }
+ }
+
+ #[test]
+ fn child_exit_clears_session_and_notes_transcript() {
+ let mut s = GrokPaneState::new();
+ s.ingest_events(vec![AgentEvent::ChildExited { code: Some(1) }]);
+ assert!(s.session.is_none());
+ match s.transcript.last() {
+ Some(TranscriptEntry::Info { text }) => assert!(text.contains("exit=1")),
+ _ => panic!("expected info entry"),
+ }
+ }
+}
diff --git a/crates/ghidrust-gui/src/main.rs b/crates/ghidrust-gui/src/main.rs
index 1ea5e22..2578eff 100644
--- a/crates/ghidrust-gui/src/main.rs
+++ b/crates/ghidrust-gui/src/main.rs
@@ -50,6 +50,65 @@ use std::collections::{BTreeMap, BTreeSet};
use std::path::{Path, PathBuf};
use std::sync::mpsc::{self, Receiver, RecvError, TryRecvError};
+/// Render one pseudo-C snippet from the Grok pane using the shared
+/// `decomp_tokens` highlighter — so agent-produced pseudo-C looks the same as
+/// the Decompiler pane's output.
+fn render_pseudo_c_inline(ui: &mut egui::Ui, body: &str) {
+ let lines = tokenize_decomp(body);
+ ui.group(|ui| {
+ for line in &lines {
+ let mut job = egui::text::LayoutJob::default();
+ for tok in &line.tokens {
+ let (color, italic) = token_style(&tok.kind, ui.visuals().text_color());
+ let mut fmt = egui::TextFormat {
+ color,
+ font_id: egui::FontId::monospace(12.0),
+ italics: italic,
+ ..Default::default()
+ };
+ // Preserve original whitespace / newlines faithfully.
+ if matches!(tok.kind, TokenKind::Comment) {
+ fmt.italics = true;
+ }
+ job.append(&tok.text, 0.0, fmt);
+ }
+ ui.label(job);
+ }
+ });
+}
+
+/// Locate the workspace `skill/SKILL.md` when running from a repo checkout so
+/// the Grok session prompt can inline the exhaustive catalog. When Ghidrust
+/// is installed as a released binary and no adjacent skill file exists we
+/// return `(String::new(), None)` — the `SystemPromptBuilder` still emits the
+/// honesty rules from its own body, just without the catalog.
+fn load_skill_body() -> (String, Option<PathBuf>) {
+ let candidates: Vec<PathBuf> = {
+ let mut v = Vec::new();
+ // 1. Adjacent to the running binary (production layout).
+ if let Ok(exe) = std::env::current_exe() {
+ if let Some(dir) = exe.parent() {
+ v.push(dir.join("skill").join("SKILL.md"));
+ if let Some(root) = dir.parent() {
+ v.push(root.join("skill").join("SKILL.md"));
+ }
+ }
+ }
+ // 2. Workspace-local (development layout — cargo run from repo root).
+ if let Ok(cwd) = std::env::current_dir() {
+ v.push(cwd.join("skill").join("SKILL.md"));
+ v.push(cwd.join("..").join("skill").join("SKILL.md"));
+ }
+ v
+ };
+ for c in candidates {
+ if let Ok(body) = std::fs::read_to_string(&c) {
+ return (body, Some(c));
+ }
+ }
+ (String::new(), None)
+}
+
fn recent_projects_path() -> PathBuf {
// %APPDATA%/ghidrust/recent_projects.txt (or home fallback)
if let Ok(appdata) = std::env::var("APPDATA") {
@@ -2893,12 +2952,12 @@ impl GhidrustApp {
if ui.button("Start Session").clicked() {
self.start_grok_session_from_ui();
}
- if self.grok_pane.grok_bin.is_none() {
- if ui.button("Install Grok Build…").clicked() {
- let status = agent_pane::spawn_install_grok();
- self.log(status.clone());
- self.grok_pane.install_status = Some(status);
- }
+ if self.grok_pane.grok_bin.is_none()
+ && ui.button("Install Grok Build…").clicked()
+ {
+ let status = agent_pane::spawn_install_grok();
+ self.log(status.clone());
+ self.grok_pane.install_status = Some(status);
}
if ui.button("Re-scan for grok").clicked() {
self.grok_pane.refresh_grok_binary();
@@ -3016,7 +3075,7 @@ impl GhidrustApp {
f.sections.push(ghidrust_agent::SectionFact {
name: s.name.clone(),
va: format!("{:#x}", s.va),
- size: s.virtual_size as u64,
+ size: s.virtual_size,
});
}
}