feat(ghidra): apply validated analyzer overrides before analysis

Apply caller-selected analyzer opt-outs before Ghidra analysis, reject unknown or ineffective names, and commit raw/header imports to the same analyzer profile. Use supported x86 raw compiler specs and cover the real analyzer/readback and raw workflows.

Adopts the original implementation from #1800 with validated corrections. Refs #1783, #1836.

Co-authored-by: akushonkamen <74654766+akushonkamen@users.noreply.github.com>
Co-authored-by: N0zoM1z0 <161784452+N0zoM1z0@users.noreply.github.com>
Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
This commit is contained in:
Ysopwnable
2026-10-12 03:49:31 +08:00
committed by GitHub
co-authored by akushonkamen Kaoru0822
parent 12ee785e5e
commit 9878bb7296
22 changed files with 677 additions and 38 deletions
@@ -289,6 +289,99 @@ describe("Ghidra configured import language and seeds", () => {
});
});
describe("Ghidra disabled analyzers", () => {
const base = {
platform: "darwin" as const,
projectRoot: "/tmp/project",
targetPath: "/tmp/target",
bridgeScriptPath: "/package/bridge/ReaGhidraBridge.java",
descriptorPath: "/tmp/session.json",
ghidraLogPath: "/tmp/ghidra.log",
scriptLogPath: "/tmp/script.log",
};
it("applies the analyzer options after seeds and before analysis scripts", () => {
const arguments_ = ghidraHeadlessArguments({
...base,
dosCom: true,
seedPath: posix.join("/tmp/runtime/seeds", "seeds.tsv"),
disabledAnalyzers: [
"Objective-C Message Analyzer",
"Decompiler Switch Analysis",
],
});
const options = arguments_.indexOf(
posix.join("/package/bridge", "ReaGhidraAnalysisOptions.java"),
);
expect(arguments_[options - 1]).toBe("-preScript");
expect(arguments_[options + 1]).toBe(
"Objective-C Message Analyzer,Decompiler Switch Analysis",
);
const prepare = arguments_.indexOf(
posix.join("/package/bridge", "ReaGhidraPrepareCom.java"),
);
const seeds = arguments_.indexOf(
posix.join("/package/bridge", "ReaGhidraApplySeeds.java"),
);
expect(prepare).toBeLessThan(seeds);
expect(seeds).toBeLessThan(options);
expect(options).toBeLessThan(arguments_.indexOf("-postScript"));
});
it.each(["darwin", "win32"] as const)(
"uses the target platform's script path for the options script on %s",
(platform) => {
const path = platform === "win32" ? win32 : posix;
const arguments_ = ghidraHeadlessArguments({
...base,
platform,
bridgeScriptPath: path.join(
"/package",
"bridge",
"ReaGhidraBridge.java",
),
disabledAnalyzers: ["Objective-C Message Analyzer"],
});
const options = arguments_.indexOf(
path.join("/package", "bridge", "ReaGhidraAnalysisOptions.java"),
);
expect(arguments_[options - 1]).toBe("-preScript");
expect(arguments_[options + 1]).toBe("Objective-C Message Analyzer");
expect(options).toBeLessThan(arguments_.indexOf("-postScript"));
},
);
it("keeps the invocation byte-identical without an override", () => {
expect(ghidraHeadlessArguments(base)).toEqual([
"/tmp/project",
"rea-project",
"-import",
"/tmp/target",
"-readOnly",
"-deleteProject",
"-log",
"/tmp/ghidra.log",
"-scriptlog",
"/tmp/script.log",
"-scriptPath",
"/package/bridge",
"-postScript",
"/package/bridge/ReaGhidraNoReturnFix.java",
"-postScript",
"/package/bridge/ReaGhidraBridge.java",
"/tmp/session.json",
]);
});
it("adds no analyzer script for an empty override", () => {
expect(
ghidraHeadlessArguments({ ...base, disabledAnalyzers: [] }),
).not.toContain(
posix.join("/package/bridge", "ReaGhidraAnalysisOptions.java"),
);
});
});
describe("Ghidra Windows launcher", () => {
it("keeps analysis repair outside Windows P0 authority", () => {
const args = ghidraHeadlessArguments({
@@ -0,0 +1,19 @@
import ghidra.app.util.headless.HeadlessScript;
/** Independent readback oracle for the production analyzer-options pre-script. */
public final class ReaAnalyzerOptionsRegressionProbe extends HeadlessScript {
@Override
public void run() throws Exception {
String[] arguments = getScriptArgs();
if (arguments.length != 1 || arguments[0].isBlank()) {
throw new IllegalArgumentException("Expected one analyzer name");
}
monitor.checkCancelled();
String name = arguments[0];
String enabled = getCurrentAnalysisOptionsAndValues(currentProgram).get(name);
if (!"false".equals(enabled)) {
throw new IllegalStateException("Analyzer option is not disabled: " + name);
}
println("REA_ANALYZER_OPTIONS_DISABLED_OK " + name);
}
}