Skip to content

Craft Anything: understand how any software works, and craft your own.

Rust

Refuse a Ghidra with no decompiler for this computer before its long analysis (#1023)

adamsardo2271338ae89e
diff --git a/crates/engines/src/ghidra/mod.rs b/crates/engines/src/ghidra/mod.rs
index efa2eb38..5dbbcf2b 100644
--- a/crates/engines/src/ghidra/mod.rs
+++ b/crates/engines/src/ghidra/mod.rs
@@ -500,6 +500,55 @@ fn lock_is_fresh(lock: &Path) -> bool {
std::fs::metadata(lock).and_then(|m| m.modified()).is_ok_and(|t| t.elapsed().is_ok_and(|age| age < LOCK_STALE))
}
+/// The start of the folder names Ghidra gives this system's native programs (`mac_arm_64`, ...).
+/// None where we don't know them, so nothing is refused there.
+fn native_folder_prefix() -> Option<&'static str> {
+ if cfg!(target_os = "macos") {
+ Some("mac_")
+ } else if cfg!(target_os = "linux") {
+ Some("linux_")
+ } else if cfg!(windows) {
+ Some("win_")
+ } else {
+ None
+ }
+}
+
+/// Whether an install at `root` has a decompiler for a system whose folders start with `prefix`.
+/// Ghidra's public releases leave macOS out, and building them puts them under `build/os`.
+/// An install laid out in a way we don't recognise counts as having one: Ghidra then decides.
+fn has_decompiler_for(root: &Path, prefix: &str) -> bool {
+ let decompiler = root.join("Ghidra").join("Features").join("Decompiler");
+ let shipped = decompiler.join("os");
+ if !shipped.is_dir() {
+ return true;
+ }
+ [shipped, decompiler.join("build").join("os")].iter().any(|folder| {
+ std::fs::read_dir(folder).is_ok_and(|entries| {
+ entries
+ .flatten()
+ .any(|e| e.file_name().to_string_lossy().starts_with(prefix) && ["decompile", "decompile.exe"].iter().any(|exe| e.path().join(exe).is_file()))
+ })
+ })
+}
+
+/// Stops before a long analysis that couldn't lead to pseudo-code: without its decompiler program
+/// Ghidra analyses for as long as ever and then answers nothing.
+fn check_decompiler(analyze_headless: &Path) -> Result<(), GhidraError> {
+ let Some(prefix) = native_folder_prefix() else { return Ok(()) };
+ // <install>/support/analyzeHeadless; a linked launcher is followed to the real install.
+ let launcher = std::fs::canonicalize(analyze_headless).unwrap_or_else(|_| analyze_headless.to_path_buf());
+ let Some(root) = launcher.parent().and_then(Path::parent) else { return Ok(()) };
+ if has_decompiler_for(root, prefix) {
+ return Ok(());
+ }
+ let gradle = root.join("support").join("gradle");
+ Err(GhidraError::Launch(format!(
+ "this Ghidra has no decompiler program for this computer, which its public downloads leave out on macOS. Build it once by running `./gradlew buildNatives` in {}",
+ gradle.display()
+ )))
+}
+
/// Make sure the target is analysed and saved in its cached project, analysing it now if no one
/// has (a big program can take hours; it happens once). If another process is already analysing
/// it, wait for that instead of starting over. Returns the cached project folder, as the path to
@@ -513,6 +562,7 @@ pub fn analyse(
cancel: &Cancel<'_>,
progress: &Progress<'_>,
) -> Result<PathBuf, GhidraError> {
+ check_decompiler(&cfg.analyze_headless)?;
let started = Instant::now();
let minutes = || started.elapsed().as_secs() / 60;
let deadline = started + cfg.startup_timeout;
diff --git a/crates/engines/src/ghidra/tests.rs b/crates/engines/src/ghidra/tests.rs
index 6c6fa4d3..be174165 100644
--- a/crates/engines/src/ghidra/tests.rs
+++ b/crates/engines/src/ghidra/tests.rs
@@ -597,3 +597,36 @@ fn a_bridge_that_stops_early_leaves_its_log_beside_the_analysis() {
assert_eq!(keep_log(&[&none], &d.path().join("other.bridge.log")), none);
assert!(!d.path().join("other.bridge.log").exists());
}
+
+/// An install's decompiler folder, with this program in it.
+fn install_with(root: &std::path::Path, folder: &[&str], exe: &str) {
+ let mut dir = root.join("Ghidra").join("Features").join("Decompiler");
+ for part in folder {
+ dir = dir.join(part);
+ }
+ std::fs::create_dir_all(&dir).unwrap();
+ std::fs::write(dir.join(exe), b"").unwrap();
+}
+
+#[test]
+fn a_public_download_on_macos_has_no_decompiler_until_it_is_built() {
+ let d = tempfile::tempdir().unwrap();
+ install_with(d.path(), &["os", "linux_x86_64"], "decompile");
+ install_with(d.path(), &["os", "win_x86_64"], "decompile.exe");
+ assert!(!has_decompiler_for(d.path(), "mac_"), "other systems' programs don't count");
+ assert!(has_decompiler_for(d.path(), "linux_"));
+ assert!(has_decompiler_for(d.path(), "win_"));
+
+ install_with(d.path(), &["build", "os", "mac_arm_64"], "decompile");
+ assert!(has_decompiler_for(d.path(), "mac_"), "`gradlew buildNatives` puts it under build/os");
+}
+
+#[test]
+fn an_empty_platform_folder_is_not_a_decompiler_and_an_unknown_layout_is_left_to_ghidra() {
+ let d = tempfile::tempdir().unwrap();
+ std::fs::create_dir_all(d.path().join("Ghidra/Features/Decompiler/os/mac_arm_64")).unwrap();
+ assert!(!has_decompiler_for(d.path(), "mac_"));
+
+ let unknown = tempfile::tempdir().unwrap();
+ assert!(has_decompiler_for(unknown.path(), "mac_"), "never refused on a guess");
+}
diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md
index 5da07d33..e1194c82 100644
--- a/docs/ROADMAP.md
+++ b/docs/ROADMAP.md
@@ -485,6 +485,9 @@ yet, and the quick start is how every new person begins.
- [ ] A live run of a project copied between two real computers with Claude Code (#451, #452); done
on one Mac with a second `CLAUDE_CONFIG_DIR` standing in for the other computer (STATUS.md)
- [ ] Ghidra setup tried for real on Linux and macOS (the Java pins were checked by tests only)
+- [x] A Ghidra with no decompiler program for this computer (public downloads leave out macOS) is
+ refused before the long analysis, with the command that builds it; checked on a real Mac
+- [ ] `engines_install` builds Ghidra's native programs on macOS, so a Mac install works unaided
- [ ] Follow the README quick start on a clean machine (Windows, and Linux or macOS)
- [ ] Build the new DMG on a Mac (release dry run) and look at the window once
- [ ] #490 on macOS: a real Deep build through Claude Code with the published 0.3.0 CLI, with
diff --git a/docs/STATUS.md b/docs/STATUS.md
index 5490c163..06823281 100644
--- a/docs/STATUS.md
+++ b/docs/STATUS.md
@@ -51,7 +51,7 @@ workspace clippy, layers, fmt and the secret scan of all history were clean. Chi
| SQLite payload limits | Capped records retain column positions, disclose partial TEXT and BLOB values, omit incomplete BLOB hashes, and report partial coverage with read notes | Hand-built overflow-page regressions for five oversized records (including WITHOUT ROWID in declaration order) and two controls; table and index engine coverage and limitation regressions |
| SQLite added columns | Short records include missing trailing fields using literal column defaults, or NULL when absent; unsupported default expressions produce NULL with a row note. Stored fields and records longer than the schema retain their values. Defaults are filled before restoring rowid aliases | Nine hand-built parser regressions and an engine tool test cover added-column defaults, rewritten records and short records with a rowid alias, including a missing alias field |
| OpenCode models and thinking | OpenCode V2 locally and over SSH; Settings → AI lists only that instance's enabled chat models and supported Low/Medium/High/Xhigh/Max variants. Selection is validated and saved through UI, CLI and `ai_models_list` / `ai_model_set`. Explicit selections run natively with the Craft Anything MCP server (local runs; none over SSH yet). See [OpenCode](opencode.md). | Stand-in catalogue/process, persistence, remote-command and UI tests; local live catalogue checks (34 models, all five depths represented). Regression checks route explicit selections natively and parse V2 tool events. Live (2026-11-04, Windows, OpenCode 2.2.5, opencode-go/deepseek-v4.1-flash): a `--standalone` run connected the server (38 tools) and called `core_session_show`. No live SSH host or paid generation used |
-| Ghidra and closing the app | Closing the app stops an analysis a build started, and waits for it to end, so `java.exe` isn't left running (#946). An app that crashes or is killed can still leave one (#951). Deep mode doesn't analyse an Electron program's runtime, whose logic is in `app.asar` (#947) | Stopping tested with a waiting analysis; not run against a live Ghidra |
+| Ghidra and closing the app | Closing the app stops an analysis a build started, and waits for it to end, so `java.exe` isn't left running (#946). An app that crashes or is killed can still leave one (#951). Deep mode doesn't analyse an Electron program's runtime, whose logic is in `app.asar` (#947) | Stopping tested with a waiting analysis; not run against a live Ghidra A Ghidra with no decompiler program for this computer, as public downloads have on macOS, is refused before the analysis starts, with the command that builds one. |
| Gemini tool calls | A tool call's `extra_content` (Gemini's thought signature) goes back with it unchanged, so Gemini 3 builders get past their first tool call; errors Gemini wraps in an array show their message (#978) | Unit-tested; not run against the live API |
| OpenCode models and thinking | OpenCode V2 locally and over SSH; Settings → AI lists only that instance's enabled chat models and supported Low/Medium/High/Xhigh/Max variants. Selection is validated and saved through UI, CLI and `ai_models_list` / `ai_model_set`. Explicit selections run natively with the Craft Anything MCP server (local runs, and over SSH: one `ssh` run checks `craft-anything-cli` on the host's PATH and writes the config on the host, `~/.cache/craft-anything/`, mode 600). See [OpenCode](opencode.md). | Stand-in catalogue/process, persistence, remote-command and UI tests; local live catalogue checks (34 models, all five depths represented). Regression checks route explicit selections natively and parse V2 tool events. Live (2026-11-04, Windows, OpenCode 2.2.5, opencode-go/deepseek-v4.1-flash): a `--standalone` run connected the server (38 tools) and called `core_session_show`. The SSH path is covered by a POSIX-shell regression test (probe fails fast without the helper; config written byte-exact, mode 600, atomic rename) and was exercised against a localhost SSH host; it has not been run with a live agent over SSH. No paid generation used |
| Claude desktop app without Claude Code | When the `claude` command isn't found but the Claude desktop app is (Windows: the Store package's `claude-desktop` app alias or the older installer's `AnthropicClaude` folder; macOS: `Claude.app`), the builder dialog under "No coding agent was found" and `ai detect` (on stderr) say the desktop app is installed but building needs Claude Code, installed apart (#259). Typed as `DetectHint` from `AiHub::detect_hints` | A regression finds the app in temp folders laid out as each Windows installer leaves it, and nothing on Linux; a UI test shows the hint in the dialog. On Windows 10 the real Store package's alias was found. Not checked: macOS, the older installer, and a computer with no `claude` installed |