feat(native): expose typed incoming references at exact addresses (#1715)

This commit is contained in:
Arthas
2026-10-11 19:52:09 +08:00
committed by GitHub
parent 031d7781f0
commit cdd9fe7167
9 changed files with 212 additions and 10 deletions
+2 -2
View File
@@ -54,7 +54,7 @@ export const OFFICIAL_TOOL_CONTRACTS = [
),
official(
"inspect_native_instruction",
"Inspect one exact instruction address: decoded bytes, mnemonic, ordered operand tokens, flow and typed references. Memory addressing decomposition is unavailable when the provider supplies only tokens. Data, interior instruction addresses and undecodable bytes are distinct outcomes.",
"Inspect one exact code or data address: decoded bytes, mnemonic, ordered operand tokens, flow, outgoing instruction references and typed incoming references where available. Incoming references preserve source, access kind, operand index and analysis provenance even at data addresses; they do not prove runtime access. Memory addressing decomposition is unavailable when the provider supplies only tokens. Data, interior instruction addresses and undecodable bytes are distinct outcomes.",
nativeInstructionInputSchema,
),
official(
@@ -231,7 +231,7 @@ export const OFFICIAL_TOOL_CONTRACTS = [
),
official(
"xrefs",
"Return analyzed references to a code or data address. Hopper may default to its current cursor; headless providers such as Ghidra require an explicit address. Use to connect strings, globals, selectors, and functions; bare addresses are untyped and indirect references may be incomplete.",
"Return analyzed references to a code or data address. Hopper may default to its current cursor; headless providers such as Ghidra require an explicit address. Use to connect strings, globals, selectors, and functions; bare addresses are untyped and indirect references may be incomplete. Use inspect_native_instruction at the target address for typed incoming references where supported.",
z.object({ document, address: optionalAddress }),
),
] as const satisfies readonly ToolContract[];
+8 -1
View File
@@ -1,6 +1,6 @@
import { z } from "zod";
/** Exact instruction location within the active analysis program. */
/** Exact code or data location within the active analysis program. */
export const nativeInstructionInputSchema = z.strictObject({
address: z.string().min(1),
document: z.string().optional(),
@@ -99,6 +99,13 @@ export const nativeInstructionSchema = z.strictObject({
),
}),
references: z.array(reference),
incoming_references: z
.array(reference)
.nullable()
.optional()
.describe(
"Static references to this exact code or data address, excluding synthetic entry-point references. An empty array means the provider examined the address and found none; null or omission means unavailable. Analyzer references do not prove literal addressing or runtime access.",
),
limitations: z.array(z.string()),
});
+1
View File
@@ -113,6 +113,7 @@ export const resolveGhidraAnalysisProfile = async (
string_inventory_evidence: "defined-data-coverage-v1",
location_resolution: "explicit-address-exact-entry-symbol-first-v3",
instruction_flow_evidence: "decoded-return-pcode-v1",
instruction_references: "exact-address-incoming-v1",
function_boundary_observations: "ghidra-terminal-call-limitations-v1",
no_return_repair:
installation.platform === "win32"
+39
View File
@@ -172,6 +172,45 @@ describe("Ghidra function-analysis result values", () => {
});
describe("Ghidra compact reference provenance", () => {
it("distinguishes incoming references, examined emptiness and unavailable coverage at data addresses", () => {
const instruction = {
...compactInstruction(),
address: "ram:00402000",
status: "data",
procedure: null,
};
const reference = {
...compactReference(),
source_address: "ram:00401000",
target_address: instruction.address,
type: "WRITE",
call: false,
data: true,
write: true,
};
for (const incoming of [
{},
{ incoming_references: null },
{ incoming_references: [] },
{ incoming_references: [reference] },
{ incoming_references: [{ ...reference, primary: null, source: null }] },
]) {
const expected = { ...instruction, ...incoming };
const parsed = parseFunctionValueFixture(
"inspect_native_instruction",
expected,
);
if (!parsed.ok) throw parsed.error;
expect(parsed.value).toEqual(expected);
}
expect(
parseFunctionValueFixture("inspect_native_instruction", {
...instruction,
incoming_references: [{ ...reference, primary: "false" }],
}),
).toMatchObject({ ok: false, error: { _tag: "AnalysisOutputError" } });
});
const operations = [
["inspect_native_instruction", compactInstruction],
["resolve_native_call_targets", compactCallTargets],
+36
View File
@@ -4,6 +4,7 @@ import { createTestBinarySession } from "../../tests/fixtures/binarySession.js";
import { parseConfig } from "../config/parseConfig.js";
import type { BinaryTarget } from "../domain/binaryTargetTypes.js";
import { functionDossierSchema } from "../domain/hopperValues.js";
import { createAnalysisProfile } from "../domain/analysisProfile.js";
import { ghidraFunctionDossier } from "../domain/ghidraValues.fixture.js";
import { err, ok } from "../domain/result.js";
import { silentLogger } from "../logger.js";
@@ -130,6 +131,41 @@ const open = async (session: ReturnType<typeof fixture>["session"]) => {
};
describe("Ghidra snapshot cache", () => {
it("refuses snapshots whose profile predates typed incoming references", async () => {
const initial = fixture();
await open(initial.session);
const snapshot = initial.session.exportAnalysisSnapshot();
if (!snapshot.ok) throw snapshot.error;
await initial.session.close();
const profile = snapshot.value.binding.analysis_profile;
expect(profile.parameters.instruction_references).toBe(
"exact-address-incoming-v1",
);
const legacy = {
...snapshot.value,
binding: {
...snapshot.value.binding,
analysis_profile: createAnalysisProfile(
profile.provider,
Object.fromEntries(
Object.entries(profile.parameters).filter(
([key]) => key !== "instruction_references",
),
),
),
},
};
const replay = fixture();
const imported = replay.session.importAnalysisSnapshot(legacy);
if (!imported.ok) throw imported.error;
expect(await replay.session.previewTarget(TARGET)).toMatchObject({
ok: false,
error: { _tag: "EvidenceIntegrityError" },
});
expect(replay.calls).toEqual([]);
await replay.session.close();
});
it.each([
{ operation: "analyze_function", parameters: { procedure: "0x1000" } },
{