mirror of
https://github.com/morluto/rea.git
synced 2026-11-22 14:35:45 +00:00
* feat(ida): support the official Hex-Rays IDA MCP headlessly Hex-Rays IDA MCP serves database reads only through execute_python, so REA rejected it as an upstream. A `hexrays` headless stdio registration now leases a private idalib worker through open_database, answers the existing database-supervisor reads with a fixed, packaged, read-only query module, and releases the lease with close_database, verified by list_databases. Observations record execute_python, the query and the module digest. Tool errors are typed so a completed rejection is distinguished from an unknown outcome; an unconfirmed release is retried and a late lease on the private input is adopted. Validated IDA source and bridge tests, static checks, docs, and npm run verify:ida on Linux x64 against x86-64 and AArch64 ELF fixtures. * feat(ida): name the Hex-Rays registration for its catalog A registration without `protocol` that reaches the official Hex-Rays server failed with only the missing database-supervisor tools. Startup profile failures now report the advertised catalog, and when it is the Hex-Rays one the message and recovery name the `hexrays` registration. Refs #1416 * docs(ida): state Hex-Rays prerequisites and upstream session traces Upstream needs IDA 9.4 or later with idalib, Python 3.11 or later, uv and Git. The profile does not analyze databases open in the IDA GUI, and the server keeps its own session traces outside REA's workspace. Refs #1416 * fix(ida): skip inline data when scanning Hex-Rays calls The call scan decoded every head that FuncItems yields. Inline data such as a jump table can decode as a call and refer to a function or import, which reported false callees and call-graph edges. Skip non-code heads before decoding, as disassembly already does. Refs #1416 * fix(ida): retain Hex-Rays health reads in evidence The identity and readiness reads around each operation kept only their parsed result, dropping the bridge digest and any engine output. Keep them whole as health_observations beside the parsed metadata, in both successful and partial-failure Evidence. Refs #1416 * test(ida): list the Hex-Rays bridge in package fixtures The packed-bridge verifier has required bridge/ida/hexrays_queries.py since the Hex-Rays profile landed, but three package tests still built their member lists without it. The verifier stopped at that file, so 21 cases failed or asserted on the wrong omission. Refs #1416 * feat(ida): open existing IDA databases through the Hex-Rays profile A headless open re-ran auto-analysis from the input binary, discarding the names, types and comments of an existing database and taking far longer on large targets. Target admission now identifies IDA databases by their IDA1/IDA2 signature, and the hexrays profile opens a private copy of one; Hopper and the other IDA profiles reject them. The copy is required, not incidental: idalib repacks a database when its last lease is released, even without a save. A database reports the input it was created from, so the session is bound to the opened copy's idb_path, and health now reports the input SHA-256 it records. Validated with resolver, provider and session tests, check:fast, docs:check and test:changed, plus a real Hex-Rays MCP run against a 1.4 GB SC2 .i64 whose original file was left byte-identical. Refs #1416 * fix(ida): verify the private workspace of a database target by idb_path * test(ida): fix Hex-Rays health stand-ins and Windows path and runtime teardown * refactor(ida): resolve the registration once for target support * docs(ida): record the real Hex-Rays run on an existing .i64 * docs(ida): make the Hex-Rays registration example install-neutral * chore: keep merge-hook formatting outside the IDA change * fix(ida): retain live Hex-Rays databases this server does not lease A list_databases row with instance_id null is a live owner, not a stopped database. Mapping it to the supervisor's released-worker shape made cleanup delete files another client still held. Unleased rows stay active, so the private path must leave inventory before the workspace is removed. Accept idat inventory rows, hash the query bridge with sha256Hex, and complete databaseEngine on Hopper fixtures added on main. * fix(ida): report uncapped Hex-Rays call graphs * docs(ida): link to the Hex-Rays bridge on GitHub * fix(ida): verify Hex-Rays worker identity and cleanup * feat(ida): support Hex-Rays idat headless workers Refs #12921 * fix(ida): retain workspace after ambiguous Hex-Rays startup * fix(ida): preserve typed Hex-Rays call edges and deadlines * test(ida): verify Hex-Rays cleanup with a peer lease * test(ci): use project deadlines for the Cutter verifier * test(ida): keep verifier cleanup fixtures scoped to mocked modules * fix(ida): retain the worker backend in partial evidence --------- Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: morluto <morluto@users.noreply.github.com> Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
549 lines
20 KiB
TypeScript
549 lines
20 KiB
TypeScript
import { createHash } from "node:crypto";
|
|
import { readdir, readFile, realpath, rm, writeFile } from "node:fs/promises";
|
|
import { snapshotExecution } from "../../src/domain/analysisSnapshot.fixture.js";
|
|
import { join } from "node:path";
|
|
import { afterEach, describe, expect, it } from "vitest";
|
|
import { projectAnalysisError } from "../../src/domain/analysisErrorProjection.js";
|
|
import { IdaProvider } from "../../src/ida/IdaProvider.js";
|
|
import { createIdaTarget, RecordingIdaMcp } from "../fixtures/idaMcp.js";
|
|
import { createTestBinarySession } from "../fixtures/binarySession.js";
|
|
import { parseConfig } from "../../src/config/parseConfig.js";
|
|
import {
|
|
createAnalysisSnapshotEntry,
|
|
snapshotBinding,
|
|
snapshotTarget,
|
|
} from "../../src/domain/analysisSnapshot.js";
|
|
import { createEvidence } from "../../src/domain/evidence.js";
|
|
import { createEvidenceBundle } from "../../src/domain/evidenceBundle.js";
|
|
import { createAnalysisExecution } from "../../src/ports/AnalysisProvider.js";
|
|
import { EnhancedTools } from "../../src/application/EnhancedTools.js";
|
|
import { IDA_DATABASE_TARGET_LIMITATION } from "../../src/ida/IdaProviderCapabilities.js";
|
|
import type { BinaryTarget } from "../../src/domain/binaryTargetTypes.js";
|
|
import { RecordingHexRaysIdaMcp } from "../fixtures/idaHexRaysMcp.js";
|
|
import { IDA_PROVIDER_IDENTITY } from "../../src/ida/IdaProviderMetadata.js";
|
|
import { parseBinaryTarget } from "../../src/application/BinaryTargetResolver.js";
|
|
import { fat } from "../../src/domain/binaryTarget.fixture.js";
|
|
import { createTestTempDirectory } from "../fixtures/temporaryDirectory.js";
|
|
import { BinarySession } from "../../src/application/binary/BinarySession.js";
|
|
import { SessionProviderRouter } from "../../src/application/binary/SessionProviderRouter.js";
|
|
import { AnalysisProviderRegistry } from "../../src/application/binary/AnalysisProviderRegistry.js";
|
|
|
|
const roots: string[] = [];
|
|
afterEach(async () => {
|
|
for (const root of roots.splice(0))
|
|
await rm(root, { recursive: true, force: true });
|
|
});
|
|
|
|
const reobservesExternallyMutableState = async (): Promise<void> => {
|
|
const { root, target } = await createIdaTarget();
|
|
roots.push(root);
|
|
const path = join(root, "registration.json");
|
|
await writeFile(
|
|
path,
|
|
JSON.stringify({ command: "fixture", protocol: "native" }),
|
|
);
|
|
const config = parseConfig({ REA_IDA_MCP_CONFIG: path });
|
|
if (!config.ok) throw config.error;
|
|
const producer = new RecordingIdaMcp(target);
|
|
const session = createTestBinarySession(
|
|
new IdaProvider(config.value, {}, () => producer),
|
|
);
|
|
expect((await session.open(target.path)).ok).toBe(true);
|
|
const query = { procedure: "main", document: target.path };
|
|
const first = await session.execute("procedure_pseudo_code", query);
|
|
expect(first.ok && first.value.result).toContain("42");
|
|
const snapshot = session.exportAnalysisSnapshot();
|
|
if (!snapshot.ok) throw snapshot.error;
|
|
expect(snapshot.value.entries).toEqual([]);
|
|
const profile = session.analysisProfile();
|
|
if (profile === undefined) throw new Error("Missing profile");
|
|
const cached = createAnalysisExecution(
|
|
"stale output",
|
|
IDA_PROVIDER_IDENTITY,
|
|
{
|
|
analysisProfile: profile,
|
|
subject: {
|
|
path: target.path,
|
|
sha256: target.sha256,
|
|
format: target.format,
|
|
...(target.architecture === undefined
|
|
? {}
|
|
: { architecture: target.architecture }),
|
|
},
|
|
},
|
|
);
|
|
snapshot.value.entries.push(
|
|
createAnalysisSnapshotEntry({
|
|
target: snapshotTarget(target),
|
|
binding: snapshotBinding(profile),
|
|
operation: "procedure_pseudo_code",
|
|
parameters: query,
|
|
execution: snapshotExecution(cached),
|
|
}),
|
|
);
|
|
snapshot.value.evidence_bundle = createEvidenceBundle([
|
|
...snapshot.value.evidence_bundle.records,
|
|
createEvidence(target, IDA_PROVIDER_IDENTITY, {
|
|
operation: "procedure_pseudo_code",
|
|
parameters: query,
|
|
result: cached.result,
|
|
rawResult: cached.rawResult,
|
|
analysisProfile: profile,
|
|
}),
|
|
]);
|
|
expect(session.importAnalysisSnapshot(snapshot.value).ok).toBe(true);
|
|
expect(session.allowsSnapshotReplay("procedure_pseudo_code")).toBe(false);
|
|
expect(session.allowsSnapshotReplay("binary_overview")).toBe(false);
|
|
producer.pseudocode = "int main(void) { return 99; }";
|
|
const second = await session.execute("procedure_pseudo_code", query);
|
|
expect(second.ok && second.value.result).toContain("99");
|
|
expect(
|
|
producer.calls.filter(({ name }) => name === "decompile"),
|
|
).toHaveLength(2);
|
|
await session.close();
|
|
expect(producer.closes).toBe(1);
|
|
};
|
|
|
|
describe("IDA provider composition", () => {
|
|
it("discovers without launching and commits adapter semantics without persisting credentials", async () => {
|
|
const { root, target } = await createIdaTarget();
|
|
roots.push(root);
|
|
const path = join(root, "registration.json");
|
|
await writeFile(
|
|
path,
|
|
JSON.stringify({
|
|
url: "http://127.0.0.1:8745/mcp",
|
|
headers: { Authorization: "Bearer private-fixture-token" },
|
|
mode: "headless",
|
|
}),
|
|
);
|
|
const config = parseConfig({ REA_IDA_MCP_CONFIG: path });
|
|
if (!config.ok) throw config.error;
|
|
const producer = new RecordingIdaMcp(target, "headless");
|
|
const provider = new IdaProvider(config.value, {}, () => producer);
|
|
expect(await provider.inspectAvailability()).toMatchObject({
|
|
status: "available",
|
|
diagnostics: { live_connection_probed: false },
|
|
});
|
|
const resolution = await provider.resolveAnalysisProfile(target);
|
|
if (!resolution.ok) throw resolution.error;
|
|
expect(resolution.value.profile.parameters).toMatchObject({
|
|
engine_version: null,
|
|
upstream_distribution_version: null,
|
|
cache_policy: "live",
|
|
version_scope: "rea-ida-adapter",
|
|
});
|
|
expect(JSON.stringify(resolution)).not.toContain("private-fixture-token");
|
|
expect(producer.connects).toBe(0);
|
|
expect(
|
|
(await provider.inspectReadinessSnapshot()).capabilities.find(
|
|
({ operation }) => operation === "procedure_callers",
|
|
)?.available,
|
|
).toBe(false);
|
|
});
|
|
it(
|
|
"re-observes externally mutable state even when a document is explicit and a snapshot is imported",
|
|
reobservesExternallyMutableState,
|
|
);
|
|
it("rejects unsupported target kinds and reports incomplete upstream profiles on first analysis", async () => {
|
|
const { root, target } = await createIdaTarget();
|
|
roots.push(root);
|
|
const path = join(root, "registration.json");
|
|
await writeFile(
|
|
path,
|
|
JSON.stringify({
|
|
command: "fixture",
|
|
mode: "headless",
|
|
workspaceRoot: root,
|
|
}),
|
|
);
|
|
const config = parseConfig({ REA_IDA_MCP_CONFIG: path });
|
|
if (!config.ok) throw config.error;
|
|
const producer = new RecordingIdaMcp(target);
|
|
const provider = new IdaProvider(config.value, {}, () => producer);
|
|
expect(
|
|
await provider.inspectTargetSupportWithOptions(
|
|
{
|
|
path: target.path,
|
|
sha256: target.sha256,
|
|
kind: "database",
|
|
format: "analysis-database",
|
|
databaseEngine: "ida",
|
|
},
|
|
{},
|
|
),
|
|
).toMatchObject({ status: "unsupported", code: "target_kind_unsupported" });
|
|
const session = createTestBinarySession(provider);
|
|
expect((await session.open(target.path)).ok).toBe(true);
|
|
expect(producer.connects).toBe(0);
|
|
const analyzed = await session.execute("procedure_pseudo_code", {
|
|
procedure: "main",
|
|
});
|
|
expect(analyzed).toMatchObject({
|
|
ok: false,
|
|
error: {
|
|
_tag: "ProviderAdapterError",
|
|
userMessage: expect.stringContaining(
|
|
"headless compatibility profile is missing tools: idb_open",
|
|
),
|
|
},
|
|
});
|
|
if (analyzed.ok) throw new Error("Expected incompatible IDA profile");
|
|
expect(projectAnalysisError(analyzed.error).details).toMatchObject({
|
|
provider_id: "ida",
|
|
diagnostics: {
|
|
mode: "headless",
|
|
expected_profile: "database-supervisor",
|
|
missing_tools: expect.arrayContaining(["idb_open"]),
|
|
},
|
|
});
|
|
expect(producer.connects).toBe(1);
|
|
expect((await session.close()).ok).toBe(true);
|
|
expect(producer.closes).toBe(1);
|
|
});
|
|
});
|
|
|
|
describe("IDA provider selection cancellation", () => {
|
|
it("restores a cancelled replacement through the prior selected registration binding", async () => {
|
|
const first = await createIdaTarget();
|
|
const second = await createIdaTarget();
|
|
roots.push(first.root, second.root);
|
|
const path = join(first.root, "registration.json");
|
|
await writeFile(
|
|
path,
|
|
JSON.stringify({ command: "first-server", protocol: "native" }),
|
|
);
|
|
const config = parseConfig({ REA_IDA_MCP_CONFIG: path });
|
|
if (!config.ok) throw config.error;
|
|
const factorySelections: string[] = [];
|
|
const controller = new AbortController();
|
|
const cancellationReason = new Error(
|
|
"cancel after retiring previous IDA client",
|
|
);
|
|
let cancelWhenPreviousCloses = false;
|
|
const provider = new IdaProvider(config.value, {}, (registration) => {
|
|
const command =
|
|
"command" in registration ? registration.command : registration.url;
|
|
factorySelections.push(command);
|
|
const producer = new RecordingIdaMcp(first.target, "attached");
|
|
if (factorySelections.length === 1) {
|
|
const close = producer.close.bind(producer);
|
|
producer.close = async () => {
|
|
await close();
|
|
if (cancelWhenPreviousCloses) controller.abort(cancellationReason);
|
|
};
|
|
}
|
|
return producer;
|
|
});
|
|
const session = createTestBinarySession(provider);
|
|
expect((await session.open(first.target.path)).ok).toBe(true);
|
|
expect(
|
|
(await session.execute("procedure_pseudo_code", { procedure: "main" }))
|
|
.ok,
|
|
).toBe(true);
|
|
await writeFile(
|
|
path,
|
|
JSON.stringify({ command: "replacement-server", protocol: "native" }),
|
|
);
|
|
cancelWhenPreviousCloses = true;
|
|
const replacement = await session.open(second.target.path, {
|
|
signal: controller.signal,
|
|
});
|
|
expect(replacement.ok).toBe(false);
|
|
expect(replacement).toMatchObject({
|
|
ok: false,
|
|
error: { _tag: "AnalysisCancelledError", cause: cancellationReason },
|
|
});
|
|
if (replacement.ok) throw new Error("Expected cancellation");
|
|
expect(replacement.error.cause).toBe(cancellationReason);
|
|
expect(session.activeTarget()?.sha256).toBe(first.target.sha256);
|
|
expect(
|
|
(await session.execute("procedure_pseudo_code", { procedure: "main" }))
|
|
.ok,
|
|
).toBe(true);
|
|
expect(factorySelections).toEqual(["first-server", "first-server"]);
|
|
expect((await session.close()).ok).toBe(true);
|
|
});
|
|
it("preserves an already-aborted profile signal without reading registration", async () => {
|
|
const { root, target } = await createIdaTarget();
|
|
roots.push(root);
|
|
const config = parseConfig({
|
|
REA_IDA_MCP_CONFIG: join(root, "registration-that-must-not-be-read.json"),
|
|
});
|
|
if (!config.ok) throw config.error;
|
|
const reason = new Error("cancel before IDA profile inspection");
|
|
const controller = new AbortController();
|
|
controller.abort(reason);
|
|
let runCalls = 0;
|
|
const profile = await new IdaProvider(
|
|
config.value,
|
|
{},
|
|
).resolveAnalysisProfile(target, {
|
|
signal: controller.signal,
|
|
resourceScope: {
|
|
retain: () => undefined,
|
|
run: async (operation) => {
|
|
runCalls += 1;
|
|
return operation();
|
|
},
|
|
},
|
|
});
|
|
expect(profile).toMatchObject({
|
|
ok: false,
|
|
error: { _tag: "AnalysisCancelledError", cause: reason },
|
|
});
|
|
if (profile.ok) throw new Error("Expected cancellation");
|
|
expect(profile.error.cause).toBe(reason);
|
|
expect(runCalls).toBe(0);
|
|
});
|
|
});
|
|
|
|
describe("IDA universal Mach-O target identity", () => {
|
|
const openUniversal = async (registration: Record<string, unknown>) => {
|
|
const root = await createTestTempDirectory("rea-ida-universal-");
|
|
const input = join(root, "universal");
|
|
// x86_64 and arm64 slices share one whole-file digest.
|
|
await writeFile(input, fat([0x01000007, 0x0100000c]));
|
|
const resolved = await parseBinaryTarget(input);
|
|
if (!resolved.ok) throw resolved.error;
|
|
const path = join(root, "registration.json");
|
|
await writeFile(
|
|
path,
|
|
JSON.stringify({ ...registration, workspaceRoot: root }),
|
|
);
|
|
const config = parseConfig({ REA_IDA_MCP_CONFIG: path });
|
|
if (!config.ok) throw config.error;
|
|
const producer = new RecordingIdaMcp(
|
|
resolved.value,
|
|
registration.mode === "headless" ? "headless" : "attached",
|
|
);
|
|
// The production registry consults IDA's own target admission.
|
|
const session = new BinarySession(
|
|
SessionProviderRouter.selectable(
|
|
new AnalysisProviderRegistry([
|
|
new IdaProvider(config.value, {}, () => producer),
|
|
]),
|
|
[],
|
|
),
|
|
);
|
|
return {
|
|
producer,
|
|
session,
|
|
opened: await session.open(input, { providerId: "ida" }),
|
|
};
|
|
};
|
|
|
|
it.each([
|
|
{
|
|
profile: "native stdio attached",
|
|
registration: { command: "fixture", protocol: "native" },
|
|
},
|
|
{
|
|
profile: "native HTTP attached",
|
|
registration: {
|
|
url: "http://127.0.0.1:13337/mcp",
|
|
mode: "attached",
|
|
protocol: "native",
|
|
},
|
|
},
|
|
])(
|
|
"refuses $profile analysis whose recorded whole-file digest cannot identify the loaded slice",
|
|
async ({ registration }) => {
|
|
const { producer, session, opened } = await openUniversal(registration);
|
|
expect(opened).toMatchObject({
|
|
ok: false,
|
|
error: {
|
|
_tag: "ProviderSelectionError",
|
|
reason: "target_unsupported",
|
|
rejections: [
|
|
{
|
|
providerId: "ida",
|
|
code: "target_format_unsupported",
|
|
reason: expect.stringContaining("lipo -thin"),
|
|
},
|
|
],
|
|
},
|
|
});
|
|
expect(producer.connects).toBe(0);
|
|
expect((await session.close()).ok).toBe(true);
|
|
},
|
|
);
|
|
|
|
it("keeps admitting headless analysis, which thins the selected slice", async () => {
|
|
const { session, opened } = await openUniversal({
|
|
command: "fixture",
|
|
mode: "headless",
|
|
});
|
|
expect(opened.ok).toBe(true);
|
|
expect((await session.close()).ok).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe("IDA binary_overview execution", () => {
|
|
it("uses the bound IDA document and omits unsupported segment coverage", async () => {
|
|
const { root, target } = await createIdaTarget();
|
|
roots.push(root);
|
|
const path = join(root, "registration.json");
|
|
await writeFile(
|
|
path,
|
|
JSON.stringify({ command: "fixture", protocol: "native" }),
|
|
);
|
|
const config = parseConfig({ REA_IDA_MCP_CONFIG: path });
|
|
if (!config.ok) throw config.error;
|
|
const producer = new RecordingIdaMcp(target);
|
|
const session = createTestBinarySession(
|
|
new IdaProvider(config.value, {}, () => producer),
|
|
);
|
|
expect((await session.open(target.path)).ok).toBe(true);
|
|
const tools = new EnhancedTools(session);
|
|
const overview = await tools.execute("binary_overview", {});
|
|
expect(overview.ok).toBe(true);
|
|
if (overview.ok) {
|
|
expect(overview.value).toMatchObject({
|
|
document: target.path,
|
|
procedure_count: 1,
|
|
string_count: 1,
|
|
});
|
|
expect(overview.value).not.toHaveProperty("segments");
|
|
expect(overview.value).not.toHaveProperty("segment_count");
|
|
}
|
|
const procedures = await session.execute("list_procedures", {});
|
|
expect(procedures.ok).toBe(true);
|
|
expect((await session.close()).ok).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe("IDA database targets", () => {
|
|
const hexRaysSession = async () => {
|
|
const { root } = await createIdaTarget();
|
|
roots.push(root);
|
|
const registration = join(root, "registration.json");
|
|
await writeFile(
|
|
registration,
|
|
JSON.stringify({
|
|
command: "uvx",
|
|
args: ["ida-mcp", "stdio"],
|
|
mode: "headless",
|
|
protocol: "hexrays",
|
|
workspaceRoot: root,
|
|
}),
|
|
);
|
|
const config = parseConfig({ REA_IDA_MCP_CONFIG: registration });
|
|
if (!config.ok) throw config.error;
|
|
const bytes = Buffer.concat([
|
|
Buffer.from("IDA2", "latin1"),
|
|
Buffer.alloc(60, 7),
|
|
]);
|
|
const path = await realpath(root).then((dir) =>
|
|
join(dir, "target.exe.i64"),
|
|
);
|
|
await writeFile(path, bytes);
|
|
const target: BinaryTarget = {
|
|
path,
|
|
sha256: createHash("sha256").update(bytes).digest("hex"),
|
|
kind: "database",
|
|
format: "analysis-database",
|
|
databaseEngine: "ida",
|
|
};
|
|
const producer = new RecordingHexRaysIdaMcp(target);
|
|
producer.recordedInputPath = "/original/target.exe";
|
|
const provider = new IdaProvider(config.value, {}, () => producer);
|
|
return {
|
|
root,
|
|
path,
|
|
bytes,
|
|
target,
|
|
producer,
|
|
provider,
|
|
session: new BinarySession(
|
|
SessionProviderRouter.selectable(
|
|
new AnalysisProviderRegistry([provider]),
|
|
[],
|
|
),
|
|
),
|
|
};
|
|
};
|
|
|
|
it("analyzes a private database copy through idat and leaves the selected database unchanged", async () => {
|
|
const { root, path, bytes, target, producer, provider, session } =
|
|
await hexRaysSession();
|
|
producer.openBackend = "idat";
|
|
expect(
|
|
provider.inspectTargetSupport({
|
|
path: join(root, "sample.hop"),
|
|
sha256: "a".repeat(64),
|
|
kind: "database",
|
|
format: "analysis-database",
|
|
databaseEngine: "hopper",
|
|
}),
|
|
).toMatchObject({
|
|
status: "unsupported",
|
|
code: "target_format_unsupported",
|
|
});
|
|
// The registration protocol decides database support, so only the
|
|
// registration-aware check can admit an IDA database.
|
|
expect(provider.inspectTargetSupport(target)).toMatchObject({
|
|
status: "unknown",
|
|
});
|
|
expect(
|
|
await provider.inspectTargetSupportWithOptions(target, {}),
|
|
).toMatchObject({ status: "supported" });
|
|
|
|
const opened = await session.open(path, { providerId: "ida" });
|
|
expect(opened).toMatchObject({
|
|
ok: true,
|
|
value: { kind: "database", databaseEngine: "ida" },
|
|
});
|
|
const listed = await session.execute("list_procedures", {});
|
|
if (!listed.ok) throw listed.error;
|
|
expect(listed.value.limitations).toContain(IDA_DATABASE_TARGET_LIMITATION);
|
|
const open = producer.calls.find(({ name }) => name === "open_database");
|
|
expect(open?.args.path).not.toBe(path);
|
|
expect(String(open?.args.path).replaceAll("\\", "/")).toMatch(
|
|
/rea-ida-[^/]+\/target\.exe\.i64$/u,
|
|
);
|
|
|
|
expect((await session.close()).ok).toBe(true);
|
|
// The worker repacked only its private copy, which REA then removed.
|
|
expect(producer.leases.size).toBe(0);
|
|
expect((await readFile(path)).equals(bytes)).toBe(true);
|
|
expect(
|
|
(await readdir(root)).filter((name) => name.startsWith("rea-ida-")),
|
|
).toEqual([]);
|
|
});
|
|
|
|
it("refuses a signature-recognized database without the upstream filename suffix before opening it", async () => {
|
|
const { root, bytes, producer, session } = await hexRaysSession();
|
|
const path = join(root, "saved-database");
|
|
await writeFile(path, bytes);
|
|
|
|
const opened = await session.open(path, { providerId: "ida" });
|
|
expect(opened).toMatchObject({
|
|
ok: false,
|
|
error: {
|
|
_tag: "ProviderSelectionError",
|
|
rejections: [
|
|
{
|
|
providerId: "ida",
|
|
code: "target_format_unsupported",
|
|
reason: expect.stringContaining(".idb or .i64"),
|
|
},
|
|
],
|
|
},
|
|
});
|
|
expect(producer.calls).toEqual([]);
|
|
});
|
|
|
|
it("binds the database by its opened path, not the input it records", async () => {
|
|
const { path, producer, session } = await hexRaysSession();
|
|
expect((await session.open(path, { providerId: "ida" })).ok).toBe(true);
|
|
expect((await session.execute("list_procedures", {})).ok).toBe(true);
|
|
producer.reads.idbPath = "/elsewhere/other.i64";
|
|
const moved = await session.execute("list_procedures", {});
|
|
expect(moved.ok).toBe(false);
|
|
if (!moved.ok)
|
|
expect(moved.error.message).toContain("input identity changed");
|
|
await session.close();
|
|
});
|
|
});
|