mirror of
https://github.com/morluto/rea.git
synced 2026-12-06 14:59:05 +00:00
* feat(managed): describe the protobuf descriptor recovery report and its budget Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com> * feat(managed): recover protobuf descriptors from generated Reflection classes Google.Protobuf's generated <File>Reflection classes build each FileDescriptorProto in a static constructor that concatenates string literals and passes them to System.Convert.FromBase64String. Read those literals from the CIL in order, decode each site and keep the results that parse as FileDescriptorProtos, byte for byte. A FileDescriptorSet lists them dependencies first, with the well-known protobuf files they import; other imports are named as missing. Literal characters count against max_descriptor_bytes before they are joined. Nothing is loaded or run. Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com> * fix(managed): report descriptor recovery refusals as parse failures A metadata representation budget stops the whole call as a named limit, including inside one static constructor; other managed reader refusals become malformed or unsupported input. Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com> * feat(managed): recover protobuf descriptors through an identity-checked provider The provider reads one bounded managed assembly. A refusal at max_descriptor_bytes, max_metadata_representation_bytes or max_snapshot_bytes names the control to raise. Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com> * feat(analysis): summarize retained protobuf descriptor recovery Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com> * feat(managed): add the recover_protobuf_descriptors tool CLI recover-protobuf-descriptors and MCP recover_protobuf_descriptors return each embedded .proto file's package, imports, messages, enums and services, and a FileDescriptorSet for decoding captured payloads. Large reports return the retained per-file summary within the agent budget. Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com> * test(managed): cover protobuf descriptor recovery through the service, MCP and CLI The protoc-style assembly fixture moves to tests/fixtures so the unit, MCP and CLI tests share it. Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com> * docs(managed): describe protobuf descriptor recovery Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com> * docs(skill): route Google.Protobuf assemblies to recover_protobuf_descriptors Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com> * ci: scope protobuf descriptor recovery with the managed formats Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com> * chore(schemas): record the advertised recover_protobuf_descriptors catalog summary Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com> * fix(managed): attribute, bound and account for every descriptor search - Static constructors are found among physical MethodDef rows and named by the shared ownership lookup, so a MethodPtr table cannot attribute a descriptor to the wrong type. - A FileDescriptorProto's wire form is walked along its schema first, and every nested message it would create is charged to the representation budget before protobuf-es decodes it. - A body whose CIL was not fully decoded, and malformed member lists, make coverage partial instead of looking searched. Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com> * test(managed): build descriptor fixtures in protoc's String.Concat shapes The fixture's static constructor now joins its literals through String.Concat, as arguments or a string[], before calling FromBase64String with its real static byte[](string) signature; the managed PE fixture can name each MemberRef row. Tests cover both forms and the descriptor tree bound. Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com> * fix(analysis): sample missing imports in the protobuf descriptor summary Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com> * docs(managed): save the descriptor set from complete delivery and fail on null Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com> * fix(managed): name the descriptor nesting limit instead of rejecting deep files The nesting cutoff is now the max_descriptor_depth control (100 by default, up to 1,000). A deeper descriptor stops the call with a named limit rather than being listed as not a descriptor, and protobuf-es decodes up to the same depth so it cannot refuse what the walk admitted. Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com> * docs(managed): list the descriptor depth budget and record its schema Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com> --------- Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
699 lines
23 KiB
TypeScript
699 lines
23 KiB
TypeScript
import {
|
|
createCapabilityServices,
|
|
type CapabilityServiceOptions,
|
|
} from "../composition/capabilityServices.js";
|
|
import { HOST_PLATFORM, type HostPlatform } from "../platform/HostPlatform.js";
|
|
import {
|
|
isToolFamilyAdvertised,
|
|
registerToolFamilies,
|
|
} from "../contracts/toolFamilyIds.js";
|
|
import { toolFamilyId } from "../contracts/toolFamilies.js";
|
|
import { SCOPED_NO_TARGET_RECOVERY } from "./recoveryInstructions.js";
|
|
import { AnalysisSettings } from "../application/AnalysisSettings.js";
|
|
import { parseMcpInputBudget } from "../config/mcpInputBudget.js";
|
|
import { parseMcpToolsListPageBudget } from "../config/mcpToolsListPageBudget.js";
|
|
import { serverInstructions } from "./serverInstructions.js";
|
|
import {
|
|
registerServiceTools,
|
|
type ToolServices,
|
|
} from "./serviceToolBindings.js";
|
|
import {
|
|
artifactAnalysisForAdmission,
|
|
artifactExecutionParameters,
|
|
managedAnalysisForAdmission,
|
|
} from "./providerOperationFamilies.js";
|
|
import { OFFICIAL_TOOL_CONTRACTS } from "../contracts/officialToolContracts.js";
|
|
import { NATIVE_TOOL_CONTRACTS } from "../contracts/native/nativeToolContracts.js";
|
|
import { ARTIFACT_TOOL_CONTRACTS } from "../contracts/artifactToolContracts.js";
|
|
import { MANAGED_TOOL_CONTRACTS } from "../contracts/managed/managedToolContracts.js";
|
|
import { promptsForToolFamilies } from "../contracts/promptToolFamilyScope.js";
|
|
import { retainedDebuggerDiagnostics } from "../process/ownedDebuggerCleanupError.js";
|
|
import { snapshotEnvironment } from "../process/snapshotEnvironment.js";
|
|
import { createByteEntropyService } from "../composition/binaryDiagnostics/byteEntropy.js";
|
|
import { FridaInstrumentationService } from "../application/frida/FridaInstrumentationService.js";
|
|
import { EvidenceMcpServer } from "./EvidenceMcpServer.js";
|
|
import { catalogIdentityForToolFamilies } from "../contracts/catalog/catalogIdentity.js";
|
|
import { parseMcpToolFamilies } from "../config/mcpToolFamilies.js";
|
|
import { parseMcpToolCatalogProfile } from "../config/mcpToolCatalogProfile.js";
|
|
import { createToolResultDelivery } from "./toolResult.js";
|
|
import type { ToolResultDelivery } from "./ToolResultDelivery.js";
|
|
import { parseMcpResponseBudget } from "../config/mcpResponseBudget.js";
|
|
import { parseMcpOutputSchemaProfile } from "../config/mcpOutputSchemaProfile.js";
|
|
import { parseMcpInputSchemaProfile } from "../config/mcpInputSchemaProfile.js";
|
|
import type { CompactInputSchemaPresentation } from "../contracts/compactInputSchema.js";
|
|
import type {
|
|
BinarySessionPort,
|
|
ManagedBinarySessionPort,
|
|
} from "../application/binary/BinarySessionPort.js";
|
|
import { PRODUCT_IDENTITY } from "../identity.js";
|
|
import { silentLogger } from "../logger.js";
|
|
import type { Logger } from "pino";
|
|
import { JavaScriptRecoveryService } from "../application/javascript/JavaScriptRecoveryService.js";
|
|
import { AndroidAnalysisService } from "../application/android/AndroidAnalysisService.js";
|
|
import {
|
|
createJebAnalysisService,
|
|
createPcapAnalysisService,
|
|
createApktoolResourceAnalysisService,
|
|
createFlutterBuildAnalysisService,
|
|
} from "../application/ProviderOperationServices.js";
|
|
import { AdbDeviceAnalysisService } from "../application/adb/AdbDeviceAnalysisService.js";
|
|
import { registerGuidedPrompts } from "./registerPrompts.js";
|
|
import { registerSessionTools } from "./registerSessionTools.js";
|
|
import type { AvailabilityPolicy } from "../application/CapabilityInventory.js";
|
|
import { sessionAvailabilityPolicy } from "./sessionAvailabilityPolicy.js";
|
|
import {
|
|
withAdmittedAnalysis,
|
|
toolAdmission,
|
|
type ServerAnalysisSource,
|
|
} from "./analysisAdmission.js";
|
|
import {
|
|
resolveMcpOutputSchemaProfile,
|
|
type McpOutputSchemaProfile,
|
|
COMPACT_INPUT_SCHEMA_PRESENTATION,
|
|
} from "../contracts/mcpSchemaPresentation.js";
|
|
import { errorMessage } from "../kernel/errorMessage.js";
|
|
|
|
export interface CreateServerOptions extends CapabilityServiceOptions {
|
|
readonly analysisSettings?: AnalysisSettings;
|
|
/** Preserve the connection's creation time when materializing its runtime. */
|
|
readonly startedAt?: string;
|
|
/** Existing SDK server whose deferred registrations are being materialized. */
|
|
readonly mcpServer?: EvidenceMcpServer;
|
|
readonly environment?: Readonly<NodeJS.ProcessEnv>;
|
|
readonly delivery?: ToolResultDelivery;
|
|
readonly providerEnvironment?: Readonly<NodeJS.ProcessEnv>;
|
|
readonly logger?: Logger;
|
|
readonly availabilityPolicy?: () => AvailabilityPolicy;
|
|
readonly createManagedBinarySession?: () =>
|
|
| ManagedBinarySessionPort
|
|
| Promise<ManagedBinarySessionPort>;
|
|
/**
|
|
* The host the server's integrations run on: it decides environment-name
|
|
* rules, host-restricted availability and execution checks. Defaults to the
|
|
* running host; tests select another host here.
|
|
*/
|
|
readonly host?: HostPlatform;
|
|
}
|
|
|
|
const createMcpServer = (
|
|
session: BinarySessionPort | undefined,
|
|
delivery: ToolResultDelivery,
|
|
compactPresentation: CompactInputSchemaPresentation,
|
|
outputSchemaProfile: McpOutputSchemaProfile,
|
|
advertisedToolFamilies: ReadonlySet<string> | undefined,
|
|
inputElementBudget: string | undefined,
|
|
toolsListPageBudget: string | undefined,
|
|
): EvidenceMcpServer => {
|
|
const configured = parseMcpInputBudget(inputElementBudget);
|
|
if (!configured.ok) throw configured.error;
|
|
const pageBudget = parseMcpToolsListPageBudget(toolsListPageBudget);
|
|
if (!pageBudget.ok) throw pageBudget.error;
|
|
return new EvidenceMcpServer(
|
|
{
|
|
name: PRODUCT_IDENTITY.mcpServerKey,
|
|
version: PRODUCT_IDENTITY.packageVersion,
|
|
},
|
|
{
|
|
capabilities: {},
|
|
maxToolInputElements: configured.value,
|
|
instructions: serverInstructions(session !== undefined, (tool) =>
|
|
isToolFamilyAdvertised(advertisedToolFamilies, toolFamilyId(tool)),
|
|
),
|
|
},
|
|
session === undefined
|
|
? undefined
|
|
: (evidence) => session.recordEvidence(evidence),
|
|
delivery,
|
|
compactPresentation,
|
|
outputSchemaProfile,
|
|
catalogIdentityForToolFamilies(
|
|
compactPresentation,
|
|
outputSchemaProfile,
|
|
advertisedToolFamilies,
|
|
),
|
|
advertisedToolFamilies,
|
|
pageBudget.value,
|
|
);
|
|
};
|
|
|
|
/** A scoped connection without session tools cannot open a target itself. */
|
|
const scopedNoTargetRecovery = (
|
|
hasSession: boolean,
|
|
advertisedToolFamilies: ReadonlySet<string> | undefined,
|
|
): string | undefined =>
|
|
hasSession &&
|
|
advertisedToolFamilies !== undefined &&
|
|
!advertisedToolFamilies.has("session")
|
|
? SCOPED_NO_TARGET_RECOVERY
|
|
: undefined;
|
|
|
|
/**
|
|
* Construct one MCP server without acquiring subprocess resources.
|
|
* Supplying a session adds target lifecycle tools; omitting it retains the
|
|
* fixed-target seam used by focused tests and embedders.
|
|
*/
|
|
export const createServer = (
|
|
source: ServerAnalysisSource,
|
|
options: CreateServerOptions = {},
|
|
): EvidenceMcpServer => {
|
|
const session = source.kind === "session" ? source.session : undefined;
|
|
const analysis = source.kind === "session" ? source.session : source.analysis;
|
|
const host = options.host ?? HOST_PLATFORM;
|
|
const environment = snapshotEnvironment(
|
|
options.environment ?? process.env,
|
|
host.platform,
|
|
);
|
|
const analysisSettings =
|
|
options.analysisSettings ?? new AnalysisSettings(environment);
|
|
const compactInputPresentation =
|
|
selectCompactInputSchemaPresentation(environment);
|
|
const selectedOutputSchemaProfile = outputSchemaProfile(environment);
|
|
const catalogProfile = parseMcpToolCatalogProfile(
|
|
environment.REA_MCP_TOOL_CATALOG_PROFILE,
|
|
);
|
|
if (!catalogProfile.ok) throw catalogProfile.error;
|
|
const advertisedToolFamilies = selectAdvertisedToolFamilies(environment);
|
|
const providerEnvironment = snapshotEnvironment(
|
|
options.providerEnvironment ?? environment,
|
|
host.platform,
|
|
);
|
|
const baseDelivery = selectToolResultDelivery(environment, options.delivery);
|
|
const noTargetRecovery = scopedNoTargetRecovery(
|
|
session !== undefined,
|
|
advertisedToolFamilies,
|
|
);
|
|
const delivery =
|
|
noTargetRecovery === undefined
|
|
? baseDelivery
|
|
: baseDelivery.withNoTargetRecovery(noTargetRecovery);
|
|
const capabilities = createCapabilityServices({
|
|
environment,
|
|
providerEnvironment,
|
|
settings: analysisSettings.read,
|
|
options,
|
|
platform: host.platform,
|
|
arch: host.architecture,
|
|
});
|
|
const {
|
|
evmInterface,
|
|
sqliteDatabase,
|
|
binaryLayout,
|
|
recordedCrash,
|
|
webSourceLocation,
|
|
webModuleTrace,
|
|
desktopApplication,
|
|
desktopBuildComputers,
|
|
goBinary,
|
|
rustBinary,
|
|
erlangBeam,
|
|
v8CodeCache,
|
|
modelArtifact,
|
|
gpuCodeObjects,
|
|
il2cppMetadata,
|
|
peResources,
|
|
uniffiLibrary,
|
|
labviewArtifact,
|
|
nativeExports,
|
|
devicetree,
|
|
espNvs,
|
|
firmwareMmio,
|
|
firmwareVectorTable,
|
|
elfNotes,
|
|
elfDebugLink,
|
|
nativeInitializers,
|
|
elfUnwindRanges,
|
|
appleIps,
|
|
kernelModule,
|
|
kernelBuildConfig,
|
|
peLoadConfig,
|
|
peUnwindRanges,
|
|
machoFunctionStarts,
|
|
peOverlay,
|
|
binaryHardening,
|
|
peCertificates,
|
|
peImports,
|
|
windowsShortcut,
|
|
firmwareArchitectureCandidates,
|
|
electronFuses,
|
|
releaseExposure,
|
|
nugetNupkg,
|
|
vsixPackage,
|
|
ociImageLayout,
|
|
yaraMatches,
|
|
pythonPyc,
|
|
baml,
|
|
protobufDescriptors,
|
|
debPackage,
|
|
mavenGradleMetadata,
|
|
dwarfUnits,
|
|
nativeToolchain,
|
|
elfDependencies,
|
|
webNetworkCapture,
|
|
javascriptRecovery,
|
|
artifactResources,
|
|
reverseEngineering,
|
|
uefiAnalysis,
|
|
firmwareAnalysis,
|
|
gdbSessions,
|
|
rizinDebugSessions,
|
|
android,
|
|
pcap,
|
|
flutter,
|
|
fridaInstrumentation,
|
|
wasmArtifact,
|
|
apkSignature,
|
|
packetCapture,
|
|
signalRecording,
|
|
webRuntime,
|
|
apktool,
|
|
jeb,
|
|
adbDevice,
|
|
cutter,
|
|
} = capabilities.services;
|
|
const startedAt = options.startedAt ?? new Date().toISOString();
|
|
const logger = options.logger ?? silentLogger;
|
|
const server =
|
|
options.mcpServer ??
|
|
createMcpServer(
|
|
session,
|
|
delivery,
|
|
compactInputPresentation,
|
|
selectedOutputSchemaProfile,
|
|
advertisedToolFamilies,
|
|
environment.REA_MCP_MAX_INPUT_ELEMENTS,
|
|
environment.REA_MCP_TOOLS_LIST_PAGE_BYTES,
|
|
);
|
|
server.analysisSettings = analysisSettings;
|
|
if (options.mcpServer !== undefined) {
|
|
server.attachRuntime(
|
|
session === undefined
|
|
? undefined
|
|
: (evidence) => session.recordEvidence(evidence),
|
|
delivery,
|
|
catalogIdentityForToolFamilies(
|
|
compactInputPresentation,
|
|
selectedOutputSchemaProfile,
|
|
advertisedToolFamilies,
|
|
),
|
|
);
|
|
}
|
|
const closeProviders = capabilities.close;
|
|
const availability =
|
|
session === undefined
|
|
? undefined
|
|
: (() => {
|
|
const basePolicy = sessionAvailabilityPolicy(
|
|
options.availabilityPolicy,
|
|
{
|
|
...capabilities.availability,
|
|
observeOptionalFeatures: () =>
|
|
server.advertisesFamily("artifact")
|
|
? capabilities.observeOptionalFeatures()
|
|
: {},
|
|
optionalProviderLoadFailures:
|
|
options.optionalProviderLoadFailures,
|
|
},
|
|
host.platform,
|
|
);
|
|
return {
|
|
policy: (): AvailabilityPolicy => {
|
|
const value = basePolicy();
|
|
const failures = capabilities.observeProviderLoadFailures();
|
|
const commandFailures =
|
|
capabilities.observeCommandProviderFailures();
|
|
const hasFailures = Object.keys(failures).length > 0;
|
|
const hasCommandFailures =
|
|
Object.keys(commandFailures).length > 0;
|
|
if (!hasFailures && !hasCommandFailures) return value;
|
|
return {
|
|
...value,
|
|
...(hasFailures
|
|
? {
|
|
optionalProviderLoadFailures: {
|
|
...value.optionalProviderLoadFailures,
|
|
...failures,
|
|
},
|
|
}
|
|
: {}),
|
|
...(hasCommandFailures
|
|
? {
|
|
commandProviderFailures: {
|
|
...value.commandProviderFailures,
|
|
...commandFailures,
|
|
},
|
|
}
|
|
: {}),
|
|
};
|
|
},
|
|
};
|
|
})();
|
|
const toolLogger = logger.child({ layer: "server" });
|
|
const {
|
|
evidenceById,
|
|
activeTarget,
|
|
recordEvidence,
|
|
recordEvidenceWithUnknown,
|
|
} = createSessionRecorders(server, session);
|
|
// Over-budget summaries link the complete record they replaced.
|
|
if (evidenceById !== undefined) server.serveRetainedEvidence(evidenceById);
|
|
const analysisAdmission = withAdmittedAnalysis(source);
|
|
server.withAdmittedAnalysis = analysisAdmission;
|
|
server.toolAdmission = toolAdmission(source, noTargetRecovery);
|
|
server.registerTransportCloseHook(() => {
|
|
void closeProviders().catch((cause: unknown) => {
|
|
logger.error(
|
|
{
|
|
error: errorMessage(cause),
|
|
...retainedDebuggerDiagnostics(cause),
|
|
},
|
|
"Provider cleanup failed during server shutdown",
|
|
);
|
|
});
|
|
});
|
|
server.registerCloseHook(closeProviders, {
|
|
failureMessage: "REA server cleanup failed",
|
|
});
|
|
const contractTools = {
|
|
logger: toolLogger,
|
|
recordEvidence,
|
|
recordEvidenceWithUnknown,
|
|
withAdmittedAnalysis: analysisAdmission,
|
|
evidenceById,
|
|
};
|
|
const registerServices = (services: Partial<ToolServices>): void =>
|
|
registerServiceTools(server, services, contractTools);
|
|
const javascriptRecoveryService = new JavaScriptRecoveryService(
|
|
javascriptRecovery,
|
|
);
|
|
registerToolFamilies({
|
|
direct: () =>
|
|
registerServices({
|
|
providerOperations: {
|
|
contracts: OFFICIAL_TOOL_CONTRACTS,
|
|
activeTarget,
|
|
...(session === undefined
|
|
? {}
|
|
: {
|
|
admitRecovery: session.admitRecoveryObservation.bind(session),
|
|
}),
|
|
},
|
|
}),
|
|
enhanced: () => registerServices({ enhancedWorkflows: { session } }),
|
|
native: () => {
|
|
registerServices({
|
|
providerOperations: {
|
|
contracts: NATIVE_TOOL_CONTRACTS,
|
|
activeTarget,
|
|
},
|
|
});
|
|
registerServices({
|
|
reverseEngineering: { service: reverseEngineering, session },
|
|
});
|
|
registerServiceTools(
|
|
server,
|
|
{
|
|
cutter: { service: cutter, session },
|
|
gdb: { manager: gdbSessions, session },
|
|
rizinDebug: { manager: rizinDebugSessions, session },
|
|
},
|
|
{ logger: toolLogger, recordEvidence, evidenceById },
|
|
);
|
|
registerServices({
|
|
binaryLayout,
|
|
byteEntropy: createByteEntropyService(artifactResources),
|
|
peResources,
|
|
uniffiLibrary,
|
|
labviewArtifact,
|
|
nativeExports,
|
|
devicetree,
|
|
espNvs,
|
|
firmwareMmio,
|
|
firmwareVectorTable,
|
|
elfNotes,
|
|
elfDebugLink,
|
|
nativeInitializers,
|
|
elfUnwindRanges,
|
|
appleIps,
|
|
kernelModule,
|
|
kernelBuildConfig,
|
|
peLoadConfig,
|
|
peUnwindRanges,
|
|
machoFunctionStarts,
|
|
peOverlay,
|
|
releaseExposure,
|
|
binaryHardening,
|
|
peCertificates,
|
|
peImports,
|
|
windowsShortcut,
|
|
firmwareArchitectureCandidates,
|
|
recordedCrash,
|
|
dwarfUnits,
|
|
nativeToolchain,
|
|
elfDependencies,
|
|
});
|
|
},
|
|
artifact: () => {
|
|
registerServices({
|
|
providerOperations: {
|
|
contracts: ARTIFACT_TOOL_CONTRACTS,
|
|
activeTarget,
|
|
parametersForExecution: artifactExecutionParameters,
|
|
analysisForAdmission: artifactAnalysisForAdmission(
|
|
capabilities.createArtifactPathInspection,
|
|
),
|
|
},
|
|
});
|
|
registerServices({
|
|
desktopApplication,
|
|
modelArtifact,
|
|
gpuCodeObjects,
|
|
evmInterface,
|
|
goBinary,
|
|
il2cppMetadata,
|
|
rustBinary,
|
|
nugetNupkg,
|
|
vsixPackage,
|
|
ociImageLayout,
|
|
yaraMatches,
|
|
pythonPyc,
|
|
baml,
|
|
protobufDescriptors,
|
|
debPackage,
|
|
erlangBeam,
|
|
v8CodeCache,
|
|
wasmArtifact,
|
|
apkSignature,
|
|
sqliteDatabase,
|
|
packetCapture,
|
|
signalRecording,
|
|
mavenGradleMetadata,
|
|
});
|
|
},
|
|
managed: () => {
|
|
registerServices({
|
|
providerOperations: {
|
|
contracts: MANAGED_TOOL_CONTRACTS,
|
|
activeTarget,
|
|
analysisForAdmission: managedAnalysisForAdmission(
|
|
activeTarget,
|
|
options.createManagedBinarySession ??
|
|
(session === undefined
|
|
? capabilities.createManagedBinarySession
|
|
: () =>
|
|
session.createManagedBinarySession?.() ??
|
|
capabilities.createManagedBinarySession()),
|
|
),
|
|
},
|
|
});
|
|
if (session !== undefined)
|
|
registerServices({ managedWorkflows: session });
|
|
},
|
|
firmware: () => registerServices({ firmwareAnalysis }),
|
|
uefi: () => registerServices({ uefiAnalysis }),
|
|
android: () =>
|
|
registerServices({
|
|
androidAnalysis: new AndroidAnalysisService(android, recordEvidence),
|
|
}),
|
|
pcap: () => {
|
|
registerServices({ pcapAnalysis: createPcapAnalysisService(pcap) });
|
|
},
|
|
flutter: () => {
|
|
registerServices({
|
|
flutterAnalysis: createFlutterBuildAnalysisService(flutter),
|
|
});
|
|
},
|
|
frida: () =>
|
|
// Frida instruments a live process the caller selects, outside
|
|
// analysis admission.
|
|
registerServiceTools(
|
|
server,
|
|
{ frida: new FridaInstrumentationService(fridaInstrumentation) },
|
|
{ logger: toolLogger, recordEvidence, evidenceById },
|
|
),
|
|
apktool: () =>
|
|
registerServices({
|
|
apktoolAnalysis: createApktoolResourceAnalysisService(apktool),
|
|
}),
|
|
jeb: () => registerServices({ jebAnalysis: createJebAnalysisService(jeb) }),
|
|
adb: () =>
|
|
registerServices({
|
|
adbDeviceAnalysis: new AdbDeviceAnalysisService(adbDevice),
|
|
}),
|
|
browser: () => {
|
|
registerServices({
|
|
browserObservation: {
|
|
browser: options.browserObservation,
|
|
loadFailure: options.optionalProviderLoadFailures?.browserObservation,
|
|
},
|
|
});
|
|
registerServices({
|
|
browserScenario: {
|
|
provider: options.browserScenarioCapture,
|
|
loadFailure:
|
|
options.optionalProviderLoadFailures?.browserScenarioCapture,
|
|
},
|
|
webRuntime,
|
|
webNetworkCapture,
|
|
});
|
|
},
|
|
electron: () =>
|
|
registerServices({
|
|
electronFuses,
|
|
electronObservation: {
|
|
provider: options.electronObservation,
|
|
loadFailure:
|
|
options.optionalProviderLoadFailures?.electronObservation,
|
|
},
|
|
electronScenario: {
|
|
provider: options.electronActiveObservation,
|
|
loadFailure:
|
|
options.optionalProviderLoadFailures?.electronActiveObservation,
|
|
},
|
|
javascriptApplication: {
|
|
resources: artifactResources,
|
|
environment,
|
|
settings: analysisSettings.read,
|
|
},
|
|
}),
|
|
"javascript-runtime": () =>
|
|
registerServices({
|
|
javascriptRuntime: {
|
|
runtime: options.javascriptRuntimeObservation,
|
|
loadFailure:
|
|
options.optionalProviderLoadFailures?.javascriptRuntimeObservation,
|
|
},
|
|
}),
|
|
application: () => {
|
|
registerServices({
|
|
analysisSettings: {
|
|
settings: analysisSettings,
|
|
delivery: server.delivery,
|
|
},
|
|
analysisView: {
|
|
resources: artifactResources,
|
|
agentBudgetSeed: server.delivery.agentBudgetSeed,
|
|
},
|
|
webScripts: artifactResources,
|
|
guidance: artifactResources,
|
|
webModuleTrace,
|
|
webSourceLocation,
|
|
javascriptRecovery: javascriptRecoveryService,
|
|
applicationWorkflows: {
|
|
resources: artifactResources,
|
|
environment,
|
|
settings: analysisSettings.read,
|
|
},
|
|
guidedWorkflows: promptsForToolFamilies(server.advertisedToolFamilies),
|
|
});
|
|
// Build tool responses are redacted as a whole; they record nothing.
|
|
registerServiceTools(
|
|
server,
|
|
{ desktopBuild: desktopBuildComputers },
|
|
{ logger: toolLogger },
|
|
);
|
|
},
|
|
session: () => {
|
|
if (session === undefined) return;
|
|
registerSessionTools(server, session, toolLogger, {
|
|
environment,
|
|
platform: host.platform,
|
|
artifactResources,
|
|
createArtifactPathInspection: capabilities.createArtifactPathInspection,
|
|
...(availability === undefined
|
|
? {}
|
|
: { availabilityPolicy: availability.policy }),
|
|
...capabilities.probes,
|
|
startedAt,
|
|
});
|
|
},
|
|
});
|
|
registerGuidedPrompts(server, analysis, session);
|
|
if (catalogProfile.value === "hot-cold") server.enableProgressiveCatalog();
|
|
return server;
|
|
};
|
|
|
|
const selectToolResultDelivery = (
|
|
environment: Readonly<NodeJS.ProcessEnv>,
|
|
selected: ToolResultDelivery | undefined,
|
|
): ToolResultDelivery => {
|
|
if (selected !== undefined) return selected;
|
|
const configured = parseMcpResponseBudget(
|
|
environment.REA_MCP_MAX_RESPONSE_BYTES,
|
|
);
|
|
if (!configured.ok) throw configured.error;
|
|
return createToolResultDelivery(configured.value, environment);
|
|
};
|
|
|
|
const outputSchemaProfile = (
|
|
environment: Readonly<NodeJS.ProcessEnv>,
|
|
): McpOutputSchemaProfile => {
|
|
const configured = parseMcpOutputSchemaProfile(
|
|
environment.REA_MCP_OUTPUT_SCHEMA_PROFILE,
|
|
);
|
|
if (!configured.ok) throw configured.error;
|
|
return resolveMcpOutputSchemaProfile(configured.value);
|
|
};
|
|
|
|
/** Only `compact` remains; the setting is still parsed so a removed value fails closed. */
|
|
const selectCompactInputSchemaPresentation = (
|
|
environment: Readonly<NodeJS.ProcessEnv>,
|
|
): CompactInputSchemaPresentation => {
|
|
const configured = parseMcpInputSchemaProfile(
|
|
environment.REA_MCP_INPUT_SCHEMA_PROFILE,
|
|
);
|
|
if (!configured.ok) throw configured.error;
|
|
return COMPACT_INPUT_SCHEMA_PRESENTATION;
|
|
};
|
|
|
|
const createSessionRecorders = (
|
|
server: EvidenceMcpServer,
|
|
session: BinarySessionPort | undefined,
|
|
) => ({
|
|
evidenceById:
|
|
session === undefined
|
|
? undefined
|
|
: session.evidenceForAnalysis.bind(session),
|
|
activeTarget:
|
|
session === undefined ? undefined : () => session.activeTarget(),
|
|
recordEvidence:
|
|
session === undefined
|
|
? undefined
|
|
: (evidence: Parameters<typeof session.recordEvidence>[0]) =>
|
|
session.recordEvidence(evidence),
|
|
recordEvidenceWithUnknown:
|
|
session === undefined
|
|
? undefined
|
|
: (
|
|
evidence: Parameters<typeof session.recordEvidenceWithUnknown>[0],
|
|
input: Parameters<typeof session.recordEvidenceWithUnknown>[1],
|
|
) => session.recordEvidenceWithUnknown(evidence, input),
|
|
});
|
|
|
|
const selectAdvertisedToolFamilies = (
|
|
environment: Readonly<NodeJS.ProcessEnv>,
|
|
): ReadonlySet<string> | undefined => {
|
|
const configured = parseMcpToolFamilies(environment.REA_MCP_TOOL_FAMILIES);
|
|
if (!configured.ok) throw configured.error;
|
|
return configured.value === undefined ? undefined : new Set(configured.value);
|
|
};
|