util: Add common aapt2 helper

This commit is contained in:
Danny Lin 2021-11-11 01:28:35 -08:00
parent c497401e80
commit a60c36178f
2 changed files with 11 additions and 7 deletions

View file

@ -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<string>) {
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)
}

8
src/util/aapt2.ts Normal file
View file

@ -0,0 +1,8 @@
import { $ } from 'zx'
$.verbose = false
export async function aapt2(path: string, ...args: Array<string>) {
let procOut = await $`${path} ${args.join('\n')}`
return procOut.stdout.trim()
}