Reverse engineer anything with agents, from app behavior down to native binaries.
TypeScript agent-skillsai-agentsbinary-analysisclaude-codeclicodexcordisdecompilerdeveloper-toolsdshdsh-pluginghidrahopperllmmcpmodel-context-protocolreareverse-engineeringstatic-analysistouhou
fix(adb): preserve empty string activity extras
morluto9051809343ac
diff --git a/src/adb/AdbProvider.test.ts b/src/adb/AdbProvider.test.tsindex 8509bf3a8..59085a523 100644--- a/src/adb/AdbProvider.test.ts+++ b/src/adb/AdbProvider.test.ts@@ -1862,22 +1862,6 @@ ${shellStub({ "am:start": "Starting: Intent { act=android.intent.action.VIEW dat]);});-it("rejects mistyped intent extras before touching the device", async () => {- const { binary } = await writeAdbStub(- () => `if [ "$1" = "version" ]; then ${VERSION_BLOCK}; exit 0; fi-: > should-not-exist`,- );- const projected = await refusedBy(providerOver(binary), {- operation: "start_adb_activity",- input: {- serial: "emulator-5554",- action: "com.example.ACTION",- extras: [{ key: "flag", type: "boolean", value: "yes" }],- },- });- expect(projected).toMatchObject({ code: "invalid_request" });-});-it("collects a device bugreport archive with its digest", async () => {const { binary, root } = await writeAdbStub(() => `if [ "$1" = "version" ]; then ${VERSION_BLOCK}; exit 0; fidiff --git a/src/adb/AdbProvider.ts b/src/adb/AdbProvider.tsindex e1430804a..e56c0448a 100644--- a/src/adb/AdbProvider.ts+++ b/src/adb/AdbProvider.ts@@ -2762,32 +2762,6 @@ export class AdbProvider {long: "--el",float: "--ef",};- for (const extra of input.extras)- if (extra.type === "boolean" && !/^(true|false)$/u.test(extra.value))- return err(- new AnalysisInputError(operation, {- cause: new Error(- `Boolean extra ${extra.key} must be true or false`,- ),- }),- );- else if (- (extra.type === "int" || extra.type === "long") &&- !/^-?\d+$/u.test(extra.value)- )- return err(- new AnalysisInputError(operation, {- cause: new Error(- `${extra.type === "int" ? "Integer" : "Long"} extra ${extra.key} must be an integer`,- ),- }),- );- else if (extra.type === "float" && !/^-?\d+(\.\d+)?$/u.test(extra.value))- return err(- new AnalysisInputError(operation, {- cause: new Error(`Float extra ${extra.key} must be a number`),- }),- );const arguments_ = ["-a",input.action,diff --git a/src/domain/adb/adbDeviceAnalysis.test.ts b/src/domain/adb/adbDeviceAnalysis.test.tsindex 822292945..82ce18f8f 100644--- a/src/domain/adb/adbDeviceAnalysis.test.ts+++ b/src/domain/adb/adbDeviceAnalysis.test.ts@@ -80,3 +80,63 @@ it("preserves ADB key, action and component admission when making advertised patvariant.previous.test(sample),);});++it("admits empty string extras and validates typed extra text at domain admission", () => {+ const input = {+ serial: "emulator-5554",+ action: "android.intent.action.VIEW",+ };+ expect(+ adbInputSchemas.start_adb_activity.safeParse({+ ...input,+ extras: [{ key: "empty", type: "string", value: "" }],+ }).success,+ ).toBe(true);+ const accepted = [+ { type: "boolean", value: "false" },+ { type: "int", value: "-2147483648" },+ { type: "long", value: "9007199254740993" },+ { type: "float", value: "-1.25" },+ ] as const;+ for (const { type, value } of accepted)+ expect(+ adbInputSchemas.start_adb_activity.safeParse({+ ...input,+ extras: [{ key: "value", type, value }],+ }).success,+ `${type}: ${value}`,+ ).toBe(true);+ const rejected = [+ { type: "boolean", value: "True" },+ { type: "int", value: "1.5" },+ { type: "long", value: "" },+ { type: "float", value: "1e3" },+ ] as const;+ for (const { type, value } of rejected) {+ const result = adbInputSchemas.start_adb_activity.safeParse({+ ...input,+ extras: [{ key: "value", type, value }],+ });+ expect(result.success, `${type}: ${value}`).toBe(false);+ if (!result.success)+ expect(result.error.issues[0]?.path).toEqual(["extras", 0, "value"]);+ }+ expect(+ adbInputSchemas.start_adb_activity.safeParse({+ ...input,+ extras: [{ key: "text", type: "string", value: "payload" }],+ }).success,+ ).toBe(true);+ expect(+ adbInputSchemas.start_adb_activity.safeParse({+ ...input,+ extras: [{ key: "text", type: "string", value: "x".repeat(2048) }],+ }).success,+ ).toBe(true);+ expect(+ adbInputSchemas.start_adb_activity.safeParse({+ ...input,+ extras: [{ key: "text", type: "string", value: "x".repeat(2049) }],+ }).success,+ ).toBe(false);+});diff --git a/src/domain/adb/adbDeviceAnalysis.ts b/src/domain/adb/adbDeviceAnalysis.tsindex 4b4f7f422..07f7b863f 100644--- a/src/domain/adb/adbDeviceAnalysis.ts+++ b/src/domain/adb/adbDeviceAnalysis.ts@@ -51,6 +51,51 @@ export type AdbDeviceState = (typeof ADB_DEVICE_STATES)[number];const keyStringSchema = z.string().min(1).max(256);const keyPattern = /^[A-Za-z0-9._\x2d]+$/u;+const activityExtraKeySchema = keyStringSchema+ .regex(keyPattern, "Extra keys are identifiers")+ .describe("Extra key");+const activityExtraStringValueSchema = z+ .string()+ .max(2048)+ .regex(/^[^\x00]*$/u, "Extra values cannot contain NUL");+const activityExtraNonEmptyValueSchema = activityExtraStringValueSchema.min(1);+const activityExtraSchema = z.discriminatedUnion("type", [+ z.strictObject({+ key: activityExtraKeySchema,+ type: z.literal("string").describe("String extra value type"),+ value: activityExtraStringValueSchema.describe(+ "String extra value as text; an explicitly empty value is preserved",+ ),+ }),+ z.strictObject({+ key: activityExtraKeySchema,+ type: z.literal("boolean").describe("Boolean extra value type"),+ value: activityExtraNonEmptyValueSchema+ .regex(/^(true|false)$/u, "Boolean extra values must be true or false")+ .describe("Boolean extra value as true or false text"),+ }),+ z.strictObject({+ key: activityExtraKeySchema,+ type: z.literal("int").describe("Integer extra value type"),+ value: activityExtraNonEmptyValueSchema+ .regex(/^-?\d+$/u, "Integer extra values must be an integer")+ .describe("Integer extra value as signed decimal text"),+ }),+ z.strictObject({+ key: activityExtraKeySchema,+ type: z.literal("long").describe("Long extra value type"),+ value: activityExtraNonEmptyValueSchema+ .regex(/^-?\d+$/u, "Long extra values must be an integer")+ .describe("Long extra value as signed decimal text"),+ }),+ z.strictObject({+ key: activityExtraKeySchema,+ type: z.literal("float").describe("Float extra value type"),+ value: activityExtraNonEmptyValueSchema+ .regex(/^-?\d+(\.\d+)?$/u, "Float extra values must be a number")+ .describe("Float extra value as decimal text"),+ }),+]);/*** Caller intent for ADB-backed device inspection and acquisition.@@ -282,22 +327,7 @@ export const adbInputSchemas = {.optional().describe("Explicit component to start (-n)"),extras: z- .array(- z.strictObject({- key: keyStringSchema- .regex(keyPattern, "Extra keys are identifiers")- .describe("Extra key"),- type: z- .enum(["string", "boolean", "int", "long", "float"])- .describe("Extra value type"),- value: z- .string()- .min(1)- .max(2048)- .regex(/^[^\x00]*$/u, "Extra values cannot contain NUL")- .describe("Extra value as text, parsed per type"),- }),- )+ .array(activityExtraSchema).max(16).default([]).describe("Typed intent extras (--es/--ez/--ei/--el/--ef)"),diff --git a/tests/boundary/cli/adbCli.test.ts b/tests/boundary/cli/adbCli.test.tsindex e41aeb7e8..5d67eed04 100644--- a/tests/boundary/cli/adbCli.test.ts+++ b/tests/boundary/cli/adbCli.test.ts@@ -146,6 +146,16 @@ it.each(["string:key", ":", "string"])(it.each([["bogus:key:value", "invalid_request"],["string:key:value", "capability_unavailable"],+ ["string:key:", "capability_unavailable"],+ ["int:key:", "invalid_request"],+ ["boolean:key:yes", "invalid_request"],+ ["int:key:1.5", "invalid_request"],+ ["long:key:1.5", "invalid_request"],+ ["float:key:1e3", "invalid_request"],+ ["boolean:key:false", "capability_unavailable"],+ ["int:key:-3", "capability_unavailable"],+ ["long:key:9007199254740993", "capability_unavailable"],+ ["float:key:-1.25", "capability_unavailable"],] as const)("preserves downstream validation for well-delimited activity extra %j",async (extra, code) => {diff --git a/tests/boundary/mcp/adbStartMcp.test.ts b/tests/boundary/mcp/adbStartMcp.test.tsindex 702a6360d..098bcefc0 100644--- a/tests/boundary/mcp/adbStartMcp.test.ts+++ b/tests/boundary/mcp/adbStartMcp.test.ts@@ -1,4 +1,5 @@import { Client, InMemoryTransport } from "@modelcontextprotocol/client";+import { Ajv2020 } from "ajv/dist/2020.js";import { chmod, readFile, writeFile } from "node:fs/promises";import { join } from "node:path";import { expect, it, onTestFinished } from "vitest";@@ -55,6 +56,54 @@ if (args[0] === "version") {};};+const assertAdvertisedActivityExtras = async (+ client: Client,+ input: Readonly<Record<string, unknown>>,+ calls: () => Promise<string[]>,+) => {+ const advertised = (await client.listTools()).tools.find(+ ({ name }) => name === "start_adb_activity",+ );+ if (advertised === undefined) throw new Error("Missing ADB activity tool");+ const ajv = new Ajv2020({ strict: false, validateFormats: false });+ expect(ajv.validateSchema(advertised.inputSchema)).toBe(true);+ const validateInput = ajv.compile(advertised.inputSchema);+ expect(validateInput(input)).toBe(true);+ expect(+ validateInput({+ ...input,+ extras: [+ { key: "bool", type: "boolean", value: "false" },+ { key: "int", type: "int", value: "-3" },+ { key: "long", type: "long", value: "9007199254740993" },+ { key: "float", type: "float", value: "-1.25" },+ ],+ }),+ ).toBe(true);+ for (const [type, value] of [+ ["boolean", ""],+ ["boolean", "yes"],+ ["int", "1.5"],+ ["long", ""],+ ["float", "1e3"],+ ])+ expect(+ validateInput({ ...input, extras: [{ key: "invalid", type, value }] }),+ `${type}: ${value}`,+ ).toBe(false);++ const callsBeforeInvalidExtra = await calls();+ const invalidExtra = await client.callTool({+ name: "start_adb_activity",+ arguments: {+ ...input,+ extras: [{ key: "invalid", type: "boolean", value: "yes" }],+ },+ });+ expect(invalidExtra.isError).toBe(true);+ expect(await calls()).toEqual(callsBeforeInvalidExtra);+};+it.skipIf(process.platform === "win32").each(["start_adb_app", "start_adb_activity"] as const)(@@ -97,7 +146,10 @@ itaction: "android.intent.action.MAIN",data_uri: "https://example.invalid/launch",component: "com.example/.Main",- extras: [{ key: "mode", type: "string" as const, value: "test" }],+ extras: [+ { key: "mode", type: "string" as const, value: "test" },+ { key: "empty", type: "string" as const, value: "" },+ ],};const success = await client.callTool({name: operation,@@ -115,6 +167,9 @@ it});expect(evidence.raw_result).toEqual({ stdout, stderr });+ if (operation === "start_adb_activity")+ await assertAdvertisedActivityExtras(client, input, fakeAdb.calls);+stdout = `${starting}Status: timeout\nActivity: com.example/.Main\nWaitTime: 10004\nComplete\n`;await fakeAdb.setReport(stdout, stderr);const timeout = await client.callTool({@@ -181,6 +236,7 @@ it"-d https://example.invalid/launch","-n com.example/.Main","--es mode test",+ "--es empty ''",]),].join(" "),),