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(adb): normalize absent installer package sentinels (#4073)
Yankı Küçük7721d59e1a92
diff --git a/src/adb/AdbProvider.test.ts b/src/adb/AdbProvider.test.tsindex 8ef84f200..5567fe869 100644--- a/src/adb/AdbProvider.test.ts+++ b/src/adb/AdbProvider.test.ts@@ -784,6 +784,33 @@ it("projects package details from dumpsys package output", async () => {});});+// Package Manager prints an absent installer as the text "null"; the+// normalized result must report the absence, not a package named "null"+// (morluto/rea#3943).+it("reports a null installer declaration as an absent installer", async () => {+ const { binary } = await writeAdbStub(+ shellStub({+ "dumpsys:package": `Packages:+ Package [com.example] (abcdef):+ versionName=1.2.3+ installerPackageName=null+ requested permissions:+ android.permission.INTERNET+`,+ }),+ );+ const result = await evidenceResult(providerOver(binary), {+ operation: "inspect_adb_package",+ input: { serial: "emulator-5554", package: "com.example" },+ });+ expect(result).toMatchObject({+ version_name: "1.2.3",+ installer_package_name: null,+ requested_permissions_count: 1,+ coverage: "complete",+ });+});+// PackageInfo.getLongVersionCode() combines versionCodeMajor and versionCode// into a signed 64-bit long, which JSON numbers cannot hold exactly.it.each(["9007199254740993", "-4294967296"])(diff --git a/src/adb/AdbShellOutput.test.ts b/src/adb/AdbShellOutput.test.tsindex 6984767f1..0d22c6b2c 100644--- a/src/adb/AdbShellOutput.test.ts+++ b/src/adb/AdbShellOutput.test.ts@@ -7,6 +7,52 @@ import {parseWindowFocusOutput,} from "./AdbShellOutput.js";+const packageDump = (installerLine: string | undefined): string =>+ [+ "Packages:",+ " Package [com.example] (abcdef):",+ " versionName=1.2.3",+ ...(installerLine === undefined ? [] : [` ${installerLine}`]),+ " pkgFlags=[ HAS_CODE ]",+ "",+ ].join("\n");++describe("parseDumpsysPackageOutput", () => {+ it("keeps a reported installer package name", () => {+ expect(+ parseDumpsysPackageOutput(+ packageDump("installerPackageName=com.android.vending"),+ ).installerPackageName,+ ).toBe("com.android.vending");+ });++ // Package Manager prints an absent String field as the text "null"; a+ // missing or empty declaration means the same absence (morluto/rea#3943).+ it.each([+ ["the literal null sentinel", "installerPackageName=null"],+ ["an empty value", "installerPackageName="],+ ["a missing line", undefined],+ ])("reports an absent installer as null for %s", (_case, line) => {+ expect(parseDumpsysPackageOutput(packageDump(line))).toMatchObject({+ versionName: "1.2.3",+ installerPackageName: null,+ });+ });++ // A manifest may declare the literal string "null" as its version name and+ // dumpsys prints it the same way as an absent one, so the text is kept.+ it("keeps a version name printed as the text null", () => {+ expect(+ parseDumpsysPackageOutput(+ packageDump("installerPackageName=null").replace(+ "versionName=1.2.3",+ "versionName=null",+ ),+ ).versionName,+ ).toBe("null");+ });+});+describe("parseWindowFocusOutput display contexts", () => {it.each([false, true])("retains both display owners independent of block order: %s",diff --git a/src/adb/AdbShellOutput.ts b/src/adb/AdbShellOutput.tsindex 74a832429..9ce558ceb 100644--- a/src/adb/AdbShellOutput.ts+++ b/src/adb/AdbShellOutput.ts@@ -275,6 +275,17 @@ export interface AdbPackageDetails {const DETAIL_LINE = /^\s+([A-Za-z][A-Za-z0-9_]*)=(.*)$/u;+/**+ * Package Manager prints its `String` fields by concatenation, so an absent+ * `installerPackageName` appears as the literal text `null`+ * (morluto/rea#3943). No installer can be named "null", so an empty value or+ * that sentinel is the absence of the fact and becomes the nullable result's+ * null. `versionName` keeps the printed text: a manifest may declare the+ * string "null" on purpose, and the parser cannot tell the two apart.+ */+const absentInstallerOrName = (value: string): string | null =>+ value === "" || value === "null" ? null : value;+/*** Project `dumpsys package PACKAGE` output. Only the listed fields are* extracted; the input is version-dependent and everything else is ignored@@ -340,7 +351,7 @@ export const parseDumpsysPackageOutput = (key === "installerPackageName" &&details.installerPackageName === null)- details.installerPackageName = value === "" ? null : value;+ details.installerPackageName = absentInstallerOrName(value);else if (key === "userId" && details.userId === null) {const parsed = /^(\d+)/u.exec(value);if (parsed !== null) details.userId = Number(parsed[1]!);