You've already forked revanced-patcher
mirror of
https://github.com/revanced/revanced-patcher
synced 2025-09-10 05:30:49 +02:00
Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
44f6a3ebc5 | ||
![]() |
7882a8d928 | ||
![]() |
cc3d32748b | ||
![]() |
f9da2ad531 | ||
![]() |
b19e1131e8 | ||
![]() |
123ad54c15 | ||
![]() |
09f6ab4155 | ||
![]() |
01cf3fb50f | ||
![]() |
6c5f9d4198 | ||
![]() |
7b2d058144 | ||
![]() |
db2804270e | ||
![]() |
2572cd04b5 |
35
CHANGELOG.md
35
CHANGELOG.md
@@ -1,3 +1,38 @@
|
|||||||
|
# [3.4.0](https://github.com/revanced/revanced-patcher/compare/v3.3.3...v3.4.0) (2022-08-31)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* nullable parameters ([7882a8d](https://github.com/revanced/revanced-patcher/commit/7882a8d928cad8de8cfea711947fc02659549d20))
|
||||||
|
|
||||||
|
## [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)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* revert soft dependencies ([7b2d058](https://github.com/revanced/revanced-patcher/commit/7b2d058144b0718992d329731e2af7cc704e4370))
|
||||||
|
|
||||||
|
# [3.3.0](https://github.com/revanced/revanced-patcher/compare/v3.2.1...v3.3.0) (2022-08-02)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* add getValue & setValue for PatchOption ([2572cd0](https://github.com/revanced/revanced-patcher/commit/2572cd04b5da4eeae738c8dde31493177edf0bf8))
|
||||||
|
|
||||||
## [3.2.1](https://github.com/revanced/revanced-patcher/compare/v3.2.0...v3.2.1) (2022-08-02)
|
## [3.2.1](https://github.com/revanced/revanced-patcher/compare/v3.2.0...v3.2.1) (2022-08-02)
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1,2 +1,2 @@
|
|||||||
kotlin.code.style = official
|
kotlin.code.style = official
|
||||||
version = 3.2.1
|
version = 3.4.0
|
||||||
|
@@ -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")
|
||||||
@@ -262,16 +269,16 @@ class Patcher(private val options: PatcherOptions) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// recursively apply all dependency patches
|
// recursively apply all dependency patches
|
||||||
patch.dependencies.forEach {
|
patch.dependencies?.forEach {
|
||||||
val dependency = it.patch.java
|
val patchDependency = it.java
|
||||||
|
|
||||||
|
val result = applyPatch(patchDependency, appliedPatches)
|
||||||
|
|
||||||
val result = applyPatch(dependency, appliedPatches)
|
|
||||||
if (result.isSuccess()) return@forEach
|
if (result.isSuccess()) return@forEach
|
||||||
|
|
||||||
val error = result.error()!!
|
val error = result.error()!!
|
||||||
val errorMessage = error.cause ?: error.message
|
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 '${dependency.patchName}' but the following error was raised: $errorMessage")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val patchInstance = patch.getDeclaredConstructor().newInstance()
|
val patchInstance = patch.getDeclaredConstructor().newInstance()
|
||||||
|
@@ -24,5 +24,5 @@ annotation class Compatibility(
|
|||||||
@MustBeDocumented
|
@MustBeDocumented
|
||||||
annotation class Package(
|
annotation class Package(
|
||||||
val name: String,
|
val name: String,
|
||||||
val versions: Array<String>
|
val versions: Array<String> = [],
|
||||||
)
|
)
|
@@ -7,9 +7,6 @@ import app.revanced.patcher.annotation.Version
|
|||||||
import app.revanced.patcher.data.Data
|
import app.revanced.patcher.data.Data
|
||||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||||
import app.revanced.patcher.patch.Patch
|
import app.revanced.patcher.patch.Patch
|
||||||
import app.revanced.patcher.patch.annotations.Dependencies
|
|
||||||
import app.revanced.patcher.patch.annotations.DependencyType
|
|
||||||
import app.revanced.patcher.patch.annotations.DependsOn
|
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -38,26 +35,20 @@ private fun <T : Annotation> Class<*>.findAnnotationRecursively(
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
private typealias PatchClass = Class<out Patch<Data>>
|
|
||||||
|
|
||||||
object PatchExtensions {
|
object PatchExtensions {
|
||||||
val PatchClass.patchName: String get() = recursiveAnnotation(Name::class)?.name ?: this.javaClass.simpleName
|
val Class<out Patch<Data>>.patchName: String
|
||||||
val PatchClass.version get() = recursiveAnnotation(Version::class)?.version
|
get() = recursiveAnnotation(Name::class)?.name ?: this.javaClass.simpleName
|
||||||
val PatchClass.include get() = recursiveAnnotation(app.revanced.patcher.patch.annotations.Patch::class)!!.include
|
val Class<out Patch<Data>>.version get() = recursiveAnnotation(Version::class)?.version
|
||||||
val PatchClass.description get() = recursiveAnnotation(Description::class)?.description
|
val Class<out Patch<Data>>.include get() = recursiveAnnotation(app.revanced.patcher.patch.annotations.Patch::class)!!.include
|
||||||
val PatchClass.dependencies get() = buildList {
|
val Class<out Patch<Data>>.description get() = recursiveAnnotation(Description::class)?.description
|
||||||
recursiveAnnotation(DependsOn::class)?.let { add(PatchDependency(it.value, it.type)) }
|
val Class<out Patch<Data>>.dependencies get() = recursiveAnnotation(app.revanced.patcher.patch.annotations.DependsOn::class)?.dependencies
|
||||||
recursiveAnnotation(Dependencies::class)?.dependencies?.forEach { add(PatchDependency(it, DependencyType.HARD)) }
|
val Class<out Patch<Data>>.compatiblePackages get() = recursiveAnnotation(Compatibility::class)?.compatiblePackages
|
||||||
}.toTypedArray()
|
|
||||||
val PatchClass.compatiblePackages get() = recursiveAnnotation(Compatibility::class)?.compatiblePackages
|
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun PatchClass.dependsOn(patch: PatchClass): Boolean {
|
fun Class<out Patch<Data>>.dependsOn(patch: Class<out Patch<Data>>): Boolean {
|
||||||
if (this.patchName == patch.patchName) throw IllegalArgumentException("thisval and patch may not be the same")
|
if (this.patchName == patch.patchName) throw IllegalArgumentException("thisval and patch may not be the same")
|
||||||
return this.dependencies.any { it.patch.java.patchName == this@dependsOn.patchName }
|
return this.dependencies?.any { it.java.patchName == this@dependsOn.patchName } == true
|
||||||
}
|
}
|
||||||
|
|
||||||
class PatchDependency internal constructor(val patch: KClass<out Patch<Data>>, val type: DependencyType = DependencyType.HARD)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
object MethodFingerprintExtensions {
|
object MethodFingerprintExtensions {
|
||||||
|
@@ -22,10 +22,10 @@ import org.jf.dexlib2.iface.Method
|
|||||||
* A `null` opcode is equals to an unknown opcode.
|
* A `null` opcode is equals to an unknown opcode.
|
||||||
*/
|
*/
|
||||||
abstract class MethodFingerprint(
|
abstract class MethodFingerprint(
|
||||||
internal val returnType: String?,
|
internal val returnType: String? = null,
|
||||||
internal val access: Int?,
|
internal val access: Int? = null,
|
||||||
internal val parameters: Iterable<String>?,
|
internal val parameters: Iterable<String>? = null,
|
||||||
internal val opcodes: Iterable<Opcode?>?,
|
internal val opcodes: Iterable<Opcode?>? = null,
|
||||||
internal val strings: Iterable<String>? = null,
|
internal val strings: Iterable<String>? = null,
|
||||||
internal val customFingerprint: ((methodDef: Method) -> Boolean)? = null
|
internal val customFingerprint: ((methodDef: Method) -> Boolean)? = null
|
||||||
) : Fingerprint {
|
) : Fingerprint {
|
||||||
|
@@ -1,11 +1,14 @@
|
|||||||
@file:Suppress("CanBeParameter", "MemberVisibilityCanBePrivate")
|
@file:Suppress("CanBeParameter", "MemberVisibilityCanBePrivate", "UNCHECKED_CAST")
|
||||||
|
|
||||||
package app.revanced.patcher.patch
|
package app.revanced.patcher.patch
|
||||||
|
|
||||||
|
import kotlin.reflect.KProperty
|
||||||
|
|
||||||
class NoSuchOptionException(val option: String) : Exception("No such option: $option")
|
class NoSuchOptionException(val option: String) : Exception("No such option: $option")
|
||||||
class IllegalValueException(val value: Any?) : Exception("Illegal value: $value")
|
class IllegalValueException(val value: Any?) : Exception("Illegal value: $value")
|
||||||
class InvalidTypeException(val got: String, val expected: String) :
|
class InvalidTypeException(val got: String, val expected: String) :
|
||||||
Exception("Invalid option value type: $got, expected $expected")
|
Exception("Invalid option value type: $got, expected $expected")
|
||||||
|
|
||||||
class RequirementNotMetException : Exception("null was passed into an option that requires a value")
|
class RequirementNotMetException : Exception("null was passed into an option that requires a value")
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -82,6 +85,24 @@ sealed class PatchOption<T>(
|
|||||||
field = value
|
field = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of the option.
|
||||||
|
* Please note that using the wrong value type results in a runtime error.
|
||||||
|
*/
|
||||||
|
operator fun <T> getValue(thisRef: Nothing?, property: KProperty<*>) = value as T
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of the option.
|
||||||
|
* Please note that using the wrong value type results in a runtime error.
|
||||||
|
*/
|
||||||
|
inline operator fun <reified V> setValue(thisRef: Any?, property: KProperty<*>, new: V) {
|
||||||
|
if (value !is V) throw InvalidTypeException(
|
||||||
|
V::class.java.canonicalName,
|
||||||
|
value?.let { it::class.java.canonicalName } ?: "null"
|
||||||
|
)
|
||||||
|
value = new as T
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A [PatchOption] representing a [String].
|
* A [PatchOption] representing a [String].
|
||||||
* @see PatchOption
|
* @see PatchOption
|
||||||
|
@@ -19,29 +19,6 @@ annotation class Patch(val include: Boolean = true)
|
|||||||
@Target(AnnotationTarget.CLASS)
|
@Target(AnnotationTarget.CLASS)
|
||||||
@Retention(AnnotationRetention.RUNTIME)
|
@Retention(AnnotationRetention.RUNTIME)
|
||||||
@MustBeDocumented
|
@MustBeDocumented
|
||||||
@Deprecated(
|
|
||||||
"Does not support new parameter 'type'",
|
|
||||||
ReplaceWith("DependsOn")
|
|
||||||
)
|
|
||||||
annotation class Dependencies(
|
|
||||||
val dependencies: Array<KClass<out Patch<Data>>> = []
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Annotation for dependencies of [Patch]es .
|
|
||||||
*/
|
|
||||||
@Target(AnnotationTarget.CLASS)
|
|
||||||
@Retention(AnnotationRetention.RUNTIME)
|
|
||||||
@MustBeDocumented
|
|
||||||
@Repeatable
|
|
||||||
annotation class DependsOn(
|
annotation class DependsOn(
|
||||||
val value: KClass<out Patch<Data>>,
|
val dependencies: Array<KClass<out Patch<Data>>> = []
|
||||||
val type: DependencyType = DependencyType.HARD
|
)
|
||||||
)
|
|
||||||
|
|
||||||
enum class DependencyType {
|
|
||||||
/**
|
|
||||||
* Enforces that the dependency is applied, even if it was not selected.
|
|
||||||
*/
|
|
||||||
HARD
|
|
||||||
}
|
|
@@ -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)
|
@@ -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>>)
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -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,
|
@@ -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
|
||||||
|
|
||||||
/**
|
/**
|
@@ -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
|
||||||
|
|
@@ -3,6 +3,7 @@ package app.revanced.patcher.patch
|
|||||||
import app.revanced.patcher.usage.bytecode.ExampleBytecodePatch
|
import app.revanced.patcher.usage.bytecode.ExampleBytecodePatch
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import org.junit.jupiter.api.assertThrows
|
import org.junit.jupiter.api.assertThrows
|
||||||
|
import kotlin.test.assertNotEquals
|
||||||
|
|
||||||
internal class PatchOptionsTest {
|
internal class PatchOptionsTest {
|
||||||
private val options = ExampleBytecodePatch().options
|
private val options = ExampleBytecodePatch().options
|
||||||
@@ -31,9 +32,18 @@ internal class PatchOptionsTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
println(options["key1"].value)
|
val option = options["key1"]
|
||||||
|
println(option.value)
|
||||||
options["key1"] = "Hello, world!"
|
options["key1"] = "Hello, world!"
|
||||||
println(options["key1"].value)
|
println(option.value)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `should return a different value when changed`() {
|
||||||
|
var value: String by options["key1"]
|
||||||
|
val current = value + "" // force a copy
|
||||||
|
value = "Hello, world!"
|
||||||
|
assertNotEquals(current, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@@ -11,7 +11,6 @@ import app.revanced.patcher.patch.PatchOption
|
|||||||
import app.revanced.patcher.patch.PatchOptions
|
import app.revanced.patcher.patch.PatchOptions
|
||||||
import app.revanced.patcher.patch.PatchResult
|
import app.revanced.patcher.patch.PatchResult
|
||||||
import app.revanced.patcher.patch.PatchResultSuccess
|
import app.revanced.patcher.patch.PatchResultSuccess
|
||||||
import app.revanced.patcher.patch.annotations.DependencyType
|
|
||||||
import app.revanced.patcher.patch.annotations.DependsOn
|
import app.revanced.patcher.patch.annotations.DependsOn
|
||||||
import app.revanced.patcher.patch.annotations.Patch
|
import app.revanced.patcher.patch.annotations.Patch
|
||||||
import app.revanced.patcher.patch.impl.BytecodePatch
|
import app.revanced.patcher.patch.impl.BytecodePatch
|
||||||
@@ -39,7 +38,7 @@ import org.jf.dexlib2.util.Preconditions
|
|||||||
@Description("Example demonstration of a bytecode patch.")
|
@Description("Example demonstration of a bytecode patch.")
|
||||||
@ExampleResourceCompatibility
|
@ExampleResourceCompatibility
|
||||||
@Version("0.0.1")
|
@Version("0.0.1")
|
||||||
@DependsOn(ExampleBytecodePatch::class, DependencyType.HARD)
|
@DependsOn([ExampleBytecodePatch::class])
|
||||||
class ExampleBytecodePatch : BytecodePatch(listOf(ExampleFingerprint)) {
|
class ExampleBytecodePatch : BytecodePatch(listOf(ExampleFingerprint)) {
|
||||||
// This function will be executed by the patcher.
|
// This function will be executed by the patcher.
|
||||||
// You can treat it as a constructor
|
// You can treat it as a constructor
|
||||||
|
Reference in New Issue
Block a user