fix(adb): preserve directory identities and share byte capture
Use Android 8-compatible batched find/stat with NUL-framed names and raw symlink targets. Preserve malformed or invalid UTF-8 records as partial evidence with exact source bytes. List hidden direct children without synthetic navigation entries. Share process byte capture with UTF-8 callers and screenshots, removing duplicate timeout and cancellation supervision. Verified 35 focused process, ADB, CLI and MCP tests; compatibility checked against AOSP Oreo sources. Live Android device/emulator verification was not run.
This commit is contained in:
+69
-37
@@ -199,7 +199,7 @@ const shellStub = (
|
||||
second === undefined
|
||||
? `[ "$4" = "${first}" ]`
|
||||
: `[ "$4" = "${first}" ] && [ "$5" = "${second}" ]`;
|
||||
return ` if ${guard}; then printf '%b' '${output.replace(/'/gu, "'\\''")}'; exit 0; fi`;
|
||||
return ` if ${guard}; then printf '%b' '${output.replaceAll("\\", "\\\\").replaceAll("\0", "\\000").replace(/'/gu, "'\\''")}'; exit 0; fi`;
|
||||
})
|
||||
.join("\n");
|
||||
return () => `if [ "$1" = "version" ]; then ${VERSION_BLOCK}; exit 0; fi
|
||||
@@ -780,42 +780,74 @@ it("lists processes, features, and services through fixed commands", async () =>
|
||||
]);
|
||||
});
|
||||
|
||||
it("lists a device directory with kinds and symlink targets", async () => {
|
||||
const { binary } = await writeAdbStub(
|
||||
shellStub({
|
||||
ls: "total 4\n-rw-rw---- u0_a1 u0_a1 4096 2026-01-02 11:00 app.db\nlrwxrwxrwx root root 2026-01-01 10:00 lib -> /apex/com.android.art/lib\n",
|
||||
}),
|
||||
);
|
||||
const result = await evidenceResult(providerOver(binary), {
|
||||
operation: "list_adb_directory",
|
||||
input: {
|
||||
serial: "emulator-5554",
|
||||
device_path: "/data/data/com.example.app",
|
||||
},
|
||||
});
|
||||
expect(result.entries).toEqual([
|
||||
{
|
||||
name: "app.db",
|
||||
kind: "file",
|
||||
permissions: "-rw-rw----",
|
||||
owner: "u0_a1",
|
||||
group: "u0_a1",
|
||||
bytes: 4096,
|
||||
date: "2026-01-02 11:00",
|
||||
link_target: null,
|
||||
},
|
||||
{
|
||||
name: "lib",
|
||||
kind: "symlink",
|
||||
permissions: "lrwxrwxrwx",
|
||||
owner: "root",
|
||||
group: "root",
|
||||
bytes: null,
|
||||
date: "2026-01-01 10:00",
|
||||
link_target: "/apex/com.android.art/lib",
|
||||
},
|
||||
]);
|
||||
});
|
||||
it.each(["complete", "truncated"] as const)(
|
||||
"preserves framed directory identities with %s output",
|
||||
async (variant) => {
|
||||
const date = "2026-01-02 11:00:00.000000000 +0000";
|
||||
const names = [
|
||||
"app.db",
|
||||
" app.db ",
|
||||
" ",
|
||||
"one -> two -> three",
|
||||
"line\r",
|
||||
"line\u2028break",
|
||||
"foo\n-rw-rw---- root root 0 2026-01-01 10:00 ghost",
|
||||
"literal\\n",
|
||||
];
|
||||
const links = [
|
||||
["lib", "/apex/com.android.art/lib"],
|
||||
[" lib ", " /apex/lib "],
|
||||
["one -> two\n", "three -> four\n\n"],
|
||||
] as const;
|
||||
const truncated = `-rw-rw----|u0_a1|u0_a1|4096|${date}\0unfinished`;
|
||||
const output = [
|
||||
...names.map(
|
||||
(name) => `-rw-rw----|u0_a1|u0_a1|4096|${date}\0${name}\0\0`,
|
||||
),
|
||||
...links.map(
|
||||
([name, target]) =>
|
||||
`lrwxrwxrwx|root|root|${Buffer.byteLength(target)}|${date}\0${name}\0${target}\0`,
|
||||
),
|
||||
...(variant === "truncated" ? [truncated] : []),
|
||||
].join("");
|
||||
const { binary } = await writeAdbStub(shellStub({ sh: output }));
|
||||
const result = await evidenceResult(providerOver(binary), {
|
||||
operation: "list_adb_directory",
|
||||
input: {
|
||||
serial: "emulator-5554",
|
||||
device_path: "/data/data/com.example.app",
|
||||
},
|
||||
});
|
||||
expect(result.entries).toEqual([
|
||||
...names.map((name) => ({
|
||||
name,
|
||||
kind: "file",
|
||||
permissions: "-rw-rw----",
|
||||
owner: "u0_a1",
|
||||
group: "u0_a1",
|
||||
bytes: 4096,
|
||||
date,
|
||||
link_target: null,
|
||||
})),
|
||||
...links.map(([name, target]) => ({
|
||||
name,
|
||||
kind: "symlink",
|
||||
permissions: "lrwxrwxrwx",
|
||||
owner: "root",
|
||||
group: "root",
|
||||
bytes: Buffer.byteLength(target),
|
||||
date,
|
||||
link_target: target,
|
||||
})),
|
||||
]);
|
||||
expect(result.unparsed_lines).toEqual(
|
||||
variant === "truncated" ? [truncated] : [],
|
||||
);
|
||||
expect(result.coverage).toBe(
|
||||
variant === "truncated" ? "partial" : "complete",
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
it("inspects the display and window focus", async () => {
|
||||
const { binary } = await writeAdbStub(
|
||||
|
||||
Reference in New Issue
Block a user