--- name: ghidra-cli-skill description: > Use ghidra-cli for reverse engineering tasks: binary analysis, decompilation, function inspection, cross-reference analysis, pattern discovery, and binary patching. Activate when the user requests: - Binary analysis or reverse engineering - Decompilation or disassembly - Function listing, inspection, or renaming - Cross-reference or call graph analysis - String or byte pattern searches - Binary patching or modification - Ghidra project management --- # ghidra-cli Use ghidra-cli for reverse engineering tasks: binary analysis, decompilation, function inspection, cross-reference analysis, pattern discovery, and binary patching. ## When to Use Activate when the user requests: - Binary analysis or reverse engineering - Decompilation or disassembly - Function listing, inspection, or renaming - Cross-reference or call graph analysis - String or byte pattern searches - Binary patching or modification - Ghidra project management ## Workflow ### Pre-flight Check Before running queries, verify the environment: ```bash # Check if daemon is running for fast queries ghidra daemon status --project # If not running, start it ghidra daemon start --project --program ``` ### Quick Start (New Binary) For one-off analysis, use quick mode: ```bash ghidra quick ./binary ghidra daemon start --project quick-analysis --program binary ``` ### Full Project Setup For sustained analysis: ```bash ghidra project create myproject ghidra import ./binary --project myproject ghidra analyze --project myproject --program binary ghidra daemon start --project myproject --program binary ``` ## Command Reference ### Querying Functions ```bash # List all functions ghidra function list --project

--program # Filter functions by size or name ghidra function list --filter "size > 500" ghidra function list --filter "name contains 'crypt'" # Get function details ghidra function get main # Decompile to pseudocode ghidra function decompile main # Disassemble ghidra function disasm main # Cross-references ghidra function xrefs main ghidra function calls main ``` ### Search Operations ```bash # Find functions by pattern ghidra find function "*crypt*" # Find strings ghidra find string "password" # Find byte patterns (hex) ghidra find bytes "4883ec08" # Find crypto constants ghidra find crypto # Find suspicious patterns (anti-analysis, obfuscation) ghidra find interesting ``` ### Cross-References ```bash # References TO an address ghidra x-ref to 0x401000 # References FROM an address ghidra x-ref from 0x401000 ``` ### Call Graphs ```bash # Full call graph ghidra graph calls # Who calls this function (callers) ghidra graph callers main --depth 3 # What does this function call (callees) ghidra graph callees main --depth 3 # Export as DOT format ghidra graph export dot ``` ### Symbols and Strings ```bash # List symbols ghidra symbol list # List strings ghidra strings list --limit 100 # References to a string ghidra strings refs "error" ``` ### Memory and Types ```bash # Memory map ghidra memory map # Read memory at address ghidra memory read 0x401000 64 # List data types ghidra type list # Apply type to address ghidra type apply 0x402000 "char[32]" ``` ### Modifications ```bash # Rename function ghidra function rename sub_401000 decrypt_password # Add comment ghidra comment set 0x401000 "Key derivation starts here" # Patch bytes ghidra patch bytes 0x401000 "90909090" # NOP instructions ghidra patch nop 0x401010 --count 5 # Export patched binary ghidra patch export --output patched.bin ``` ### Scripting ```bash # Run Python script ghidra script run analysis.py # Inline Python ghidra script python "print(currentProgram.getName())" # Batch commands from file ghidra batch commands.txt ``` ## Output Handling ghidra-cli outputs JSON by default. Parse the structured data: ```bash # JSON output (default) ghidra function list # Table format for display ghidra function list --format table # Count only ghidra function list --format count ``` When processing results, extract relevant fields from JSON rather than displaying raw output. ## Common Patterns ### Investigate a Function ```bash ghidra function get # Overview ghidra function decompile # Pseudocode ghidra function calls # What it calls ghidra function xrefs # Who calls it ghidra graph callers --depth 2 ``` ### Find Interesting Code ```bash ghidra find crypto # Crypto constants ghidra find interesting # Suspicious patterns ghidra find function "*alloc*" # Memory functions ghidra strings list --filter "length > 50" ``` ### Trace Data Flow ```bash ghidra x-ref to

# Who writes here ghidra x-ref from
# What this references ghidra graph callees --depth 3 ``` ## Error Recovery | Situation | Resolution | | ------------------ | ------------------------------------------------------------- | | Daemon not running | `ghidra daemon start --project

--program ` | | No project exists | `ghidra project create ` or use `ghidra quick ` | | Function not found | Use `ghidra find function "*pattern*"` to search | | Address format | Use hex with 0x prefix: `0x401000` | | Slow queries | Start daemon for sub-second response times | ## Global Options All commands accept: - `--project ` - Target project - `--program ` - Target program within project - `--format json|table|count` - Output format - `--filter ` - Filter expression - `--limit ` - Max results