Merge pull request #1303 from kvalls/codex/windows-ghidra-native-dlls

feat(ghidra): support native PE DLLs on Windows
This commit is contained in:
morluto
2026-10-10 13:50:11 +08:00
committed by GitHub
13 changed files with 376 additions and 180 deletions
+6
View File
@@ -34,6 +34,12 @@ export const resolveGhidraAnalysisProfile = (
profile: createAnalysisProfile(provider, {
target_kind: target.kind,
target_format: target.format,
...(target.format === "pe"
? {
executable_role: target.executableRole ?? null,
managed: target.managed ?? null,
}
: {}),
architecture: target.architecture ?? null,
available_architectures: [
...(target.availableArchitectures ?? []),
+101 -83
View File
@@ -198,6 +198,32 @@ describe("Ghidra Mach-O slice support", () => {
});
describe("Ghidra platform support", () => {
it("commits the PE role and managed classification to profile identity", async () => {
const ghidra = provider({ ...installationHost(), platform: "win32" });
const application = peTarget("x86_64");
const library = {
...application,
executableRole: "shared-library",
} as const;
const digests = new Set<string>();
for (const target of [
application,
library,
{ ...library, managed: true },
]) {
const resolved = await ghidra.resolveAnalysisProfile(target);
if (!resolved.ok) throw resolved.error;
const profile = resolved.value.profile;
if (profile === null) throw new Error("Expected a PE analysis profile");
expect(profile.parameters).toMatchObject({
executable_role: target.executableRole,
managed: target.managed,
});
digests.add(profile.digest);
}
expect(digests.size).toBe(3);
});
it("keeps Windows annotation mutation unavailable independently of native controls", () => {
const ghidra = provider({ ...installationHost(), platform: "win32" });
expect(
@@ -270,7 +296,7 @@ describe("Ghidra platform support", () => {
expect(
ghidra.inspectTargetSupport({
...nativeApplication,
executableRole: "shared-library",
executableRole: "non-executable",
}),
).toMatchObject({
status: "unsupported",
@@ -295,45 +321,59 @@ describe("Ghidra platform support", () => {
code: "architecture_unsupported",
});
});
it("admits generated PE32 applications while rejecting unsupported x86 roles", async () => {
});
describe("Ghidra Windows PE fixture admission", () => {
it("admits generated PE32 and PE32+ DLLs and applications while preserving native-only Windows admission", async () => {
const root = fileURLToPath(new URL("../../", import.meta.url));
await promisify(execFile)(process.execPath, [
join(root, "scripts/create-ghidra-windows-fixture.mjs"),
]);
const path = join(root, "build/fixtures/rea-ghidra-windows-x86.exe");
const bytes = await readFile(path);
const metadata = parseExecutableHeader(bytes, "x64");
expect(metadata).toMatchObject({
ok: true,
value: {
format: "pe",
architecture: "x86",
executableRole: "application",
managed: false,
},
});
if (!metadata.ok) throw new Error(metadata.error);
if (metadata.value.format !== "pe")
throw new Error("Expected a PE fixture");
const target: BinaryTarget = {
path,
sha256: createHash("sha256").update(bytes).digest("hex"),
kind: "executable",
...metadata.value,
};
const ghidra = provider({ ...installationHost(), platform: "win32" });
expect(ghidra.inspectTargetSupport(target).status).toBe("supported");
for (const [candidate, code] of [
[
{ ...target, executableRole: "shared-library" },
"target_role_unsupported",
],
[{ ...target, managed: true }, "managed_target_unsupported"],
] as const)
expect(ghidra.inspectTargetSupport(candidate)).toMatchObject({
status: "unsupported",
code,
});
for (const architecture of ["x86", "x86_64"] as const) {
for (const dll of [false, true]) {
const path = join(
root,
"build/fixtures",
`rea-ghidra-windows${architecture === "x86" ? "-x86" : ""}.${dll ? "dll" : "exe"}`,
);
const bytes = await readFile(path);
const metadata = parseExecutableHeader(bytes, "x64");
const role = dll ? "shared-library" : "application";
expect(metadata).toMatchObject({
ok: true,
value: {
format: "pe",
architecture,
executableRole: role,
managed: false,
},
});
if (!metadata.ok) throw new Error(metadata.error);
if (metadata.value.format !== "pe")
throw new Error("Expected a PE fixture");
const target: BinaryTarget = {
path,
sha256: createHash("sha256").update(bytes).digest("hex"),
kind: "executable",
...metadata.value,
};
expect(ghidra.inspectTargetSupport(target).status).toBe("supported");
for (const [candidate, code] of [
[
{ ...target, executableRole: "non-executable" },
"target_role_unsupported",
],
[{ ...target, managed: true }, "managed_target_unsupported"],
[{ ...target, architecture: "arm64" }, "architecture_unsupported"],
] as const) {
expect(ghidra.inspectTargetSupport(candidate)).toMatchObject({
status: "unsupported",
code,
});
}
}
}
});
});
@@ -500,24 +540,23 @@ describe("Ghidra client projection", () => {
});
describe("Ghidra result projection", () => {
const createElfClient = async (ghidra: GhidraProvider) => {
const target = executableTarget("elf", "x86_64");
const resolved = await ghidra.resolveAnalysisProfile(target);
if (!resolved.ok) throw resolved.error;
if (resolved.value.profile === null)
throw new Error("Expected a bound Ghidra profile");
return ghidra.createClient(target, resolved.value.profile);
};
it("rejects malformed inventory output before Evidence creation", async () => {
const ghidra = provider(installationHost(), () => ({
start: () => Promise.resolve(ok(sessionInfo())),
callTool: () => Promise.resolve(ok({ items: "not-an-inventory" })),
close: () => Promise.resolve(ok(null)),
}));
const resolved = await ghidra.resolveAnalysisProfile(
executableTarget("elf", "x86_64"),
);
if (!resolved.ok) throw resolved.error;
if (resolved.value.profile === null)
throw new Error("Expected a bound Ghidra profile");
await expect(
ghidra
.createClient(executableTarget("elf", "x86_64"), resolved.value.profile)
.execute("list_procedures", {}),
).resolves.toMatchObject({
const client = await createElfClient(ghidra);
await expect(client.execute("list_procedures", {})).resolves.toMatchObject({
ok: false,
error: { _tag: "AnalysisOutputError" },
});
@@ -546,21 +585,13 @@ describe("Ghidra result projection", () => {
),
close: () => Promise.resolve(ok(null)),
}));
const resolved = await ghidra.resolveAnalysisProfile(
executableTarget("elf", "x86_64"),
);
if (!resolved.ok) throw resolved.error;
if (resolved.value.profile === null)
throw new Error("Expected a bound Ghidra profile");
const client = await createElfClient(ghidra);
await expect(
ghidra
.createClient(
executableTarget("elf", "x86_64"),
resolved.value.profile,
)
.execute("list_procedures", {}),
).resolves.toMatchObject({ ok: false, error: { _tag: tag } });
client.execute("list_procedures", {}),
).resolves.toMatchObject({
ok: false,
error: { _tag: tag },
});
},
);
@@ -582,19 +613,12 @@ describe("Ghidra result projection", () => {
),
close: () => Promise.resolve(ok(null)),
}));
const resolved = await ghidra.resolveAnalysisProfile(
executableTarget("elf", "x86_64"),
);
if (!resolved.ok) throw resolved.error;
if (resolved.value.profile === null)
throw new Error("Expected a bound profile");
const client = await createElfClient(ghidra);
await expect(
ghidra
.createClient(executableTarget("elf", "x86_64"), resolved.value.profile)
.execute("annotate_native_function", {
procedure: "0x10100",
name: "bad name",
}),
client.execute("annotate_native_function", {
procedure: "0x10100",
name: "bad name",
}),
).resolves.toMatchObject({
ok: false,
error: {
@@ -622,16 +646,10 @@ describe("Ghidra result projection", () => {
),
close: () => Promise.resolve(ok(null)),
}));
const resolved = await ghidra.resolveAnalysisProfile(
executableTarget("elf", "x86_64"),
);
if (!resolved.ok) throw resolved.error;
if (resolved.value.profile === null)
throw new Error("Expected a bound Ghidra profile");
const result = await ghidra
.createClient(executableTarget("elf", "x86_64"), resolved.value.profile)
.execute("procedure_pseudo_code", { procedure: "main" });
const client = await createElfClient(ghidra);
const result = await client.execute("procedure_pseudo_code", {
procedure: "main",
});
expect(result).toMatchObject({
ok: false,
error: { _tag: tag },
+6 -3
View File
@@ -247,12 +247,15 @@ const inspectWindowsP0TargetSupport = (
reason: "Windows Ghidra P0 accepts x86 and x86-64 PE targets only.",
diagnostics,
};
if (target.executableRole !== "application")
if (
target.executableRole !== "application" &&
target.executableRole !== "shared-library"
)
return {
status: "unsupported",
code: "target_role_unsupported",
reason:
"Windows Ghidra P0 accepts PE applications, not DLL or non-executable images.",
"Windows Ghidra P0 accepts PE applications and DLLs, not non-executable or unclassified images.",
diagnostics,
};
if (target.managed !== false)
@@ -260,7 +263,7 @@ const inspectWindowsP0TargetSupport = (
status: "unsupported",
code: "managed_target_unsupported",
reason:
"Windows Ghidra P0 accepts native PE applications; managed or unclassified PE targets are unsupported.",
"Windows Ghidra P0 accepts native PE applications and DLLs; managed or unclassified PE targets are unsupported.",
diagnostics,
};
return {
+1 -1
View File
@@ -31,7 +31,7 @@ export const healthLimitations = Object.freeze([
/** Additional limitations applied to the experimental Windows x64 P0 boundary. */
export const windowsP0Limitations = Object.freeze([
"Windows Ghidra P0 accepts approved native x86 and x86-64 PE applications only; DLL, managed, hostile, sensitive, and mutable-path targets are unsupported.",
"Windows Ghidra P0 accepts approved native x86 and x86-64 PE applications and DLLs; managed, hostile, sensitive, and mutable-path targets are unsupported.",
"The Windows bridge uses authenticated IPv4 loopback because Node path-based IPC does not expose Java AF_UNIX sockets; the endpoint file contains no bearer token.",
"Windows sessions require the matching packaged Windows x64 native addon, local NTFS targets and runtimes, and Windows 10 or later. Native handles enforce path admission, private DACLs, and Job Object ownership automatically.",
]);