Skip to content

armgit / rea

Public Imported from GitHub
0

Reverse engineer anything with agents, from app behavior down to native binaries.

fix(adb): delimit permission section by indentation

morlutoe90782283c71
diff --git a/src/adb/AdbProvider.test.ts b/src/adb/AdbProvider.test.ts
index 1312603d1..2bba049f6 100644
--- a/src/adb/AdbProvider.test.ts
+++ b/src/adb/AdbProvider.test.ts
@@ -874,7 +874,7 @@ it("counts Unicode requested-permission names and continues through the section"
versionCode=45 minSdk=24 targetSdk=34
requested permissions:
com.example.permission.FIRST
- com.example.permission.ÉCRIRE
+ com.example.permission.ÉCRIRE WITH SPACE
android.permission.CAMERA
install permissions:
android.permission.CAMERA: granted=true
@@ -891,6 +891,30 @@ it("counts Unicode requested-permission names and continues through the section"
});
});
+it("ends requested permissions at a same-indent dumpsys field", async () => {
+ const { binary } = await writeAdbStub(
+ shellStub({
+ "dumpsys:package": `Packages:
+ Package [com.example] (abcdef):
+ pkg=Package{abcdef com.example}
+ versionCode=45 minSdk=24 targetSdk=34
+ requested permissions:
+ android.permission.INTERNET
+ gids=[1000]
+ android.permission.CAMERA
+`,
+ }),
+ );
+ const result = await evidenceResult(providerOver(binary), {
+ operation: "inspect_adb_package",
+ input: { serial: "emulator-5554", package: "com.example" },
+ });
+ expect(result).toMatchObject({
+ requested_permissions_count: 1,
+ coverage: "complete",
+ });
+});
+
it("reports an uninstalled package from dumpsys refusal output", async () => {
const { binary } = await writeAdbStub(
shellStub({ "dumpsys:package": "Unable to find package: com.absent\n" }),
diff --git a/src/adb/AdbShellOutput.test.ts b/src/adb/AdbShellOutput.test.ts
index f66a50439..e0338854f 100644
--- a/src/adb/AdbShellOutput.test.ts
+++ b/src/adb/AdbShellOutput.test.ts
@@ -293,7 +293,7 @@ describe("parseDumpsysPackageOutput", () => {
" pkg=Package{abcdef com.example}",
" requested permissions:",
" com.example.permission-First",
- " com.example.permission.ÉCRIRE",
+ " com.example.permission.ÉCRIRE WITH SPACE",
" android.permission.CAMERA",
" install permissions:",
" android.permission.CAMERA: granted=true",
@@ -301,6 +301,21 @@ describe("parseDumpsysPackageOutput", () => {
).requestedPermissions,
).toBe(3);
});
+
+ it("ends requested permissions at a same-indent field", () => {
+ expect(
+ parseDumpsysPackageOutput(
+ [
+ "Package [com.example] (abcdef):",
+ " pkg=Package{abcdef com.example}",
+ " requested permissions:",
+ " android.permission.INTERNET",
+ " gids=[1000]",
+ " android.permission.CAMERA",
+ ].join("\n"),
+ ).requestedPermissions,
+ ).toBe(1);
+ });
});
describe("parseWmDensityOutput", () => {
diff --git a/src/adb/AdbShellOutput.ts b/src/adb/AdbShellOutput.ts
index 45df52e2d..16453f226 100644
--- a/src/adb/AdbShellOutput.ts
+++ b/src/adb/AdbShellOutput.ts
@@ -311,24 +311,30 @@ export const parseDumpsysPackageOutput = (
userId: null,
pkgFlags: null,
};
- let inPermissions = false;
+ let permissionsIndent: number | null = null;
let hasPermissionsSection = false;
let permissions = 0;
let parsedPackageAvailable: boolean | null = null;
for (const line of stdout.split(/\r?\n/u)) {
// Hidden system packages describe a separate section, not the requested package.
if (/^\s*Hidden system packages:\s*$/u.test(line)) break;
- if (line.trim().startsWith("requested permissions:")) {
+ const permissionsHeader = /^(\s*)requested permissions:\s*$/u.exec(line);
+ if (permissionsHeader !== null) {
hasPermissionsSection = true;
- inPermissions = true;
+ permissionsIndent = permissionsHeader[1]!.length;
continue;
}
- // Android 10 and 11 mark restricted entries as "NAME: restricted=true".
- if (inPermissions && /^\s{2,}\S+(?:: restricted=true)?$/u.test(line)) {
- permissions += 1;
- continue;
+ if (permissionsIndent !== null) {
+ const indentation = /^\s*/u.exec(line)![0].length;
+ if (line.trim() !== "" && indentation > permissionsIndent) {
+ // Android 10 and 11 may append ": restricted=true" to a row. The
+ // section is indentation-delimited; permission strings are arbitrary.
+ permissions += 1;
+ continue;
+ }
+ if (line.trim() === "" && indentation > permissionsIndent) continue;
+ permissionsIndent = null;
}
- inPermissions = false;
const match = DETAIL_LINE.exec(line);
if (match === null) continue;
const key = match[1]!;