worker: optional PyGhidra back-end for Ghidra 11.4+/12.x (no Jython)

The .py extractor runs fine under PyGhidra in the GUI; only `analyzeHeadless`
doesn't init PyGhidra. Add an env-gated CPython path so modern Ghidra works headless:

- ghidra.run_extractor_pyghidra(): runs the same GhidraScript via pyghidra.run_script
  (boots Ghidra in-process, imports+analyses, getScriptArgs()=[out_path]); run_extractor
  dispatches to it when AMS_USE_PYGHIDRA is set. No script changes needed.
- worker image installs pyghidra + sets GHIDRA_INSTALL_DIR; compose exposes
  AMS_USE_PYGHIDRA (default off). Jython path stays the default and untouched.
- README documents both variants (Jython <=11.3.x vs PyGhidra 11.4+/12.x).
- test: AMS_USE_PYGHIDRA routes to the PyGhidra back-end (clear error if pkg missing).

35/35 tests pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Patryk Gensch
2026-05-31 18:03:04 +02:00
parent aa65beb7c1
commit ba9db82a4c
5 changed files with 85 additions and 14 deletions

View File

@@ -136,6 +136,18 @@ def test_acquire_zip_no_sink(tmp_path, golden_snapshot):
assert r.imported_id is None and r.sink == "none"
def test_pyghidra_dispatch_without_dep(tmp_path, monkeypatch):
"""AMS_USE_PYGHIDRA routes to the PyGhidra back-end; without the package it fails clearly."""
import importlib.util
from ams.acquire import ghidra
if importlib.util.find_spec("pyghidra") is not None:
pytest.skip("pyghidra is installed; this exercises the missing-dependency path")
monkeypatch.setenv("AMS_USE_PYGHIDRA", "1")
with pytest.raises(ghidra.GhidraNotFound, match="pyghidra"):
ghidra.run_extractor(str(tmp_path / "x.dll"), str(tmp_path / "out.json"))
def test_acquire_loose_dll_into_db(tmp_path, golden_snapshot):
from ams.api.db import configure