Files
reverse-engineering-anything/src/contracts/reverseEngineeringToolContracts.ts
T
morluto 402ce20b80 fix(session): declare, admit and advertise the open-target prerequisite through one owner (#15356)
* fix(contracts): declare the open-target prerequisite once in availability

Replace the requiresActiveTarget boolean with an "active-target" value of the
availability declaration. 18 contracts that read a required caller path, all
declared standalone or host-restricted or named inventory rules, no longer
claim to need an open target.

* fix(session): admit tools through one session evaluator shared with binary_session

binary_session availability and call-time dispatch now read one admission
evaluator for active-target tools and external mutations. Resource-only
lane refusals and Ghidra or resource-only external-mutation refusals carry
the open_binary or close_binary recovery that binary_session reports,
instead of a generic capability or unreadable-output error. Packet
capture, Wakaru, firmware and mitmproxy refuse an unsupported host before
reading tool configuration.

* fix(mcp): advertise the open-target prerequisite and name open_binary on first contact

Each active-target tool's advertised description ends with one sentence
derived from its availability declaration. When the SDK refuses such a
tool's arguments while the session would also refuse it, the
invalid_request remediation names the session recovery first, read from
the same admission evaluator as binary_session and dispatch.

* fix(mcp): refuse composed workflows as a whole and keep scoped recovery and catalog identity in step

A composed workflow such as batch_decompile now refuses with the
advertised open_binary or close_binary recovery before it runs, instead of
reporting a batch of failed children. Malformed arguments on a connection
that does not advertise session tools lead with the scoped restart
recovery, and catalog digests cover the advertised prerequisite sentence.
The prerequisite test reads union alternatives.
2026-12-01 03:55:48 +00:00

73 lines
4.5 KiB
TypeScript

import { commandObservationSchema } from "../domain/commandObservation.js";
import { objdumpSummaryViewResultSchema } from "../domain/analysisView/summarySchemas/objdumpSummarySchema.js";
import {
objdumpInputSchema,
rizinInputSchema,
} from "../domain/reverseEngineering.js";
import type { ToolContract } from "./toolContractTypes.js";
import { evidenceResultOf } from "./toolOutputSchemaPrimitives.js";
import { analysisDetailOutputSchemaOf } from "./analysisDetail.js";
import { toolContractMetadata, toolEffects } from "./toolEffects.js";
/** Caller-selected GNU objdump and Rizin observations. */
export const REVERSE_ENGINEERING_TOOL_CONTRACTS = [
{
name: "inspect_with_objdump",
cli: true,
...toolContractMetadata(
"inspect_with_objdump",
toolEffects({
mutatesSession: true,
launchesProcess: true,
}),
),
kind: "native-provider",
description:
"Inspect a local artifact with caller-selected objdump and GNU-style arguments; the executable implementation/version is unverified. operation disassemble optionally scopes to symbol; omission selects all code sections. operation architectures needs no path and captures -i output without establishing artifact support. Returns authoritative stdout/stderr and artifact SHA-256, with lossy UTF-8 and truncation explicit; there is no stable normalized disassembly format. DWARF debug links are off unless follow_debug_links true; external file identities remain unbound. DEBUGINFOD_URLS is cleared to prevent debuginfod requests. Omitted detail returns Evidence within the agent result budget, else the retained summary; summary retains it and returns one command observation for later inspect_analysis_view/export via parent_evidence_id. command_timeout_ms bounds each phase; max_output_bytes independently bounds combined output (16 MiB default). Both apply next call without restart; truncation termination leaves completion unknown, and raising output does not raise client receive limits.",
inputSchema: objdumpInputSchema,
outputSchema: analysisDetailOutputSchemaOf(
commandObservationSchema,
objdumpSummaryViewResultSchema,
),
examples: [
{
title: "Disassemble code sections",
input: { path: "/tmp/program", operation: "disassemble" },
},
{
title: "List advertised BFD targets",
input: { operation: "architectures" },
},
],
},
{
name: "execute_rizin_command",
cli: true,
...toolContractMetadata(
"execute_rizin_command",
toolEffects({
mutatesTarget: true,
mutatesSession: true,
writesFilesystem: true,
launchesProcess: true,
accessesNetwork: true,
mayDiscardData: true,
executesForeignCode: true,
idempotent: false,
}),
),
kind: "native-provider",
description:
"Run one caller-selected Rizin command on a local artifact. Commands/plugins can execute code, mutate files, access network and read outside the artifact; those external inputs are not Evidence-bound. Suppresses user settings/scripts but retains plugins. Raw stdout/stderr is authoritative, JSON is command-specific, and UTF-8 loss/truncation is explicit; output-limit termination leaves completion unknown. Rizin exits 0 even when its shell refuses a statement; completion_status rejected marks that refusal, and later statements did not run. Other command failures can still exit 0, so inspect stderr before treating empty output as absence. Before each command REA also runs the selected executable with -v; provider.name/version come from its banner and can name another tool REA_RIZIN_COMMAND selected, such as radare2, or are assumed without an identifying banner (provider_identity). For raw images, asm_arch/asm_bits/asm_cpu select decoding and base_address maps offset 0; base_address also passes -n to skip loaders even on ELF, without REA confirming either. An admitted command retires shared binary analysis: call close_binary first if Ghidra or a resource-only session is active, then open_binary after effects settle. command_timeout_ms is per-phase and max_output_bytes bounds combined output (16 MiB default); both apply next call without restart and do not raise client receive limits or persistent debugger deadlines.",
inputSchema: rizinInputSchema,
outputSchema: evidenceResultOf(commandObservationSchema),
examples: [
{
title: "Inspect binary information",
input: { path: "/tmp/program", command: "iI" },
},
],
},
] as const satisfies readonly ToolContract[];