From cc9416dd11b66140c2882021cbe5088659d85371 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Sat, 7 May 2022 05:07:27 +0200 Subject: [PATCH] perf: depend on `androlib` instead of `ApkDecoder` Signed-off-by: oSumAtrIX --- .../kotlin/app/revanced/patcher/Patcher.kt | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/main/kotlin/app/revanced/patcher/Patcher.kt b/src/main/kotlin/app/revanced/patcher/Patcher.kt index e4fe88eb..d9844386 100644 --- a/src/main/kotlin/app/revanced/patcher/Patcher.kt +++ b/src/main/kotlin/app/revanced/patcher/Patcher.kt @@ -12,7 +12,7 @@ import app.revanced.patcher.signature.MethodSignature import app.revanced.patcher.signature.resolver.SignatureResolver import app.revanced.patcher.util.ListBackedSet import brut.androlib.Androlib -import brut.androlib.ApkDecoder +import brut.androlib.meta.UsesFramework import brut.directory.ExtFile import lanchon.multidexlib2.BasicDexFileNamer import lanchon.multidexlib2.DexIO @@ -40,25 +40,32 @@ class Patcher( val packageVersion: String val packageName: String + private val usesFramework: UsesFramework private val patcherData: PatcherData private val opcodes: Opcodes private var signaturesResolved = false private val androlib = Androlib() + init { - // FIXME: only use androlib instead of ApkDecoder which is currently a temporal solution - val decoder = ApkDecoder(androlib) + val extFileInput = ExtFile(inputFile) + val resourceTable = androlib.getResTable(extFileInput, true) + val outDir = File(resourceCacheDirectory) + + if (outDir.exists()) outDir.deleteRecursively() + outDir.mkdir() + + // 1. decode resources to cache directory + androlib.decodeManifestWithResources(extFileInput, outDir, resourceTable) + androlib.decodeResourcesFull(extFileInput, outDir, resourceTable) - decoder.setApkFile(inputFile) - decoder.setDecodeSources(ApkDecoder.DECODE_SOURCES_NONE) - decoder.setForceDelete(true) - // decode resources to cache directory - decoder.setOutDir(File(resourceCacheDirectory)) - decoder.decode() + // 2. read framework ids from the resource table + usesFramework = UsesFramework() + usesFramework.ids = resourceTable.listFramePackages().map { it.id }.sorted() - // get package info - packageName = decoder.resTable.packageOriginal - packageVersion = decoder.resTable.versionInfo.versionName + // 3. read package info + packageName = resourceTable.packageOriginal + packageVersion = resourceTable.versionInfo.versionName // read dex files val dexFile = MultiDexIO.readDexFile(true, inputFile, NAMER, null, null) @@ -116,7 +123,7 @@ class Patcher( // build modified resources if (patchResources) { val extDir = ExtFile(resourceCacheDirectory) - androlib.buildResources(extDir, androlib.readMetaFile(extDir).usesFramework) + androlib.buildResources(extDir, usesFramework) } // write dex modified files