refactor(provider): declare deep capabilities from source (#892)
This commit is contained in:
@@ -2,10 +2,7 @@ import { describe, expect, it } from "vitest";
|
||||
|
||||
import { parseConfig } from "../config.js";
|
||||
import { silentLogger } from "../logger.js";
|
||||
import {
|
||||
HopperProvider,
|
||||
HOPPER_PROVIDER_TOOL_CONTRACTS,
|
||||
} from "./HopperProvider.js";
|
||||
import { HopperProvider, HOPPER_OPERATIONS } from "./HopperProvider.js";
|
||||
|
||||
describe("Hopper provider capabilities", () => {
|
||||
it("declines DOS MZ targets with a provider-specific support reason", () => {
|
||||
@@ -35,9 +32,9 @@ describe("Hopper provider capabilities", () => {
|
||||
const provider = new HopperProvider(config.value, silentLogger);
|
||||
const capabilities = provider.capabilities();
|
||||
const published = structuredClone(capabilities);
|
||||
expect(capabilities.map(({ operation }) => operation)).toEqual(
|
||||
HOPPER_PROVIDER_TOOL_CONTRACTS.map(({ name }) => name),
|
||||
);
|
||||
expect(capabilities.map(({ operation }) => operation)).toEqual([
|
||||
...HOPPER_OPERATIONS,
|
||||
]);
|
||||
expect(new Set(capabilities.map(({ operation }) => operation)).size).toBe(
|
||||
capabilities.length,
|
||||
);
|
||||
|
||||
@@ -18,7 +18,6 @@ import type { BinaryTarget } from "../domain/binaryTarget.js";
|
||||
import type { Logger } from "../logger.js";
|
||||
import { AnalysisCapabilityUnavailableError } from "../domain/analysisErrorCore.js";
|
||||
import { err } from "../domain/result.js";
|
||||
import { GENERATED_MCP_TOOL_CATALOG } from "../generatedMcpToolCatalog.js";
|
||||
import { HopperApplicationLauncher } from "./BridgeLauncher.js";
|
||||
import {
|
||||
hopperLoaderArgsForTarget,
|
||||
@@ -26,63 +25,17 @@ import {
|
||||
} from "./HopperAnalysisProfile.js";
|
||||
import { HopperClient } from "./HopperClient.js";
|
||||
|
||||
/** Public identity committed by every Hopper-backed observation. */
|
||||
export const HOPPER_PROVIDER_IDENTITY: ProviderIdentity = Object.freeze({
|
||||
id: "hopper",
|
||||
name: "Hopper Disassembler",
|
||||
version: null,
|
||||
});
|
||||
import {
|
||||
CAPABILITIES,
|
||||
HOPPER_PROVIDER_IDENTITY,
|
||||
} from "./HopperProviderCapabilities.js";
|
||||
|
||||
export {
|
||||
HOPPER_PROVIDER_IDENTITY,
|
||||
HOPPER_OPERATIONS,
|
||||
} from "./HopperProviderCapabilities.js";
|
||||
|
||||
const IDENTITY = HOPPER_PROVIDER_IDENTITY;
|
||||
const MUTATING_OPERATIONS = new Set([
|
||||
"set_address_name",
|
||||
"set_addresses_names",
|
||||
"set_bookmark",
|
||||
"set_comment",
|
||||
"set_inline_comment",
|
||||
"unset_bookmark",
|
||||
]);
|
||||
|
||||
/** Tool contracts implemented directly by the Hopper adapter. */
|
||||
export const HOPPER_PROVIDER_TOOL_CONTRACTS = Object.freeze([
|
||||
...GENERATED_MCP_TOOL_CATALOG.filter(
|
||||
({ kind, name }) =>
|
||||
kind === "official-proxy" &&
|
||||
name !== "annotate_native_function" &&
|
||||
name !== "inspect_native_load_image" &&
|
||||
name !== "inspect_native_data_type" &&
|
||||
name !== "inspect_native_instruction" &&
|
||||
name !== "resolve_native_call_targets",
|
||||
),
|
||||
...GENERATED_MCP_TOOL_CATALOG.filter(
|
||||
({ name }) => name === "analyze_function",
|
||||
),
|
||||
]);
|
||||
|
||||
const CAPABILITIES: readonly CapabilityDescriptor[] = Object.freeze(
|
||||
HOPPER_PROVIDER_TOOL_CONTRACTS.map((contract) => {
|
||||
const operation = contract.analysisOperation;
|
||||
if (operation === null)
|
||||
throw new TypeError(`Missing analysis operation for ${contract.name}`);
|
||||
return Object.freeze({
|
||||
provider: IDENTITY,
|
||||
operation,
|
||||
available: true,
|
||||
reason: null,
|
||||
effects: Object.freeze({
|
||||
mutatesArtifact: MUTATING_OPERATIONS.has(contract.name),
|
||||
launchesProcess: true,
|
||||
mayShowUi: true,
|
||||
mayAccessNetwork: false,
|
||||
mayWriteFilesystem: MUTATING_OPERATIONS.has(contract.name),
|
||||
changesPermissions: false,
|
||||
requiresRoot: false,
|
||||
}),
|
||||
limitations: Object.freeze([
|
||||
"Results depend on Hopper's completed static analysis.",
|
||||
]),
|
||||
});
|
||||
}),
|
||||
);
|
||||
|
||||
/** Concrete analysis provider backed by REA's private Hopper bridge. */
|
||||
export class HopperProvider implements AnalysisProviderCandidate {
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
import type {
|
||||
CapabilityDescriptor,
|
||||
ProviderIdentity,
|
||||
} from "../application/AnalysisProvider.js";
|
||||
import type { OfficialToolName } from "../contracts/officialToolContracts.js";
|
||||
|
||||
/** Public identity committed by every Hopper-backed observation. */
|
||||
export const HOPPER_PROVIDER_IDENTITY: ProviderIdentity = Object.freeze({
|
||||
id: "hopper",
|
||||
name: "Hopper Disassembler",
|
||||
version: null,
|
||||
});
|
||||
|
||||
/** Analyst operations implemented by REA's private Hopper bridge. */
|
||||
export const HOPPER_OPERATIONS = Object.freeze([
|
||||
"address_name",
|
||||
"comment",
|
||||
"current_address",
|
||||
"current_procedure",
|
||||
"current_document",
|
||||
"goto_address",
|
||||
"inline_comment",
|
||||
"list_bookmarks",
|
||||
"list_documents",
|
||||
"list_names",
|
||||
"list_procedures",
|
||||
"list_segments",
|
||||
"list_strings",
|
||||
"next_address",
|
||||
"prev_address",
|
||||
"procedure_address",
|
||||
"procedure_assembly",
|
||||
"procedure_callees",
|
||||
"procedure_callers",
|
||||
"procedure_info",
|
||||
"read_function_instructions",
|
||||
"read_bytes",
|
||||
"address_to_file_offset",
|
||||
"procedure_references",
|
||||
"procedure_pseudo_code",
|
||||
"resolve_containing_procedure",
|
||||
"search_procedures",
|
||||
"search_strings",
|
||||
"set_address_name",
|
||||
"set_addresses_names",
|
||||
"set_bookmark",
|
||||
"set_comment",
|
||||
"set_current_document",
|
||||
"set_inline_comment",
|
||||
"unset_bookmark",
|
||||
"xrefs",
|
||||
"analyze_function",
|
||||
] as const satisfies readonly (OfficialToolName | "analyze_function")[]);
|
||||
|
||||
const MUTATING_OPERATIONS = new Set<string>([
|
||||
"set_address_name",
|
||||
"set_addresses_names",
|
||||
"set_bookmark",
|
||||
"set_comment",
|
||||
"set_inline_comment",
|
||||
"unset_bookmark",
|
||||
]);
|
||||
|
||||
/** Source-owned capabilities without acquiring or probing a Hopper session. */
|
||||
export const CAPABILITIES: readonly CapabilityDescriptor[] = Object.freeze(
|
||||
HOPPER_OPERATIONS.map((operation) =>
|
||||
Object.freeze({
|
||||
provider: HOPPER_PROVIDER_IDENTITY,
|
||||
operation,
|
||||
available: true,
|
||||
reason: null,
|
||||
effects: Object.freeze({
|
||||
mutatesArtifact: MUTATING_OPERATIONS.has(operation),
|
||||
launchesProcess: true,
|
||||
mayShowUi: true,
|
||||
mayAccessNetwork: false,
|
||||
mayWriteFilesystem: MUTATING_OPERATIONS.has(operation),
|
||||
changesPermissions: false,
|
||||
requiresRoot: false,
|
||||
}),
|
||||
limitations: Object.freeze([
|
||||
"Results depend on Hopper's completed static analysis.",
|
||||
]),
|
||||
}),
|
||||
),
|
||||
);
|
||||
Reference in New Issue
Block a user