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
+11 -120
View File
@@ -77,16 +77,10 @@ import ghidra.program.model.pcode.HighSymbol;
import ghidra.program.model.pcode.JumpTable;
public final class ReaGhidraBridge extends HeadlessScript {
private static final int BRIDGE_VERSION = 6;
private static final int BRIDGE_VERSION = 7;
private static final int MAX_DESCRIPTOR_BYTES = 16 * 1024;
private static final int MAX_REQUEST_CHARACTERS = 256 * 1024;
private static final int MAX_RESPONSE_BYTES = 1024 * 1024;
private static final int RESPONSE_ENVELOPE_RESERVE_BYTES = 32 * 1024;
private static final int MAX_NATIVE_API_RESPONSE_BYTES = 192 * 1024;
private static final int MAX_NATIVE_API_PARAMETERS = 64;
private static final int MAX_NATIVE_API_JUMP_TABLES = 4;
private static final int MAX_NATIVE_API_LOAD_TABLES = 4;
private static final int MAX_NATIVE_API_MAPPINGS = 32;
private static final int MAX_RESPONSE_BYTES = 64 * 1024 * 1024;
private static final int DECOMPILE_TIMEOUT_SECONDS = 30;
private static final int DECOMPILE_PAYLOAD_MBYTES = 8;
private static final Gson GSON = new GsonBuilder().serializeNulls().create();
@@ -537,18 +531,9 @@ public final class ReaGhidraBridge extends HeadlessScript {
result.add("referenced_strings", referencedStrings);
result.add("referenced_names", referencedNames);
result.add("basic_blocks", blocks);
int nativeApiBudget = Math.min(
MAX_NATIVE_API_RESPONSE_BYTES,
Math.max(
0,
MAX_RESPONSE_BYTES -
encodedUtf8Length(result) -
RESPONSE_ENVELOPE_RESERVE_BYTES
)
);
result.add(
"native_api",
nativeApiBoundary(function, decompilation, nativeApiBudget)
nativeApiBoundary(function, decompilation)
);
JsonArray limitations = new JsonArray();
limitations.add(
@@ -827,8 +812,7 @@ public final class ReaGhidraBridge extends HeadlessScript {
private JsonObject nativeApiBoundary(
Function function,
DecompileResults decompilation,
int maximumBytes
DecompileResults decompilation
) throws Exception {
if (decompilation == null || decompilation.getHighFunction() == null) {
return unavailableNativeApiBoundary(
@@ -868,11 +852,9 @@ public final class ReaGhidraBridge extends HeadlessScript {
JsonArray parameters = new JsonArray();
result.add("parameters", parameters);
result.addProperty("parameters_truncated", false);
JsonArray jumpTables = new JsonArray();
result.add("jump_tables", jumpTables);
result.addProperty("jump_tables_truncated", false);
JsonObject pseudocode = new JsonObject();
pseudocode.addProperty("classification", "decompiler-generated-non-source");
@@ -898,17 +880,7 @@ public final class ReaGhidraBridge extends HeadlessScript {
"Pseudocode is neither original source nor guaranteed to compile."
);
result.add("limitations", limitations);
if (encodedUtf8Length(result) > maximumBytes) {
return unavailableNativeApiBoundary(
"The remaining Ghidra response budget cannot contain a structured native API boundary"
);
}
int parameterCount = Math.min(
prototype.getNumParams(),
MAX_NATIVE_API_PARAMETERS
);
for (int index = 0; index < parameterCount; index += 1) {
for (int index = 0; index < prototype.getNumParams(); index += 1) {
HighSymbol parameter = prototype.getParam(index);
if (parameter == null) {
continue;
@@ -924,32 +896,12 @@ public final class ReaGhidraBridge extends HeadlessScript {
signatureSource
)
);
if (encodedUtf8Length(result) > maximumBytes) {
parameters.remove(parameters.size() - 1);
break;
}
}
result.addProperty(
"parameters_truncated",
prototype.getNumParams() > parameters.size()
);
JumpTable[] recoveredJumpTables = highFunction.getJumpTables();
int jumpTableCount = Math.min(
recoveredJumpTables.length,
MAX_NATIVE_API_JUMP_TABLES
);
for (int index = 0; index < jumpTableCount; index += 1) {
for (int index = 0; index < recoveredJumpTables.length; index += 1) {
jumpTables.add(inferredJumpTable(recoveredJumpTables[index]));
if (encodedUtf8Length(result) > maximumBytes) {
jumpTables.remove(jumpTables.size() - 1);
break;
}
}
result.addProperty(
"jump_tables_truncated",
recoveredJumpTables.length > jumpTables.size()
);
return result;
}
@@ -964,10 +916,6 @@ public final class ReaGhidraBridge extends HeadlessScript {
return unavailable;
}
private static int encodedUtf8Length(JsonElement value) {
return GSON.toJson(value).getBytes(StandardCharsets.UTF_8).length;
}
private static JsonObject inferredBoundaryType(
String role,
Integer ordinal,
@@ -1059,11 +1007,7 @@ public final class ReaGhidraBridge extends HeadlessScript {
? dispatchPathDataReferences(jumpTable)
: List.of();
JsonArray dataSources = new JsonArray();
int loadTableCount = Math.min(
loadTables.length,
MAX_NATIVE_API_LOAD_TABLES
);
for (int index = 0; index < loadTableCount; index += 1) {
for (int index = 0; index < loadTables.length; index += 1) {
JumpTable.LoadTable loadTable = loadTables[index];
JsonObject source = new JsonObject();
source.addProperty("address", canonicalAddress(loadTable.getAddress()));
@@ -1084,11 +1028,7 @@ public final class ReaGhidraBridge extends HeadlessScript {
source.add("evidence", evidence);
dataSources.add(source);
}
int referencedDataCount = Math.min(
referencedDataAddresses.size(),
MAX_NATIVE_API_LOAD_TABLES - loadTableCount
);
for (int index = 0; index < referencedDataCount; index += 1) {
for (int index = 0; index < referencedDataAddresses.size(); index += 1) {
Address address = referencedDataAddresses.get(index);
JsonObject source = new JsonObject();
source.addProperty("address", canonicalAddress(address));
@@ -1113,17 +1053,10 @@ public final class ReaGhidraBridge extends HeadlessScript {
dataSources.add(source);
}
result.add("data_sources", dataSources);
result.addProperty(
"data_sources_truncated",
loadTables.length > loadTableCount ||
referencedDataAddresses.size() > referencedDataCount
);
Address[] targets = jumpTable.getCases();
Integer[] labels = jumpTable.getLabelValues();
JsonArray mappings = new JsonArray();
int mappingCount = Math.min(targets.length, MAX_NATIVE_API_MAPPINGS);
for (int index = 0; index < mappingCount; index += 1) {
for (int index = 0; index < targets.length; index += 1) {
JsonObject mapping = new JsonObject();
if (labels == null || index >= labels.length || labels[index] == null) {
mapping.add("case_value", JsonNull.INSTANCE);
@@ -1134,7 +1067,7 @@ public final class ReaGhidraBridge extends HeadlessScript {
String targetAddress = canonicalAddress(targets[index]);
mapping.addProperty("target_address", targetAddress);
JsonArray dataAddresses = new JsonArray();
for (int sourceIndex = 0; sourceIndex < loadTableCount; sourceIndex += 1) {
for (int sourceIndex = 0; sourceIndex < loadTables.length; sourceIndex += 1) {
dataAddresses.add(
canonicalAddress(loadTables[sourceIndex].getAddress())
);
@@ -1157,8 +1090,6 @@ public final class ReaGhidraBridge extends HeadlessScript {
mappings.add(mapping);
}
result.add("mappings", mappings);
result.addProperty("mappings_truncated", targets.length > mappingCount);
JsonArray limitations = new JsonArray();
if (loadTables.length == 0 && referencedDataAddresses.isEmpty()) {
limitations.add(
@@ -1175,15 +1106,6 @@ public final class ReaGhidraBridge extends HeadlessScript {
"Case labels were unavailable or incomplete; null labels are preserved."
);
}
if (
loadTables.length > loadTableCount ||
referencedDataAddresses.size() > referencedDataCount ||
targets.length > mappingCount
) {
limitations.add(
"Native API jump-table observations reached REA's bounded output limits."
);
}
result.add("limitations", limitations);
return result;
}
@@ -1593,37 +1515,6 @@ public final class ReaGhidraBridge extends HeadlessScript {
return result;
}
private static JsonObject bounded(
JsonArray values,
int offset,
int limit,
boolean complete) {
int start = Math.min(offset, values.size());
int end = Math.min(values.size(), start + limit);
JsonArray items = new JsonArray();
for (int index = start; index < end; index += 1) {
items.add(values.get(index).deepCopy());
}
boolean hasMore = end < values.size();
JsonObject result = new JsonObject();
result.add("items", items);
if (complete) {
result.addProperty("total", values.size());
}
else {
result.add("total", JsonNull.INSTANCE);
}
result.addProperty("returned", items.size());
result.addProperty("truncated", !complete || hasMore);
if (complete && hasMore) {
result.addProperty("next_offset", end);
}
else {
result.add("next_offset", JsonNull.INSTANCE);
}
return result;
}
private static String exclusiveAddress(Address inclusive) {
Address next = inclusive.next();
if (next != null && next.getAddressSpace().equals(inclusive.getAddressSpace())) {
@@ -2040,7 +1931,7 @@ public final class ReaGhidraBridge extends HeadlessScript {
int id = response.get("id").getAsInt();
JsonObject error = new JsonObject();
error.addProperty("code", "output_limit");
error.addProperty("message", "Ghidra response exceeds the 1 MiB wire limit");
error.addProperty("message", "Ghidra response exceeds the internal 64 MiB process-line safety bound");
JsonObject bounded = new JsonObject();
bounded.addProperty("id", id);
bounded.addProperty("ok", false);
+5 -5
View File
@@ -91,9 +91,9 @@ capability from a successful import.
| Procedures | Both non-external and external functions are listed. A local thunk remains distinct from its resolved target; exact and qualified name lookup fails on ambiguity rather than guessing. |
| Strings | Only Ghidra-defined string `Data` is observed. Items report charset, byte length, and whether a required null terminator is missing. The API cannot distinguish a present terminator from fixed/Pascal layouts when no terminator is missing, so that state is named `present_or_not_required`. |
| Memory | Memory-block end addresses are exclusive. Read/write/execute, initialization, overlay, address space, and image base are direct Ghidra observations. |
| Inventory | Procedure, symbol, and string listings plus searches return the complete matching collection in one response; callers do not provide offsets or limits. The bridge still enforces the declared transport response ceiling. |
| Inventory | Procedure, symbol, and string listings plus searches return the complete matching collection in one response; callers do not provide offsets or limits. The bridge retains a 64 MiB internal process-line safety bound for exceptional responses. |
| Search | Literal search scans the immutable inventory with a 1,000,000-unit cumulative work budget. Regex uses a conservative finite Java-regex subset with 10,000 static paths, 4,096 UTF-16 code units per candidate, and the same cumulative budget. Exceeding a budget fails explicitly; returned values identify truncation. |
| Analysis state | The socket is exposed only after default auto-analysis. A 300-second analysis timeout fails target opening; ordinary established requests have a 10-second client deadline and every response has a 1 MiB ceiling. |
| Analysis state | The socket is exposed only after default auto-analysis. A 300-second analysis timeout fails target opening; ordinary established requests have a 10-second client deadline. The internal response-line guard is sized for complete analysis output. |
## Admitted function-analysis semantics
@@ -102,11 +102,11 @@ capability from a successful import.
| Decompiler lifetime | One persistent `DecompInterface` is opened for the imported Program and disposed during bridge shutdown. Each native decompile has a 30-second deadline; the socket leaves a bounded 35-second projection window. External functions or functions without bodies return `null`; timeout, cancellation, and native failure remain distinct. |
| Serialization | A bounded FIFO admits at most 32 active-plus-queued requests and sends one Program request at a time. Queue wait counts against the caller's deadline, and queued cancellation is prompt. This is an adapter safety commitment, not a claim that every Ghidra API is thread-safe. |
| Function identity | Every function result carries the entry address and Ghidra FunctionManager classification for external, thunk, and resolved thunk target. These are observations, not proof that unresolved targetless calls have been recovered. |
| Assembly and pseudocode | Assembly is bounded Ghidra Listing text; pseudocode is bounded Ghidra decompiler output. Neither is original source, and cross-provider comparison never treats Hopper and Ghidra text as equal or unequal semantic facts. |
| Instruction fast path | `read_function_instructions` returns one offset-paginated raw Listing window without invoking the decompiler or whole-program name/string inventories. It reports scan work, exact-or-unknown totals, truncation, and continuation metadata. |
| Assembly and pseudocode | Assembly is complete Ghidra Listing text; pseudocode is Ghidra decompiler output. Neither is original source, and cross-provider comparison never treats Hopper and Ghidra text as equal or unequal semantic facts. |
| Instruction fast path | `read_function_instructions` returns every raw Listing instruction for the requested function without invoking the decompiler or whole-program name/string inventories. |
| Calls and references | Callers/callees contain only resolved functions. Reference edges preserve exact ReferenceManager type and call/jump/data/read/write/indirect/computed/conditional/terminal/external facts. Targetless computed flow remains unknown. Synthetic entry-point references without actionable memory sources are omitted explicitly. |
| CFG | Dossiers use `BasicBlockModel` and retain only non-call successors inside the function body. CFG topology is address-normalized for comparison; provider-specific block construction remains a declared difference. |
| Bounds | Direct assembly fails above 100,000 instructions or the wire ceiling. Dossiers scan at most 5,000 requested instructions, return bounded independent pages, mark unknown totals after an incomplete scan, and paginate pseudocode by Unicode code points. |
| Bounds | Function instruction scans and native API boundary observations do not use item-count caps or caller pagination. A 64 MiB internal process-line guard fails exceptionally large individual responses with an explicit output error; it does not intentionally truncate ordinary full analysis. |
`npm run verify:ghidra` compiles the versioned C oracles into x86-64 debug and
stripped ELF, AArch64 ELF, x86-64 PE, and x86-64 Mach-O targets. It proves all
+6 -16
View File
@@ -73,20 +73,19 @@ export function assertDenseSwitchDossier(dossier, address) {
requireAssembly: true,
requireMultiBlock: true,
});
const truncated = dossier.native_api.jump_tables.find(
({ mappings_truncated: mappingsTruncated }) => mappingsTruncated,
const denseTable = dossier.native_api.jump_tables.find(
({ mappings }) => mappings.length > 32,
);
if (
truncated === undefined ||
truncated.mappings.length !== 32 ||
truncated.mappings.some(
denseTable === undefined ||
denseTable.mappings.some(
({ target_address: target, evidence }) =>
!/^0x[0-9a-f]+$/u.test(target) ||
!evidence.some(({ kind }) => kind === "jump-table"),
)
)
throw new Error(
`Ghidra dense jump-table truncation drifted: ${JSON.stringify(dossier.native_api.jump_tables)}`,
`Ghidra dense jump-table completeness drifted: ${JSON.stringify(dossier.native_api.jump_tables)}`,
);
}
@@ -94,8 +93,6 @@ function assertNativeApiBoundary(observed, requireJumpTable) {
if (
observed?.available !== true ||
observed.provenance !== "ghidra-high-function" ||
observed.parameters_truncated !== false ||
observed.jump_tables_truncated !== false ||
!["low", "medium", "high"].includes(observed.return_type?.confidence) ||
!observed.return_type?.evidence?.some(
({ source }) => source === "ghidra-high-function",
@@ -111,14 +108,7 @@ function assertNativeApiBoundary(observed, requireJumpTable) {
if (
observed.jump_tables.length === 0 ||
!observed.jump_tables.some(
({
data_sources: sources,
data_sources_truncated: sourcesTruncated,
mappings,
mappings_truncated: mappingsTruncated,
}) =>
!sourcesTruncated &&
!mappingsTruncated &&
({ data_sources: sources, mappings }) =>
sources.length > 0 &&
sources.every(
({ address, evidence }) =>
+7 -11
View File
@@ -191,33 +191,29 @@ async function verifyNativeApiCli(targetPath) {
{
cwd: process.cwd(),
env: process.env,
maxBuffer: 2 * 1024 * 1024,
maxBuffer: 72 * 1024 * 1024,
},
);
const evidence = JSON.parse(stdout);
const boundary = evidence.normalized_result?.boundary;
const truncated = boundary?.jump_tables?.find(
({ mappings_truncated: mappingsTruncated }) => mappingsTruncated === true,
const denseTable = boundary?.jump_tables?.find(
({ mappings }) => mappings.length > 32,
);
const omittedQuestion =
"Which additional data sources or targets were omitted";
if (
evidence.operation !== "inspect_native_api" ||
evidence.provider?.id !== "rea-workflow" ||
evidence.analysis_profile?.provider?.id !== "rea-workflow" ||
boundary?.available !== true ||
truncated?.mappings?.length !== 32 ||
!evidence.normalized_result?.residual_unknowns?.some((question) =>
question.includes(omittedQuestion),
)
denseTable === undefined ||
evidence.normalized_result?.residual_unknowns?.length !== 0
)
throw new Error(
`The shipped inspect-native-api CLI did not preserve dense jump-table truncation: ${stdout}`,
`The shipped inspect-native-api CLI did not preserve complete dense jump-table output: ${stdout}`,
);
return {
operation: evidence.operation,
provider: evidence.provider,
mappings_returned: truncated.mappings.length,
mappings_returned: denseTable.mappings.length,
residual_unknowns: evidence.normalized_result.residual_unknowns.length,
};
}
-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]);
});
});
+2 -6
View File
@@ -111,7 +111,7 @@ const installationHost = (): GhidraInstallationHost => ({
const sessionInfo = (profileDigest: string, targetSha256: string) => ({
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: profileDigest,
provider: { id: "ghidra" as const, version: "12.1.2" },
@@ -240,11 +240,7 @@ const resultBuilders = new Map<GhidraOperation, GhidraResultBuilder>([
["xrefs", () => ["0x401001"]],
[
"analyze_function",
(input, _limit) =>
ghidraFunctionDossier(
input.include_assembly === true,
input.procedure === "fixture_truncated",
),
(input) => ghidraFunctionDossier(input.include_assembly === true),
],
]);
+6 -55
View File
@@ -2,27 +2,25 @@ import { describe, expect, it } from "vitest";
import { connectGhidraMcp, sessionEvidence } from "./ghidraMcpHarness.js";
describe("Ghidra MCP native API evidence", () => {
it("records approved native API truncation once and links its evidence", async () => {
it("returns complete native API boundaries without output-cap unknowns", async () => {
const harness = await connectGhidraMcp("ghidra-native-api");
const { mcp, session } = harness;
try {
const unapprovedInspection = sessionEvidence(
const inspection = sessionEvidence(
session,
(
await mcp.callTool({
name: "inspect_native_api",
arguments: { procedure: "fixture_truncated" },
arguments: { procedure: "fixture_main" },
})
).structuredContent,
);
expect(unapprovedInspection.normalized_result).toMatchObject({
expect(inspection.normalized_result).toMatchObject({
boundary: {
available: true,
jump_tables: [{ mappings_truncated: true }],
jump_tables: [{ mappings: [{ target_address: "0x401020" }] }],
},
residual_unknowns: [
expect.stringContaining("additional data sources or targets"),
],
residual_unknowns: [],
});
expect(
(
@@ -32,53 +30,6 @@ describe("Ghidra MCP native API evidence", () => {
})
).structuredContent,
).toMatchObject({ result: { items: [] } });
const approvedInspection = sessionEvidence(
session,
(
await mcp.callTool({
name: "inspect_native_api",
arguments: {
procedure: "fixture_truncated",
unknown_registry_approved: true,
},
})
).structuredContent,
);
await mcp.callTool({
name: "inspect_native_api",
arguments: {
procedure: "fixture_truncated",
unknown_registry_approved: true,
},
});
expect(
(
await mcp.callTool({
name: "list_unknowns",
arguments: {},
})
).structuredContent,
).toMatchObject({
result: {
items: [
{
status: "open",
domain: "native-api",
question: expect.stringContaining(
"additional data sources or targets",
),
supporting_evidence_ids: [approvedInspection.evidence_id],
recommended_probes: [
{
operation: "inspect_native_api",
rationale: expect.stringContaining("ABI probe"),
},
],
},
],
},
});
} finally {
await harness.close();
}
@@ -156,7 +156,7 @@ describe("GhidraClient", () => {
await expect(client.start()).resolves.toMatchObject({
ok: true,
value: {
bridge_version: 6,
bridge_version: 7,
target: { sha256: TARGET_SHA256 },
},
});
+1 -1
View File
@@ -178,7 +178,7 @@ const sessionInfo = ({
timedOut,
}) => ({
name: "REA Ghidra bridge",
bridge_version: 6,
bridge_version: 7,
run_id: sessionRunId,
profile_digest: digest,
provider: { id: "ghidra", version },