fix(ghidra): disclose missing PDB symbol coverage (#2275)

* fix(ghidra): disclose missing PDB symbol coverage

* style: format reviewed source changes

* fix(ghidra): bound PDB handshake and retain coverage uncertainty

---------

Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
Co-authored-by: morluto <17176810+morluto@users.noreply.github.com>
This commit is contained in:
Hifza Zafar
2026-10-13 22:17:27 +08:00
committed by GitHub
co-authored by morluto morluto
parent 1016c96e6b
commit 865c35e25a
9 changed files with 391 additions and 7 deletions
+71
View File
@@ -25,6 +25,13 @@ export const GHIDRA_MUTATING_OPERATIONS: ReadonlySet<string> = new Set([
...GHIDRA_NAMING_OPERATIONS,
]);
// Shared wire budget: Java bounds the aggregate before serializing the handshake.
const PDB_ATTRIBUTE_UTF16_BUDGET = 4096;
const pdbAttributeSchema = z
.string()
.max(PDB_ATTRIBUTE_UTF16_BUDGET)
.nullable();
const capabilitySchema = z.enum(GHIDRA_SESSION_CAPABILITIES);
const sessionInfoSchema = z
@@ -41,6 +48,39 @@ const sessionInfoSchema = z
read_only: z.boolean(),
analysis_complete: z.boolean(),
analysis_timed_out: z.boolean(),
/** Program Information attributes; absent load state remains unknown. */
pdb: z
.strictObject({
file: pdbAttributeSchema,
guid: pdbAttributeSchema,
/** Ghidra stores CodeView age as a hexadecimal string. */
age: pdbAttributeSchema,
signature: pdbAttributeSchema,
version: pdbAttributeSchema,
loaded: z.boolean().nullable(),
resource_limit: z
.strictObject({
utf16_budget: z.literal(PDB_ATTRIBUTE_UTF16_BUDGET),
omitted_attributes: z
.array(z.enum(["file", "guid", "age", "signature", "version"]))
.min(1)
.max(5),
})
.optional(),
})
.refine(
(pdb) =>
[
pdb.file,
pdb.guid,
pdb.age,
pdb.signature,
pdb.version,
].reduce<number>((sum, value) => sum + (value?.length ?? 0), 0) <=
PDB_ATTRIBUTE_UTF16_BUDGET,
"PDB attributes exceed the aggregate wire budget",
)
.optional(),
analysis_extensions: z.array(ghidraExtensionResultSchema).optional(),
analysis_seeds: ghidraSeedReportSchema.optional(),
mips_soft_float_storage: z
@@ -68,6 +108,37 @@ const sessionInfoSchema = z
/** Authenticated metadata produced after Ghidra finishes auto-analysis. */
export type GhidraSessionInfo = z.infer<typeof sessionInfoSchema>;
/** Describe missing PDB authority without claiming all names are generated. */
export const ghidraPdbLimitations = (
pdb: GhidraSessionInfo["pdb"],
): readonly string[] => {
if (pdb === undefined)
return [
"Ghidra did not report PDB attributes; debug-symbol coverage is unknown.",
];
const limitations: string[] = [];
if (pdb.resource_limit !== undefined)
limitations.push(
`PDB attributes ${pdb.resource_limit.omitted_attributes.join(", ")} were omitted because the handshake's ${pdb.resource_limit.utf16_budget}-UTF-16-unit PDB attribute budget was exhausted. Omitted values remain unknown; they were not truncated or reported as absent.`,
);
if (pdb.loaded === true)
return [
...limitations,
"Ghidra reports a loaded PDB; this is not an independent PDB identity or complete symbol/type-coverage attestation. Original names and types may still be missing; an empty name search does not prove a procedure is absent. Use list_procedures and address-based analysis to inspect recovered functions.",
];
if (
[pdb.file, pdb.guid, pdb.age, pdb.signature, pdb.version].every(
(value) => value === null,
)
)
return limitations;
const state = pdb.loaded === false ? "not loaded" : "load state unknown";
return [
...limitations,
`The target references PDB ${pdb.file ?? "(file unknown)"} (GUID ${pdb.guid ?? "unknown"}, age (hex) ${pdb.age ?? "unknown"}, signature ${pdb.signature ?? "unknown"}, version ${pdb.version ?? "unknown"}); Ghidra reports ${state}. Original names and types may be missing; an empty name search does not prove a procedure is absent. Use list_procedures and address-based analysis to inspect recovered functions. REA does not admit a caller-selected PDB companion.`,
];
};
/** Require exact run, provider, and profile identity from the Java bridge. */
export const parseGhidraSessionInfo = (
value: JsonValue,