fix(ghidra): resolve file offsets in decompile (#2101)
* fix(native): expose loaded image bases in overviews * test(ghidra): retain resources when verifier cleanup fails * docs(ghidra): spell out file-offset address mapping * fix(ci): separate and retry NativeAOT dependency restoration * fix(test): resolve CI script file URLs on Windows * fix(native): retain conflict observations and actionable CLI guidance * fix(fixtures): keep NativeAOT retry logs credential-safe * fix(fixtures): redact authenticated URLs at diagnostic creation * fix(ghidra): restrict source-coordinate observations to decompilation * fix(cli): identify conflicting file-offset selectors accurately * fix(ghidra): bind file offsets to admitted target sources * fix(ghidra): preserve resolved file-offset failure context * test(ghidra): verify ELF address and file-offset round trips * test(nativeaot): align diagnostic regressions with fixture host support
This commit is contained in:
@@ -12,6 +12,38 @@ const selectors = [
|
||||
] as const;
|
||||
|
||||
describe("CLI analysis selector boundaries", () => {
|
||||
cliTest(
|
||||
"accepts file offsets and rejects mixed coordinate selectors before opening a target",
|
||||
async ({ cli }) => {
|
||||
const selected = await cli.run({
|
||||
arguments: [
|
||||
"decompile",
|
||||
"does-not-exist",
|
||||
"--file-offset=0x210",
|
||||
"--json",
|
||||
],
|
||||
environment: { REA_LOG_LEVEL: "silent" },
|
||||
});
|
||||
expect(selected.json).toMatchObject({ code: "target_unavailable" });
|
||||
const conflicting = await cli.run({
|
||||
arguments: [
|
||||
"decompile",
|
||||
"does-not-exist",
|
||||
"0x140001010",
|
||||
"--file-offset=0x210",
|
||||
"--json",
|
||||
],
|
||||
environment: { REA_LOG_LEVEL: "silent" },
|
||||
});
|
||||
expect(conflicting.json).toMatchObject({
|
||||
code: "invalid_request",
|
||||
details: {
|
||||
operation: "procedure_pseudo_code",
|
||||
issues: [{ path: ["file-offset"], reason: "invalid_value" }],
|
||||
},
|
||||
});
|
||||
},
|
||||
);
|
||||
cliTest(
|
||||
"rejects missing and conflicting selectors before opening a target",
|
||||
async ({ cli }) => {
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
writeFile,
|
||||
} from "node:fs/promises";
|
||||
import { dirname, join, matchesGlob } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
import { afterAll, beforeAll, expect, it } from "vitest";
|
||||
import { parse } from "yaml";
|
||||
@@ -85,7 +86,7 @@ async function classify(
|
||||
await writeFile(output, "");
|
||||
const result = await execFileAsync(
|
||||
process.execPath,
|
||||
[new URL("../../../scripts/ci/plan.mjs", import.meta.url).pathname],
|
||||
[fileURLToPath(new URL("../../../scripts/ci/plan.mjs", import.meta.url))],
|
||||
{
|
||||
cwd: directory,
|
||||
env: {
|
||||
@@ -658,8 +659,9 @@ it.each([
|
||||
);
|
||||
|
||||
it("rejects skipped selected work while allowing unselected lanes to skip", async () => {
|
||||
const command = new URL("../../../scripts/ci/required.mjs", import.meta.url)
|
||||
.pathname;
|
||||
const command = fileURLToPath(
|
||||
new URL("../../../scripts/ci/required.mjs", import.meta.url),
|
||||
);
|
||||
const jobs = {
|
||||
changes: { result: "success", outputs: { evm: "true" } },
|
||||
static: { result: "success" },
|
||||
|
||||
@@ -144,14 +144,26 @@ describe("enhanced MCP tools", () => {
|
||||
);
|
||||
expect(result).toEqual({
|
||||
document: "fixture",
|
||||
image_base: "0x1000",
|
||||
segments: [
|
||||
{ name: "__TEXT", start: "0x1000", end: "0x1800", length: 2048 },
|
||||
{ name: "__DATA", start: "0x1800", end: "0x2000", length: 2048 },
|
||||
{
|
||||
name: "__TEXT",
|
||||
start: "0x1000",
|
||||
end: "0x1800",
|
||||
length: 2048,
|
||||
image_base: "0x1000",
|
||||
},
|
||||
{
|
||||
name: "__DATA",
|
||||
start: "0x1800",
|
||||
end: "0x2000",
|
||||
length: 2048,
|
||||
image_base: "0x1000",
|
||||
},
|
||||
],
|
||||
segment_count: 2,
|
||||
procedure_count: 2,
|
||||
string_count: 700,
|
||||
image_base: "0x1000",
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
import { afterEach, expect, it } from "vitest";
|
||||
import { Ajv2020 } from "ajv/dist/2020.js";
|
||||
import type { AnySchemaObject } from "ajv";
|
||||
import {
|
||||
closeEnhancedToolResources,
|
||||
connect,
|
||||
jsonResult,
|
||||
} from "./enhancedToolsHarness.js";
|
||||
import { observed as ok } from "../../fixtures/analysisExecution.js";
|
||||
import type { SegmentSummary } from "../../../src/domain/hopperValues.js";
|
||||
|
||||
afterEach(closeEnhancedToolResources);
|
||||
|
||||
const segment = {
|
||||
name: ".text",
|
||||
start: "0x101000",
|
||||
end: "0x101100",
|
||||
readable: true,
|
||||
writable: false,
|
||||
executable: true,
|
||||
image_base: "0x100000",
|
||||
address_space: "ram",
|
||||
};
|
||||
const overviewClient = (segments: SegmentSummary[]) =>
|
||||
connect({
|
||||
execute: (name) => {
|
||||
switch (name) {
|
||||
case "current_document":
|
||||
return Promise.resolve(ok("fixture"));
|
||||
case "list_documents":
|
||||
return Promise.resolve(ok(["fixture"]));
|
||||
case "list_segments":
|
||||
return Promise.resolve(ok(segments));
|
||||
case "list_procedures":
|
||||
return Promise.resolve(ok([{ address: "0x101013", value: "entry" }]));
|
||||
case "list_strings":
|
||||
return Promise.resolve(ok([]));
|
||||
default:
|
||||
throw new Error(`Unexpected operation: ${name}`);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
it("preserves observed coordinates and main's optional-string output contract after SDK conversion", async () => {
|
||||
const client = await overviewClient([segment]);
|
||||
const schema = (await client.listTools()).tools.find(
|
||||
({ name }) => name === "binary_overview",
|
||||
)?.outputSchema;
|
||||
if (schema === undefined) throw new Error("Missing overview output schema");
|
||||
const validate = new Ajv2020({ strict: false }).compile(
|
||||
schema as AnySchemaObject,
|
||||
);
|
||||
const response = await client.callTool({
|
||||
name: "binary_overview",
|
||||
arguments: {},
|
||||
});
|
||||
expect(validate(response.structuredContent)).toBe(true);
|
||||
expect(jsonResult(response)).toMatchObject({
|
||||
image_base: "0x100000",
|
||||
segments: [
|
||||
{ start: "0x101000", image_base: "0x100000", address_space: "ram" },
|
||||
],
|
||||
});
|
||||
const absent = JSON.parse(JSON.stringify(response.structuredContent));
|
||||
delete absent.normalized_result.image_base;
|
||||
expect(validate(absent)).toBe(true);
|
||||
absent.normalized_result.image_base = null;
|
||||
expect(validate(absent)).toBe(false);
|
||||
});
|
||||
|
||||
it("omits unreported bases without inventing zero and preserves explicit zero", async () => {
|
||||
const { image_base: _base, ...unreported } = segment;
|
||||
const client = await overviewClient([unreported]);
|
||||
expect(
|
||||
jsonResult(
|
||||
await client.callTool({ name: "binary_overview", arguments: {} }),
|
||||
),
|
||||
).not.toHaveProperty("image_base");
|
||||
const zero = await overviewClient([{ ...segment, image_base: "0x0" }]);
|
||||
expect(
|
||||
jsonResult(await zero.callTool({ name: "binary_overview", arguments: {} })),
|
||||
).toMatchObject({ image_base: "0x0" });
|
||||
});
|
||||
|
||||
it("keeps a partially reported base unknown while retaining the reported segment observation", async () => {
|
||||
const { image_base: _base, ...unreported } = segment;
|
||||
const client = await overviewClient([
|
||||
segment,
|
||||
{ ...unreported, name: ".data" },
|
||||
]);
|
||||
const result = jsonResult(
|
||||
await client.callTool({ name: "binary_overview", arguments: {} }),
|
||||
);
|
||||
expect(result).not.toHaveProperty("image_base");
|
||||
expect(result).toMatchObject({
|
||||
segments: [{ image_base: "0x100000" }, { name: ".data" }],
|
||||
});
|
||||
});
|
||||
|
||||
it("retains all conflicting observations after repeated early bases without selecting one", async () => {
|
||||
const { address_space: _space, ...unreported } = segment;
|
||||
const client = await overviewClient([
|
||||
...Array.from({ length: 40 }, () => unreported),
|
||||
{
|
||||
...segment,
|
||||
name: ".data",
|
||||
start: "other%20space:0x201000",
|
||||
end: "other%20space:0x201100",
|
||||
image_base: "0x200000",
|
||||
address_space: "other space",
|
||||
},
|
||||
]);
|
||||
const result = jsonResult(
|
||||
await client.callTool({ name: "binary_overview", arguments: {} }),
|
||||
);
|
||||
expect(result).not.toHaveProperty("image_base");
|
||||
expect(result).toHaveProperty("segments.length", 41);
|
||||
expect(result).toHaveProperty("segments.40.image_base", "0x200000");
|
||||
expect(result).toHaveProperty("segments.40.address_space", "other space");
|
||||
expect(result).not.toHaveProperty("segments.0.address_space");
|
||||
});
|
||||
Reference in New Issue
Block a user