Files
Athena-Deck/integrations/opencode-athena/rea/GHIDRA.md
T

4.8 KiB

Ghidra provider for OpenCode / REA

Prepared 2026-10-15 inside the existing Alpine OpenCode container. No additional container, Docker socket, host SSH identity, published port or service restart. All paths below belong to the existing persistent /root appdata mount.

Pinned components

  • REA 6.5.0, existing locked npm installation.
  • Official NSA Ghidra 12.1.4 public release, archive ghidra_12.1.4_PUBLIC_20260921.zip (569649598 bytes).
  • Source: https://github.com/NationalSecurityAgency/ghidra/releases/tag/Ghidra_12.1.4_build
  • Archive SHA-256, verified against the release asset digest: ddac49f903da9d5bac833e5cc79395098b9c33cfd3279be5f31bd00387d2d4db.
  • Private Alpine OpenJDK 21.0.12+8, including javac.
  • Private build-base/GCC 15.2.0, make, bison, flex and Bash, plus dependencies. Exact package archive filenames and hashes are in apk-sha256.txt.

Installation root: /root/.local/share/rea (R below). Ghidra is extracted into R/providers/ghidra_12.1.4_PUBLIC (G). Restore ZIP Unix executable permission bits when extracting using Python zipfile. Java and Alpine dependencies are unpacked into R/sysroot (S), without installing/replacing container system packages. Keep downloaded APKs in R/apk.

The stock Ghidra Linux decompiler targets glibc. This container uses musl; compile the bundled decompiler source for Alpine rather than assuming that a successful file-existence check establishes executable compatibility:

export PATH="$S/bin:$S/usr/bin:$PATH"
export LD_LIBRARY_PATH="$S/usr/lib:$S/lib"
export BISON_PKGDATADIR="$S/usr/share/bison"
export M4="$S/usr/bin/m4"
cd "$G/Ghidra/Features/Decompiler/src/decompile/cpp"
nice -n 10 make -j2 ghidra_opt \
  "CXX=g++ --sysroot=$S -B$S/usr/bin/ -std=c++11"
install -m 755 ghidra_opt "$G/Ghidra/Features/Decompiler/os/linux_x86_64/decompile"

REA-only environment

Preserve all other OpenCode settings and configure only mcp.rea.environment:

  • GHIDRA_INSTALL_DIR=R/providers/ghidra_12.1.4_PUBLIC
  • JAVA_HOME=R/sysroot/usr/lib/jvm/java-21-openjdk
  • PATH prepends JAVA_HOME/bin, R/sysroot/bin, R/sysroot/usr/bin.
  • LD_LIBRARY_PATH prepends R/sysroot/usr/lib, R/sysroot/lib.

Use actual absolute paths, not literal R/S/G. The same overrides are stored in R/private-env.json for separate smoke tests. Do not commit this private file or OpenCode configuration/installer backups; they can inherit sensitive settings. No active OpenCode session is reloaded during this installation. A separately verified MCP process does not establish that an already running client has loaded the new configuration.

Verified result

The Alpine native build completed successfully. Installed decompiler SHA-256: d9a25620ce2bbbf36199562b1b14f7253c727791381f73a73487d5fa8417ae17. REA doctor identifies Ghidra as available and its provider scope as healthy; its broader environment reports missing optional providers, not a fully green all-provider setup. The end-to-end synthetic test passed: DOS-MZ/x86, exact identity match, two procedures, 229 characters of nonempty pseudocode. The first pre-build analysis attempt failed; only the final native-build test is accepted. Ghidra/Java paths were saved in the REA-only MCP environment. Other persisted model/MCP settings were compared internally and unchanged.

Verification and limitations

Run node verify-dos.mjs inside OpenCode. It creates a tiny synthetic DOS MZ EXE, opens it through Ghidra's REA provider, verifies its format and SHA-256, lists procedures and requests nonempty pseudocode. It never executes the EXE. Only synthetic result counts are printed; its fixture and MCP child are cleaned up. Do not treat provider discovery/doctor alone as proof of decompilation.

DOS program support does not promise original source code, original variable names, reliable reconstruction of packed/self-modifying code, or an executable modern port. Analyze user binaries statically first. Actual user EXEs have not been tested as part of installation.

Backup / restore

Back up the complete persistent OpenCode /root mount with Unraid appdata, including runtime, Ghidra, sysroot, configuration and private state. Athena Deck's separate backup does not automatically include this Unraid service. Public archives can instead be downloaded again using the pinned sources/hashes. Re-run the native build and both REA smoke tests after changing Alpine ABI.

For future native Debian, install a supported 64-bit JDK 21 and procps with the native package manager, extract this pinned official Ghidra distribution and use its supplied glibc decompiler. Set JAVA_HOME/GHIDRA_INSTALL_DIR for the actual service account; do not copy Alpine musl libraries or its rebuilt executable onto Debian. Reconstruct REA using the lockfile and repeat the DOS test. A fresh Debian host restore remains untested; no native Deck installation is changed.