fix: set resource table via resource decoder

This commit is contained in:
oSumAtrIX 2023-07-26 05:53:10 +02:00
parent 416d69142f
commit e0f8e1b71a
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4
2 changed files with 22 additions and 21 deletions

View File

@ -10,7 +10,6 @@ import app.revanced.patcher.patch.*
import brut.androlib.AaptInvoker import brut.androlib.AaptInvoker
import brut.androlib.ApkDecoder import brut.androlib.ApkDecoder
import brut.androlib.Config import brut.androlib.Config
import brut.androlib.Config.DECODE_RESOURCES_FULL
import brut.androlib.res.Framework import brut.androlib.res.Framework
import brut.androlib.res.ResourcesDecoder import brut.androlib.res.ResourcesDecoder
import brut.androlib.res.decoder.AndroidManifestResourceParser import brut.androlib.res.decoder.AndroidManifestResourceParser
@ -191,8 +190,7 @@ class Patcher(private val options: PatcherOptions) {
val outDir = File(options.resourceCacheDirectory) val outDir = File(options.resourceCacheDirectory)
if (outDir.exists()) { if (outDir.exists()) {
logger.info("Deleting existing resource cache directory") logger.info("Deleting existing resource cache directory")
if (!outDir.deleteRecursively()) if (!outDir.deleteRecursively()) logger.error("Failed to delete existing resource cache directory")
logger.error("Failed to delete existing resource cache directory")
} }
outDir.mkdirs() outDir.mkdirs()
@ -202,8 +200,9 @@ class Patcher(private val options: PatcherOptions) {
resourcesDecoder.decodeManifest(outDir) resourcesDecoder.decodeManifest(outDir)
resourcesDecoder.decodeResources(outDir) resourcesDecoder.decodeResources(outDir)
context.packageMetadata.apkInfo.doNotCompress = context.packageMetadata.also {
ApkDecoder(config, extInputFile).recordUncompressedFiles( it.apkInfo = resourcesDecoder.apkInfo
}.apkInfo.doNotCompress = ApkDecoder(config, extInputFile).recordUncompressedFiles(
context.packageMetadata.apkInfo, resourcesDecoder.resFileMapping context.packageMetadata.apkInfo, resourcesDecoder.resFileMapping
) )
} }
@ -213,9 +212,9 @@ class Patcher(private val options: PatcherOptions) {
// Instead of using resourceDecoder.decodeManifest which decodes the whole file // Instead of using resourceDecoder.decodeManifest which decodes the whole file
// use the XmlPullStreamDecoder in order to get necessary information from the manifest // use the XmlPullStreamDecoder in order to get necessary information from the manifest
// used below. // used below.
XmlPullStreamDecoder( XmlPullStreamDecoder(AndroidManifestResourceParser().apply {
AndroidManifestResourceParser().apply { attrDecoder = ResAttrDecoder() }, attrDecoder = ResAttrDecoder().apply { this.resTable = resourceTable }
ExtMXSerializer().apply { }, ExtMXSerializer().apply {
setProperty( setProperty(
ExtXmlSerializer.PROPERTY_SERIALIZER_INDENTATION, " " ExtXmlSerializer.PROPERTY_SERIALIZER_INDENTATION, " "
) )
@ -240,8 +239,10 @@ class Patcher(private val options: PatcherOptions) {
// Get the package name and version from the manifest using the XmlPullStreamDecoder. // Get the package name and version from the manifest using the XmlPullStreamDecoder.
// XmlPullStreamDecoder.decodeManifest() sets metadata.apkInfo. // XmlPullStreamDecoder.decodeManifest() sets metadata.apkInfo.
context.packageMetadata.let { metadata -> context.packageMetadata.let { metadata ->
metadata.apkInfo = resourcesDecoder.apkInfo
metadata.packageName = resourceTable.currentResPackage.name metadata.packageName = resourceTable.currentResPackage.name
metadata.apkInfo.versionInfo.let { resourcesDecoder.apkInfo.versionInfo.let {
metadata.packageVersion = it.versionName ?: it.versionCode metadata.packageVersion = it.versionName ?: it.versionCode
} }
} }

View File

@ -11,5 +11,5 @@ class PackageMetadata {
lateinit var packageVersion: String lateinit var packageVersion: String
internal set internal set
internal val apkInfo: ApkInfo = ApkInfo() internal lateinit var apkInfo: ApkInfo
} }