Files
reverse-engineering-anything/scripts/verify/android/bridge-catalog.mjs
T
Xiangfang Chen 85154de8ab fix(android): advertise the external-reference inputs the bridge accepts
The bridge-owned catalog omitted method_name and reference_target from
get_class_summary and reference_target from get_xrefs_to_method, even
though the bridge reads both on its external-prototype path and REA
sends both for reference queries. Neither side validates against the
schema today, but the verified catalog contradicted the traffic it
describes, and any schema-validating client would reject REA's own
reference queries.

The REA call sites also stopped sending limit, resolve_line and
smali_fallback, which the bridge never reads.

Validation: check:fast, and the Android MCP boundary plus JadxAnalysis
tests (92 tests). The bridge source itself was not compiled here; the
local engine JAR is absent, so verify:android against the real 0.8.0
JAR remains the authoritative catalog check.
2026-11-22 16:01:00 +08:00

135 lines
4.2 KiB
JavaScript

import assert from "node:assert/strict";
import { Client } from "@modelcontextprotocol/client";
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
import { jadxBridgeIdentity } from "../../../dist/android/JadxRelease.js";
/** Retained Java diagnostics tail; a failing bridge can be arbitrarily noisy. */
const STDERR_TAIL_BYTES = 64 * 1024;
/**
* Input schemas and property types the bridge advertises for the tools it
* reimplements. REA owns these, so a caller can page, select over one overload
* and read manifest facts without depending on whichever schema the pinned
* engine happens to publish.
*/
const expectedInputs = {
list_classes: {
properties: { offset: "integer", limit: "integer", query: "string" },
required: [],
},
get_class_summary: {
properties: {
class_name: "string",
method_name: "string",
reference_target: "boolean",
dex_static_values: "boolean",
},
required: ["class_name"],
},
get_method_body: {
properties: {
class_name: "string",
method_name: "string",
overload_index: "integer",
},
required: ["class_name", "method_name"],
},
get_xrefs_to_class: {
properties: { class_name: "string" },
required: ["class_name"],
},
get_xrefs_to_method: {
properties: {
class_name: "string",
method_name: "string",
overload_index: "integer",
reference_target: "boolean",
},
required: ["class_name", "method_name"],
},
rea_jvm_status: { properties: {}, required: [] },
rea_native_declarations: {
properties: { path: "string" },
required: ["path"],
},
get_app_info: { properties: {}, required: [] },
get_android_manifest: { properties: {}, required: [] },
};
/** Prove the real bridge advertises a serializable, REA-owned tool catalog. */
export const verifyAndroidBridgeCatalog = async ({
java,
jar,
bridge,
repository,
jvmArguments = [],
}) => {
const bridgeIdentity = jadxBridgeIdentity();
if (!bridgeIdentity.ok) throw new Error(bridgeIdentity.error);
const transport = new StdioClientTransport({
command: java,
args: [...jvmArguments, "-classpath", jar, bridge],
cwd: repository,
stderr: "pipe",
});
let diagnostics = "";
transport.stderr?.on("data", (chunk) => {
diagnostics = `${diagnostics}${chunk}`.slice(-STDERR_TAIL_BYTES);
});
const client = new Client({ name: "rea-bridge-catalog", version: "1" });
try {
await client.connect(transport);
assert.deepEqual(
client.getServerVersion(),
{
name: bridgeIdentity.value.name,
version: bridgeIdentity.value.version,
},
"The bridge must report the identity REA expects",
);
const tools = new Map(
(await client.listTools()).tools.map((tool) => [tool.name, tool]),
);
assert.deepEqual(
[...tools.keys()].sort(),
[...Object.keys(expectedInputs), "load_apk"].sort(),
"The bridge must advertise only the tools REA consumes",
);
assert.ok(
tools.get("load_apk").inputSchema.properties?.path,
"load_apk must keep advertising the caller's target path",
);
for (const [name, expected] of Object.entries(expectedInputs)) {
const { inputSchema } = tools.get(name);
const properties = inputSchema.properties ?? {};
assert.deepEqual(
Object.keys(properties).sort(),
Object.keys(expected.properties).sort(),
`${name} input properties`,
);
for (const [field, type] of Object.entries(expected.properties))
assert.equal(
properties[field]?.type,
type,
`${name}.${field} must stay ${type}`,
);
assert.deepEqual(
[...(inputSchema.required ?? [])].sort(),
[...expected.required].sort(),
`${name} required fields`,
);
}
console.log("PASS real bridge tool catalog and input schemas");
} catch (cause) {
const tail = diagnostics.trim();
if (tail === "") throw cause;
throw new Error(
`${cause instanceof Error ? cause.message : String(cause)}\n--- bridge stderr (last ${STDERR_TAIL_BYTES} bytes) ---\n${tail}`,
{ cause },
);
} finally {
await client.close();
await transport.close();
}
};