Skip to content

fix(ghidra): pre-create the launch-support config directory - #2470

Merged
morluto merged 4 commits into
morluto:mainfrom
AbdulAzizWang:fix/ghidra-windows-launch-config
Oct 13, 2026
Merged

morluto merged 4 commits into
morluto:mainfrom
AbdulAzizWang:fix/ghidra-windows-launch-config

Conversation

@AbdulAzizWang

@AbdulAzizWang AbdulAzizWang commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Problem

On Windows x64 the first Ghidra-backed query fails even though rea doctor reports a valid
Ghidra installation and 64-bit JDK. Ghidra's launch support cannot persist its JDK choice
inside REA's private runtime:

java.io.IOException: Failed to create directory:
...\config\ghidra\ghidra_12.1.4_PUBLIC
    at ghidra.launch.AppConfig.saveJavaHome(AppConfig.java:145)
    at LaunchSupport.findJavaHome(LaunchSupport.java:210)

LaunchSupport then falls back to its interactive prompt, reads EOF, and prints
JDK 21+ (64-bit) could not be found and must be manually chosen!, so the provider fails
with Ghidra exited before bridge startup.

Cause

createGhidraRuntimeDirectories creates the six runtime roots but not the launch-support
release directory Ghidra writes into. The private runtime's DACL lets the owning process
write, but the launched JVM does not create those directories itself, so saveJavaHome
throws and JDK resolution aborts.

Fix

Create <config>/ghidra/<release directory> before launch, one level at a time, while this
process still owns the runtime, so Ghidra only has to write a file inside it. The release
coordinate comes from the installation's Ghidra/application.properties
(application.version plus application.release.name), with the extraction directory name
as a fallback.

Validation

Windows x64, Ghidra 12.1.4, 64-bit Temurin JDK 21, REA's packaged native addon:

  • rea inspect <x64 PE DLL> --provider ghidra --format json completes and reports 21
    segments, 1436 procedures, and 2761 strings.
  • The equivalent MCP binary_overview call returns the same Evidence record.

rea doctor --provider ghidra was already healthy before this change, so the failure was
only observable on the first real Ghidra query.

Reproduction

Observed on: Windows 10+ x64, Node.js 24.15.0, Ghidra 12.1.4 (official zip), 64-bit Temurin
JDK 21.0.12.1, native addon from the packaged artifact. TEMP/TMP were left at their
defaults.

  1. Build the parent commit with the pinned toolchain (npm ci && npm run build:cached) and
    export absolute paths:

    $env:GHIDRA_INSTALL_DIR = "C:\tools\ghidra_12.1.4_PUBLIC"
    $env:JAVA_HOME          = "C:\tools\jdk-21"
  2. Confirm the installation itself is accepted. This is healthy both before and after the
    change, which is why the failure looked unrelated to setup:

    rea doctor --provider ghidra --json
    # ghidra-java             -> 21.0.12.1; 64-bit; JDK; accepted
    # ghidra-native_authority -> verified
  3. Run the first Ghidra-backed query on any native x64 PE (EXE or DLL), using the documented
    entry point from docs/windows-ghidra-p0.md:

    rea inspect "C:\fixtures\sample.exe" --provider ghidra --format json
  4. Result: execution_failure, failure_kind: "process",
    failure_message: "Ghidra exited before bridge startup". The retained diagnostics carry
    the cause. stdout:

    ******************************************************************
    JDK 21+ (64-bit) could not be found and must be manually chosen!
    ******************************************************************
    Enter path to JDK home directory (ENTER for dialog):
    ERROR: Failed to find a supported JDK.
    

    stderr:

    java.io.IOException: Failed to create directory:
      <runtime>\config\ghidra\ghidra_12.1.4_PUBLIC
        at ghidra.launch.AppConfig.saveJavaHome(AppConfig.java:145)
        at LaunchSupport.findJavaHome(LaunchSupport.java:210)
        at LaunchSupport.handleJavaHome(LaunchSupport.java:153)
        at LaunchSupport.main(LaunchSupport.java:113)
    java.lang.NullPointerException: Cannot invoke "String.trim()" because the return value
    of "java.io.BufferedReader.readLine()" is null
        at LaunchSupport.askJavaHome(LaunchSupport.java:300)
        at LaunchSupport.handleJavaHome(LaunchSupport.java:151)
    

    The askJavaHome NPE is LaunchSupport falling back to its interactive prompt after the
    saveJavaHome IOException; there is no console, so it reads EOF and reports that no
    supported JDK was found.

  5. After this change the same command completes and open_binary / binary_overview return
    analysis Evidence. Ghidra's launch support now resolves the JDK from JAVA_HOME and
    writes java_home.save into the pre-created directory itself:

    <runtime>\config\ghidra\ghidra_12.1.4_PUBLIC\java_home.save
    

The same launch path is exercised by npm run verify:ghidra:windows.

Notes for review

  • The report is Windows-specific; I have not tested other hosts, where the runtime roots are
    created with plain mkdir rather than the native private-runtime owner.
  • If the intended contract is that the launched JVM should be able to create that directory
    itself, a pointer to where that is enforced would be welcome — pre-creating it is the
    minimal change that unblocked the P0 path here.
  • Adjacent to fix(ghidra): retain bounded LaunchSupport failure output #2010, which made this diagnosable by retaining LaunchSupport output.

Ghidra's launch support resolves its JDK before the headless run starts and
persists that choice under `<config>/ghidra/<release directory>`. Inside REA's
private runtime a child JVM cannot create those directories, so the first
Windows Ghidra query aborted at ghidra.launch.AppConfig.saveJavaHome with:

    java.io.IOException: Failed to create directory:
    ...\config\ghidra\ghidra_12.1.4_PUBLIC
        at ghidra.launch.AppConfig.saveJavaHome(AppConfig.java:145)
        at LaunchSupport.findJavaHome(LaunchSupport.java:210)

LaunchSupport then fell back to its interactive prompt, read EOF, and reported
"JDK 21+ (64-bit) could not be found and must be manually chosen!", so the
provider failed with "Ghidra exited before bridge startup" even though
`rea doctor` reported a valid Ghidra installation and JDK.

Create the release directory while this process still owns the runtime, leaving
Ghidra only a file write inside it. The release coordinate comes from the
installation's Ghidra/application.properties (application.version plus
application.release.name) with the extraction directory name as a fallback. On
Windows each level goes through the native private-runtime owner, which opens
every existing component and creates only the final one.

Verified on Windows x64 with Ghidra 12.1.4, a 64-bit Temurin JDK 21, and REA's
packaged native addon: `rea inspect <x64 PE DLL> --provider ghidra` and the
equivalent MCP `binary_overview` call both complete and report 21 segments,
1436 procedures, and 2761 strings. Windows Ghidra remains read-only P0; this
change does not extend that boundary.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@CassieFox23

Copy link
Copy Markdown
Contributor

TL;DR: This is a Linux check, and it does not reproduce the Windows bug. On Linux, the head gives the same Ghidra results as its parent, and its new folder has the right name. REA's Linux launch never writes into that folder.

Results

I ran rea inspect <elf> --provider ghidra --format json on Linux, with head c74d9cc and its direct parent a2d8b94 (#2409). GitHub's base bb154d1 (#2277) is not in this branch's history.

ELF Parent Head
copy of a system true exit 0; 34 segments, 149 procedures, 140 strings same as Parent
copy of a system echo exit 0; 34, 151, 150 same as Parent
true, install reached by a symlink exit 0; 34, 149, 140 same as Parent
  • The head's new folder, config/ghidra/ghidra_12.1.4_PUBLIC, appears before Ghidra starts. It stays empty.
  • Ghidra's headless run made config/<user>-ghidra/ghidra_12.1.4_PUBLIC, on both sides. Launch support run by hand did not. Nothing went under the home folder, and no java_home.save appeared anywhere.
  • Run by hand on Linux, Ghidra's launch support with -jdk_home -save writes java_home.save into config/ghidra/ghidra_12.1.4_PUBLIC. So the name matches.
  • On Linux, REA only asks launch support for -envvars and -vmargs. Windows runs the Ghidra script, whose launch.bat passes -save (read, not run). That fits why only Windows hit the error.
  • So on Linux the two folders share the release name, not the parent folder. Only launch support's -save writes into the head's.
  • I named the symlink ghidra-link, yet the head made ghidra_12.1.4_PUBLIC. So the name comes from application.properties.

Not run

  • The Windows failure, since I have no Windows host.
  • The fallback to the install folder name. By its code it applies when the properties file is unreadable or incomplete. I did not exercise it.
  • Any test file. None in the repo mentions createGhidraRuntimeDirectories.
  • The MCP binary_overview route, and main's tip.
  • The PR lists no CI result.

Thanks, AbdulAzizWang, for the fix and the detailed write-up.

Test setup
Commands
env -i HOME=<job>/home-<side> TMPDIR=<job>/tmp-<side> GHIDRA_INSTALL_DIR=<install> \
  JAVA_HOME=<jdk-21> systemd-run --user --scope -p MemoryMax=8G -- \
  node <tree>/scripts/rea.mjs inspect <elf> --provider ghidra --format json

A small node script watched the temporary runtime every 50 ms. All six runs exited 0.

🤖 Generated with Claude Code (Sonnet 5.5, verified by Opus 5.5) 🦊

@morluto

morluto commented Oct 13, 2026

Copy link
Copy Markdown
Owner

@greptileai review

@greptile-apps

greptile-apps Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; the release lookup now matches installation checks.

Summary

Pre-creates Ghidra’s release-specific configuration directory before launch, with parent directories created first on Windows.

  • Ghidra's launch folder is ready before analysis starts.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Read installation properties] --> B{Properties usable?}
  B -->|Yes| C[Build release directory name]
  B -->|No| D[Use installation basename]
  C --> E[Create runtime roots]
  D --> E
  E --> F[Create config/ghidra]
  F --> G[Create release directory]
  G --> H[Launch Ghidra]
  H --> I[LaunchSupport saves Java home]
Loading

Reviews (4) · Last reviewed commit: "fix(ghidra): reuse Java Properties parsi..." · Reviewed by Greptile

Comment thread src/ghidra/GhidraLauncher.ts Resolved
Comment thread src/ghidra/GhidraLauncher.ts Resolved
@morluto
morluto merged commit 0ca70e1 into morluto:main Oct 13, 2026
1 check passed
@morluto

morluto commented Oct 13, 2026

Copy link
Copy Markdown
Owner

Review findings addressed at their producing boundaries and consumers. Latest changes were reviewed from source; tests and provider runs were skipped at the maintainer's request. Findings requiring separate decisions or verification remain open.

  1. thread 1

Handled in 79f93f3. Added Windows production-boundary launcher scenarios for a renamed installation with readable application.properties, an unreadable/missing properties fallback, and a missing release-key fallback. Each goes through the owned Windows runtime before an injected spawn boundary and asserts the release directory exists. Reaching spawn proves parent-before-child directory admission succeeded; these Windows scenarios have not been executed.

Source inspection and git diff --check completed. Tests, builds, typechecking, lint, and real-provider verification were skipped at the user's explicit request.

  1. thread 1

Handled in 79f93f3. Removed the separate regex lookup. Launch release identity now uses the same parseGhidraJavaProperties owner as installation admission, reading ISO-8859-1 text and preserving escaped keys/values, continuations, colon separators, and last-key-wins overrides before selecting the release directory.

Source inspection and git diff --check completed. Tests, builds, typechecking, lint, and real-provider verification were skipped at the user's explicit request.

@morluto morluto added bug Something isn't working area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior labels Oct 14, 2026
@morluto morluto added area: setup Setup, packaging, upgrade, install, Doctor, and client registration provider: ghidra Analysis provider / engine: ghidra labels Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior area: setup Setup, packaging, upgrade, install, Doctor, and client registration bug Something isn't working provider: ghidra Analysis provider / engine: ghidra

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants