Implementation:416rehman DeepZero GhidraDecompile
| Knowledge Sources | |
|---|---|
| Domains | Decompilation, Security_Research, External_Tool |
| Last Updated | 2026-10-27 00:00 GMT |
Overview
External MapProcessor that decompiles binaries using Ghidra headless analysis with a configurable Jython post-script, featuring memory-safe auto-parallelism, should_skip caching, and dispatch-table extraction.
Description
The GhidraDecompile class is an external MapProcessor (located in processors/ghidra_decompile/) that decompiles PE binaries using the Ghidra headless analyzer. It is the heaviest processor in the BYOVD pipeline and implements several optimizations:
- Memory-safe auto-parallelism: each Ghidra headless worker is a JVM holding a full program database in memory (~4 GiB). The max_parallelism() override derives a safe worker count from available RAM (~4 GiB/worker, capped at 16), so parallel: 0 cannot exhaust the machine.
- should_skip caching: before processing, checks if decompiled/ghidra_result.json already exists and is valid JSON. If so, the sample is skipped—the work was done previously.
- Dispatch-table extraction: the Jython post-script (extract_dispatch.py) analyzes the decompiled code to find the IRP dispatch routine, extract IOCTL codes, identify the device name and symbolic link, and write results to ghidra_result.json and dispatch_ioctl.c.
- Timeout handling: the stage timeout (from YAML or config) is passed to Ghidra's analysisTimeoutPerFile. If the JVM hangs, it is killed after the timeout.
The processor provides dispatch-related data (device_name, symbolic_link, dispatch_name, ioctl_codes, ioctl_count, function_count) plus artifact names for the decompiled outputs.
Usage
- BYOVD decompilation: configure ghidra_install_dir (via ${GHIDRA_INSTALL_DIR}), strategy: "extract_dispatch.py", stage timeout: 600.
- Limiting analysis depth: max_functions: 500, max_depth: 3.
- Controlling parallelism: max_parallel: 8 (or 0 for auto-RAM-derived).
Code Reference
Source Location
- Repository: DeepZero
- File: processors/ghidra_decompile/ghidra_decompile.py
Signature
class GhidraDecompile(MapProcessor):
description = "decompiles binaries using ghidra headless analysis with a configurable post-script"
version = "2.0"
provides = (
"device_name", "symbolic_link", "device_created_in",
"device_on_load_path", "dispatch_name", "function_count",
"ioctl_codes", "ioctl_count",
"decompiled_ghidra_result_json", "decompiled_dispatch_ioctl_c",
)
@dataclass
class Config:
strategy: str = ""
timeout: int = 300
max_functions: int | None = None
max_depth: int | None = None
ghidra_install_dir: str = ""
java_home: str = ""
max_parallel: int = 0
def max_parallelism(self) -> int | None: ...
def validate(self, ctx: ProcessorContext) -> list[str]: ...
def should_skip(self, ctx: ProcessorContext, entry: ProcessorEntry) -> str | None: ...
def process(self, ctx: ProcessorContext, entry: ProcessorEntry) -> ProcessorResult: ...
Import
# Loaded via pipeline YAML as: processor: ghidra_decompile/ghidra_decompile.py
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| entry.source_path | Path | Yes | The binary file to decompile |
| strategy | str | Yes (config) | Post-script filename (e.g. "extract_dispatch.py") |
| ghidra_install_dir | str | Yes (config) | Ghidra install path (env-expanded) |
| java_home | str | No (config) | JDK path (optional) |
| timeout | int | No (config) | Per-file analysis timeout (default 300) |
| max_functions | None | No (config) | Limit functions analyzed |
| max_depth | None | No (config) | Limit dispatch call depth |
| max_parallel | int | No (config) | Parallelism ceiling (0 = auto from RAM) |
Outputs
| Name | Type | Description |
|---|---|---|
| returns | ProcessorResult | ok with artifacts + dispatch data, or fail |
| artifacts["ghidra_result"] | str | "decompiled/ghidra_result.json" |
| artifacts["dispatch_ioctl"] | str | "decompiled/dispatch_ioctl.c" (if produced) |
| data | dict | device_name, symbolic_link, dispatch_name, function_count, ioctl_codes, ioctl_count, device_created_in, device_on_load_path |
Usage Examples
BYOVD Pipeline YAML
stages:
- name: decompile
processor: ghidra_decompile/ghidra_decompile.py
config:
strategy: "extract_dispatch.py"
ghidra_install_dir: ${GHIDRA_INSTALL_DIR}
java_home: ${JAVA_HOME:-}
timeout: 300
max_parallel: 0 # auto-derive from RAM (~4 GiB/worker)
parallel: 0
timeout: 600
on_failure: skip
Ghidra Headless Command
# The processor builds and runs this command internally:
analyzeHeadless <project_dir> dz_<binary_stem> \
-import <binary_path> \
-postScript extract_dispatch.py \
-scriptPath <scripts_dir> \
-overwrite \
-deleteProject \
-analysisTimeoutPerFile 300