You've already forked revanced-patcher
mirror of
https://github.com/revanced/revanced-patcher
synced 2025-09-17 07:30:49 +02:00
Compare commits
20 Commits
v1.0.0-dev
...
v1.0.0-dev
Author | SHA1 | Date | |
---|---|---|---|
![]() |
a06c0db6a7 | ||
![]() |
3f0c740200 | ||
![]() |
545c5c144d | ||
![]() |
0fa529fcdf | ||
![]() |
7573db2575 | ||
![]() |
70ca184cf9 | ||
![]() |
72f16b7785 | ||
![]() |
fc03639b26 | ||
![]() |
88a85f94e7 | ||
![]() |
45a167e785 | ||
![]() |
699d8abf59 | ||
![]() |
b58c718699 | ||
![]() |
266d6810a9 | ||
![]() |
40b1fa43e1 | ||
![]() |
94f9594eed | ||
![]() |
cff58ab180 | ||
![]() |
989646b0b5 | ||
![]() |
5c3fbaee7a | ||
![]() |
08525e9c26 | ||
![]() |
5630e49663 |
1
.github/workflows/release.yml
vendored
1
.github/workflows/release.yml
vendored
@@ -1,5 +1,6 @@
|
|||||||
name: Release
|
name: Release
|
||||||
on:
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
|
41
CHANGELOG.md
41
CHANGELOG.md
@@ -1,3 +1,44 @@
|
|||||||
|
# [1.0.0-dev.16](https://github.com/revanced/revanced-patcher/compare/v1.0.0-dev.15...v1.0.0-dev.16) (2022-05-27)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* `JarPatchBundle` loading non-class files to class loader ([3f0c740](https://github.com/revanced/revanced-patcher/commit/3f0c740200dd91a060426638c2f8f516938b4c53))
|
||||||
|
* remove dependency to fork of Apktool ([0fa529f](https://github.com/revanced/revanced-patcher/commit/0fa529fcdf9a7b5ea9a361b9f9f32f3f3fce009f))
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* migrate to `DexPatchBundle` and `JarPatchBundle` ([7573db2](https://github.com/revanced/revanced-patcher/commit/7573db25757de89824af4f3aea167e500120eabb))
|
||||||
|
|
||||||
|
# [1.0.0-dev.15](https://github.com/revanced/revanced-patcher/compare/v1.0.0-dev.14...v1.0.0-dev.15) (2022-05-25)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* utility functions to get metadata of patch & sigs ([72f16b7](https://github.com/revanced/revanced-patcher/commit/72f16b778587c28d8f8e91da502f197e7dc35d6d))
|
||||||
|
|
||||||
|
# [1.0.0-dev.14](https://github.com/revanced/revanced-patcher/compare/v1.0.0-dev.13...v1.0.0-dev.14) (2022-05-24)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* reformat (trigger release) ([45a167e](https://github.com/revanced/revanced-patcher/commit/45a167e7856da0306f796953775c7b7543d9bec0))
|
||||||
|
|
||||||
|
# [1.0.0-dev.13](https://github.com/revanced/revanced-patcher/compare/v1.0.0-dev.12...v1.0.0-dev.13) (2022-05-24)
|
||||||
|
|
||||||
|
|
||||||
|
### Performance Improvements
|
||||||
|
|
||||||
|
* decode manifest only when not using resource patcher ([40b1fa4](https://github.com/revanced/revanced-patcher/commit/40b1fa43e1704ace29d3e349df2f4a8ea828c5c2))
|
||||||
|
|
||||||
|
# [1.0.0-dev.12](https://github.com/revanced/revanced-patcher/compare/v1.0.0-dev.11...v1.0.0-dev.12) (2022-05-22)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* using old instance of `Androlib` when saving ([5630e49](https://github.com/revanced/revanced-patcher/commit/5630e4966310311cdfd53e2ba128255047626adc))
|
||||||
|
|
||||||
# [1.0.0-dev.11](https://github.com/revanced/revanced-patcher/compare/v1.0.0-dev.10...v1.0.0-dev.11) (2022-05-22)
|
# [1.0.0-dev.11](https://github.com/revanced/revanced-patcher/compare/v1.0.0-dev.10...v1.0.0-dev.11) (2022-05-22)
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
plugins {
|
plugins {
|
||||||
kotlin("jvm") version "1.6.20"
|
kotlin("jvm") version "1.6.21"
|
||||||
java
|
java
|
||||||
`maven-publish`
|
`maven-publish`
|
||||||
}
|
}
|
||||||
@@ -15,8 +15,10 @@ repositories {
|
|||||||
// Instead, you should set them in:
|
// Instead, you should set them in:
|
||||||
// Windows: %homepath%\.gradle\gradle.properties
|
// Windows: %homepath%\.gradle\gradle.properties
|
||||||
// Linux: ~/.gradle/gradle.properties
|
// Linux: ~/.gradle/gradle.properties
|
||||||
username = project.findProperty("gpr.user") as String? ?: System.getenv("GITHUB_ACTOR") // DO NOT CHANGE!
|
username =
|
||||||
password = project.findProperty("gpr.key") as String? ?: System.getenv("GITHUB_TOKEN") // DO NOT CHANGE!
|
project.findProperty("gpr.user") as String? ?: System.getenv("GITHUB_ACTOR") // DO NOT CHANGE!
|
||||||
|
password =
|
||||||
|
project.findProperty("gpr.key") as String? ?: System.getenv("GITHUB_TOKEN") // DO NOT CHANGE!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -24,6 +26,7 @@ repositories {
|
|||||||
dependencies {
|
dependencies {
|
||||||
implementation(kotlin("stdlib"))
|
implementation(kotlin("stdlib"))
|
||||||
|
|
||||||
|
api("xpp3:xpp3:1.1.4c")
|
||||||
api("org.apktool:apktool-lib:2.6.1")
|
api("org.apktool:apktool-lib:2.6.1")
|
||||||
api("app.revanced:multidexlib2:2.5.2.r2")
|
api("app.revanced:multidexlib2:2.5.2.r2")
|
||||||
api("org.smali:smali:2.5.2")
|
api("org.smali:smali:2.5.2")
|
||||||
|
@@ -1,2 +1,2 @@
|
|||||||
kotlin.code.style = official
|
kotlin.code.style = official
|
||||||
version = 1.0.0-dev.11
|
version = 1.0.0-dev.16
|
||||||
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,5 +1,5 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-all.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
@@ -5,6 +5,7 @@ import app.revanced.patcher.data.PatcherData
|
|||||||
import app.revanced.patcher.data.base.Data
|
import app.revanced.patcher.data.base.Data
|
||||||
import app.revanced.patcher.data.implementation.findIndexed
|
import app.revanced.patcher.data.implementation.findIndexed
|
||||||
import app.revanced.patcher.extensions.findAnnotationRecursively
|
import app.revanced.patcher.extensions.findAnnotationRecursively
|
||||||
|
import app.revanced.patcher.extensions.nullOutputStream
|
||||||
import app.revanced.patcher.patch.base.Patch
|
import app.revanced.patcher.patch.base.Patch
|
||||||
import app.revanced.patcher.patch.implementation.BytecodePatch
|
import app.revanced.patcher.patch.implementation.BytecodePatch
|
||||||
import app.revanced.patcher.patch.implementation.ResourcePatch
|
import app.revanced.patcher.patch.implementation.ResourcePatch
|
||||||
@@ -14,6 +15,11 @@ import app.revanced.patcher.signature.implementation.method.resolver.MethodSigna
|
|||||||
import app.revanced.patcher.util.ListBackedSet
|
import app.revanced.patcher.util.ListBackedSet
|
||||||
import brut.androlib.Androlib
|
import brut.androlib.Androlib
|
||||||
import brut.androlib.meta.UsesFramework
|
import brut.androlib.meta.UsesFramework
|
||||||
|
import brut.androlib.res.AndrolibResources
|
||||||
|
import brut.androlib.res.data.ResPackage
|
||||||
|
import brut.androlib.res.decoder.AXmlResourceParser
|
||||||
|
import brut.androlib.res.decoder.ResAttrDecoder
|
||||||
|
import brut.androlib.res.decoder.XmlPullStreamDecoder
|
||||||
import brut.directory.ExtFile
|
import brut.directory.ExtFile
|
||||||
import lanchon.multidexlib2.BasicDexFileNamer
|
import lanchon.multidexlib2.BasicDexFileNamer
|
||||||
import lanchon.multidexlib2.DexIO
|
import lanchon.multidexlib2.DexIO
|
||||||
@@ -41,33 +47,51 @@ class Patcher(
|
|||||||
val packageVersion: String
|
val packageVersion: String
|
||||||
val packageName: String
|
val packageName: String
|
||||||
|
|
||||||
private val usesFramework: UsesFramework
|
private lateinit var usesFramework: UsesFramework
|
||||||
private val patcherData: PatcherData
|
private val patcherData: PatcherData
|
||||||
private val opcodes: Opcodes
|
private val opcodes: Opcodes
|
||||||
private var signaturesResolved = false
|
private var signaturesResolved = false
|
||||||
private val androlib = Androlib()
|
|
||||||
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val extFileInput = ExtFile(inputFile)
|
val extFileInput = ExtFile(inputFile)
|
||||||
val resourceTable = androlib.getResTable(extFileInput, true)
|
|
||||||
val outDir = File(resourceCacheDirectory)
|
val outDir = File(resourceCacheDirectory)
|
||||||
|
|
||||||
if (outDir.exists()) outDir.deleteRecursively()
|
if (outDir.exists()) outDir.deleteRecursively()
|
||||||
outDir.mkdir()
|
outDir.mkdir()
|
||||||
|
|
||||||
// 1. decode resources to cache directory
|
// load the resource table from the input file
|
||||||
androlib.decodeManifestWithResources(extFileInput, outDir, resourceTable)
|
val androlib = Androlib()
|
||||||
androlib.decodeResourcesFull(extFileInput, outDir, resourceTable)
|
val resourceTable = androlib.getResTable(extFileInput, true)
|
||||||
|
|
||||||
// 2. read framework ids from the resource table
|
if (patchResources) {
|
||||||
usesFramework = UsesFramework()
|
// 1. decode resources to cache directory
|
||||||
usesFramework.ids = resourceTable.listFramePackages().map { it.id }.sorted()
|
androlib.decodeManifestWithResources(extFileInput, outDir, resourceTable)
|
||||||
|
androlib.decodeResourcesFull(extFileInput, outDir, resourceTable)
|
||||||
|
|
||||||
// 3. read package info
|
// 2. read framework ids from the resource table
|
||||||
packageName = resourceTable.packageOriginal
|
usesFramework = UsesFramework()
|
||||||
|
usesFramework.ids = resourceTable.listFramePackages().map { it.id }.sorted()
|
||||||
|
} else {
|
||||||
|
// 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(
|
||||||
|
extFileInput.directory.getFileInput("AndroidManifest.xml"), nullOutputStream
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// set package information
|
||||||
packageVersion = resourceTable.versionInfo.versionName
|
packageVersion = resourceTable.versionInfo.versionName
|
||||||
|
packageName = resourceTable.currentResPackage.name
|
||||||
// read dex files
|
// read dex files
|
||||||
val dexFile = MultiDexIO.readDexFile(true, inputFile, NAMER, null, null)
|
val dexFile = MultiDexIO.readDexFile(true, inputFile, NAMER, null, null)
|
||||||
opcodes = dexFile.opcodes
|
opcodes = dexFile.opcodes
|
||||||
@@ -83,9 +107,7 @@ class Patcher(
|
|||||||
* @param throwOnDuplicates If this is set to true, the patcher will throw an exception if a duplicate class has been found.
|
* @param throwOnDuplicates If this is set to true, the patcher will throw an exception if a duplicate class has been found.
|
||||||
*/
|
*/
|
||||||
fun addFiles(
|
fun addFiles(
|
||||||
files: Iterable<File>,
|
files: Iterable<File>, allowedOverwrites: Iterable<String> = emptyList(), throwOnDuplicates: Boolean = false
|
||||||
allowedOverwrites: Iterable<String> = emptyList(),
|
|
||||||
throwOnDuplicates: Boolean = false
|
|
||||||
) {
|
) {
|
||||||
for (file in files) {
|
for (file in files) {
|
||||||
val dexFile = MultiDexIO.readDexFile(true, file, NAMER, null, null)
|
val dexFile = MultiDexIO.readDexFile(true, file, NAMER, null, null)
|
||||||
@@ -124,16 +146,16 @@ class Patcher(
|
|||||||
// build modified resources
|
// build modified resources
|
||||||
if (patchResources) {
|
if (patchResources) {
|
||||||
val extDir = ExtFile(resourceCacheDirectory)
|
val extDir = ExtFile(resourceCacheDirectory)
|
||||||
androlib.buildResources(extDir, usesFramework)
|
|
||||||
|
// TODO: figure out why a new instance of Androlib is necessary here
|
||||||
|
Androlib().buildResources(extDir, usesFramework)
|
||||||
}
|
}
|
||||||
|
|
||||||
// write dex modified files
|
// write dex modified files
|
||||||
val output = mutableMapOf<String, MemoryDataStore>()
|
val output = mutableMapOf<String, MemoryDataStore>()
|
||||||
MultiDexIO.writeDexFile(
|
MultiDexIO.writeDexFile(
|
||||||
true, -1, // core count
|
true, -1, // core count
|
||||||
output, NAMER, newDexFile,
|
output, NAMER, newDexFile, DexIO.DEFAULT_MAX_DEX_POOL_SIZE, null
|
||||||
DexIO.DEFAULT_MAX_DEX_POOL_SIZE,
|
|
||||||
null
|
|
||||||
)
|
)
|
||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
@@ -174,8 +196,7 @@ class Patcher(
|
|||||||
* If the [Patch] failed to apply, an Exception will always be returned to the wrapping Result object.
|
* If the [Patch] failed to apply, an Exception will always be returned to the wrapping Result object.
|
||||||
*/
|
*/
|
||||||
fun applyPatches(
|
fun applyPatches(
|
||||||
stopOnError: Boolean = false,
|
stopOnError: Boolean = false, callback: (String) -> Unit = {}
|
||||||
callback: (String) -> Unit = {}
|
|
||||||
): Map<String, Result<PatchResultSuccess>> {
|
): Map<String, Result<PatchResultSuccess>> {
|
||||||
if (!signaturesResolved) {
|
if (!signaturesResolved) {
|
||||||
resolveSignatures()
|
resolveSignatures()
|
||||||
|
@@ -14,8 +14,7 @@ class ResourceData(private val resourceCacheDirectory: File) : Data {
|
|||||||
private fun resolve(path: String) = resourceCacheDirectory.resolve(path)
|
private fun resolve(path: String) = resourceCacheDirectory.resolve(path)
|
||||||
|
|
||||||
fun forEach(action: (File) -> Unit) = resourceCacheDirectory.walkTopDown().forEach(action)
|
fun forEach(action: (File) -> Unit) = resourceCacheDirectory.walkTopDown().forEach(action)
|
||||||
fun reader(path: String) = resolve(path).reader()
|
fun get(path: String) = resolve(path)
|
||||||
fun writer(path: String) = resolve(path).writer()
|
|
||||||
|
|
||||||
fun replace(path: String, oldValue: String, newValue: String, oldValueIsRegex: Boolean = false) {
|
fun replace(path: String, oldValue: String, newValue: String, oldValueIsRegex: Boolean = false) {
|
||||||
// TODO: buffer this somehow
|
// TODO: buffer this somehow
|
||||||
|
@@ -0,0 +1,32 @@
|
|||||||
|
package app.revanced.patcher.extensions
|
||||||
|
|
||||||
|
import app.revanced.patcher.annotation.Compatibility
|
||||||
|
import app.revanced.patcher.annotation.Description
|
||||||
|
import app.revanced.patcher.annotation.Name
|
||||||
|
import app.revanced.patcher.annotation.Version
|
||||||
|
import app.revanced.patcher.patch.base.Patch
|
||||||
|
import app.revanced.patcher.signature.implementation.method.MethodSignature
|
||||||
|
import app.revanced.patcher.signature.implementation.method.annotation.FuzzyPatternScanMethod
|
||||||
|
import app.revanced.patcher.signature.implementation.method.annotation.MatchingMethod
|
||||||
|
|
||||||
|
private inline fun <reified T : Annotation> Any.firstAnnotation() =
|
||||||
|
this::class.annotations.first { it is T } as T
|
||||||
|
|
||||||
|
private inline fun <reified T : Annotation> Any.recursiveAnnotation() =
|
||||||
|
this::class.java.findAnnotationRecursively(T::class.java)!!
|
||||||
|
|
||||||
|
object PatchExtensions {
|
||||||
|
val Patch<*>.name get() = firstAnnotation<Name>().name
|
||||||
|
val Patch<*>.version get() = firstAnnotation<Version>().version
|
||||||
|
val Patch<*>.description get() = firstAnnotation<Description>().description
|
||||||
|
val Patch<*>.compatiblePackages get() = recursiveAnnotation<Compatibility>().compatiblePackages
|
||||||
|
}
|
||||||
|
|
||||||
|
object MethodSignatureExtensions {
|
||||||
|
val MethodSignature.name get() = firstAnnotation<Name>().name
|
||||||
|
val MethodSignature.version get() = firstAnnotation<Version>().version
|
||||||
|
val MethodSignature.description get() = firstAnnotation<Description>().description
|
||||||
|
val MethodSignature.compatiblePackages get() = recursiveAnnotation<Compatibility>().compatiblePackages
|
||||||
|
val MethodSignature.matchingMethod get() = firstAnnotation<MatchingMethod>()
|
||||||
|
val MethodSignature.fuzzyThreshold get() = firstAnnotation<FuzzyPatternScanMethod>().threshold
|
||||||
|
}
|
@@ -9,6 +9,7 @@ import org.jf.dexlib2.iface.reference.MethodReference
|
|||||||
import org.jf.dexlib2.immutable.ImmutableMethod
|
import org.jf.dexlib2.immutable.ImmutableMethod
|
||||||
import org.jf.dexlib2.immutable.ImmutableMethodImplementation
|
import org.jf.dexlib2.immutable.ImmutableMethodImplementation
|
||||||
import org.jf.dexlib2.util.MethodUtil
|
import org.jf.dexlib2.util.MethodUtil
|
||||||
|
import java.io.OutputStream
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Recursively find a given annotation on a class
|
* Recursively find a given annotation on a class
|
||||||
@@ -105,4 +106,9 @@ internal fun parametersEqual(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal val nullOutputStream: OutputStream =
|
||||||
|
object : OutputStream() {
|
||||||
|
override fun write(b: Int) {}
|
||||||
|
}
|
@@ -10,7 +10,7 @@ import app.revanced.patcher.signature.implementation.method.MethodSignature
|
|||||||
@Target(AnnotationTarget.CLASS)
|
@Target(AnnotationTarget.CLASS)
|
||||||
@Retention(AnnotationRetention.RUNTIME)
|
@Retention(AnnotationRetention.RUNTIME)
|
||||||
annotation class MatchingMethod(
|
annotation class MatchingMethod(
|
||||||
val definingClass: String = "L<unspecified-class>",
|
val definingClass: String = "L<unspecified-class>;",
|
||||||
val name: String = "<unspecified-method>"
|
val name: String = "<unspecified-method>"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@@ -16,7 +16,7 @@ class ProxyBackedClassList(internal val internalClasses: MutableList<ClassDef>)
|
|||||||
/**
|
/**
|
||||||
* Apply all resolved classes into [internalClasses] and clean the [proxies] list.
|
* Apply all resolved classes into [internalClasses] and clean the [proxies] list.
|
||||||
*/
|
*/
|
||||||
fun applyProxies() {
|
internal fun applyProxies() {
|
||||||
// FIXME: check if this could cause issues when multiple patches use the same proxy
|
// FIXME: check if this could cause issues when multiple patches use the same proxy
|
||||||
proxies.removeIf { proxy ->
|
proxies.removeIf { proxy ->
|
||||||
// if the proxy is unused, keep it in the list
|
// if the proxy is unused, keep it in the list
|
||||||
|
@@ -0,0 +1,17 @@
|
|||||||
|
package app.revanced.patcher.util.patch.base
|
||||||
|
|
||||||
|
import app.revanced.patcher.patch.base.Patch
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param patchBundlePath The path to the patch bundle.
|
||||||
|
*/
|
||||||
|
abstract class PatchBundle(patchBundlePath: String) : File(patchBundlePath) {
|
||||||
|
internal fun loadPatches(classLoader: ClassLoader, classNames: Iterator<String>) = buildList {
|
||||||
|
classNames.forEach { className ->
|
||||||
|
val clazz = classLoader.loadClass(className)
|
||||||
|
if (!clazz.isAnnotationPresent(app.revanced.patcher.patch.annotations.Patch::class.java)) return@forEach
|
||||||
|
@Suppress("UNCHECKED_CAST") this.add(clazz as Class<Patch<*>>)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,17 @@
|
|||||||
|
package app.revanced.patcher.util.patch.implementation
|
||||||
|
|
||||||
|
import app.revanced.patcher.util.patch.base.PatchBundle
|
||||||
|
import app.revanced.patcher.util.patch.util.StringIterator
|
||||||
|
import org.jf.dexlib2.DexFileFactory
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A patch bundle of the ReVanced [DexPatchBundle] format.
|
||||||
|
* @param patchBundlePath The path to a patch bundle of dex format.
|
||||||
|
* @param dexClassLoader The dex class loader.
|
||||||
|
*/
|
||||||
|
class DexPatchBundle(patchBundlePath: String, private val dexClassLoader: ClassLoader) : PatchBundle(patchBundlePath) {
|
||||||
|
fun loadPatches() = loadPatches(dexClassLoader,
|
||||||
|
StringIterator(DexFileFactory.loadDexFile(path, null).classes.iterator()) { classDef ->
|
||||||
|
classDef.type.substring(1, classDef.length - 1).replace('/', '.')
|
||||||
|
})
|
||||||
|
}
|
@@ -0,0 +1,30 @@
|
|||||||
|
package app.revanced.patcher.util.patch.implementation
|
||||||
|
|
||||||
|
import app.revanced.patcher.util.patch.base.PatchBundle
|
||||||
|
import app.revanced.patcher.util.patch.util.StringIterator
|
||||||
|
import java.net.URLClassLoader
|
||||||
|
import java.util.jar.JarFile
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A patch bundle of the ReVanced [JarPatchBundle] format.
|
||||||
|
* @param patchBundlePath The path to the patch bundle.
|
||||||
|
*/
|
||||||
|
class JarPatchBundle(patchBundlePath: String) : PatchBundle(patchBundlePath) {
|
||||||
|
fun loadPatches() = loadPatches(
|
||||||
|
URLClassLoader(
|
||||||
|
arrayOf(this.toURI().toURL()),
|
||||||
|
Thread.currentThread().contextClassLoader // TODO: find out why this is required
|
||||||
|
),
|
||||||
|
StringIterator(
|
||||||
|
JarFile(this)
|
||||||
|
.entries()
|
||||||
|
.toList() // TODO: find a cleaner solution than that to filter non class files
|
||||||
|
.filter {
|
||||||
|
it.name.endsWith(".class") && !it.name.contains("$")
|
||||||
|
}
|
||||||
|
.iterator()
|
||||||
|
) {
|
||||||
|
it.realName.replace('/', '.').replace(".class", "")
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
@@ -0,0 +1,10 @@
|
|||||||
|
package app.revanced.patcher.util.patch.util
|
||||||
|
|
||||||
|
internal class StringIterator<T, I : Iterator<T>>(
|
||||||
|
private val iterator: I,
|
||||||
|
private val _next: (T) -> String
|
||||||
|
) : Iterator<String> {
|
||||||
|
override fun hasNext() = iterator.hasNext()
|
||||||
|
|
||||||
|
override fun next() = _next(iterator.next())
|
||||||
|
}
|
@@ -1,4 +1,4 @@
|
|||||||
package app.revanced.patcher
|
package app.revanced.patcher.usage
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
|
|
@@ -18,21 +18,17 @@ import org.w3c.dom.Element
|
|||||||
@Version("0.0.1")
|
@Version("0.0.1")
|
||||||
class ExampleResourcePatch : ResourcePatch() {
|
class ExampleResourcePatch : ResourcePatch() {
|
||||||
override fun execute(data: ResourceData): PatchResult {
|
override fun execute(data: ResourceData): PatchResult {
|
||||||
val editor = data.getXmlEditor("AndroidManifest.xml")
|
data.getXmlEditor("AndroidManifest.xml").use { domFileEditor ->
|
||||||
|
val element = domFileEditor // regular DomFileEditor
|
||||||
// regular DomFileEditor
|
.file
|
||||||
val element = editor
|
.getElementsByTagName("application")
|
||||||
.file
|
.item(0) as Element
|
||||||
.getElementsByTagName("application")
|
element
|
||||||
.item(0) as Element
|
.setAttribute(
|
||||||
element
|
"exampleAttribute",
|
||||||
.setAttribute(
|
"exampleValue"
|
||||||
"exampleAttribute",
|
)
|
||||||
"exampleValue"
|
}
|
||||||
)
|
|
||||||
|
|
||||||
// close the editor to write changes
|
|
||||||
editor.close()
|
|
||||||
|
|
||||||
// iterate through all available resources
|
// iterate through all available resources
|
||||||
data.forEach {
|
data.forEach {
|
||||||
|
Reference in New Issue
Block a user