fix(hopper): add bounded analysis recovery

This commit is contained in:
N0zoM1z0
2026-07-24 00:33:29 +09:00
committed by N0zoM1z0
parent 161377a505
commit e0bc7fd973
68 changed files with 1750 additions and 368 deletions
@@ -0,0 +1,71 @@
import { requireMcpResult } from "./mcp-verifier-results.mjs";
export const verifyHopperFunctionBasics = async (
client,
options,
procedure,
) => {
const containment = requireMcpResult(
await client.callTool(
{
name: "resolve_containing_procedure",
arguments: { address: procedure },
},
options,
),
"resolve_containing_procedure",
);
if (
containment?.found !== true ||
containment.procedure?.address !== procedure
) {
throw new Error(
"resolve_containing_procedure returned the wrong procedure",
);
}
const references = requireMcpResult(
await client.callTool(
{
name: "procedure_references",
arguments: {
procedure,
direction: "outgoing",
limit: 10,
max_instructions: 100,
},
},
options,
),
"procedure_references",
);
if (!Array.isArray(references?.references?.items)) {
throw new Error("procedure_references returned an invalid bounded result");
}
const instructions = requireMcpResult(
await client.callTool(
{
name: "read_function_instructions",
arguments: { procedure, limit: 2 },
},
options,
),
"read_function_instructions",
);
if (
instructions?.procedure?.address !== procedure ||
!Array.isArray(instructions.instructions?.items) ||
instructions.instructions.items.length === 0 ||
instructions.instructions.items.length > 2
) {
throw new Error(
"read_function_instructions returned an invalid bounded window",
);
}
return {
outgoingReferenceCount: references.references.items.length,
instructionWindowCount: instructions.instructions.items.length,
};
};
+29 -2
View File
@@ -44,10 +44,27 @@ export async function verifyDebugFunctionOperations(
if (entryString === undefined)
throw new Error("Ghidra debug string function probe is unavailable");
const [info, assembly, pseudocode, callees, callers, outgoing, entryXrefs] =
await collectEntryFunctionData(client, entry);
const [
info,
assembly,
instructionWindow,
pseudocode,
callees,
callers,
outgoing,
entryXrefs,
] = await collectEntryFunctionData(client, entry);
assertLocalProcedureInfo(info, entry.address);
assertProviderText(assembly, pseudocode, entry.address);
if (
instructionWindow.procedure?.address !== entry.address ||
instructionWindow.instructions?.items?.length !== 1 ||
instructionWindow.instructions.returned !== 1 ||
instructionWindow.instructions_scanned < 1
)
throw new Error(
"Ghidra read_function_instructions failed its bounded fast-path contract",
);
assertEntryCallGraph({ branch, indirect, main, callees, callers });
const { xrefOwners, xrefOwnerFailures } = await resolveXrefOwners(
client,
@@ -83,6 +100,10 @@ export async function verifyDebugFunctionOperations(
entry: dossierSummary(entryDossier),
branch: dossierSummary(branchDossier),
indirect: dossierSummary(indirectDossier),
instruction_window: {
returned: instructionWindow.instructions.returned,
truncated: instructionWindow.instructions.truncated,
},
cancellation,
timeout,
concurrency: concurrent,
@@ -99,6 +120,12 @@ async function collectEntryFunctionData(client, entry) {
document: null,
procedure: entry.value,
}),
functionCall(client, "read_function_instructions", {
document: null,
procedure: entry.value,
offset: 0,
limit: 1,
}),
functionCall(client, "procedure_pseudo_code", {
document: null,
procedure: entry.value,
+1
View File
@@ -146,6 +146,7 @@ try {
"procedure_callers",
"procedure_info",
"procedure_pseudo_code",
"read_function_instructions",
"procedure_references",
])
await functionOperation(operation, { procedure: procedure.value });
+7 -36
View File
@@ -26,6 +26,7 @@ import {
requireMcpResult,
requireWorkflowEvidenceProvider,
} from "./lib/mcp-verifier-results.mjs";
import { verifyHopperFunctionBasics } from "./lib/real-hopper-function-basics.mjs";
import { openAndVerifyLargeFixture } from "./lib/real-hopper-pagination.mjs";
import { completeVerifierRun, createVerifierRun } from "./lib/verifier-run.mjs";
import { startUnrelatedHopperSentinel } from "./lib/unrelated-hopper-sentinel.mjs";
@@ -155,42 +156,11 @@ const verifyCurrentTarget = async (client, options) => {
"list_procedures",
);
const firstAddress = firstProcedureAddress(procedures);
const containment = requireSuccessfulTool(
await client.callTool(
{
name: "resolve_containing_procedure",
arguments: { address: firstAddress },
},
options,
),
"resolve_containing_procedure",
const basics = await verifyHopperFunctionBasics(
client,
options,
firstAddress,
);
if (
containment?.found !== true ||
containment.procedure?.address !== firstAddress
) {
throw new Error(
"resolve_containing_procedure returned the wrong procedure",
);
}
const references = requireSuccessfulTool(
await client.callTool(
{
name: "procedure_references",
arguments: {
procedure: firstAddress,
direction: "outgoing",
limit: 10,
max_instructions: 100,
},
},
options,
),
"procedure_references",
);
if (!Array.isArray(references?.references?.items)) {
throw new Error("procedure_references returned an invalid bounded result");
}
const relationships = await verifyRelationships(
client,
options,
@@ -245,7 +215,8 @@ const verifyCurrentTarget = async (client, options) => {
callerCount: relationships.procedure_callers.length,
calleeCount: relationships.procedure_callees.length,
xrefCount: relationships.xrefs.length,
outgoingReferenceCount: references.references.items.length,
outgoingReferenceCount: basics.outgoingReferenceCount,
instructionWindowCount: basics.instructionWindowCount,
};
};