From 11a7a34dfc7748b7cf7efcdc6e6c80b7ba123783 Mon Sep 17 00:00:00 2001 From: morluto <76467478+morluto@users.noreply.github.com> Date: Sun, 22 Nov 2026 21:46:36 -0500 Subject: [PATCH] feat(adb): add optional limit and offset paging to list_adb_features and list_adb_services (#13873) * feat(adb): add optional limit and offset paging to list_adb_features and list_adb_services * test(adb): verify feature and service paging guidance --- docs/guides/android/adb-device-analysis.md | 32 ++++++++--------- docs/reference/limits-and-recovery.md | 7 ++++ .../tools/list_adb_features.json | 2 +- .../tools/list_adb_services.json | 2 +- src/adb/AdbProvider.test.ts | 34 +++++++++++++++++-- src/adb/AdbProvider.ts | 10 ++++-- src/domain/adb/adbDeviceAnalysis.ts | 2 ++ 7 files changed, 64 insertions(+), 25 deletions(-) diff --git a/docs/guides/android/adb-device-analysis.md b/docs/guides/android/adb-device-analysis.md index 4a033af388..0d6476c120 100644 --- a/docs/guides/android/adb-device-analysis.md +++ b/docs/guides/android/adb-device-analysis.md @@ -101,16 +101,16 @@ existing analysis families directly, for example | `list_adb_devices` | read | Serial, state, transport, model metadata, inferred emulator/physical kind with basis | | `inspect_adb_device` | read | Fixed `getprop` whitelist: build, SDK, patch, fingerprint, product, ABIs, debuggable, `ro.kernel.qemu` | | `inspect_adb_display` | read | `wm size` and `wm density` as declared | -| `list_adb_features` | read | `pm list features` (hardware/software features, hex GL versions) | -| `list_adb_services` | read | `service list` binder services and interfaces | -| `list_adb_processes` | read | `ps -A`: user, pid, ppid, rss, state, name; optional `limit` (1..10000) and `offset` paging | +| `list_adb_features` | read | `pm list features` (hardware/software features, hex GL versions); optional `limit` and `offset` paging | +| `list_adb_services` | read | `service list` binder services and interfaces; optional `limit` and `offset` paging | +| `list_adb_processes` | read | `ps -A`: user, pid, ppid, rss, state, name; optional `limit` and `offset` paging | | `inspect_adb_window` | read | `dumpsys window` focus declarations (what is on screen) | | `read_adb_setting` | read | One `settings get` value; device-side null is reported as such | | `read_adb_logcat` | read | Bounded `logcat -d -t` dump for one buffer, optional pid filter | -| `list_adb_packages` | read | `pm list packages -f` with scope; base APK device paths; optional `limit` (1..10000) and `offset` paging | +| `list_adb_packages` | read | `pm list packages -f` with scope; base APK device paths; optional `limit` and `offset` paging | | `resolve_adb_packages` | read | Case-insensitive package-name substring search with exact-match flag | | `inspect_adb_package` | read | `dumpsys package` projection: versions, install times, installer, flags, and count of listed requested-permission rows (including Unicode names) | -| `list_adb_directory` | read | NUL-framed immediate children, including hidden entries: kinds, permissions, owner, group, sizes, symlink targets; optional `limit` (1..10000) and `offset` paging | +| `list_adb_directory` | read | NUL-framed immediate children, including hidden entries: kinds, permissions, owner, group, sizes, symlink targets; optional `limit` and `offset` paging | | `pull_adb_package` | read | Complete split APK set from `pm path`, each file digested | | `pull_adb_file` | read | One absolute device path pulled and digested | | `capture_adb_screen` | read | One `screencap -p` frame (exec-out, no device-side file) with dimensions | @@ -122,12 +122,6 @@ existing analysis families directly, for example | `start_adb_activity` | **mutates device** | Starts an intent (`am start -W -a` with optional URI, component, and up to 16 typed extras); preserves the activity manager's verdict | | `stop_adb_app` | **mutates device** | Force-stops every process of a package, ending a dynamic-analysis run | -`list_adb_packages`, `list_adb_processes`, and `list_adb_directory` accept -optional `limit` (`1..10000`) and `offset` (`>= 0`) arguments (CLI `--limit` -and `--offset`). Omitting both returns every parsed entry. When paging omits -entries, `coverage` is `"partial"` and `limitations` reports the returned and -total counts so the caller can adjust `offset` or `limit` on the next call. - Screen capture validates the PNG signature, IHDR framing and checksum, dimensions, and encoding fields before publishing. Evidence records that pixel data remains undecoded. @@ -165,13 +159,15 @@ and during shutdown. ## Interpret the result -Package, process, and directory listings accept an optional `limit` and a -zero-based `offset` among parsed rows. Use `--limit` and `--offset` on the -CLI. Omitting both returns the full parsed listing. Paging trims the returned -rows after ADB captures the listing. Coverage is `partial` when rows are -omitted or ADB output contains unparsed lines. Repeat the same operation with -the next offset to continue. Each request captures a new listing, so rows may -shift if device state changes between calls. +Package, process, directory, feature, and service listings accept an optional +positive integer `limit` and a zero-based `offset` among parsed rows. Use +`--limit` and `--offset` on the CLI. Omitting both returns the full parsed +listing. Paging trims the returned rows after ADB captures the listing. When +paging omits rows, `coverage` is `partial` and the limitation reports the +returned count, total parsed count, and selected page. Unparsed output can +also make coverage partial. Repeat the operation with the next offset to +continue. Each call captures a new listing, so rows may shift if device state +changes between calls. - **Package numeric declarations retain failures.** `inspect_adb_package` admits the first valid `userId` or `appId` as `user_id`: a nonnegative safe diff --git a/docs/reference/limits-and-recovery.md b/docs/reference/limits-and-recovery.md index 007220d79f..e195c4d9f8 100644 --- a/docs/reference/limits-and-recovery.md +++ b/docs/reference/limits-and-recovery.md @@ -82,10 +82,17 @@ report the resolved policy separately where needed. See the owning guides for [Android class search](../guides/android/android-analysis.md), and [Frida capture](../guides/runtime/frida-instrumentation.md). +ADB package, process, directory, feature, and service listings apply `limit` +and `offset` after capturing the listing. The [ADB guide](../guides/android/adb-device-analysis.md#interpret-the-result) +describes coverage and how to continue. + Frida process discovery applies `limit` and `offset` after enumerating the selected device. It reports `total_processes` and `truncated`. Moving to another page runs a fresh discovery on that device. +Graph tools accept per-call traversal bounds (`max_depth` and `max_nodes` on +`get_call_graph` and `trace_call_path`). + The same accepted policy must reach acquisition, parsing, worker requests, serialization, cached-result admission and generated consumers where those stages exist. Desktop state views and emitted AgentEnv Python share one policy; diff --git a/scripts/verify/advertised-schemas/tools/list_adb_features.json b/scripts/verify/advertised-schemas/tools/list_adb_features.json index bbccac9cd5..05a50c2cd7 100644 --- a/scripts/verify/advertised-schemas/tools/list_adb_features.json +++ b/scripts/verify/advertised-schemas/tools/list_adb_features.json @@ -1,6 +1,6 @@ { "schemas": { - "input compact": "0eefd4f4245ea66b", + "input compact": "f6876dac509aa36b", "output compact": "4bda7c3651bfc579" }, "patterns": { diff --git a/scripts/verify/advertised-schemas/tools/list_adb_services.json b/scripts/verify/advertised-schemas/tools/list_adb_services.json index bbccac9cd5..05a50c2cd7 100644 --- a/scripts/verify/advertised-schemas/tools/list_adb_services.json +++ b/scripts/verify/advertised-schemas/tools/list_adb_services.json @@ -1,6 +1,6 @@ { "schemas": { - "input compact": "0eefd4f4245ea66b", + "input compact": "f6876dac509aa36b", "output compact": "4bda7c3651bfc579" }, "patterns": { diff --git a/src/adb/AdbProvider.test.ts b/src/adb/AdbProvider.test.ts index 9ef453a9d0..54c9550956 100644 --- a/src/adb/AdbProvider.test.ts +++ b/src/adb/AdbProvider.test.ts @@ -1941,7 +1941,9 @@ it("lists processes, features, and services through fixed commands", async () => "Found 2 services:\n 1 package: [android.content.pm.IPackageManager]\n 2 activity: [android.app.IActivityManager]\n", }), ); - const processes = await evidenceResult(providerOver(binary), { + const provider = providerOver(binary); + onTestFinished(() => provider.close()); + const processes = await evidenceResult(provider, { operation: "list_adb_processes", input: { serial: "emulator-5554" }, }); @@ -1955,7 +1957,7 @@ it("lists processes, features, and services through fixed commands", async () => name: "com.example.app", }, ]); - const features = await evidenceResult(providerOver(binary), { + const features = await evidenceResult(provider, { operation: "list_adb_features", input: { serial: "emulator-5554" }, }); @@ -1963,7 +1965,19 @@ it("lists processes, features, and services through fixed commands", async () => { name: "android.hardware.camera", version: null }, { name: "android.hardware.nfc", version: 1 }, ]); - const services = await evidenceResult(providerOver(binary), { + const pagedFeatures = await provider.execute({ + operation: "list_adb_features", + input: { serial: "emulator-5554", limit: 1, offset: 1 }, + }); + if (!pagedFeatures.ok) throw pagedFeatures.error; + expect(pagedFeatures.value.result).toMatchObject({ + features: [{ name: "android.hardware.nfc", version: 1 }], + coverage: "partial", + }); + expect(pagedFeatures.value.limitations).toEqual([ + expect.stringMatching(/1 of 2 features.*offset 1, limit 1/u), + ]); + const services = await evidenceResult(provider, { operation: "list_adb_services", input: { serial: "emulator-5554" }, }); @@ -1971,6 +1985,20 @@ it("lists processes, features, and services through fixed commands", async () => { name: "package", interface: "android.content.pm.IPackageManager" }, { name: "activity", interface: "android.app.IActivityManager" }, ]); + const pagedServices = await provider.execute({ + operation: "list_adb_services", + input: { serial: "emulator-5554", limit: 1, offset: 0 }, + }); + if (!pagedServices.ok) throw pagedServices.error; + expect(pagedServices.value.result).toMatchObject({ + services: [ + { name: "package", interface: "android.content.pm.IPackageManager" }, + ], + coverage: "partial", + }); + expect(pagedServices.value.limitations).toEqual([ + expect.stringMatching(/1 of 2 services.*offset 0, limit 1/u), + ]); }); it.each(["complete", "truncated"] as const)( diff --git a/src/adb/AdbProvider.ts b/src/adb/AdbProvider.ts index 3071d83f84..a5ebec2044 100644 --- a/src/adb/AdbProvider.ts +++ b/src/adb/AdbProvider.ts @@ -1052,11 +1052,14 @@ export class AdbProvider { const { features, unparsedLines } = parseFeatureListOutput( ran.value.stdout, ); + const page = pageListingItems(features, "features", request.input); return ok( parsedListingExecution( - { client, serial: request.input.serial, features }, + { client, serial: request.input.serial, features: page.items }, unparsedLines, provider, + page.limitations, + page.truncated, ), ); } @@ -1069,11 +1072,14 @@ export class AdbProvider { const { services, unparsedLines } = parseServiceListOutput( ran.value.stdout, ); + const page = pageListingItems(services, "services", request.input); return ok( parsedListingExecution( - { client, serial: request.input.serial, services }, + { client, serial: request.input.serial, services: page.items }, unparsedLines, provider, + page.limitations, + page.truncated, ), ); } diff --git a/src/domain/adb/adbDeviceAnalysis.ts b/src/domain/adb/adbDeviceAnalysis.ts index f409c24c7e..30303eb826 100644 --- a/src/domain/adb/adbDeviceAnalysis.ts +++ b/src/domain/adb/adbDeviceAnalysis.ts @@ -336,11 +336,13 @@ export const adbInputSchemas = { serial: deviceSerialSchema.describe( "Device serial exactly as `adb devices` reports it", ), + ...listingPagingFields, }), list_adb_services: z.strictObject({ serial: deviceSerialSchema.describe( "Device serial exactly as `adb devices` reports it", ), + ...listingPagingFields, }), inspect_adb_display: z.strictObject({ serial: deviceSerialSchema.describe(