Ghidra CLI
A high-performance Rust CLI for automating Ghidra reverse engineering tasks, designed for both direct usage and AI agent integration (like Claude Code).
Features
- Direct bridge architecture - CLI connects directly to a Java bridge running inside Ghidra's JVM
- Auto-start bridge - Import/analyze commands automatically start the bridge
- Fast queries - Sub-second response times with Ghidra kept in memory
- Comprehensive analysis - Functions, symbols, types, strings, cross-references
- Binary patching - Modify bytes, NOP instructions, export patches
- Call graphs - Generate caller/callee graphs, export to DOT format
- Search capabilities - Find strings, bytes, functions, crypto patterns
- Script execution - Run Java/Python Ghidra scripts, inline or from files
- Batch operations - Execute multiple commands from a file
- Flexible output - Human-readable, JSON, or pretty JSON formats
- Filtering - Powerful expression-based filtering (e.g.,
size > 100)
Architecture
┌─────────────────┐ ┌──────────────────────────────────────┐
│ CLI Command │──TCP──▶ │ GhidraCliBridge.java │
│ ghidra ... │ │ (GhidraScript in analyzeHeadless) │
│ --project X │ │ ServerSocket on localhost:dynamic │
└─────────────────┘ └──────────────────────────────────────┘
The CLI connects directly to a Java bridge running inside Ghidra's JVM. This provides:
- Consistent state - Single Ghidra process for all operations
- Fast queries - No JVM startup overhead per command
- Auto-start - Bridge starts automatically when needed
- Per-project isolation - Each project gets its own bridge process and port file, enabling concurrent analysis of multiple binaries
- Minimal dependencies - Only Ghidra + Java required (no Python/PyGhidra)
Installation
From Source
Requirements
- Ghidra 10.0+ - Download from ghidra-sre.org
- Java 17+ - Required by Ghidra
- Rust 1.70+ - For building from source
Set the Ghidra installation path:
# Or configure via CLI:
Quick Start
# Check installation
# Import and analyze a binary (daemon auto-starts)
# Or step by step:
# Query functions (uses running daemon)
# Decompile a function
# Find interesting strings
# Get cross-references
# Generate call graph
Commands
Project & Program Management
Function Analysis
Symbols & Types
Cross-References
Search
Call Graphs
Binary Patching
Comments
Scripts
Batch Operations
Statistics
Bridge Management
The bridge keeps Ghidra loaded in memory. It starts automatically when needed, but you can also control it manually:
# Start bridge with a program loaded
# Check bridge status
# All commands use the bridge automatically
# Stop bridge
# Restart with different program
Multi-Project Support
Each project gets its own bridge process and port file, allowing concurrent analysis:
# Work on multiple projects simultaneously
# Query each independently
Output Formats
Default output is human-readable in all contexts. Use flags to request machine formats:
- Default: Compact human-readable format (designed for both humans and AI agents)
- --json: Compact JSON for machine parsing
- --pretty: Pretty-printed JSON (indented, multi-line)
Override with flags:
# Force JSON output (compact, single-line)
# Force pretty JSON (indented, multi-line)
# Select specific fields
Output Format Design
Format detection occurs at the CLI boundary rather than in daemon handlers. Handlers always return compact JSON for IPC efficiency and caching stability. The CLI applies format transformation (human-readable, pretty JSON) at the output boundary based on TTY detection or explicit flags. This design maintains a stable IPC protocol with a single format decision point, preventing daemon cache invalidation from format variations.
Filtering
Use expressions to filter results:
AI Agent Integration
Ghidra CLI is designed to work seamlessly with AI coding assistants like Claude Code. The structured output and comprehensive command set make it ideal for automated reverse engineering workflows.
Example workflow with an AI agent:
ghidra quick suspicious.exe- Import, analyze, start daemonghidra find interesting- AI analyzes suspicious patternsghidra decompile <func>- AI examines specific functionsghidra x-ref to <addr>- AI traces data flowghidra patch nop <addr>- AI patches anti-debug codeghidra patch export- Export patched binary
Troubleshooting
Common Issues
Missing X11 Libraries (Linux/WSL)
If you see errors like libXtst.so.6: cannot open shared object file, install X11 libraries:
# Arch Linux / WSL with Arch
# Ubuntu / Debian / WSL with Ubuntu
# Fedora / RHEL
Java Version Issues
Ghidra requires JDK 17 or higher (not just JRE):
# Arch Linux
# Ubuntu / Debian
# Verify installation
WSL-Specific Notes
WSL requires X11 libraries even for headless operation because Java AWT is loaded during initialization:
- Install X11 libraries (see above)
- If using WSL1, consider upgrading to WSL2 for better compatibility
- Bridge port/PID files are stored in
~/.local/share/ghidra-cli/
Running Doctor
Use the doctor command to verify your installation:
This checks:
- Ghidra installation directory
- analyzeHeadless availability
- Project directory configuration
- Config file status
Contributing
Contributions are welcome! Please feel free to submit issues and pull requests.
License
GPL-3.0 License - See LICENSE for details.