From a60c36178fdae0ef0902350e2396408a3a22fe3d Mon Sep 17 00:00:00 2001 From: Danny Lin Date: Thu, 11 Nov 2021 01:28:35 -0800 Subject: [PATCH] util: Add common aapt2 helper --- src/blobs/presigned.ts | 10 +++------- src/util/aapt2.ts | 8 ++++++++ 2 files changed, 11 insertions(+), 7 deletions(-) create mode 100644 src/util/aapt2.ts diff --git a/src/blobs/presigned.ts b/src/blobs/presigned.ts index 5c3b5b7..7307c7c 100644 --- a/src/blobs/presigned.ts +++ b/src/blobs/presigned.ts @@ -1,13 +1,11 @@ import { promises as fs } from 'fs' import * as path from 'path' -import { $ } from 'zx' import { parseSeappContexts } from '../sepolicy/seapp' +import { aapt2 } from '../util/aapt2' import { listFilesRecursive } from '../util/fs' import { BlobEntry } from './entry' -$.verbose = false - export async function parsePresignedRecursive(sepolicyDirs: Array) { let contexts = [] for (let dir of sepolicyDirs) { @@ -42,8 +40,7 @@ export async function updatePresignedBlobs( entryCallback(entry) } - let procOut = await $`${aapt2Path} dump packagename ${source}/${entry.srcPath}` - let pkgName = procOut.stdout.trim() + let pkgName = await aapt2(aapt2Path, 'dump', 'packagename', `${source}/${entry.srcPath}`) if (presignedPkgs.has(pkgName)) { entry.isPresigned = true updatedEntries.push(entry) @@ -64,8 +61,7 @@ export async function enumeratePresignedBlobs( continue } - let procOut = await $`${aapt2Path} dump packagename ${file}` - let pkgName = procOut.stdout.trim() + let pkgName = await aapt2(aapt2Path, 'dump', 'packagename', file) if (presignedPkgs.has(pkgName)) { presignedPaths.push(file) } diff --git a/src/util/aapt2.ts b/src/util/aapt2.ts new file mode 100644 index 0000000..7523a00 --- /dev/null +++ b/src/util/aapt2.ts @@ -0,0 +1,8 @@ +import { $ } from 'zx' + +$.verbose = false + +export async function aapt2(path: string, ...args: Array) { + let procOut = await $`${path} ${args.join('\n')}` + return procOut.stdout.trim() +}