refactor(provider): declare deep capabilities from source (#892)

This commit is contained in:
ysopwnable
2026-10-07 15:41:50 +08:00
committed by GitHub
parent 4037c6545d
commit b808e2d6bb
17 changed files with 220 additions and 133 deletions
+2 -6
View File
@@ -10,7 +10,7 @@ import {
CAPABILITIES,
windowsP0Capabilities,
} from "./GhidraProviderCapabilities.js";
import { HOPPER_PROVIDER_TOOL_CONTRACTS } from "../hopper/HopperProvider.js";
import { HOPPER_OPERATIONS } from "../hopper/HopperProvider.js";
const result = () => {
const dossier = functionDossierSchema.parse(ghidraFunctionDossier());
@@ -105,10 +105,6 @@ describe("Ghidra function annotations", () => {
(c) => c.operation === "annotate_native_function",
),
).toMatchObject({ available: false });
expect(
HOPPER_PROVIDER_TOOL_CONTRACTS.some(
(c) => c.name === "annotate_native_function",
),
).toBe(false);
expect(HOPPER_OPERATIONS).not.toContain("annotate_native_function");
});
});
+4 -4
View File
@@ -13,7 +13,7 @@ import type { BinaryTarget } from "../domain/binaryTarget.js";
import { createAnalysisProfile } from "../domain/analysisProfile.js";
import {
GHIDRA_PROVIDER_IDENTITY,
GHIDRA_PROVIDER_TOOL_CONTRACTS,
GHIDRA_OPERATIONS,
GhidraProvider,
type GhidraProviderClientFactory,
} from "./GhidraProvider.js";
@@ -140,9 +140,9 @@ describe("Ghidra provider", () => {
const ghidra = provider(host);
expect(ghidra.identity()).toEqual(GHIDRA_PROVIDER_IDENTITY);
expect(ghidra.capabilities().map(({ operation }) => operation)).toEqual(
GHIDRA_PROVIDER_TOOL_CONTRACTS.map(({ name }) => name),
);
expect(ghidra.capabilities().map(({ operation }) => operation)).toEqual([
...GHIDRA_OPERATIONS,
]);
expect(ghidra.capabilities()).toEqual(
expect.arrayContaining([
expect.objectContaining({
+2 -2
View File
@@ -34,7 +34,7 @@ import {
CAPABILITIES,
windowsP0Capabilities,
GHIDRA_PROVIDER_IDENTITY,
GHIDRA_PROVIDER_TOOL_CONTRACTS,
GHIDRA_OPERATIONS,
} from "./GhidraProviderCapabilities.js";
import {
createGhidraProviderClient,
@@ -46,7 +46,7 @@ import {
windowsNativeCapabilities,
} from "../process/WindowsAuthority.js";
export { GHIDRA_PROVIDER_IDENTITY, GHIDRA_PROVIDER_TOOL_CONTRACTS };
export { GHIDRA_PROVIDER_IDENTITY, GHIDRA_OPERATIONS };
export type { GhidraProviderClientFactory };
const SUPPORTED_ARCHITECTURES = new Set(["x86", "x86_64", "arm", "arm64"]);
+7 -25
View File
@@ -6,7 +6,6 @@ import {
hasWindowsNativeAuthority,
windowsNativeAuthorityUnavailableReason,
} from "../process/WindowsAuthority.js";
import { GENERATED_MCP_TOOL_CATALOG } from "../generatedMcpToolCatalog.js";
import { GHIDRA_FUNCTION_OPERATIONS } from "./GhidraFunctionValues.js";
import { GHIDRA_INVENTORY_OPERATIONS } from "./GhidraInventoryValues.js";
@@ -17,25 +16,11 @@ export const GHIDRA_PROVIDER_IDENTITY: ProviderIdentity = Object.freeze({
version: null,
});
const providerContractByName = new Map(
GENERATED_MCP_TOOL_CATALOG.filter(
({ kind }) => kind === "official-proxy" || kind === "enhanced",
).map((contract) => [contract.name, contract]),
);
/** Provider-neutral contracts implemented by the Ghidra adapter. */
export const GHIDRA_PROVIDER_TOOL_CONTRACTS = Object.freeze(
[...GHIDRA_INVENTORY_OPERATIONS, ...GHIDRA_FUNCTION_OPERATIONS].map(
(operation) => {
const contract = providerContractByName.get(operation);
if (contract === undefined)
throw new TypeError(
`Missing provider-neutral contract for ${operation}`,
);
return contract;
},
),
);
/** Analyst operations implemented by the Ghidra inventory and function adapters. */
export const GHIDRA_OPERATIONS = Object.freeze([
...GHIDRA_INVENTORY_OPERATIONS,
...GHIDRA_FUNCTION_OPERATIONS,
]);
/** Health limitations shared by every Ghidra-backed capability. */
export const healthLimitations = Object.freeze([
@@ -157,10 +142,7 @@ export const limitationsFor = (operation: string): readonly string[] => {
/** Provider-neutral capabilities advertised by every non-Windows Ghidra session. */
export const CAPABILITIES: readonly CapabilityDescriptor[] = Object.freeze(
GHIDRA_PROVIDER_TOOL_CONTRACTS.map((contract) => {
const operation = contract.analysisOperation;
if (operation === null)
throw new TypeError(`Missing analysis operation for ${contract.name}`);
GHIDRA_OPERATIONS.map((operation) => {
return Object.freeze({
provider: GHIDRA_PROVIDER_IDENTITY,
operation,
@@ -175,7 +157,7 @@ export const CAPABILITIES: readonly CapabilityDescriptor[] = Object.freeze(
changesPermissions: false,
requiresRoot: false,
}),
limitations: Object.freeze(limitationsFor(contract.name)),
limitations: Object.freeze(limitationsFor(operation)),
});
}),
);