Skip to content

armgit / rea

Public Imported from GitHub
0

Reverse engineer anything with agents, from app behavior down to native binaries.

fix(frida): clarify device selection and cleanup contracts

morluto2ec602b191d3
diff --git a/src/contracts/fridaToolContracts.ts b/src/contracts/fridaToolContracts.ts
index cc07c2c53..d470eb75f 100644
--- a/src/contracts/fridaToolContracts.ts
+++ b/src/contracts/fridaToolContracts.ts
@@ -90,10 +90,14 @@ export const FRIDA_TOOL_CONTRACTS = [
kind: "native-provider",
description:
"List processes observed on a selected Frida device or caller-supplied remote endpoint. A remote connection is closed after discovery; authentication values are never returned or recorded.",
- inputSchema: exclusiveDeviceSelector(deviceSelector).refine(
- (value) => value.device_id !== undefined || value.remote !== undefined,
- "Select a device_id or a remote endpoint",
- ),
+ inputSchema: exclusiveDeviceSelector(deviceSelector)
+ .refine(
+ (value) => value.device_id !== undefined || value.remote !== undefined,
+ "Select a device_id or a remote endpoint",
+ )
+ .describe(
+ 'Provide exactly one of device_id or remote. device_id selects a device (use "local" for this host); remote requires an address.',
+ ),
outputSchema: z.strictObject({
device_id: z.string(),
processes: z.array(
@@ -251,7 +255,7 @@ export const FRIDA_TOOL_CONTRACTS = [
...toolContractMetadata("close_frida_session"),
kind: "native-provider",
description:
- "Unload session scripts and detach REA's Frida session. If a spawned process is still paused, resume it before detaching so it is not left suspended. REA never kills the target; its final state is reported as unknown.",
+ "Unload session scripts and attempt to detach REA's Frida session. Then resume a still-paused spawned process if script cleanup or session detach confirms instrumentation was released. Cleanup failures are reported. REA never kills the target; its final state is reported as unknown.",
inputSchema: z.strictObject({ session_id: sessionId }),
outputSchema: z.strictObject({ target_state: z.literal("unknown") }),
examples: [
diff --git a/tests/boundary/mcp/fridaMcp.test.ts b/tests/boundary/mcp/fridaMcp.test.ts
index a66538580..8ed3cc874 100644
--- a/tests/boundary/mcp/fridaMcp.test.ts
+++ b/tests/boundary/mcp/fridaMcp.test.ts
@@ -139,6 +139,49 @@ const expectFridaProcessDiscovery = async (client: Client) => {
});
};
+const expectFridaSelectorGuidance = async (
+ client: Client,
+ tools: Awaited<ReturnType<Client["listTools"]>>["tools"],
+) => {
+ const ajv = new Ajv2020({ strict: false, validateFormats: false });
+ const processTool = tools.find(
+ (tool) => tool.name === "list_frida_processes",
+ );
+ if (processTool === undefined) throw new Error("Missing Frida process tool");
+ expect(processTool.inputSchema.description).toMatch(
+ /exactly one of device_id or remote/u,
+ );
+ expect(ajv.validateSchema(processTool.inputSchema)).toBe(true);
+ for (const args of [
+ { device_id: "local" },
+ { remote: { address: "127.0.0.1:27042" } },
+ ]) {
+ expect(ajv.validate(processTool.inputSchema, args)).toBe(true);
+ expect(
+ (await client.callTool({ name: "list_frida_processes", arguments: args }))
+ .isError,
+ ).not.toBe(true);
+ }
+ // Runtime refinements enforce the choice that advertisement describes.
+ for (const { args, reason } of [
+ { args: {}, reason: "Select a device_id or a remote endpoint" },
+ {
+ args: { device_id: "local", remote: { address: "127.0.0.1:27042" } },
+ reason: "Choose either device_id or remote, not both",
+ },
+ ]) {
+ const rejected = await client.callTool({
+ name: "list_frida_processes",
+ arguments: args,
+ });
+ expect(rejected.isError).toBe(true);
+ expect(rejected.content).toContainEqual({
+ type: "text",
+ text: expect.stringContaining(reason),
+ });
+ }
+};
+
it("advertises Frida MCP schemas and keeps remote credentials out of results", async () => {
const session = createTestBinarySession(() => {
throw new Error("Binary provider must not start");
@@ -193,6 +236,8 @@ it("advertises Frida MCP schemas and keeps remote credentials out of results", a
});
expect(toolContract("start_frida_session").effects.mutatesTarget).toBe(true);
+ await expectFridaSelectorGuidance(client, tools);
+
await expectFridaProcessDiscovery(client);
const started = await client.callTool({