mirror of
https://github.com/revanced/revanced-patcher.git
synced 2025-05-08 08:04:25 +02:00
fix: set resource table via resource decoder
This commit is contained in:
parent
416d69142f
commit
e0f8e1b71a
@ -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,10 +200,11 @@ 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
|
||||||
context.packageMetadata.apkInfo, resourcesDecoder.resFileMapping
|
}.apkInfo.doNotCompress = ApkDecoder(config, extInputFile).recordUncompressedFiles(
|
||||||
)
|
context.packageMetadata.apkInfo, resourcesDecoder.resFileMapping
|
||||||
|
)
|
||||||
}
|
}
|
||||||
ResourceDecodingMode.MANIFEST_ONLY -> {
|
ResourceDecodingMode.MANIFEST_ONLY -> {
|
||||||
logger.info("Decoding AndroidManifest.xml only, because resources are not needed")
|
logger.info("Decoding AndroidManifest.xml only, because resources are not needed")
|
||||||
@ -213,18 +212,18 @@ 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, " "
|
||||||
)
|
)
|
||||||
setProperty(
|
setProperty(
|
||||||
ExtXmlSerializer.PROPERTY_SERIALIZER_LINE_SEPARATOR,
|
ExtXmlSerializer.PROPERTY_SERIALIZER_LINE_SEPARATOR,
|
||||||
System.getProperty("line.separator")
|
System.getProperty("line.separator")
|
||||||
)
|
)
|
||||||
setProperty(
|
setProperty(
|
||||||
ExtXmlSerializer.PROPERTY_DEFAULT_ENCODING,
|
ExtXmlSerializer.PROPERTY_DEFAULT_ENCODING,
|
||||||
"utf-8"
|
"utf-8"
|
||||||
)
|
)
|
||||||
setDisabledAttrEscape(true)
|
setDisabledAttrEscape(true)
|
||||||
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user