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(jeb): retain requested operation during metadata probes
morlutoece277b30ba2
diff --git a/src/jeb/JebProvider.ts b/src/jeb/JebProvider.tsindex 797060d59..9fc43fde2 100644--- a/src/jeb/JebProvider.ts+++ b/src/jeb/JebProvider.ts@@ -128,7 +128,7 @@ export class JebProvider implements JebAnalysisPort {): Promise<JebAnalysisAvailability> {try {const tools = new Set(await this.#connection.listTools(signal));- await this.#refreshClientInformation(signal);+ await this.#refreshClientInformation("inspect_jeb_client", signal);return {status: "available",code: null,@@ -209,13 +209,17 @@ export class JebProvider implements JebAnalysisPort {}}- async #engine(signal?: AbortSignal): Promise<{+ async #engine(+ operation: JebOperation,+ signal?: AbortSignal,+ ): Promise<{readonly name: string;readonly version: string | null;readonly endpoint: string;readonly gui_client: boolean | null;}> {- await this.#requireClientInformation(signal);+ if (this.#identity.version === null)+ await this.#refreshClientInformation(operation, signal);return {name: "jeb",version: this.#identity.version,@@ -224,45 +228,33 @@ export class JebProvider implements JebAnalysisPort {};}- async #requireClientInformation(signal?: AbortSignal): Promise<void> {- if (this.#identity.version !== null) return;- await this.#refreshClientInformation(signal);- }-async #refreshClientInformation(+ operation: JebOperation,signal: AbortSignal | undefined,- ): Promise<void> {+ ) {if (signal?.aborted === true)- throw new AnalysisCancelledError("inspect_jeb_client");+ throw new AnalysisCancelledError(operation, { cause: signal.reason });const payload = await this.#connection.call("get_client_information",{},signal,);const information = clientInformation.parse(- this.#requireSuccess(payload, "inspect_jeb_client"),+ this.#requireSuccess(payload, operation),);this.#identity = {...this.#identity,version: information.version ?? null,};this.#guiClient = information.gui_client ?? null;+ return { information, payload };}async #inspectClient(signal?: AbortSignal) {- const payload = await this.#connection.call(- "get_client_information",- {},+ const { information, payload } = await this.#refreshClientInformation(+ "inspect_jeb_client",signal,);- const information = clientInformation.parse(- this.#requireSuccess(payload, "inspect_jeb_client"),- );- this.#identity = {- ...this.#identity,- version: information.version ?? null,- };- this.#guiClient = information.gui_client ?? null;const result = jebResultSchemas.inspect_jeb_client.parse({engine: {name: "jeb",@@ -298,7 +290,7 @@ export class JebProvider implements JebAnalysisPort {const opened = openProject.parse(this.#requireSuccess(payload, request.operation),);- const engine = await this.#engine(signal);+ const engine = await this.#engine(request.operation, signal);const result = jebResultSchemas.open_jeb_project.parse({engine,project_name: opened.name ?? null,@@ -335,7 +327,7 @@ export class JebProvider implements JebAnalysisPort {this.#requireSuccess(payload, request.operation),);const units = listed.units;- const engine = await this.#engine(signal);+ const engine = await this.#engine(request.operation, signal);const result = jebResultSchemas.list_jeb_units.parse({engine,filter: filter ?? null,@@ -372,7 +364,7 @@ export class JebProvider implements JebAnalysisPort {const decompiled = decompiledItem.parse(this.#requireSuccess(payload, request.operation),);- const engine = await this.#engine(signal);+ const engine = await this.#engine(request.operation, signal);const result = jebResultSchemas.decompile_jeb_item.parse({engine,unit_path: unit_path ?? null,diff --git a/tests/boundary/cli/jebCli.test.ts b/tests/boundary/cli/jebCli.test.tsindex 56c4ee15b..ec36adcbc 100644--- a/tests/boundary/cli/jebCli.test.ts+++ b/tests/boundary/cli/jebCli.test.ts@@ -1,6 +1,13 @@import { expect, it } from "vitest";import { serveCli } from "./cliServeHarness.js";+import { createTestCli } from "../../support/cli/cliFixture.js";+import { createTestProcessRegistry } from "../../support/process/processFixture.js";+import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";+import {+ startJebMcpFixture,+ jebPrimaryResponses,+} from "../../fixtures/jebMcp.js";const jebEnvironment = {REA_JEB_MCP_URL: "http://127.0.0.1:1/mcp",@@ -53,3 +60,74 @@ it.each([});},);++it.each(+ [+ {+ operation: "list_jeb_units",+ tool: "list_units",+ argv: ["list-jeb-units", "--count", "2", "--json"],+ },+ {+ operation: "decompile_jeb_item",+ tool: "decompile_code_item",+ argv: [+ "decompile-jeb-item",+ "LSample;->value()I",+ "method",+ "--unit-path",+ "sample.dex",+ "--json",+ ],+ },+ {+ operation: "open_jeb_project",+ tool: "open_project",+ argv: ["open-jeb-project", "sample.apk", "--json"],+ },+ ].flatMap((request) =>+ ["metadata-refusal", "primary-refusal", "success"].map((stage) => ({+ ...request,+ stage,+ })),+ ),+)(+ "preserves $operation attribution and primary payload with $stage",+ async ({ operation, tool, argv, stage }) => {+ const fixture = await startJebMcpFixture((name) =>+ (stage === "metadata-refusal" && name === "get_client_information") ||+ (stage === "primary-refusal" && name === tool)+ ? { success: false, message: "Selected stage refused" }+ : jebPrimaryResponses[name]!,+ );+ const processes = createTestProcessRegistry();+ const cli = createTestCli(processes);+ try {+ const home = await createTestTempDirectory("rea-jeb-attribution-cli-");+ const result = await cli.run({+ arguments: argv,+ environment: { HOME: home, REA_JEB_MCP_URL: fixture.endpoint },+ timeoutMs: 10_000,+ });+ const output = JSON.parse(result.stdout);+ if (stage === "success") {+ expect(result.exitCode).toBe(0);+ expect(output.operation).toBe(operation);+ expect(output.raw_result).toEqual(jebPrimaryResponses[tool]);+ } else {+ expect(result.exitCode).toBe(1);+ expect(output).toMatchObject({+ code: "unsupported_target",+ details: { operation, reason: "Selected stage refused" },+ });+ expect(output.message).toContain(operation);+ }+ expect(fixture.calls).toEqual(+ stage === "primary-refusal" ? [tool] : [tool, "get_client_information"],+ );+ } finally {+ await processes.shutdown();+ await fixture.close();+ }+ },+);diff --git a/tests/boundary/mcp/jebMcp.test.ts b/tests/boundary/mcp/jebMcp.test.tsindex 742e28929..4bd85759c 100644--- a/tests/boundary/mcp/jebMcp.test.ts+++ b/tests/boundary/mcp/jebMcp.test.ts@@ -14,6 +14,12 @@ import { createServer } from "../../../src/server/createServer.js";import { createTestBinarySession } from "../../fixtures/binarySession.js";import { expandToolAvailability } from "../../../src/contracts/toolOutputSchemaPrimitives.js";+import { JebProvider } from "../../../src/jeb/JebProvider.js";+import {+ startJebMcpFixture,+ jebPrimaryResponses,+} from "../../fixtures/jebMcp.js";+const identity = { id: "jeb", name: "JEB", version: "5.48.0" } as const;it("discovers current JEB operation support and recovery through binary_session", async () => {@@ -289,3 +295,71 @@ it("keeps the MCP server usable when REA_JEB_MCP_URL is invalid", async () => {},});});++it.each([+ { operation: "list_jeb_units", tool: "list_units", input: { count: 2 } },+ {+ operation: "decompile_jeb_item",+ tool: "decompile_code_item",+ input: {+ item_address: "LSample;->value()I",+ item_kind: "method",+ unit_path: "sample.dex",+ },+ },+ {+ operation: "open_jeb_project",+ tool: "open_project",+ input: { path: "sample.apk" },+ },+])(+ "attributes auxiliary metadata refusal to requested $operation through MCP",+ async ({ operation, tool, input }) => {+ const fixture = await startJebMcpFixture((name) =>+ name === "get_client_information"+ ? { success: false, message: "Client information temporarily refused" }+ : jebPrimaryResponses[name]!,+ );+ const provider = new JebProvider({+ environment: { REA_JEB_MCP_URL: fixture.endpoint },+ });+ const session = createTestBinarySession(() => {+ throw new Error("JEB must not start a deep provider");+ });+ const server = createServer(+ { kind: "session", session },+ { jebAnalysis: provider, environment: {} },+ );+ const client = new Client({ name: "jeb-attribution", version: "1" });+ try {+ const [clientTransport, serverTransport] =+ InMemoryTransport.createLinkedPair();+ await server.connect(serverTransport);+ await client.connect(clientTransport);+ const failed = await client.callTool({+ name: operation,+ arguments: input,+ });+ expect(failed.isError).toBe(true);+ const text = failed.content+ .map((block) => (block.type === "text" ? block.text : ""))+ .join("");+ expect(JSON.parse(text)).toMatchObject({+ error: {+ code: "unsupported_target",+ details: {+ operation,+ reason: "Client information temporarily refused",+ },+ },+ });+ expect(fixture.calls).toEqual([tool, "get_client_information"]);+ } finally {+ await client.close();+ await server.close();+ await session.close();+ await provider.close();+ await fixture.close();+ }+ },+);diff --git a/tests/fixtures/jebMcp.ts b/tests/fixtures/jebMcp.tsnew file mode 100644index 000000000..5d9a4f342--- /dev/null+++ b/tests/fixtures/jebMcp.ts@@ -0,0 +1,92 @@+import { createServer } from "node:http";+import { z } from "zod";+import type { JsonValue } from "../../src/domain/jsonValue.js";+import { JEB_ENGINE_TOOLS } from "../../src/jeb/JebMcpConnection.js";++const messageSchema = z.object({+ id: z.union([z.string(), z.number()]).optional(),+ method: z.string(),+ params: z.object({ name: z.string().optional() }).passthrough().optional(),+});++/** Real HTTP MCP transport with caller-selected JEB response envelopes. */+export const startJebMcpFixture = async (+ respond: (tool: string) => JsonValue,+) => {+ const calls: string[] = [];+ const server = createServer(async (request, response) => {+ if (request.method !== "POST") {+ request.resume();+ response.writeHead(request.method === "DELETE" ? 200 : 405).end();+ return;+ }+ try {+ let body = "";+ for await (const chunk of request) body += String(chunk);+ const message = messageSchema.parse(JSON.parse(body));+ if (message.id === undefined) {+ response.writeHead(202).end();+ return;+ }+ let result: unknown;+ if (message.method === "initialize")+ result = {+ protocolVersion: "2025-11-25",+ capabilities: { tools: {} },+ serverInfo: { name: "jeb-response-fixture", version: "1" },+ };+ else if (message.method === "tools/list")+ result = {+ tools: Object.values(JEB_ENGINE_TOOLS).map((name) => ({+ name,+ inputSchema: { type: "object", properties: {} },+ })),+ };+ else if (+ message.method === "tools/call" &&+ message.params?.name !== undefined+ ) {+ calls.push(message.params.name);+ const payload = respond(message.params.name);+ result = {+ structuredContent: payload,+ content: [{ type: "text", text: JSON.stringify(payload) }],+ };+ } else throw new Error(`Unexpected fixture request: ${message.method}`);+ response.writeHead(200, { "Content-Type": "application/json" });+ response.end(JSON.stringify({ jsonrpc: "2.0", id: message.id, result }));+ } catch (cause: unknown) {+ response.writeHead(500).end(String(cause));+ }+ });+ await new Promise<void>((resolve) => server.listen(0, "127.0.0.1", resolve));+ const address = server.address();+ if (address === null || typeof address === "string")+ throw new Error("Expected TCP fixture listener");+ return {+ endpoint: `http://127.0.0.1:${address.port}/mcp`,+ calls,+ close: async () => {+ server.closeAllConnections();+ await new Promise<void>((resolve, reject) =>+ server.close((cause) =>+ cause === undefined ? resolve() : reject(cause),+ ),+ );+ },+ };+};++export const jebPrimaryResponses: Readonly<Record<string, JsonValue>> = {+ get_client_information: {+ success: true,+ version: "5.48.0",+ gui_client: false,+ },+ list_units: {+ success: true,+ units: [{ unit_path: "sample.dex", unit_type: "dex" }],+ },+ decompile_code_item: { success: true, text: "int value() { return 1; }" },+ open_project: { success: true, name: "sample", input_files: [], units: [] },+};