fix(ghidra): return complete native analysis results

This commit is contained in:
morluto
2026-09-29 08:45:49 +08:00
parent 5457f4a2bc
commit a66e43a99d
16 changed files with 71 additions and 249 deletions
-12
View File
@@ -71,19 +71,7 @@ const availableResidualUnknowns = (
boundary: Extract<NativeApiBoundary, { readonly available: true }>,
): readonly string[] => {
const unknowns: string[] = [];
if (boundary.parameters_truncated)
unknowns.push(
"Which additional parameters were omitted by the native API boundary limit?",
);
if (boundary.jump_tables_truncated)
unknowns.push(
"Which additional jump tables were omitted by the native API boundary limit?",
);
for (const table of boundary.jump_tables) {
if (table.data_sources_truncated || table.mappings_truncated)
unknowns.push(
`Which additional data sources or targets were omitted for the jump table dispatched at ${table.dispatch_address}?`,
);
if (table.data_sources.length === 0)
unknowns.push(
`What backing data address produced the jump table dispatched at ${table.dispatch_address}?`,
+3 -10
View File
@@ -38,7 +38,7 @@ export const ghidraReferenceEdge = () => ({
kind: ghidraReferenceKind(),
});
export const ghidraNativeApiBoundary = (mappingsTruncated = false) => ({
export const ghidraNativeApiBoundary = () => ({
available: true as const,
provenance: "ghidra-high-function",
signature_source: "analysis",
@@ -69,7 +69,6 @@ export const ghidraNativeApiBoundary = (mappingsTruncated = false) => ({
],
},
parameters: [],
parameters_truncated: false,
jump_tables: [
{
dispatch_address: "0x401010",
@@ -89,7 +88,6 @@ export const ghidraNativeApiBoundary = (mappingsTruncated = false) => ({
],
},
],
data_sources_truncated: false,
mappings: [
{
case_value: 0,
@@ -105,11 +103,9 @@ export const ghidraNativeApiBoundary = (mappingsTruncated = false) => ({
],
},
],
mappings_truncated: mappingsTruncated,
limitations: [],
},
],
jump_tables_truncated: false,
pseudocode: {
classification: "decompiler-generated-non-source" as const,
compilable: false as const,
@@ -126,10 +122,7 @@ export const ghidraNativeApiBoundary = (mappingsTruncated = false) => ({
],
});
export const ghidraFunctionDossier = (
includeAssembly = true,
mappingsTruncated = false,
): JsonValue => {
export const ghidraFunctionDossier = (includeAssembly = true): JsonValue => {
const pseudocode = "int fixture_main(void) { return 42; }";
return {
procedure: {
@@ -155,7 +148,7 @@ export const ghidraFunctionDossier = (
],
referenced_names: [],
basic_blocks: [{ start: "0x401000", end: "0x401006", successors: [] }],
native_api: ghidraNativeApiBoundary(mappingsTruncated),
native_api: ghidraNativeApiBoundary(),
limitations: [
"Unresolved computed or indirect flows without target addresses are not represented as reference edges.",
"Thunk and external classifications are Ghidra FunctionManager observations; they do not resolve targetless calls.",
-4
View File
@@ -74,9 +74,7 @@ const inferredJumpTableSchema = z
.object({
dispatch_address: z.string().min(1),
data_sources: z.array(jumpTableDataSourceSchema),
data_sources_truncated: z.boolean(),
mappings: z.array(jumpTableMappingSchema),
mappings_truncated: z.boolean(),
limitations: z.array(z.string()),
})
.strict();
@@ -89,9 +87,7 @@ const availableNativeApiBoundarySchema = z
calling_convention: z.string().min(1),
return_type: inferredReturnTypeSchema,
parameters: z.array(inferredParameterTypeSchema),
parameters_truncated: z.boolean(),
jump_tables: z.array(inferredJumpTableSchema),
jump_tables_truncated: z.boolean(),
pseudocode: z
.object({
classification: z.literal("decompiler-generated-non-source"),
File diff suppressed because one or more lines are too long
+3 -3
View File
@@ -12,7 +12,7 @@ export const GHIDRA_REQUEST_TIMEOUT_MS = 10_000;
export const GHIDRA_DECOMPILE_TIMEOUT_SECONDS = 30;
/** Socket deadline leaves bounded time to project a native decompiler timeout. */
export const GHIDRA_DECOMPILE_REQUEST_TIMEOUT_MS = 35_000;
/** Maximum encoded response line accepted from the Java bridge. */
export const GHIDRA_MAX_LINE_BYTES = 1024 * 1024;
/** Internal safety bound for one complete Java bridge process response line. */
export const GHIDRA_MAX_LINE_BYTES = 64 * 1024 * 1024;
/** Version of REA's Java bridge handshake and request protocol. */
export const GHIDRA_BRIDGE_VERSION = 6;
export const GHIDRA_BRIDGE_VERSION = 7;
+1 -1
View File
@@ -419,7 +419,7 @@ describe("Ghidra result projection", () => {
const sessionInfo = () => ({
name: "REA Ghidra bridge" as const,
bridge_version: 6 as const,
bridge_version: 7 as const,
run_id: "11111111-1111-4111-8111-111111111111",
profile_digest: "a".repeat(64),
provider: { id: "ghidra" as const, version: "12.1.2" },
+2 -3
View File
@@ -95,13 +95,13 @@ export const limitationsFor = (operation: string): readonly string[] => {
case "read_function_instructions":
return [
...common,
"This bounded fast path reads only the requested function instruction window and does not invoke the decompiler or whole-program string/name inventories.",
"This fast path reads only the requested function and does not invoke the decompiler or whole-program string/name inventories.",
"Instruction text is Ghidra-specific and does not claim textual equivalence with Hopper output.",
];
case "procedure_assembly":
return [
...common,
"Assembly is Ghidra Listing text and fails rather than silently truncating when the 100,000-instruction or 1 MiB wire bound is exceeded.",
"Assembly is Ghidra Listing text and does not claim textual equivalence with Hopper output.",
];
case "procedure_callers":
case "procedure_callees":
@@ -120,7 +120,6 @@ export const limitationsFor = (operation: string): readonly string[] => {
...common,
"Reference kinds are direct Ghidra ReferenceManager observations; unresolved computed flows without a target are absent and remain unknown.",
"Synthetic Ghidra entry-point references without actionable memory sources are omitted.",
"Instruction scans stop at max_instructions; a truncated scan reports an unknown total and no false continuation.",
];
case "analyze_function":
return [
+22
View File
@@ -0,0 +1,22 @@
import { describe, expect, it } from "vitest";
import { GHIDRA_MAX_LINE_BYTES } from "./GhidraDefaults.js";
import { GhidraResponseBuffer } from "./GhidraResponseBuffer.js";
describe("Ghidra response buffer", () => {
it("accepts complete responses larger than the former 1 MiB ceiling", () => {
const lines: string[] = [];
const failures: string[] = [];
const buffer = new GhidraResponseBuffer({
maxLineBytes: GHIDRA_MAX_LINE_BYTES,
onLine: (line) => lines.push(line),
onFailure: (message) => failures.push(message),
});
const response = `{"result":"${"x".repeat(1_100_000)}"}`;
buffer.push(`${response}\n`);
expect(failures).toEqual([]);
expect(lines).toEqual([response]);
});
});