fix(ghidra): expose terminal-call boundary assumptions
Preserve observed terminal-call sites and callee flags across function views, raw bridge responses, Evidence, and snapshot replay. Version analysis profiles so older unqualified results cannot be reused. Qualify Ghidra function extents without changing external no-return flags or claiming recovery of excluded code. Validation: 76 focused tests, check:fast, docs:check, formatting, and the full Ghidra 12.1.4 host lane pass. Real CLI and all five stdio MCP function views retain the terminal-call evidence; returning puts calls remain unflagged. The reported stripped Rust ELF and Windows host remain unverified. Fixes #1658
This commit is contained in:
@@ -387,14 +387,54 @@ const resultSchemas = {
|
||||
xrefs: z.array(ghidraCanonicalAddressSchema),
|
||||
} satisfies Readonly<Record<GhidraFunctionOperation, z.ZodType>>;
|
||||
|
||||
const functionBoundaryObservationOperations: ReadonlySet<GhidraFunctionOperation> =
|
||||
new Set([
|
||||
"analyze_function",
|
||||
"procedure_assembly",
|
||||
"procedure_info",
|
||||
"procedure_pseudo_code",
|
||||
"read_function_instructions",
|
||||
]);
|
||||
|
||||
const functionObservationEnvelope = z.strictObject({
|
||||
value: z.unknown(),
|
||||
limitations: z.array(z.string()),
|
||||
});
|
||||
|
||||
export interface ParsedGhidraFunctionResult {
|
||||
readonly value: JsonValue;
|
||||
readonly limitations: readonly string[];
|
||||
}
|
||||
|
||||
/** Require exact, bounded Java-bridge function output before creating Evidence. */
|
||||
export const parseGhidraFunctionResult = (
|
||||
operation: GhidraFunctionOperation,
|
||||
value: JsonValue,
|
||||
): Result<JsonValue, AnalysisOutputError> => {
|
||||
const parsed = resultSchemas[operation].safeParse(value);
|
||||
): Result<ParsedGhidraFunctionResult, AnalysisOutputError> => {
|
||||
let observation: {
|
||||
readonly value: unknown;
|
||||
readonly limitations: readonly string[];
|
||||
};
|
||||
if (functionBoundaryObservationOperations.has(operation)) {
|
||||
const envelope = functionObservationEnvelope.safeParse(value);
|
||||
if (!envelope.success)
|
||||
return err(
|
||||
new AnalysisOutputError(
|
||||
operation,
|
||||
"Ghidra bridge omitted the function observation envelope",
|
||||
{ cause: envelope.error },
|
||||
),
|
||||
);
|
||||
observation = envelope.data;
|
||||
} else {
|
||||
observation = { value, limitations: [] };
|
||||
}
|
||||
const parsed = resultSchemas[operation].safeParse(observation.value);
|
||||
return parsed.success
|
||||
? ok(jsonValueSchema.parse(parsed.data))
|
||||
? ok({
|
||||
value: jsonValueSchema.parse(parsed.data),
|
||||
limitations: observation.limitations,
|
||||
})
|
||||
: err(
|
||||
new AnalysisOutputError(
|
||||
operation,
|
||||
|
||||
Reference in New Issue
Block a user