feat(acquire): resumable batch extraction queue and binary inventory
Inventory classifies the DLL repository by SHA; the batch queue runs each engine build in a fresh PyGhidra process with a timeout, fingerprints the extractor environment and keeps per-attempt state and logs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
bddb5949a6
commit
b0013c5114
+19
-1
@@ -20,6 +20,8 @@ then `analyzeHeadless` on PATH.
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import json
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
@@ -44,7 +46,7 @@ def find_headless() -> str | None:
|
||||
env = os.environ.get("GHIDRA_HEADLESS")
|
||||
if env and os.path.isfile(env):
|
||||
return env
|
||||
home = os.environ.get("GHIDRA_HOME")
|
||||
home = os.environ.get("GHIDRA_INSTALL_DIR") or os.environ.get("GHIDRA_HOME")
|
||||
if home:
|
||||
for name in ("analyzeHeadless", "analyzeHeadless.bat"):
|
||||
cand = os.path.join(home, "support", name)
|
||||
@@ -123,9 +125,20 @@ def run_extractor_pyghidra(dll_path: str, out_path: str, *, script_dir: str | No
|
||||
|
||||
proj_dir = tempfile.mkdtemp(prefix="ams_pyghidra_")
|
||||
try:
|
||||
# Keep headless preferences/caches separate from the user's GUI profile.
|
||||
from pyghidra.launcher import PyGhidraLauncher, HeadlessPyGhidraLauncher
|
||||
if not PyGhidraLauncher.has_launched():
|
||||
launcher = HeadlessPyGhidraLauncher(verbose=False)
|
||||
runtime_home = os.path.join(proj_dir, "runtime-home")
|
||||
os.makedirs(runtime_home)
|
||||
launcher.vm_args.extend(["-Duser.home=" + runtime_home, "-Xmx2G"])
|
||||
launcher.start()
|
||||
pyghidra.run_script(
|
||||
dll_path, script_path,
|
||||
project_location=proj_dir, project_name="ams_" + uuid.uuid4().hex[:8],
|
||||
# Ghidra domain-file names reject Unicode combining marks and some
|
||||
# Polish letters. This changes only the internal project name.
|
||||
program_name=re.sub(r"[^A-Za-z0-9_.-]", "_", Path(dll_path).name),
|
||||
script_args=[out_path], analyze=True, verbose=False,
|
||||
)
|
||||
except Exception as e: # jpype/Ghidra errors aren't a tidy hierarchy
|
||||
@@ -135,4 +148,9 @@ def run_extractor_pyghidra(dll_path: str, out_path: str, *, script_dir: str | No
|
||||
|
||||
if not os.path.isfile(out_path):
|
||||
raise GhidraRunError("extractor produced no snapshot at {0} (PyGhidra path)".format(out_path))
|
||||
with open(out_path, encoding="utf-8") as stream:
|
||||
snapshot = json.load(stream)
|
||||
snapshot.setdefault("binary", {})["name"] = Path(dll_path).name
|
||||
with open(out_path, "w", encoding="utf-8") as stream:
|
||||
json.dump(snapshot, stream, indent=2, ensure_ascii=False)
|
||||
return out_path
|
||||
|
||||
Reference in New Issue
Block a user