1
mirror of https://github.com/revanced/revanced-patcher synced 2025-09-10 05:30:49 +02:00

Compare commits

..

6 Commits

Author SHA1 Message Date
semantic-release-bot
cc3d32748b chore(release): 3.3.3 [skip ci]
## [3.3.3](https://github.com/revanced/revanced-patcher/compare/v3.3.2...v3.3.3) (2022-08-14)

### Bug Fixes

* show error message if cause is null ([f9da2ad](f9da2ad531))
2022-08-14 15:25:16 +00:00
oSumAtrIX
f9da2ad531 fix: show error message if cause is null 2022-08-14 17:22:43 +02:00
semantic-release-bot
b19e1131e8 chore(release): 3.3.2 [skip ci]
## [3.3.2](https://github.com/revanced/revanced-patcher/compare/v3.3.1...v3.3.2) (2022-08-06)

### Bug Fixes

* close open files ([#75](https://github.com/revanced/revanced-patcher/issues/75)) ([123ad54](123ad54c15))
2022-08-06 22:17:39 +00:00
dan1st
123ad54c15 fix: close open files (#75) 2022-08-07 00:16:23 +02:00
Sculas
09f6ab4155 Merge remote-tracking branch 'origin/main' into main 2022-08-03 18:32:34 +02:00
Sculas
01cf3fb50f refactor: util package structure 2022-08-03 18:31:31 +02:00
8 changed files with 117 additions and 95 deletions

View File

@@ -1,3 +1,17 @@
## [3.3.3](https://github.com/revanced/revanced-patcher/compare/v3.3.2...v3.3.3) (2022-08-14)
### Bug Fixes
* show error message if cause is null ([f9da2ad](https://github.com/revanced/revanced-patcher/commit/f9da2ad531644617ad5a2cc6a1819d530e18ba22))
## [3.3.2](https://github.com/revanced/revanced-patcher/compare/v3.3.1...v3.3.2) (2022-08-06)
### Bug Fixes
* close open files ([#75](https://github.com/revanced/revanced-patcher/issues/75)) ([123ad54](https://github.com/revanced/revanced-patcher/commit/123ad54c150bd04f4b8ef5c65334ea468ceb99cc))
## [3.3.1](https://github.com/revanced/revanced-patcher/compare/v3.3.0...v3.3.1) (2022-08-03) ## [3.3.1](https://github.com/revanced/revanced-patcher/compare/v3.3.0...v3.3.1) (2022-08-03)

View File

@@ -1,2 +1,2 @@
kotlin.code.style = official kotlin.code.style = official
version = 3.3.1 version = 3.3.3

View File

@@ -49,70 +49,74 @@ class Patcher(private val options: PatcherOptions) {
init { init {
val extInputFile = ExtFile(options.inputFile) val extInputFile = ExtFile(options.inputFile)
val outDir = File(options.resourceCacheDirectory) try {
if (outDir.exists()) { val outDir = File(options.resourceCacheDirectory)
logger.info("Deleting existing resource cache directory") if (outDir.exists()) {
outDir.deleteRecursively() logger.info("Deleting existing resource cache directory")
} outDir.deleteRecursively()
outDir.mkdirs() }
outDir.mkdirs()
val androlib = Androlib(BuildOptions().also { it.setBuildOptions(options) }) val androlib = Androlib(BuildOptions().also { it.setBuildOptions(options) })
val resourceTable = androlib.getResTable(extInputFile, true) val resourceTable = androlib.getResTable(extInputFile, true)
val packageMetadata = PackageMetadata() val packageMetadata = PackageMetadata()
if (options.patchResources) { if (options.patchResources) {
logger.info("Decoding resources") logger.info("Decoding resources")
// decode resources to cache directory // decode resources to cache directory
androlib.decodeManifestWithResources(extInputFile, outDir, resourceTable) androlib.decodeManifestWithResources(extInputFile, outDir, resourceTable)
androlib.decodeResourcesFull(extInputFile, outDir, resourceTable) androlib.decodeResourcesFull(extInputFile, outDir, resourceTable)
// read additional metadata from the resource table // read additional metadata from the resource table
packageMetadata.metaInfo.usesFramework = UsesFramework().also { framework -> packageMetadata.metaInfo.usesFramework = UsesFramework().also { framework ->
framework.ids = resourceTable.listFramePackages().map { it.id }.sorted() framework.ids = resourceTable.listFramePackages().map { it.id }.sorted()
}
packageMetadata.metaInfo.doNotCompress = buildList {
androlib.recordUncompressedFiles(extInputFile, this)
}
} else {
logger.info("Only decoding AndroidManifest.xml because resource patching is disabled")
// create decoder for the resource table
val decoder = ResAttrDecoder()
decoder.currentPackage = ResPackage(resourceTable, 0, null)
// create xml parser with the decoder
val axmlParser = AXmlResourceParser()
axmlParser.attrDecoder = decoder
// parse package information with the decoder and parser which will set required values in the resource table
// instead of decodeManifest another more low level solution can be created to make it faster/better
XmlPullStreamDecoder(
axmlParser, AndrolibResources().resXmlSerializer
).decodeManifest(
extInputFile.directory.getFileInput("AndroidManifest.xml"), nullOutputStream
)
} }
packageMetadata.metaInfo.doNotCompress = buildList { packageMetadata.packageName = resourceTable.currentResPackage.name
androlib.recordUncompressedFiles(extInputFile, this) packageMetadata.packageVersion = resourceTable.versionInfo.versionName
} packageMetadata.metaInfo.versionInfo = resourceTable.versionInfo
packageMetadata.metaInfo.sdkInfo = resourceTable.sdkInfo
} else { logger.info("Reading dex files")
logger.info("Only decoding AndroidManifest.xml because resource patching is disabled")
// create decoder for the resource table // read dex files
val decoder = ResAttrDecoder() val dexFile = MultiDexIO.readDexFile(true, options.inputFile, NAMER, null, null)
decoder.currentPackage = ResPackage(resourceTable, 0, null) // get the opcodes
opcodes = dexFile.opcodes
// create xml parser with the decoder // finally create patcher data
val axmlParser = AXmlResourceParser() data = PatcherData(
axmlParser.attrDecoder = decoder dexFile.classes.toMutableList(), options.resourceCacheDirectory, packageMetadata
// parse package information with the decoder and parser which will set required values in the resource table
// instead of decodeManifest another more low level solution can be created to make it faster/better
XmlPullStreamDecoder(
axmlParser, AndrolibResources().resXmlSerializer
).decodeManifest(
extInputFile.directory.getFileInput("AndroidManifest.xml"), nullOutputStream
) )
} finally {
extInputFile.close()
} }
packageMetadata.packageName = resourceTable.currentResPackage.name
packageMetadata.packageVersion = resourceTable.versionInfo.versionName
packageMetadata.metaInfo.versionInfo = resourceTable.versionInfo
packageMetadata.metaInfo.sdkInfo = resourceTable.sdkInfo
logger.info("Reading dex files")
// read dex files
val dexFile = MultiDexIO.readDexFile(true, options.inputFile, NAMER, null, null)
// get the opcodes
opcodes = dexFile.opcodes
// finally create patcher data
data = PatcherData(
dexFile.classes.toMutableList(), options.resourceCacheDirectory, packageMetadata
)
} }
/** /**
@@ -165,43 +169,46 @@ class Patcher(private val options: PatcherOptions) {
if (options.patchResources) { if (options.patchResources) {
val cacheDirectory = ExtFile(options.resourceCacheDirectory) val cacheDirectory = ExtFile(options.resourceCacheDirectory)
try {
val androlibResources = AndrolibResources().also { resources ->
resources.buildOptions = BuildOptions().also { buildOptions ->
buildOptions.setBuildOptions(options)
buildOptions.isFramework = metaInfo.isFrameworkApk
buildOptions.resourcesAreCompressed = metaInfo.compressionType
buildOptions.doNotCompress = metaInfo.doNotCompress
}
val androlibResources = AndrolibResources().also { resources -> resources.setSdkInfo(metaInfo.sdkInfo)
resources.buildOptions = BuildOptions().also { buildOptions -> resources.setVersionInfo(metaInfo.versionInfo)
buildOptions.setBuildOptions(options) resources.setSharedLibrary(metaInfo.sharedLibrary)
buildOptions.isFramework = metaInfo.isFrameworkApk resources.setSparseResources(metaInfo.sparseResources)
buildOptions.resourcesAreCompressed = metaInfo.compressionType
buildOptions.doNotCompress = metaInfo.doNotCompress
} }
resources.setSdkInfo(metaInfo.sdkInfo) val manifestFile = cacheDirectory.resolve("AndroidManifest.xml")
resources.setVersionInfo(metaInfo.versionInfo)
resources.setSharedLibrary(metaInfo.sharedLibrary)
resources.setSparseResources(metaInfo.sparseResources)
}
val manifestFile = cacheDirectory.resolve("AndroidManifest.xml") ResXmlPatcher.fixingPublicAttrsInProviderAttributes(manifestFile)
ResXmlPatcher.fixingPublicAttrsInProviderAttributes(manifestFile) val aaptFile = cacheDirectory.resolve("aapt_temp_file")
val aaptFile = cacheDirectory.resolve("aapt_temp_file") // delete if it exists
Files.deleteIfExists(aaptFile.toPath())
// delete if it exists val resDirectory = cacheDirectory.resolve("res")
Files.deleteIfExists(aaptFile.toPath()) val includedFiles = metaInfo.usesFramework.ids.map { id ->
androlibResources.getFrameworkApk(
id, metaInfo.usesFramework.tag
)
}.toTypedArray()
val resDirectory = cacheDirectory.resolve("res") logger.info("Compiling resources")
val includedFiles = metaInfo.usesFramework.ids.map { id -> androlibResources.aaptPackage(
androlibResources.getFrameworkApk( aaptFile, manifestFile, resDirectory, null, null, includedFiles
id, metaInfo.usesFramework.tag
) )
}.toTypedArray()
logger.info("Compiling resources") resourceFile = aaptFile
androlibResources.aaptPackage( } finally {
aaptFile, manifestFile, resDirectory, null, null, includedFiles cacheDirectory.close()
) }
resourceFile = aaptFile
} }
logger.trace("Creating new dex file") logger.trace("Creating new dex file")
@@ -269,7 +276,8 @@ class Patcher(private val options: PatcherOptions) {
if (result.isSuccess()) return@forEach if (result.isSuccess()) return@forEach
val errorMessage = result.error()!!.cause val error = result.error()!!
val errorMessage = error.cause ?: error.message
return PatchResultError("'$patchName' depends on '${patchDependency.patchName}' but the following error was raised: $errorMessage") return PatchResultError("'$patchName' depends on '${patchDependency.patchName}' but the following error was raised: $errorMessage")
} }

View File

@@ -5,6 +5,6 @@ import java.io.InputStream
/** /**
* Wrapper for dex files. * Wrapper for dex files.
* @param name The original name of the dex file. * @param name The original name of the dex file.
* @param dexFileInputStream The dex file as [InputStream]. * @param stream The dex file as [InputStream].
*/ */
data class DexFile(val name: String, val dexFileInputStream: InputStream) data class DexFile(val name: String, val stream: InputStream)

View File

@@ -1,17 +1,17 @@
package app.revanced.patcher.util.patch.base package app.revanced.patcher.util.patch
import app.revanced.patcher.data.Data import app.revanced.patcher.data.Data
import app.revanced.patcher.patch.Patch import app.revanced.patcher.patch.Patch
import java.io.File import java.io.File
/** /**
* @param patchBundlePath The path to the patch bundle. * @param path The path to the patch bundle.
*/ */
abstract class PatchBundle(patchBundlePath: String) : File(patchBundlePath) { abstract class PatchBundle(path: String) : File(path) {
internal fun loadPatches(classLoader: ClassLoader, classNames: Iterator<String>) = buildList { internal fun loadPatches(classLoader: ClassLoader, classNames: Iterator<String>) = buildList {
classNames.forEach { className -> for (className in classNames) {
val clazz = classLoader.loadClass(className) val clazz = classLoader.loadClass(className)
if (!clazz.isAnnotationPresent(app.revanced.patcher.patch.annotations.Patch::class.java)) return@forEach if (!clazz.isAnnotationPresent(app.revanced.patcher.patch.annotations.Patch::class.java)) continue
@Suppress("UNCHECKED_CAST") this.add(clazz as Class<out Patch<Data>>) @Suppress("UNCHECKED_CAST") this.add(clazz as Class<out Patch<Data>>)
} }
} }

View File

@@ -1,4 +1,4 @@
package app.revanced.patcher.util.patch.util package app.revanced.patcher.util.patch
internal class StringIterator<T, I : Iterator<T>>( internal class StringIterator<T, I : Iterator<T>>(
private val iterator: I, private val iterator: I,

View File

@@ -1,7 +1,7 @@
package app.revanced.patcher.util.patch.implementation package app.revanced.patcher.util.patch.impl
import app.revanced.patcher.util.patch.base.PatchBundle import app.revanced.patcher.util.patch.PatchBundle
import app.revanced.patcher.util.patch.util.StringIterator import app.revanced.patcher.util.patch.StringIterator
import org.jf.dexlib2.DexFileFactory import org.jf.dexlib2.DexFileFactory
/** /**

View File

@@ -1,7 +1,7 @@
package app.revanced.patcher.util.patch.implementation package app.revanced.patcher.util.patch.impl
import app.revanced.patcher.util.patch.base.PatchBundle import app.revanced.patcher.util.patch.PatchBundle
import app.revanced.patcher.util.patch.util.StringIterator import app.revanced.patcher.util.patch.StringIterator
import java.net.URLClassLoader import java.net.URLClassLoader
import java.util.jar.JarFile import java.util.jar.JarFile