feat(adb): complete ADB device support for Android reverse engineering (#1552)

* feat(adb): acquire installed APK sets from connected Android devices

Add a read-only ADB device-acquisition family over the caller's adb binary:
inspect_adb_client, list_adb_devices, inspect_adb_device, list_adb_packages,
and pull_adb_package, exposed through the CLI and MCP with shared admission,
Evidence provenance (binary, version, serial, transport), and fixed argv
vectors that never reach a shell.

pull_adb_package acquires the complete split set reported by pm path into a
package-named directory that must not exist, digesting every file with
SHA-256 and keeping per-file failure reasons and partial coverage. Device
kind is reported as an inference with its basis; getprop whitelisting keeps
build identity bounded. REA installs nothing and never manages devices or
emulators; the first device query may start the caller's local adb server,
recorded when observed.

Verified against adb 34.0.5 on Linux with an Android 14 (API 34) x86_64
emulator: full 224-package inventory, a real two-APK split set pulled with
byte-exact digests, and a 73.9 MB system-package pull. npm run verify:adb
records the lane; parser goldens come from the same device. READMEs carry
the new row in every supported language.

* feat(adb): complete the adb surface with observation, transfer, and lifecycle tools

Extend the ADB family from five to twenty-four operations, all through
fixed adb argument vectors with no shell exposure:

Observation: read_adb_logcat (bounded dump, count/buffer/pid), inspect_adb_package
(dumpsys package projection), list_adb_processes (ps -A), list_adb_directory
(ls -la with kinds and symlink targets), list_adb_features (hex GL versions),
list_adb_services (AIDL slash-suffixed names), inspect_adb_display (wm size and
density), inspect_adb_window (focus declarations), read_adb_setting (device-side
nulls reported as such), capture_adb_screen (exec-out screencap with PNG
dimensions), collect_adb_bugreport (digested device archive).

Transfer and search: pull_adb_file and push_adb_file (device-side sha256sum
verification, explicit overwrite authority), resolve_adb_packages (substring
package search with exact-match flag — the find step of an easy get).

Lifecycle for dynamic analysis, each declaring mutatesTarget:
install_adb_package and uninstall_adb_package preserving the device's
Success/Failure verdict, start_adb_app (resolve-activity then am start -W),
start_adb_activity (typed extras as --es/--ez/--ei/--el/--ef), and stop_adb_app
(am force-stop).

Verified end-to-end against adb 34.0.5 on Linux with an Android 14 (API 34)
x86_64 emulator: 287 services, 92 features, split-set pulls with byte-exact
digests, verified push/pull roundtrip, sized screen capture, and the full
install → resolve → start → observe-in-ps → force-stop → uninstall lifecycle.
Fixed a v-mode regex incompatibility in the settings key pattern and added
argument descriptions required by the CLI catalog audit.

* fix(adb): quote remote shell operands and protect captured output

* test(adb): cover bugreport destinations containing spaces

---------

Co-authored-by: REA Contributor <contributor@rea.tools>
Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
This commit is contained in:
Quentin Limo
2026-10-10 23:01:24 +08:00
committed by GitHub
co-authored by REA Contributor morluto
parent efd81f9776
commit fef6f73064
48 changed files with 6862 additions and 1 deletions
+382
View File
@@ -0,0 +1,382 @@
import {
adbInputSchemas,
adbResultSchemas,
} from "../../domain/adb/adbDeviceAnalysis.js";
import type { ToolContract } from "../toolContractTypes.js";
import { evidenceResultOf } from "../toolOutputSchemaPrimitives.js";
import { toolContractMetadata } from "../toolEffects.js";
/** ADB device inspection and acquisition over a caller-supplied binary. */
export const ADB_TOOL_CONTRACTS = [
{
name: "inspect_adb_client",
...toolContractMetadata("inspect_adb_client"),
description:
"Inspect the caller-selected adb client: resolved binary, version, and install path. Never contacts devices and never starts the adb server. REA never installs platform tools; select a binary with REA_ADB_PATH (absolute) or adb on PATH.",
kind: "adb-provider",
inputSchema: adbInputSchemas.inspect_adb_client,
outputSchema: evidenceResultOf(adbResultSchemas.inspect_adb_client),
examples: [{ title: "Check the adb client", input: {} }],
},
{
name: "list_adb_devices",
...toolContractMetadata("list_adb_devices"),
description:
"List attached devices exactly as `adb devices -l` reports them: serial, state, transport, model metadata, and an inferred emulator/physical kind with its evidence basis. Emulators and USB or network devices appear alike; REA neither starts nor manages them. May start the local adb server on first use.",
kind: "adb-provider",
inputSchema: adbInputSchemas.list_adb_devices,
outputSchema: evidenceResultOf(adbResultSchemas.list_adb_devices),
examples: [{ title: "List attached devices", input: {} }],
},
{
name: "inspect_adb_device",
...toolContractMetadata("inspect_adb_device"),
description:
"Inspect one device's build identity through a fixed `getprop` whitelist: Android and SDK versions, security patch, fingerprint, product identity, CPU ABIs, and debuggable flag, plus the observed emulator indicator ro.kernel.qemu. Read-only with respect to the device.",
kind: "adb-provider",
inputSchema: adbInputSchemas.inspect_adb_device,
outputSchema: evidenceResultOf(adbResultSchemas.inspect_adb_device),
examples: [
{ title: "Inspect one device", input: { serial: "emulator-5554" } },
],
},
{
name: "list_adb_packages",
...toolContractMetadata("list_adb_packages"),
description:
"List installed packages on one device with each base APK's device path, optionally scoped to third-party or system packages. Paths are device filesystem paths, not host-local. Read-only.",
kind: "adb-provider",
inputSchema: adbInputSchemas.list_adb_packages,
outputSchema: evidenceResultOf(adbResultSchemas.list_adb_packages),
examples: [
{
title: "List third-party packages",
input: { serial: "emulator-5554", scope: "third_party" },
},
],
},
{
name: "pull_adb_package",
...toolContractMetadata("pull_adb_package"),
description:
"Pull one installed package's complete APK set (base plus every split, as `pm path` reports) from the device into a caller-selected output directory, creating a package-named subdirectory that must not already exist. Every pulled file is digested with SHA-256; partial pulls keep successful artifacts and per-file failure reasons. The device keeps the originals.",
kind: "adb-provider",
inputSchema: adbInputSchemas.pull_adb_package,
outputSchema: evidenceResultOf(adbResultSchemas.pull_adb_package),
examples: [
{
title: "Pull a package APK set",
input: {
serial: "emulator-5554",
package: "com.example.app",
output_directory: "/tmp/rea-pulls",
},
},
],
},
{
name: "read_adb_logcat",
...toolContractMetadata("read_adb_logcat"),
description:
"Read a bounded dump of the device log (`logcat -d -t`) for one buffer, optionally restricted to a process id. No streaming, no clearing; the newest lines are kept when the count cap trims. Read-only.",
kind: "adb-provider",
inputSchema: adbInputSchemas.read_adb_logcat,
outputSchema: evidenceResultOf(adbResultSchemas.read_adb_logcat),
examples: [
{
title: "Read the last 200 main-buffer lines",
input: { serial: "emulator-5554", count: 200, buffer: "main" },
},
],
},
{
name: "inspect_adb_package",
...toolContractMetadata("inspect_adb_package"),
description:
"Inspect one installed package through `dumpsys package`: version name/code, install and update times, installer, user id, flags, and the requested-permission count. A fixed projection of version-dependent output; unknown sections are ignored rather than guessed. Read-only.",
kind: "adb-provider",
inputSchema: adbInputSchemas.inspect_adb_package,
outputSchema: evidenceResultOf(adbResultSchemas.inspect_adb_package),
examples: [
{
title: "Inspect an installed package",
input: { serial: "emulator-5554", package: "com.example.app" },
},
],
},
{
name: "pull_adb_file",
...toolContractMetadata("pull_adb_file"),
description:
"Pull one absolute device path (a database, shared-preferences XML, or any readable file) into a caller-selected output directory, digesting it with SHA-256. The local copy must not already exist. Read-only with respect to the device.",
kind: "adb-provider",
inputSchema: adbInputSchemas.pull_adb_file,
outputSchema: evidenceResultOf(adbResultSchemas.pull_adb_file),
examples: [
{
title: "Pull an app database",
input: {
serial: "emulator-5554",
device_path: "/data/data/com.example.app/databases/app.db",
output_directory: "/tmp/rea-pulls",
},
},
],
},
{
name: "push_adb_file",
...toolContractMetadata("push_adb_file"),
description:
"Push one local file to an absolute device path. The only device-mutating ADB tool: existing device files are refused unless overwrite is explicitly requested, and the transfer is verified by comparing the local digest with the device's own sha256sum when the device provides one.",
kind: "adb-provider",
inputSchema: adbInputSchemas.push_adb_file,
outputSchema: evidenceResultOf(adbResultSchemas.push_adb_file),
examples: [
{
title: "Push a script to tmp",
input: {
serial: "emulator-5554",
local_path: "/tmp/frida-server",
device_path: "/data/local/tmp/frida-server",
},
},
],
},
{
name: "capture_adb_screen",
...toolContractMetadata("capture_adb_screen"),
description:
"Capture one frame of the device screen as a PNG (`screencap -p` through exec-out, no device-side file) into a caller-selected output directory, digesting it and reporting its dimensions. No recording or interaction.",
kind: "adb-provider",
inputSchema: adbInputSchemas.capture_adb_screen,
outputSchema: evidenceResultOf(adbResultSchemas.capture_adb_screen),
examples: [
{
title: "Capture the current screen",
input: {
serial: "emulator-5554",
output_directory: "/tmp/rea-captures",
},
},
],
},
{
name: "list_adb_processes",
...toolContractMetadata("list_adb_processes"),
description:
"List running processes exactly as `ps -A` reports them: user, pid, ppid, rss, state, and name. Useful for pairing with instrumentation lanes. Read-only.",
kind: "adb-provider",
inputSchema: adbInputSchemas.list_adb_processes,
outputSchema: evidenceResultOf(adbResultSchemas.list_adb_processes),
examples: [{ title: "List processes", input: { serial: "emulator-5554" } }],
},
{
name: "list_adb_directory",
...toolContractMetadata("list_adb_directory"),
description:
"List one absolute device directory (`ls -la`): names, kinds, permissions, owner, group, sizes, dates, and symlink targets. Recognizes the standard errors for absent paths and denied reads. Read-only.",
kind: "adb-provider",
inputSchema: adbInputSchemas.list_adb_directory,
outputSchema: evidenceResultOf(adbResultSchemas.list_adb_directory),
examples: [
{
title: "List an app's data directory",
input: {
serial: "emulator-5554",
device_path: "/data/data/com.example.app",
},
},
],
},
{
name: "list_adb_features",
...toolContractMetadata("list_adb_features"),
description:
"List the device's declared hardware and software features (`pm list features`) for device fingerprinting. Read-only.",
kind: "adb-provider",
inputSchema: adbInputSchemas.list_adb_features,
outputSchema: evidenceResultOf(adbResultSchemas.list_adb_features),
examples: [{ title: "List features", input: { serial: "emulator-5554" } }],
},
{
name: "list_adb_services",
...toolContractMetadata("list_adb_services"),
description:
"List the device's binder services with their interfaces (`service list`). Read-only.",
kind: "adb-provider",
inputSchema: adbInputSchemas.list_adb_services,
outputSchema: evidenceResultOf(adbResultSchemas.list_adb_services),
examples: [{ title: "List services", input: { serial: "emulator-5554" } }],
},
{
name: "inspect_adb_display",
...toolContractMetadata("inspect_adb_display"),
description:
"Report the display's physical and any overridden size (`wm size`) and density (`wm density`) as the device declares them. Read-only; setting values is not exposed.",
kind: "adb-provider",
inputSchema: adbInputSchemas.inspect_adb_display,
outputSchema: evidenceResultOf(adbResultSchemas.inspect_adb_display),
examples: [
{ title: "Inspect the display", input: { serial: "emulator-5554" } },
],
},
{
name: "inspect_adb_window",
...toolContractMetadata("inspect_adb_window"),
description:
"Report the window manager's current focus declarations (`dumpsys window windows`: mCurrentFocus and mFocusedApp) — what is on screen at read time without any interaction. Read-only.",
kind: "adb-provider",
inputSchema: adbInputSchemas.inspect_adb_window,
outputSchema: evidenceResultOf(adbResultSchemas.inspect_adb_window),
examples: [
{ title: "Inspect window focus", input: { serial: "emulator-5554" } },
],
},
{
name: "read_adb_setting",
...toolContractMetadata("read_adb_setting"),
description:
"Read one settings value (`settings get`) from the system, secure, or global namespace. Absent keys report the device's own null observation. Read-only; writing settings is not exposed.",
kind: "adb-provider",
inputSchema: adbInputSchemas.read_adb_setting,
outputSchema: evidenceResultOf(adbResultSchemas.read_adb_setting),
examples: [
{
title: "Read the ADB-enabled setting",
input: {
serial: "emulator-5554",
namespace: "secure",
key: "adb_enabled",
},
},
],
},
{
name: "collect_adb_bugreport",
...toolContractMetadata("collect_adb_bugreport"),
description:
"Collect one device-generated bugreport archive (`adb bugreport`) into a caller-selected output directory, digesting the zip. The archive contains the device's own dumpstate, dumpsys, and logcat report; collection can take minutes. Read-only with respect to configuration.",
kind: "adb-provider",
inputSchema: adbInputSchemas.collect_adb_bugreport,
outputSchema: evidenceResultOf(adbResultSchemas.collect_adb_bugreport),
examples: [
{
title: "Collect a bugreport",
input: {
serial: "emulator-5554",
output_directory: "/tmp/rea-bugreports",
},
},
],
},
{
name: "resolve_adb_packages",
...toolContractMetadata("resolve_adb_packages"),
description:
"Find installed packages by case-insensitive substring of the package name (e.g. `whatsapp` → `com.whatsapp`), returning each match's base APK device path. The first step of an easy get: resolve, then pull_adb_package the exact name. Read-only.",
kind: "adb-provider",
inputSchema: adbInputSchemas.resolve_adb_packages,
outputSchema: evidenceResultOf(adbResultSchemas.resolve_adb_packages),
examples: [
{
title: "Find a package by partial name",
input: { serial: "emulator-5554", query: "whatsapp" },
},
],
},
{
name: "install_adb_package",
...toolContractMetadata("install_adb_package"),
description:
"Install one local APK on the device (`adb install [-r]`), recording the APK's host digest and byte size. A device-mutating tool: `replace` re-installs over an existing package while keeping its data; the device's own Success/Failure verdict is preserved with its reason.",
kind: "adb-provider",
inputSchema: adbInputSchemas.install_adb_package,
outputSchema: evidenceResultOf(adbResultSchemas.install_adb_package),
examples: [
{
title: "Install an APK",
input: { serial: "emulator-5554", apk_path: "/tmp/app.apk" },
},
{
title: "Replace an existing install keeping data",
input: {
serial: "emulator-5554",
apk_path: "/tmp/app.apk",
replace: true,
},
},
],
},
{
name: "uninstall_adb_package",
...toolContractMetadata("uninstall_adb_package"),
description:
"Uninstall one package from the device (`adb uninstall`), removing its data for user 0. A device-mutating tool; absent packages report the device's own refusal reason.",
kind: "adb-provider",
inputSchema: adbInputSchemas.uninstall_adb_package,
outputSchema: evidenceResultOf(adbResultSchemas.uninstall_adb_package),
examples: [
{
title: "Uninstall a package",
input: { serial: "emulator-5554", package: "com.example.app" },
},
],
},
{
name: "start_adb_app",
...toolContractMetadata("start_adb_app"),
description:
"Start one installed app by launching its declared launcher activity: the component is resolved through `cmd package resolve-activity --brief`, then started with `am start -n`. A device-mutating tool for dynamic-analysis workflows; pair with `read_adb_logcat` (pid filter) and `list_adb_processes` to observe the started app, and `stop_adb_app` to end the run.",
kind: "adb-provider",
inputSchema: adbInputSchemas.start_adb_app,
outputSchema: evidenceResultOf(adbResultSchemas.start_adb_app),
examples: [
{
title: "Start an app",
input: { serial: "emulator-5554", package: "com.example.app" },
},
],
},
{
name: "start_adb_activity",
...toolContractMetadata("start_adb_activity"),
description:
"Start an intent with `am start`: one action, optional data URI, optional explicit component, and up to 16 typed extras (string, boolean, int, long, float). A device-mutating tool; the activity manager's Starting/Error verdict is preserved verbatim.",
kind: "adb-provider",
inputSchema: adbInputSchemas.start_adb_activity,
outputSchema: evidenceResultOf(adbResultSchemas.start_adb_activity),
examples: [
{
title: "Open a deep link",
input: {
serial: "emulator-5554",
action: "android.intent.action.VIEW",
data_uri: "https://example.com/path",
},
},
{
title: "Start with typed extras",
input: {
serial: "emulator-5554",
action: "com.example.APP_ACTION",
extras: [{ key: "level", type: "int", value: "3" }],
},
},
],
},
{
name: "stop_adb_app",
...toolContractMetadata("stop_adb_app"),
description:
"Force-stop every process of one package (`am force-stop`), ending a dynamic-analysis run. A device-mutating tool; it succeeds whether or not the package had running processes.",
kind: "adb-provider",
inputSchema: adbInputSchemas.stop_adb_app,
outputSchema: evidenceResultOf(adbResultSchemas.stop_adb_app),
examples: [
{
title: "Stop an app",
input: { serial: "emulator-5554", package: "com.example.app" },
},
],
},
] as const satisfies readonly ToolContract[];
+1
View File
@@ -25,6 +25,7 @@ export const TOOL_KINDS = [
"artifact-provider",
"managed-provider",
"android-provider",
"adb-provider",
"firmware-provider",
"browser-provider",
"electron-provider",
+2
View File
@@ -6,6 +6,7 @@ import { ARTIFACT_TOOL_CONTRACTS } from "./artifactToolContracts.js";
import { MANAGED_TOOL_CONTRACTS } from "./managed/managedToolContracts.js";
import { FIRMWARE_TOOL_CONTRACTS } from "./firmware/firmwareToolContracts.js";
import { ANDROID_TOOL_CONTRACTS } from "./android/androidToolContracts.js";
import { ADB_TOOL_CONTRACTS } from "./adb/adbToolContracts.js";
import { MANAGED_WORKFLOW_TOOL_CONTRACTS } from "./managed/managedWorkflowToolContracts.js";
import { BROWSER_PROVIDER_TOOL_CONTRACTS } from "./browserProviderToolContracts.js";
import { ELECTRON_TOOL_CONTRACTS } from "./javascript/electronToolContracts.js";
@@ -30,6 +31,7 @@ export const TOOL_CONTRACTS = [
...EVM_TOOL_CONTRACTS,
...MANAGED_TOOL_CONTRACTS,
...ANDROID_TOOL_CONTRACTS,
...ADB_TOOL_CONTRACTS,
...FIRMWARE_TOOL_CONTRACTS,
...MANAGED_WORKFLOW_TOOL_CONTRACTS,
...BROWSER_PROVIDER_TOOL_CONTRACTS,
+140
View File
@@ -97,6 +97,146 @@ export const TOOL_EFFECTS: Readonly<Record<string, ToolEffects>> = {
launchesProcess: true,
writesFilesystem: true,
}),
inspect_adb_client: effects({
mutatesSession: true,
launchesProcess: true,
}),
list_adb_devices: effects({
mutatesSession: true,
launchesProcess: true,
accessesNetwork: true,
}),
inspect_adb_device: effects({
mutatesSession: true,
launchesProcess: true,
accessesNetwork: true,
}),
list_adb_packages: effects({
mutatesSession: true,
launchesProcess: true,
accessesNetwork: true,
}),
pull_adb_package: effects({
mutatesSession: true,
launchesProcess: true,
writesFilesystem: true,
accessesNetwork: true,
idempotent: false,
}),
read_adb_logcat: effects({
mutatesSession: true,
launchesProcess: true,
accessesNetwork: true,
}),
inspect_adb_package: effects({
mutatesSession: true,
launchesProcess: true,
accessesNetwork: true,
}),
pull_adb_file: effects({
mutatesSession: true,
launchesProcess: true,
writesFilesystem: true,
accessesNetwork: true,
idempotent: false,
}),
push_adb_file: effects({
mutatesTarget: true,
mutatesSession: true,
launchesProcess: true,
writesFilesystem: true,
accessesNetwork: true,
idempotent: false,
}),
capture_adb_screen: effects({
mutatesSession: true,
launchesProcess: true,
writesFilesystem: true,
accessesNetwork: true,
idempotent: false,
}),
list_adb_processes: effects({
mutatesSession: true,
launchesProcess: true,
accessesNetwork: true,
}),
list_adb_directory: effects({
mutatesSession: true,
launchesProcess: true,
accessesNetwork: true,
}),
list_adb_features: effects({
mutatesSession: true,
launchesProcess: true,
accessesNetwork: true,
}),
list_adb_services: effects({
mutatesSession: true,
launchesProcess: true,
accessesNetwork: true,
}),
inspect_adb_display: effects({
mutatesSession: true,
launchesProcess: true,
accessesNetwork: true,
}),
inspect_adb_window: effects({
mutatesSession: true,
launchesProcess: true,
accessesNetwork: true,
}),
read_adb_setting: effects({
mutatesSession: true,
launchesProcess: true,
accessesNetwork: true,
}),
collect_adb_bugreport: effects({
mutatesSession: true,
launchesProcess: true,
writesFilesystem: true,
accessesNetwork: true,
idempotent: false,
}),
resolve_adb_packages: effects({
mutatesSession: true,
launchesProcess: true,
accessesNetwork: true,
}),
install_adb_package: effects({
mutatesTarget: true,
mutatesSession: true,
launchesProcess: true,
accessesNetwork: true,
idempotent: false,
}),
uninstall_adb_package: effects({
mutatesTarget: true,
mutatesSession: true,
launchesProcess: true,
accessesNetwork: true,
idempotent: false,
}),
start_adb_app: effects({
mutatesTarget: true,
mutatesSession: true,
launchesProcess: true,
accessesNetwork: true,
idempotent: false,
}),
start_adb_activity: effects({
mutatesTarget: true,
mutatesSession: true,
launchesProcess: true,
accessesNetwork: true,
idempotent: false,
}),
stop_adb_app: effects({
mutatesTarget: true,
mutatesSession: true,
launchesProcess: true,
accessesNetwork: true,
idempotent: false,
}),
search_android_classes: effects({
mutatesSession: true,
launchesProcess: true,