From d20f7fd6e1ede6ec7baccb1500ab3fc66d78df73 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Wed, 18 May 2022 23:57:18 +0200 Subject: [PATCH] feat: use annotations instead of metadata objects Signed-off-by: oSumAtrIX --- build.gradle.kts | 1 + .../kotlin/app/revanced/patcher/Patcher.kt | 25 ++-- .../annotation/CompatibilityAnnotation.kt | 28 +++++ .../patcher/annotation/MetadataAnnotation.kt | 38 ++++++ .../data/implementation/BytecodeData.kt | 11 +- .../revanced/patcher/extensions/Extensions.kt | 29 ++++- .../patch/annotations/PatchAnnotation.kt | 9 ++ .../app/revanced/patcher/patch/base/Patch.kt | 8 +- .../patch/implementation/BytecodePatch.kt | 7 +- .../patch/implementation/ResourcePatch.kt | 6 +- .../implementation/metadata/PatchMetadata.kt | 29 ----- .../patcher/signature/MethodSignature.kt | 111 ------------------ .../patcher/signature/base/Signature.kt | 9 ++ .../implementation/method/MethodSignature.kt | 47 ++++++++ .../annotation/MethodSignatureMetadata.kt | 32 +++++ .../resolver/MethodSignatureResolver.kt} | 34 +++--- .../MethodSignatureResolverResult.kt} | 39 +++++- .../revanced/patcher/util/ListBackedSet.kt | 2 +- .../patcher/util/ProxyBackedClassList.kt | 5 +- .../method}/MethodWalker.kt | 4 +- .../patcher/{ => util}/proxy/ClassProxy.kt | 4 +- .../proxy/mutableTypes/MutableAnnotation.kt | 4 +- .../mutableTypes/MutableAnnotationElement.kt | 6 +- .../proxy/mutableTypes/MutableClass.kt | 8 +- .../proxy/mutableTypes/MutableField.kt | 8 +- .../proxy/mutableTypes/MutableMethod.kt | 6 +- .../mutableTypes/MutableMethodParameter.kt | 4 +- .../MutableAnnotationEncodedValue.kt | 4 +- .../encodedValue/MutableArrayEncodedValue.kt | 4 +- .../MutableBooleanEncodedValue.kt | 2 +- .../encodedValue/MutableByteEncodedValue.kt | 2 +- .../encodedValue/MutableCharEncodedValue.kt | 2 +- .../encodedValue/MutableDoubleEncodedValue.kt | 2 +- .../encodedValue/MutableEncodedValue.kt | 2 +- .../encodedValue/MutableEnumEncodedValue.kt | 2 +- .../encodedValue/MutableFieldEncodedValue.kt | 2 +- .../encodedValue/MutableFloatEncodedValue.kt | 2 +- .../encodedValue/MutableIntEncodedValue.kt | 2 +- .../encodedValue/MutableLongEncodedValue.kt | 2 +- .../encodedValue/MutableMethodEncodedValue.kt | 2 +- .../MutableMethodHandleEncodedValue.kt | 2 +- .../MutableMethodTypeEncodedValue.kt | 2 +- .../encodedValue/MutableNullEncodedValue.kt | 2 +- .../encodedValue/MutableShortEncodedValue.kt | 2 +- .../encodedValue/MutableStringEncodedValue.kt | 2 +- .../encodedValue/MutableTypeEncodedValue.kt | 2 +- .../{ => util}/smali/InlineSmaliCompiler.kt | 15 ++- .../{ => util}/smali/InstructionConverter.kt | 2 +- .../app/revanced/patcher/PatcherTest.kt | 53 ++++----- .../ExampleBytecodeCompatibility.kt | 14 +++ .../patch}/ExampleBytecodePatch.kt | 68 +++-------- .../bytecode/signatures/ExampleSignature.kt | 32 +++++ .../ExampleResourceCompatibility.kt | 14 +++ .../patch}/ExampleResourcePatch.kt | 23 ++-- 54 files changed, 444 insertions(+), 333 deletions(-) create mode 100644 src/main/kotlin/app/revanced/patcher/annotation/CompatibilityAnnotation.kt create mode 100644 src/main/kotlin/app/revanced/patcher/annotation/MetadataAnnotation.kt create mode 100644 src/main/kotlin/app/revanced/patcher/patch/annotations/PatchAnnotation.kt delete mode 100644 src/main/kotlin/app/revanced/patcher/patch/implementation/metadata/PatchMetadata.kt delete mode 100644 src/main/kotlin/app/revanced/patcher/signature/MethodSignature.kt create mode 100644 src/main/kotlin/app/revanced/patcher/signature/base/Signature.kt create mode 100644 src/main/kotlin/app/revanced/patcher/signature/implementation/method/MethodSignature.kt create mode 100644 src/main/kotlin/app/revanced/patcher/signature/implementation/method/annotation/MethodSignatureMetadata.kt rename src/main/kotlin/app/revanced/patcher/signature/{resolver/SignatureResolver.kt => implementation/method/resolver/MethodSignatureResolver.kt} (85%) rename src/main/kotlin/app/revanced/patcher/signature/{SignatureResolverResult.kt => implementation/method/resolver/MethodSignatureResolverResult.kt} (50%) rename src/main/kotlin/app/revanced/patcher/{methodWalker => util/method}/MethodWalker.kt (95%) rename src/main/kotlin/app/revanced/patcher/{ => util}/proxy/ClassProxy.kt (91%) rename src/main/kotlin/app/revanced/patcher/{ => util}/proxy/mutableTypes/MutableAnnotation.kt (83%) rename src/main/kotlin/app/revanced/patcher/{ => util}/proxy/mutableTypes/MutableAnnotationElement.kt (76%) rename src/main/kotlin/app/revanced/patcher/{ => util}/proxy/mutableTypes/MutableClass.kt (90%) rename src/main/kotlin/app/revanced/patcher/{ => util}/proxy/mutableTypes/MutableField.kt (84%) rename src/main/kotlin/app/revanced/patcher/{ => util}/proxy/mutableTypes/MutableMethod.kt (89%) rename src/main/kotlin/app/revanced/patcher/{ => util}/proxy/mutableTypes/MutableMethodParameter.kt (87%) rename src/main/kotlin/app/revanced/patcher/{ => util}/proxy/mutableTypes/encodedValue/MutableAnnotationEncodedValue.kt (85%) rename src/main/kotlin/app/revanced/patcher/{ => util}/proxy/mutableTypes/encodedValue/MutableArrayEncodedValue.kt (79%) rename src/main/kotlin/app/revanced/patcher/{ => util}/proxy/mutableTypes/encodedValue/MutableBooleanEncodedValue.kt (90%) rename src/main/kotlin/app/revanced/patcher/{ => util}/proxy/mutableTypes/encodedValue/MutableByteEncodedValue.kt (89%) rename src/main/kotlin/app/revanced/patcher/{ => util}/proxy/mutableTypes/encodedValue/MutableCharEncodedValue.kt (89%) rename src/main/kotlin/app/revanced/patcher/{ => util}/proxy/mutableTypes/encodedValue/MutableDoubleEncodedValue.kt (89%) rename src/main/kotlin/app/revanced/patcher/{ => util}/proxy/mutableTypes/encodedValue/MutableEncodedValue.kt (96%) rename src/main/kotlin/app/revanced/patcher/{ => util}/proxy/mutableTypes/encodedValue/MutableEnumEncodedValue.kt (90%) rename src/main/kotlin/app/revanced/patcher/{ => util}/proxy/mutableTypes/encodedValue/MutableFieldEncodedValue.kt (91%) rename src/main/kotlin/app/revanced/patcher/{ => util}/proxy/mutableTypes/encodedValue/MutableFloatEncodedValue.kt (89%) rename src/main/kotlin/app/revanced/patcher/{ => util}/proxy/mutableTypes/encodedValue/MutableIntEncodedValue.kt (89%) rename src/main/kotlin/app/revanced/patcher/{ => util}/proxy/mutableTypes/encodedValue/MutableLongEncodedValue.kt (89%) rename src/main/kotlin/app/revanced/patcher/{ => util}/proxy/mutableTypes/encodedValue/MutableMethodEncodedValue.kt (90%) rename src/main/kotlin/app/revanced/patcher/{ => util}/proxy/mutableTypes/encodedValue/MutableMethodHandleEncodedValue.kt (91%) rename src/main/kotlin/app/revanced/patcher/{ => util}/proxy/mutableTypes/encodedValue/MutableMethodTypeEncodedValue.kt (91%) rename src/main/kotlin/app/revanced/patcher/{ => util}/proxy/mutableTypes/encodedValue/MutableNullEncodedValue.kt (83%) rename src/main/kotlin/app/revanced/patcher/{ => util}/proxy/mutableTypes/encodedValue/MutableShortEncodedValue.kt (89%) rename src/main/kotlin/app/revanced/patcher/{ => util}/proxy/mutableTypes/encodedValue/MutableStringEncodedValue.kt (90%) rename src/main/kotlin/app/revanced/patcher/{ => util}/proxy/mutableTypes/encodedValue/MutableTypeEncodedValue.kt (89%) rename src/main/kotlin/app/revanced/patcher/{ => util}/smali/InlineSmaliCompiler.kt (87%) rename src/main/kotlin/app/revanced/patcher/{ => util}/smali/InstructionConverter.kt (99%) create mode 100644 src/test/kotlin/app/revanced/patcher/usage/bytecode/annotation/ExampleBytecodeCompatibility.kt rename src/test/kotlin/app/revanced/patcher/usage/{ => bytecode/patch}/ExampleBytecodePatch.kt (78%) create mode 100644 src/test/kotlin/app/revanced/patcher/usage/bytecode/signatures/ExampleSignature.kt create mode 100644 src/test/kotlin/app/revanced/patcher/usage/resource/annotation/ExampleResourceCompatibility.kt rename src/test/kotlin/app/revanced/patcher/usage/{ => resource/patch}/ExampleResourcePatch.kt (68%) diff --git a/build.gradle.kts b/build.gradle.kts index 192e4c72..e813e7f5 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -29,6 +29,7 @@ dependencies { api("org.smali:smali:2.5.2") testImplementation(kotlin("test")) + implementation(kotlin("reflect")) } tasks { diff --git a/src/main/kotlin/app/revanced/patcher/Patcher.kt b/src/main/kotlin/app/revanced/patcher/Patcher.kt index d9844386..7d836854 100644 --- a/src/main/kotlin/app/revanced/patcher/Patcher.kt +++ b/src/main/kotlin/app/revanced/patcher/Patcher.kt @@ -1,15 +1,16 @@ package app.revanced.patcher +import app.revanced.patcher.annotation.Name import app.revanced.patcher.data.PatcherData import app.revanced.patcher.data.base.Data import app.revanced.patcher.data.implementation.findIndexed +import app.revanced.patcher.extensions.findAnnotationRecursively import app.revanced.patcher.patch.base.Patch import app.revanced.patcher.patch.implementation.BytecodePatch import app.revanced.patcher.patch.implementation.ResourcePatch -import app.revanced.patcher.patch.implementation.metadata.PatchMetadata import app.revanced.patcher.patch.implementation.misc.PatchResultSuccess -import app.revanced.patcher.signature.MethodSignature -import app.revanced.patcher.signature.resolver.SignatureResolver +import app.revanced.patcher.signature.implementation.method.MethodSignature +import app.revanced.patcher.signature.implementation.method.resolver.MethodSignatureResolver import app.revanced.patcher.util.ListBackedSet import brut.androlib.Androlib import brut.androlib.meta.UsesFramework @@ -159,11 +160,12 @@ class Patcher( return emptyList() } - SignatureResolver(patcherData.bytecodeData.classes.internalClasses, signatures).resolve(patcherData) + MethodSignatureResolver(patcherData.bytecodeData.classes.internalClasses, signatures).resolve(patcherData) signaturesResolved = true return signatures } + /** * Apply patches loaded into the patcher. * @param stopOnError If true, the patches will stop on the first error. @@ -174,7 +176,7 @@ class Patcher( fun applyPatches( stopOnError: Boolean = false, callback: (String) -> Unit = {} - ): Map> { + ): Map> { if (!signaturesResolved) { resolveSignatures() } @@ -183,7 +185,12 @@ class Patcher( val resourcePatch = patch is ResourcePatch if (!patchResources && resourcePatch) continue - callback(patch.metadata.shortName) + val patchNameAnnotation = patch::class.java.findAnnotationRecursively(Name::class.java) + + patchNameAnnotation?.let { + callback(it.name) + } + val result: Result = try { val data = if (resourcePatch) { patcherData.resourceData @@ -201,7 +208,11 @@ class Patcher( } catch (e: Exception) { Result.failure(e) } - this[patch.metadata] = result + + patchNameAnnotation?.let { + this[patchNameAnnotation.name] = result + } + if (result.isFailure && stopOnError) break } } diff --git a/src/main/kotlin/app/revanced/patcher/annotation/CompatibilityAnnotation.kt b/src/main/kotlin/app/revanced/patcher/annotation/CompatibilityAnnotation.kt new file mode 100644 index 00000000..09e2df84 --- /dev/null +++ b/src/main/kotlin/app/revanced/patcher/annotation/CompatibilityAnnotation.kt @@ -0,0 +1,28 @@ +package app.revanced.patcher.annotation + +import app.revanced.patcher.patch.base.Patch +import app.revanced.patcher.signature.implementation.method.MethodSignature + +/** + * Annotation to constrain a [Patch] or [MethodSignature] to compatible packages. + * @param compatiblePackages A list of packages a [Patch] or [MethodSignature] is compatible with. + */ +@Target(AnnotationTarget.CLASS) +@Retention(AnnotationRetention.RUNTIME) +@MustBeDocumented +annotation class Compatibility( + val compatiblePackages: Array, +) + +/** + * Annotation to represent packages a patch can be compatible with. + * @param name The package identifier name. + * @param versions The versions of the package the [Patch] or [MethodSignature]is compatible with. + */ +@Target() +@Retention(AnnotationRetention.RUNTIME) +@MustBeDocumented +annotation class Package( + val name: String, + val versions: Array +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patcher/annotation/MetadataAnnotation.kt b/src/main/kotlin/app/revanced/patcher/annotation/MetadataAnnotation.kt new file mode 100644 index 00000000..d3c4820a --- /dev/null +++ b/src/main/kotlin/app/revanced/patcher/annotation/MetadataAnnotation.kt @@ -0,0 +1,38 @@ +package app.revanced.patcher.annotation + +import app.revanced.patcher.patch.base.Patch +import app.revanced.patcher.signature.implementation.method.MethodSignature + +/** + * Annotation to name a [Patch] or [MethodSignature]. + * @param name A suggestive name for the [Patch] or [MethodSignature]. + */ +@Target(AnnotationTarget.CLASS) +@Retention(AnnotationRetention.RUNTIME) +@MustBeDocumented +annotation class Name( + val name: String, +) + +/** + * Annotation to describe a [Patch] or [MethodSignature]. + * @param description A description for the [Patch] or [MethodSignature]. + */ +@Target(AnnotationTarget.CLASS) +@Retention(AnnotationRetention.RUNTIME) +@MustBeDocumented +annotation class Description( + val description: String, +) + + +/** + * Annotation to version a [Patch] or [MethodSignature]. + * @param version The version of a [Patch] or [MethodSignature]. + */ +@Target(AnnotationTarget.CLASS) +@Retention(AnnotationRetention.RUNTIME) +@MustBeDocumented +annotation class Version( + val version: String, +) diff --git a/src/main/kotlin/app/revanced/patcher/data/implementation/BytecodeData.kt b/src/main/kotlin/app/revanced/patcher/data/implementation/BytecodeData.kt index 2c3e09a7..03d1ae5d 100644 --- a/src/main/kotlin/app/revanced/patcher/data/implementation/BytecodeData.kt +++ b/src/main/kotlin/app/revanced/patcher/data/implementation/BytecodeData.kt @@ -1,12 +1,11 @@ package app.revanced.patcher.data.implementation import app.revanced.patcher.data.base.Data -import app.revanced.patcher.methodWalker.MethodWalker import app.revanced.patcher.patch.base.Patch import app.revanced.patcher.patch.implementation.BytecodePatch -import app.revanced.patcher.proxy.ClassProxy -import app.revanced.patcher.signature.SignatureResolverResult +import app.revanced.patcher.signature.implementation.method.resolver.SignatureResolverResult import app.revanced.patcher.util.ProxyBackedClassList +import app.revanced.patcher.util.method.MethodWalker import org.jf.dexlib2.iface.ClassDef import org.jf.dexlib2.iface.Method @@ -28,7 +27,7 @@ class BytecodeData( * Find a class by a given predicate * @return A proxy for the first class that matches the predicate */ - fun findClass(predicate: (ClassDef) -> Boolean): ClassProxy? { + fun findClass(predicate: (ClassDef) -> Boolean): app.revanced.patcher.util.proxy.ClassProxy? { // if we already proxied the class matching the predicate... for (patch in patches) { if (patch !is BytecodePatch) continue @@ -77,10 +76,10 @@ internal inline fun Iterable.findIndexed(predicate: (T) -> Boolean): Pair return null } -fun BytecodeData.proxy(classDef: ClassDef): ClassProxy { +fun BytecodeData.proxy(classDef: ClassDef): app.revanced.patcher.util.proxy.ClassProxy { var proxy = this.classes.proxies.find { it.immutableClass.type == classDef.type } if (proxy == null) { - proxy = ClassProxy(classDef) + proxy = app.revanced.patcher.util.proxy.ClassProxy(classDef) this.classes.proxies.add(proxy) } return proxy diff --git a/src/main/kotlin/app/revanced/patcher/extensions/Extensions.kt b/src/main/kotlin/app/revanced/patcher/extensions/Extensions.kt index 5e64bdde..5357864d 100644 --- a/src/main/kotlin/app/revanced/patcher/extensions/Extensions.kt +++ b/src/main/kotlin/app/revanced/patcher/extensions/Extensions.kt @@ -1,6 +1,6 @@ package app.revanced.patcher.extensions -import app.revanced.patcher.proxy.mutableTypes.MutableMethod.Companion.toMutable +import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMutable import org.jf.dexlib2.AccessFlags import org.jf.dexlib2.builder.BuilderInstruction import org.jf.dexlib2.builder.MutableMethodImplementation @@ -10,6 +10,33 @@ import org.jf.dexlib2.immutable.ImmutableMethod import org.jf.dexlib2.immutable.ImmutableMethodImplementation import org.jf.dexlib2.util.MethodUtil +/** + * Recursively find a given annotation on a class + * @param targetAnnotation The annotation to find + * @return The annotation + */ +fun Class<*>.findAnnotationRecursively(targetAnnotation: Class) = + this.findAnnotationRecursively(targetAnnotation, mutableSetOf()) + +private fun Class<*>.findAnnotationRecursively( + targetAnnotation: Class, + traversed: MutableSet +): T? { + val found = this.annotations.firstOrNull { it.annotationClass.java.name == targetAnnotation.name } + + @Suppress("UNCHECKED_CAST") + if (found != null) return found as T + + for (annotation in this.annotations) { + if (traversed.contains(annotation)) continue + traversed.add(annotation) + + return (annotation.annotationClass.java.findAnnotationRecursively(targetAnnotation, traversed)) ?: continue + } + + return null +} + infix fun AccessFlags.or(other: AccessFlags) = this.value or other.value infix fun Int.or(other: AccessFlags) = this or other.value diff --git a/src/main/kotlin/app/revanced/patcher/patch/annotations/PatchAnnotation.kt b/src/main/kotlin/app/revanced/patcher/patch/annotations/PatchAnnotation.kt new file mode 100644 index 00000000..4803b02e --- /dev/null +++ b/src/main/kotlin/app/revanced/patcher/patch/annotations/PatchAnnotation.kt @@ -0,0 +1,9 @@ +package app.revanced.patcher.patch.annotations + +/** + * Annotation to mark a Class as a patch. + */ +@Target(AnnotationTarget.CLASS) +@Retention(AnnotationRetention.RUNTIME) +@MustBeDocumented +annotation class Patch \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patcher/patch/base/Patch.kt b/src/main/kotlin/app/revanced/patcher/patch/base/Patch.kt index f7f99b2f..a207c716 100644 --- a/src/main/kotlin/app/revanced/patcher/patch/base/Patch.kt +++ b/src/main/kotlin/app/revanced/patcher/patch/base/Patch.kt @@ -3,20 +3,16 @@ package app.revanced.patcher.patch.base import app.revanced.patcher.data.base.Data import app.revanced.patcher.patch.implementation.BytecodePatch import app.revanced.patcher.patch.implementation.ResourcePatch -import app.revanced.patcher.patch.implementation.metadata.PatchMetadata import app.revanced.patcher.patch.implementation.misc.PatchResult /** * A ReVanced patch. - * Can either be a [ResourcePatch] or a [BytecodePatch] + * Can either be a [ResourcePatch] or a [BytecodePatch]. */ -abstract class Patch( - open val metadata: PatchMetadata -) { +abstract class Patch { /** * The main function of the [Patch] which the patcher will call. */ abstract fun execute(data: @UnsafeVariance T): PatchResult // FIXME: remove the UnsafeVariance annotation - } \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patcher/patch/implementation/BytecodePatch.kt b/src/main/kotlin/app/revanced/patcher/patch/implementation/BytecodePatch.kt index facbed1b..7671b8ec 100644 --- a/src/main/kotlin/app/revanced/patcher/patch/implementation/BytecodePatch.kt +++ b/src/main/kotlin/app/revanced/patcher/patch/implementation/BytecodePatch.kt @@ -2,15 +2,12 @@ package app.revanced.patcher.patch.implementation import app.revanced.patcher.data.implementation.BytecodeData import app.revanced.patcher.patch.base.Patch -import app.revanced.patcher.patch.implementation.metadata.PatchMetadata -import app.revanced.patcher.signature.MethodSignature +import app.revanced.patcher.signature.implementation.method.MethodSignature /** * Bytecode patch for the Patcher. - * @param metadata [PatchMetadata] for the patch. * @param signatures A list of [MethodSignature] this patch relies on. */ abstract class BytecodePatch( - override val metadata: PatchMetadata, val signatures: Iterable -) : Patch(metadata) \ No newline at end of file +) : Patch() \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patcher/patch/implementation/ResourcePatch.kt b/src/main/kotlin/app/revanced/patcher/patch/implementation/ResourcePatch.kt index bac5820b..b8fd606c 100644 --- a/src/main/kotlin/app/revanced/patcher/patch/implementation/ResourcePatch.kt +++ b/src/main/kotlin/app/revanced/patcher/patch/implementation/ResourcePatch.kt @@ -2,12 +2,8 @@ package app.revanced.patcher.patch.implementation import app.revanced.patcher.data.implementation.ResourceData import app.revanced.patcher.patch.base.Patch -import app.revanced.patcher.patch.implementation.metadata.PatchMetadata /** * Resource patch for the Patcher. - * @param metadata [PatchMetadata] for the patch. */ -abstract class ResourcePatch( - override val metadata: PatchMetadata -) : Patch(metadata) \ No newline at end of file +abstract class ResourcePatch : Patch() \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patcher/patch/implementation/metadata/PatchMetadata.kt b/src/main/kotlin/app/revanced/patcher/patch/implementation/metadata/PatchMetadata.kt deleted file mode 100644 index cfa8f839..00000000 --- a/src/main/kotlin/app/revanced/patcher/patch/implementation/metadata/PatchMetadata.kt +++ /dev/null @@ -1,29 +0,0 @@ -package app.revanced.patcher.patch.implementation.metadata - -import app.revanced.patcher.patch.base.Patch - -/** - * Metadata about a [Patch]. - * @param shortName A suggestive short name for the [Patch]. - * @param name A suggestive name for the [Patch]. - * @param description A description for the [Patch]. - * @param compatiblePackages A list of packages this [Patch] is compatible with. - * @param version The version of the [Patch]. - */ -data class PatchMetadata( - val shortName: String, - val name: String, - val description: String, - val compatiblePackages: Iterable, - val version: String, -) - -/** - * Metadata about a package. - * @param name The package name. - * @param versions Compatible versions of the package. - */ -data class PackageMetadata( - val name: String, - val versions: Iterable -) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patcher/signature/MethodSignature.kt b/src/main/kotlin/app/revanced/patcher/signature/MethodSignature.kt deleted file mode 100644 index 1e7b13a2..00000000 --- a/src/main/kotlin/app/revanced/patcher/signature/MethodSignature.kt +++ /dev/null @@ -1,111 +0,0 @@ -package app.revanced.patcher.signature - -import app.revanced.patcher.data.implementation.MethodNotFoundException -import app.revanced.patcher.patch.implementation.metadata.PackageMetadata -import org.jf.dexlib2.Opcode - -/** - * Represents the [MethodSignature] for a method. - * @param metadata Metadata for this [MethodSignature]. - * @param returnType The return type of the method. - * @param accessFlags The access flags of the method. - * @param methodParameters The parameters of the method. - * @param opcodes The list of opcodes of the method. - * @param strings A list of strings which a method contains. - * A `null` opcode is equals to an unknown opcode. - */ -class MethodSignature( - val metadata: MethodSignatureMetadata, - internal val returnType: String?, - internal val accessFlags: Int?, - internal val methodParameters: Iterable?, - internal val opcodes: Iterable?, - internal val strings: Iterable? = null -) { - /** - * The result of the signature - */ - var result: SignatureResolverResult? = null - get() { - return field ?: throw MethodNotFoundException( - "Could not resolve required signature ${metadata.name}" - ) - } - val resolved: Boolean - get() { - var resolved = false - try { - resolved = result != null - } catch (_: Exception) { - } - return resolved - } -} - -/** - * Metadata about a [MethodSignature]. - * @param name A suggestive name for the [MethodSignature]. - * @param methodMetadata Metadata about the method for the [MethodSignature]. - * @param patternScanMethod The pattern scanning method the pattern scanner should rely on. - * Can either be [PatternScanMethod.Fuzzy] or [PatternScanMethod.Direct]. - * @param description An optional description for the [MethodSignature]. - * @param compatiblePackages The list of packages the [MethodSignature] is compatible with. - * @param version The version of this signature. - */ -data class MethodSignatureMetadata( - val name: String, - val methodMetadata: MethodMetadata?, - val patternScanMethod: PatternScanMethod, - val compatiblePackages: Iterable, - val description: String?, - val version: String -) - -/** - * Metadata about the method for a [MethodSignature]. - * @param definingClass The defining class name of the method. - * @param name A suggestive name for the method which the [MethodSignature] was created for. - */ -data class MethodMetadata( - val definingClass: String?, - val name: String? -) - -/** - * The method, the patcher should rely on when scanning the opcode pattern of a [MethodSignature] - */ -interface PatternScanMethod { - /** - * When comparing the signature, if one or more of the opcodes do not match, skip. - */ - class Direct : PatternScanMethod - - /** - * When comparing the signature, if [threshold] or more of the opcodes do not match, skip. - */ - class Fuzzy(internal val threshold: Int) : PatternScanMethod { - /** - * A list of warnings the resolver found. - * - * This list will be allocated when the signature has been found. - * Meaning, if the signature was not found, - * or the signature was not yet resolved, - * the list will be null. - */ - var warnings: List? = null - - /** - * Represents a resolver warning. - * @param correctOpcode The opcode the instruction list has. - * @param wrongOpcode The opcode the pattern list of the signature currently has. - * @param instructionIndex The index of the opcode relative to the instruction list. - * @param patternIndex The index of the opcode relative to the pattern list from the signature. - */ - data class Warning( - val correctOpcode: Opcode, - val wrongOpcode: Opcode, - val instructionIndex: Int, - val patternIndex: Int, - ) - } -} \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patcher/signature/base/Signature.kt b/src/main/kotlin/app/revanced/patcher/signature/base/Signature.kt new file mode 100644 index 00000000..4ad9af62 --- /dev/null +++ b/src/main/kotlin/app/revanced/patcher/signature/base/Signature.kt @@ -0,0 +1,9 @@ +package app.revanced.patcher.signature.base + +import app.revanced.patcher.signature.implementation.method.MethodSignature + +/** + * A ReVanced signature. + * Can be a [MethodSignature]. + */ +interface Signature \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patcher/signature/implementation/method/MethodSignature.kt b/src/main/kotlin/app/revanced/patcher/signature/implementation/method/MethodSignature.kt new file mode 100644 index 00000000..8d0a8cc2 --- /dev/null +++ b/src/main/kotlin/app/revanced/patcher/signature/implementation/method/MethodSignature.kt @@ -0,0 +1,47 @@ +package app.revanced.patcher.signature.implementation.method + +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.data.implementation.MethodNotFoundException +import app.revanced.patcher.signature.base.Signature +import app.revanced.patcher.signature.implementation.method.resolver.SignatureResolverResult +import org.jf.dexlib2.Opcode + +/** + * Represents the [MethodSignature] for a method. + * @param returnType The return type of the method. + * @param accessFlags The access flags of the method. + * @param methodParameters The parameters of the method. + * @param opcodes The list of opcodes of the method. + * @param strings A list of strings which a method contains. + * A `null` opcode is equals to an unknown opcode. + */ +abstract class MethodSignature( + internal val returnType: String?, + internal val accessFlags: Int?, + internal val methodParameters: Iterable?, + internal val opcodes: Iterable?, + internal val strings: Iterable? = null +) : Signature { + /** + * The result of the signature + */ + var result: SignatureResolverResult? = null + get() { + return field ?: throw MethodNotFoundException( + "Could not resolve required signature ${ + (this::class.annotations.find { it is Name }?.let { + (it as Name).name + }) + }" + ) + } + val resolved: Boolean + get() { + var resolved = false + try { + resolved = result != null + } catch (_: Exception) { + } + return resolved + } +} \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patcher/signature/implementation/method/annotation/MethodSignatureMetadata.kt b/src/main/kotlin/app/revanced/patcher/signature/implementation/method/annotation/MethodSignatureMetadata.kt new file mode 100644 index 00000000..5529b206 --- /dev/null +++ b/src/main/kotlin/app/revanced/patcher/signature/implementation/method/annotation/MethodSignatureMetadata.kt @@ -0,0 +1,32 @@ +package app.revanced.patcher.signature.implementation.method.annotation + +import app.revanced.patcher.signature.implementation.method.MethodSignature + +/** + * Annotations for a method which matches to a [MethodSignature]. + * @param definingClass The defining class name of the method. + * @param name A suggestive name for the method which the [MethodSignature] was created for. + */ +@Target(AnnotationTarget.CLASS) +@Retention(AnnotationRetention.RUNTIME) +annotation class MatchingMethod( + val definingClass: String = "L", + val name: String = "" +) + +/** + * Annotations to scan a pattern [MethodSignature] with fuzzy algorithm. + * @param threshold if [threshold] or more of the opcodes do not match, skip. + */ +@Target(AnnotationTarget.CLASS) +@Retention(AnnotationRetention.RUNTIME) +annotation class FuzzyPatternScanMethod( + val threshold: Int = 1 +) + +/** + * Annotations to scan a pattern [MethodSignature] directly. + */ +@Target(AnnotationTarget.CLASS) +@Retention(AnnotationRetention.RUNTIME) +annotation class DirectPatternScanMethod \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patcher/signature/resolver/SignatureResolver.kt b/src/main/kotlin/app/revanced/patcher/signature/implementation/method/resolver/MethodSignatureResolver.kt similarity index 85% rename from src/main/kotlin/app/revanced/patcher/signature/resolver/SignatureResolver.kt rename to src/main/kotlin/app/revanced/patcher/signature/implementation/method/resolver/MethodSignatureResolver.kt index c7d2d0d3..de3634bb 100644 --- a/src/main/kotlin/app/revanced/patcher/signature/resolver/SignatureResolver.kt +++ b/src/main/kotlin/app/revanced/patcher/signature/implementation/method/resolver/MethodSignatureResolver.kt @@ -1,13 +1,11 @@ -package app.revanced.patcher.signature.resolver +package app.revanced.patcher.signature.implementation.method.resolver import app.revanced.patcher.data.PatcherData import app.revanced.patcher.data.implementation.proxy +import app.revanced.patcher.extensions.findAnnotationRecursively import app.revanced.patcher.extensions.parametersEqual -import app.revanced.patcher.proxy.ClassProxy -import app.revanced.patcher.signature.MethodSignature -import app.revanced.patcher.signature.PatternScanMethod -import app.revanced.patcher.signature.PatternScanResult -import app.revanced.patcher.signature.SignatureResolverResult +import app.revanced.patcher.signature.implementation.method.MethodSignature +import app.revanced.patcher.signature.implementation.method.annotation.FuzzyPatternScanMethod import org.jf.dexlib2.Opcode import org.jf.dexlib2.iface.ClassDef import org.jf.dexlib2.iface.Method @@ -15,7 +13,7 @@ import org.jf.dexlib2.iface.instruction.Instruction import org.jf.dexlib2.iface.instruction.formats.Instruction21c import org.jf.dexlib2.iface.reference.StringReference -internal class SignatureResolver( +internal class MethodSignatureResolver( private val classes: List, private val methodSignatures: Iterable ) { @@ -39,7 +37,10 @@ internal class SignatureResolver( // These functions do not require the constructor values, so they can be static. companion object { - fun resolveFromProxy(classProxy: ClassProxy, signature: MethodSignature): SignatureResolverResult? { + fun resolveFromProxy( + classProxy: app.revanced.patcher.util.proxy.ClassProxy, + signature: MethodSignature + ): SignatureResolverResult? { for (method in classProxy.immutableClass.methods) { val result = compareSignatureToMethod(signature, method) ?: continue return SignatureResolverResult( @@ -107,9 +108,10 @@ internal class SignatureResolver( val count = instructions.count() val pattern = signature.opcodes!! val size = pattern.count() - val method = signature.metadata.patternScanMethod - val threshold = if (method is PatternScanMethod.Fuzzy) - method.threshold else 0 + + val threshold = + signature::class.java.findAnnotationRecursively(FuzzyPatternScanMethod::class.java)?.threshold + ?: 0 for (instructionIndex in 0 until count) { var patternIndex = 0 @@ -126,11 +128,9 @@ internal class SignatureResolver( patternIndex-- // fix pattern offset val result = PatternScanResult(instructionIndex, instructionIndex + patternIndex) - if (method is PatternScanMethod.Fuzzy) { - method.warnings = generateWarnings( - signature, instructions, result - ) - } + + result.warnings = generateWarnings(signature, instructions, result) + return result } } @@ -152,7 +152,7 @@ internal class SignatureResolver( correctOpcode != patternOpcode ) { this.add( - PatternScanMethod.Fuzzy.Warning( + PatternScanResult.Warning( correctOpcode, patternOpcode, instructionIndex, patternIndex, ) diff --git a/src/main/kotlin/app/revanced/patcher/signature/SignatureResolverResult.kt b/src/main/kotlin/app/revanced/patcher/signature/implementation/method/resolver/MethodSignatureResolverResult.kt similarity index 50% rename from src/main/kotlin/app/revanced/patcher/signature/SignatureResolverResult.kt rename to src/main/kotlin/app/revanced/patcher/signature/implementation/method/resolver/MethodSignatureResolverResult.kt index f3e4c5bf..3002930c 100644 --- a/src/main/kotlin/app/revanced/patcher/signature/SignatureResolverResult.kt +++ b/src/main/kotlin/app/revanced/patcher/signature/implementation/method/resolver/MethodSignatureResolverResult.kt @@ -1,12 +1,13 @@ -package app.revanced.patcher.signature +package app.revanced.patcher.signature.implementation.method.resolver import app.revanced.patcher.extensions.softCompareTo -import app.revanced.patcher.proxy.ClassProxy -import app.revanced.patcher.signature.resolver.SignatureResolver +import app.revanced.patcher.signature.implementation.method.MethodSignature +import app.revanced.patcher.util.proxy.ClassProxy +import org.jf.dexlib2.Opcode import org.jf.dexlib2.iface.Method /** - * Represents the result of a [SignatureResolver]. + * Represents the result of a [MethodSignatureResolver]. * @param definingClassProxy The [ClassProxy] that the matching method was found in. * @param resolvedMethod The actual matching method. * @param scanData Opcodes pattern scan result. @@ -32,17 +33,43 @@ data class SignatureResolverResult( * * If you need to modify the method, use [method] instead. */ + @Suppress("MemberVisibilityCanBePrivate") val immutableMethod: Method get() = definingClassProxy.immutableClass.methods.first { it.softCompareTo(resolvedMethod) } fun findParentMethod(signature: MethodSignature): SignatureResolverResult? { - return SignatureResolver.resolveFromProxy(definingClassProxy, signature) + return MethodSignatureResolver.resolveFromProxy(definingClassProxy, signature) } } data class PatternScanResult( val startIndex: Int, val endIndex: Int -) +) { + /** + * A list of warnings the resolver found. + * + * This list will be allocated when the signature has been found. + * Meaning, if the signature was not found, + * or the signature was not yet resolved, + * the list will be null. + */ + var warnings: List? = null + + /** + * Represents a resolver warning. + * @param correctOpcode The opcode the instruction list has. + * @param wrongOpcode The opcode the pattern list of the signature currently has. + * @param instructionIndex The index of the opcode relative to the instruction list. + * @param patternIndex The index of the opcode relative to the pattern list from the signature. + */ + data class Warning( + val correctOpcode: Opcode, + val wrongOpcode: Opcode, + val instructionIndex: Int, + val patternIndex: Int, + ) +} + diff --git a/src/main/kotlin/app/revanced/patcher/util/ListBackedSet.kt b/src/main/kotlin/app/revanced/patcher/util/ListBackedSet.kt index f019b145..ab305d32 100644 --- a/src/main/kotlin/app/revanced/patcher/util/ListBackedSet.kt +++ b/src/main/kotlin/app/revanced/patcher/util/ListBackedSet.kt @@ -1,6 +1,6 @@ package app.revanced.patcher.util -class ListBackedSet(private val list: MutableList) : MutableSet { +internal class ListBackedSet(private val list: MutableList) : MutableSet { override val size get() = list.size override fun add(element: E) = list.add(element) override fun addAll(elements: Collection) = list.addAll(elements) diff --git a/src/main/kotlin/app/revanced/patcher/util/ProxyBackedClassList.kt b/src/main/kotlin/app/revanced/patcher/util/ProxyBackedClassList.kt index 6e28f597..bbd6d41b 100644 --- a/src/main/kotlin/app/revanced/patcher/util/ProxyBackedClassList.kt +++ b/src/main/kotlin/app/revanced/patcher/util/ProxyBackedClassList.kt @@ -1,16 +1,15 @@ package app.revanced.patcher.util -import app.revanced.patcher.proxy.ClassProxy import org.jf.dexlib2.iface.ClassDef class ProxyBackedClassList(internal val internalClasses: MutableList) : List { - internal val proxies = mutableListOf() + internal val proxies = mutableListOf() fun add(classDef: ClassDef) { internalClasses.add(classDef) } - fun add(classProxy: ClassProxy) { + fun add(classProxy: app.revanced.patcher.util.proxy.ClassProxy) { proxies.add(classProxy) } diff --git a/src/main/kotlin/app/revanced/patcher/methodWalker/MethodWalker.kt b/src/main/kotlin/app/revanced/patcher/util/method/MethodWalker.kt similarity index 95% rename from src/main/kotlin/app/revanced/patcher/methodWalker/MethodWalker.kt rename to src/main/kotlin/app/revanced/patcher/util/method/MethodWalker.kt index 04ed0e7a..64d69b15 100644 --- a/src/main/kotlin/app/revanced/patcher/methodWalker/MethodWalker.kt +++ b/src/main/kotlin/app/revanced/patcher/util/method/MethodWalker.kt @@ -1,9 +1,9 @@ -package app.revanced.patcher.methodWalker +package app.revanced.patcher.util.method import app.revanced.patcher.data.implementation.BytecodeData import app.revanced.patcher.data.implementation.MethodNotFoundException import app.revanced.patcher.extensions.softCompareTo -import app.revanced.patcher.proxy.mutableTypes.MutableMethod +import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod import org.jf.dexlib2.Format import org.jf.dexlib2.iface.Method import org.jf.dexlib2.iface.instruction.formats.Instruction35c diff --git a/src/main/kotlin/app/revanced/patcher/proxy/ClassProxy.kt b/src/main/kotlin/app/revanced/patcher/util/proxy/ClassProxy.kt similarity index 91% rename from src/main/kotlin/app/revanced/patcher/proxy/ClassProxy.kt rename to src/main/kotlin/app/revanced/patcher/util/proxy/ClassProxy.kt index 0aedeefe..6481ad8e 100644 --- a/src/main/kotlin/app/revanced/patcher/proxy/ClassProxy.kt +++ b/src/main/kotlin/app/revanced/patcher/util/proxy/ClassProxy.kt @@ -1,6 +1,6 @@ -package app.revanced.patcher.proxy +package app.revanced.patcher.util.proxy -import app.revanced.patcher.proxy.mutableTypes.MutableClass +import app.revanced.patcher.util.proxy.mutableTypes.MutableClass import org.jf.dexlib2.iface.ClassDef /** diff --git a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/MutableAnnotation.kt b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/MutableAnnotation.kt similarity index 83% rename from src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/MutableAnnotation.kt rename to src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/MutableAnnotation.kt index 927f3593..dadae858 100644 --- a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/MutableAnnotation.kt +++ b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/MutableAnnotation.kt @@ -1,6 +1,6 @@ -package app.revanced.patcher.proxy.mutableTypes +package app.revanced.patcher.util.proxy.mutableTypes -import app.revanced.patcher.proxy.mutableTypes.MutableAnnotationElement.Companion.toMutable +import app.revanced.patcher.util.proxy.mutableTypes.MutableAnnotationElement.Companion.toMutable import org.jf.dexlib2.base.BaseAnnotation import org.jf.dexlib2.iface.Annotation diff --git a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/MutableAnnotationElement.kt b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/MutableAnnotationElement.kt similarity index 76% rename from src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/MutableAnnotationElement.kt rename to src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/MutableAnnotationElement.kt index 85354fe1..f3545162 100644 --- a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/MutableAnnotationElement.kt +++ b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/MutableAnnotationElement.kt @@ -1,7 +1,7 @@ -package app.revanced.patcher.proxy.mutableTypes +package app.revanced.patcher.util.proxy.mutableTypes -import app.revanced.patcher.proxy.mutableTypes.encodedValue.MutableEncodedValue -import app.revanced.patcher.proxy.mutableTypes.encodedValue.MutableEncodedValue.Companion.toMutable +import app.revanced.patcher.util.proxy.mutableTypes.encodedValue.MutableEncodedValue +import app.revanced.patcher.util.proxy.mutableTypes.encodedValue.MutableEncodedValue.Companion.toMutable import org.jf.dexlib2.base.BaseAnnotationElement import org.jf.dexlib2.iface.AnnotationElement import org.jf.dexlib2.iface.value.EncodedValue diff --git a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/MutableClass.kt b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/MutableClass.kt similarity index 90% rename from src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/MutableClass.kt rename to src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/MutableClass.kt index eadab5f3..a5a98d39 100644 --- a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/MutableClass.kt +++ b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/MutableClass.kt @@ -1,8 +1,8 @@ -package app.revanced.patcher.proxy.mutableTypes +package app.revanced.patcher.util.proxy.mutableTypes -import app.revanced.patcher.proxy.mutableTypes.MutableAnnotation.Companion.toMutable -import app.revanced.patcher.proxy.mutableTypes.MutableField.Companion.toMutable -import app.revanced.patcher.proxy.mutableTypes.MutableMethod.Companion.toMutable +import app.revanced.patcher.util.proxy.mutableTypes.MutableAnnotation.Companion.toMutable +import app.revanced.patcher.util.proxy.mutableTypes.MutableField.Companion.toMutable +import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMutable import com.google.common.collect.Iterables import org.jf.dexlib2.base.reference.BaseTypeReference import org.jf.dexlib2.iface.ClassDef diff --git a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/MutableField.kt b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/MutableField.kt similarity index 84% rename from src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/MutableField.kt rename to src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/MutableField.kt index 34c445ac..5eeabec7 100644 --- a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/MutableField.kt +++ b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/MutableField.kt @@ -1,8 +1,8 @@ -package app.revanced.patcher.proxy.mutableTypes +package app.revanced.patcher.util.proxy.mutableTypes -import app.revanced.patcher.proxy.mutableTypes.MutableAnnotation.Companion.toMutable -import app.revanced.patcher.proxy.mutableTypes.encodedValue.MutableEncodedValue -import app.revanced.patcher.proxy.mutableTypes.encodedValue.MutableEncodedValue.Companion.toMutable +import app.revanced.patcher.util.proxy.mutableTypes.MutableAnnotation.Companion.toMutable +import app.revanced.patcher.util.proxy.mutableTypes.encodedValue.MutableEncodedValue +import app.revanced.patcher.util.proxy.mutableTypes.encodedValue.MutableEncodedValue.Companion.toMutable import org.jf.dexlib2.HiddenApiRestriction import org.jf.dexlib2.base.reference.BaseFieldReference import org.jf.dexlib2.iface.Field diff --git a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/MutableMethod.kt b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/MutableMethod.kt similarity index 89% rename from src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/MutableMethod.kt rename to src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/MutableMethod.kt index 2a778a52..9e17e15b 100644 --- a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/MutableMethod.kt +++ b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/MutableMethod.kt @@ -1,7 +1,7 @@ -package app.revanced.patcher.proxy.mutableTypes +package app.revanced.patcher.util.proxy.mutableTypes -import app.revanced.patcher.proxy.mutableTypes.MutableAnnotation.Companion.toMutable -import app.revanced.patcher.proxy.mutableTypes.MutableMethodParameter.Companion.toMutable +import app.revanced.patcher.util.proxy.mutableTypes.MutableAnnotation.Companion.toMutable +import app.revanced.patcher.util.proxy.mutableTypes.MutableMethodParameter.Companion.toMutable import org.jf.dexlib2.HiddenApiRestriction import org.jf.dexlib2.base.reference.BaseMethodReference import org.jf.dexlib2.builder.MutableMethodImplementation diff --git a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/MutableMethodParameter.kt b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/MutableMethodParameter.kt similarity index 87% rename from src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/MutableMethodParameter.kt rename to src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/MutableMethodParameter.kt index 3b5287fe..a9e8391f 100644 --- a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/MutableMethodParameter.kt +++ b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/MutableMethodParameter.kt @@ -1,6 +1,6 @@ -package app.revanced.patcher.proxy.mutableTypes +package app.revanced.patcher.util.proxy.mutableTypes -import app.revanced.patcher.proxy.mutableTypes.MutableAnnotation.Companion.toMutable +import app.revanced.patcher.util.proxy.mutableTypes.MutableAnnotation.Companion.toMutable import org.jf.dexlib2.base.BaseMethodParameter import org.jf.dexlib2.iface.MethodParameter diff --git a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableAnnotationEncodedValue.kt b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableAnnotationEncodedValue.kt similarity index 85% rename from src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableAnnotationEncodedValue.kt rename to src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableAnnotationEncodedValue.kt index e62e573e..f2df668c 100644 --- a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableAnnotationEncodedValue.kt +++ b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableAnnotationEncodedValue.kt @@ -1,6 +1,6 @@ -package app.revanced.patcher.proxy.mutableTypes.encodedValue +package app.revanced.patcher.util.proxy.mutableTypes.encodedValue -import app.revanced.patcher.proxy.mutableTypes.MutableAnnotationElement.Companion.toMutable +import app.revanced.patcher.util.proxy.mutableTypes.MutableAnnotationElement.Companion.toMutable import org.jf.dexlib2.base.value.BaseAnnotationEncodedValue import org.jf.dexlib2.iface.AnnotationElement import org.jf.dexlib2.iface.value.AnnotationEncodedValue diff --git a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableArrayEncodedValue.kt b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableArrayEncodedValue.kt similarity index 79% rename from src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableArrayEncodedValue.kt rename to src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableArrayEncodedValue.kt index 268e78eb..cbcac8d8 100644 --- a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableArrayEncodedValue.kt +++ b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableArrayEncodedValue.kt @@ -1,6 +1,6 @@ -package app.revanced.patcher.proxy.mutableTypes.encodedValue +package app.revanced.patcher.util.proxy.mutableTypes.encodedValue -import app.revanced.patcher.proxy.mutableTypes.encodedValue.MutableEncodedValue.Companion.toMutable +import app.revanced.patcher.util.proxy.mutableTypes.encodedValue.MutableEncodedValue.Companion.toMutable import org.jf.dexlib2.base.value.BaseArrayEncodedValue import org.jf.dexlib2.iface.value.ArrayEncodedValue import org.jf.dexlib2.iface.value.EncodedValue diff --git a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableBooleanEncodedValue.kt b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableBooleanEncodedValue.kt similarity index 90% rename from src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableBooleanEncodedValue.kt rename to src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableBooleanEncodedValue.kt index d6377af8..26102173 100644 --- a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableBooleanEncodedValue.kt +++ b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableBooleanEncodedValue.kt @@ -1,4 +1,4 @@ -package app.revanced.patcher.proxy.mutableTypes.encodedValue +package app.revanced.patcher.util.proxy.mutableTypes.encodedValue import org.jf.dexlib2.base.value.BaseBooleanEncodedValue import org.jf.dexlib2.iface.value.BooleanEncodedValue diff --git a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableByteEncodedValue.kt b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableByteEncodedValue.kt similarity index 89% rename from src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableByteEncodedValue.kt rename to src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableByteEncodedValue.kt index 61757c43..105ff251 100644 --- a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableByteEncodedValue.kt +++ b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableByteEncodedValue.kt @@ -1,4 +1,4 @@ -package app.revanced.patcher.proxy.mutableTypes.encodedValue +package app.revanced.patcher.util.proxy.mutableTypes.encodedValue import org.jf.dexlib2.base.value.BaseByteEncodedValue import org.jf.dexlib2.iface.value.ByteEncodedValue diff --git a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableCharEncodedValue.kt b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableCharEncodedValue.kt similarity index 89% rename from src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableCharEncodedValue.kt rename to src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableCharEncodedValue.kt index c3cb3ee0..e15854f5 100644 --- a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableCharEncodedValue.kt +++ b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableCharEncodedValue.kt @@ -1,4 +1,4 @@ -package app.revanced.patcher.proxy.mutableTypes.encodedValue +package app.revanced.patcher.util.proxy.mutableTypes.encodedValue import org.jf.dexlib2.base.value.BaseCharEncodedValue import org.jf.dexlib2.iface.value.CharEncodedValue diff --git a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableDoubleEncodedValue.kt b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableDoubleEncodedValue.kt similarity index 89% rename from src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableDoubleEncodedValue.kt rename to src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableDoubleEncodedValue.kt index ddfb07bf..b20dc150 100644 --- a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableDoubleEncodedValue.kt +++ b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableDoubleEncodedValue.kt @@ -1,4 +1,4 @@ -package app.revanced.patcher.proxy.mutableTypes.encodedValue +package app.revanced.patcher.util.proxy.mutableTypes.encodedValue import org.jf.dexlib2.base.value.BaseDoubleEncodedValue import org.jf.dexlib2.iface.value.DoubleEncodedValue diff --git a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableEncodedValue.kt b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableEncodedValue.kt similarity index 96% rename from src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableEncodedValue.kt rename to src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableEncodedValue.kt index 0f170bf2..d9888e70 100644 --- a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableEncodedValue.kt +++ b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableEncodedValue.kt @@ -1,4 +1,4 @@ -package app.revanced.patcher.proxy.mutableTypes.encodedValue +package app.revanced.patcher.util.proxy.mutableTypes.encodedValue import org.jf.dexlib2.ValueType import org.jf.dexlib2.iface.value.* diff --git a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableEnumEncodedValue.kt b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableEnumEncodedValue.kt similarity index 90% rename from src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableEnumEncodedValue.kt rename to src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableEnumEncodedValue.kt index d9fbdb9f..8d297499 100644 --- a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableEnumEncodedValue.kt +++ b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableEnumEncodedValue.kt @@ -1,4 +1,4 @@ -package app.revanced.patcher.proxy.mutableTypes.encodedValue +package app.revanced.patcher.util.proxy.mutableTypes.encodedValue import org.jf.dexlib2.base.value.BaseEnumEncodedValue import org.jf.dexlib2.iface.reference.FieldReference diff --git a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableFieldEncodedValue.kt b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableFieldEncodedValue.kt similarity index 91% rename from src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableFieldEncodedValue.kt rename to src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableFieldEncodedValue.kt index 34d9b90e..451e46c7 100644 --- a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableFieldEncodedValue.kt +++ b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableFieldEncodedValue.kt @@ -1,4 +1,4 @@ -package app.revanced.patcher.proxy.mutableTypes.encodedValue +package app.revanced.patcher.util.proxy.mutableTypes.encodedValue import org.jf.dexlib2.ValueType import org.jf.dexlib2.base.value.BaseFieldEncodedValue diff --git a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableFloatEncodedValue.kt b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableFloatEncodedValue.kt similarity index 89% rename from src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableFloatEncodedValue.kt rename to src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableFloatEncodedValue.kt index c2fff542..0f82a90b 100644 --- a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableFloatEncodedValue.kt +++ b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableFloatEncodedValue.kt @@ -1,4 +1,4 @@ -package app.revanced.patcher.proxy.mutableTypes.encodedValue +package app.revanced.patcher.util.proxy.mutableTypes.encodedValue import org.jf.dexlib2.base.value.BaseFloatEncodedValue import org.jf.dexlib2.iface.value.FloatEncodedValue diff --git a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableIntEncodedValue.kt b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableIntEncodedValue.kt similarity index 89% rename from src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableIntEncodedValue.kt rename to src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableIntEncodedValue.kt index d5918c64..87b77246 100644 --- a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableIntEncodedValue.kt +++ b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableIntEncodedValue.kt @@ -1,4 +1,4 @@ -package app.revanced.patcher.proxy.mutableTypes.encodedValue +package app.revanced.patcher.util.proxy.mutableTypes.encodedValue import org.jf.dexlib2.base.value.BaseIntEncodedValue import org.jf.dexlib2.iface.value.IntEncodedValue diff --git a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableLongEncodedValue.kt b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableLongEncodedValue.kt similarity index 89% rename from src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableLongEncodedValue.kt rename to src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableLongEncodedValue.kt index 190a2d83..2c4b10ec 100644 --- a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableLongEncodedValue.kt +++ b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableLongEncodedValue.kt @@ -1,4 +1,4 @@ -package app.revanced.patcher.proxy.mutableTypes.encodedValue +package app.revanced.patcher.util.proxy.mutableTypes.encodedValue import org.jf.dexlib2.base.value.BaseLongEncodedValue import org.jf.dexlib2.iface.value.LongEncodedValue diff --git a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableMethodEncodedValue.kt b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableMethodEncodedValue.kt similarity index 90% rename from src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableMethodEncodedValue.kt rename to src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableMethodEncodedValue.kt index 24f0ba0b..8eb7ec81 100644 --- a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableMethodEncodedValue.kt +++ b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableMethodEncodedValue.kt @@ -1,4 +1,4 @@ -package app.revanced.patcher.proxy.mutableTypes.encodedValue +package app.revanced.patcher.util.proxy.mutableTypes.encodedValue import org.jf.dexlib2.base.value.BaseMethodEncodedValue import org.jf.dexlib2.iface.reference.MethodReference diff --git a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableMethodHandleEncodedValue.kt b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableMethodHandleEncodedValue.kt similarity index 91% rename from src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableMethodHandleEncodedValue.kt rename to src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableMethodHandleEncodedValue.kt index 54ba088c..5fd05715 100644 --- a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableMethodHandleEncodedValue.kt +++ b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableMethodHandleEncodedValue.kt @@ -1,4 +1,4 @@ -package app.revanced.patcher.proxy.mutableTypes.encodedValue +package app.revanced.patcher.util.proxy.mutableTypes.encodedValue import org.jf.dexlib2.base.value.BaseMethodHandleEncodedValue import org.jf.dexlib2.iface.reference.MethodHandleReference diff --git a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableMethodTypeEncodedValue.kt b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableMethodTypeEncodedValue.kt similarity index 91% rename from src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableMethodTypeEncodedValue.kt rename to src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableMethodTypeEncodedValue.kt index dded2287..0c7dda79 100644 --- a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableMethodTypeEncodedValue.kt +++ b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableMethodTypeEncodedValue.kt @@ -1,4 +1,4 @@ -package app.revanced.patcher.proxy.mutableTypes.encodedValue +package app.revanced.patcher.util.proxy.mutableTypes.encodedValue import org.jf.dexlib2.base.value.BaseMethodTypeEncodedValue import org.jf.dexlib2.iface.reference.MethodProtoReference diff --git a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableNullEncodedValue.kt b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableNullEncodedValue.kt similarity index 83% rename from src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableNullEncodedValue.kt rename to src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableNullEncodedValue.kt index cce128de..339bd27d 100644 --- a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableNullEncodedValue.kt +++ b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableNullEncodedValue.kt @@ -1,4 +1,4 @@ -package app.revanced.patcher.proxy.mutableTypes.encodedValue +package app.revanced.patcher.util.proxy.mutableTypes.encodedValue import org.jf.dexlib2.base.value.BaseNullEncodedValue import org.jf.dexlib2.iface.value.ByteEncodedValue diff --git a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableShortEncodedValue.kt b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableShortEncodedValue.kt similarity index 89% rename from src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableShortEncodedValue.kt rename to src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableShortEncodedValue.kt index e8c0f745..8b5af292 100644 --- a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableShortEncodedValue.kt +++ b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableShortEncodedValue.kt @@ -1,4 +1,4 @@ -package app.revanced.patcher.proxy.mutableTypes.encodedValue +package app.revanced.patcher.util.proxy.mutableTypes.encodedValue import org.jf.dexlib2.base.value.BaseShortEncodedValue import org.jf.dexlib2.iface.value.ShortEncodedValue diff --git a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableStringEncodedValue.kt b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableStringEncodedValue.kt similarity index 90% rename from src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableStringEncodedValue.kt rename to src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableStringEncodedValue.kt index f02acc4b..e2a839bf 100644 --- a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableStringEncodedValue.kt +++ b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableStringEncodedValue.kt @@ -1,4 +1,4 @@ -package app.revanced.patcher.proxy.mutableTypes.encodedValue +package app.revanced.patcher.util.proxy.mutableTypes.encodedValue import org.jf.dexlib2.base.value.BaseStringEncodedValue import org.jf.dexlib2.iface.value.ByteEncodedValue diff --git a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableTypeEncodedValue.kt b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableTypeEncodedValue.kt similarity index 89% rename from src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableTypeEncodedValue.kt rename to src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableTypeEncodedValue.kt index 6f56a33d..37bb86b1 100644 --- a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/encodedValue/MutableTypeEncodedValue.kt +++ b/src/main/kotlin/app/revanced/patcher/util/proxy/mutableTypes/encodedValue/MutableTypeEncodedValue.kt @@ -1,4 +1,4 @@ -package app.revanced.patcher.proxy.mutableTypes.encodedValue +package app.revanced.patcher.util.proxy.mutableTypes.encodedValue import org.jf.dexlib2.base.value.BaseTypeEncodedValue import org.jf.dexlib2.iface.value.TypeEncodedValue diff --git a/src/main/kotlin/app/revanced/patcher/smali/InlineSmaliCompiler.kt b/src/main/kotlin/app/revanced/patcher/util/smali/InlineSmaliCompiler.kt similarity index 87% rename from src/main/kotlin/app/revanced/patcher/smali/InlineSmaliCompiler.kt rename to src/main/kotlin/app/revanced/patcher/util/smali/InlineSmaliCompiler.kt index f0ac965a..80b96c7f 100644 --- a/src/main/kotlin/app/revanced/patcher/smali/InlineSmaliCompiler.kt +++ b/src/main/kotlin/app/revanced/patcher/util/smali/InlineSmaliCompiler.kt @@ -1,4 +1,4 @@ -package app.revanced.patcher.smali +package app.revanced.patcher.util.smali import org.antlr.runtime.CommonTokenStream import org.antlr.runtime.TokenSource @@ -32,7 +32,11 @@ class InlineSmaliCompiler { * be messed up and results in broken Dalvik bytecode. * FIXME: Fix the above issue. When this is fixed, add the proper conversions in [InstructionConverter]. */ - fun compileMethodInstructions(instructions: String, parameters: String, registers: Int): List { + fun compileMethodInstructions( + instructions: String, + parameters: String, + registers: Int + ): List { val input = METHOD_TEMPLATE.format(parameters, registers, instructions) val reader = InputStreamReader(input.byteInputStream()) val lexer: LexerErrorInterface = smaliFlexLexer(reader, 15) @@ -54,5 +58,8 @@ class InlineSmaliCompiler { } } -fun String.toInstructions(parameters: String = "", registers: Int = 1) = InlineSmaliCompiler.compileMethodInstructions(this, parameters, registers) -fun String.toInstruction(parameters: String = "", registers: Int = 1) = this.toInstructions(parameters, registers).first() +fun String.toInstructions(parameters: String = "", registers: Int = 1) = + InlineSmaliCompiler.compileMethodInstructions(this, parameters, registers) + +fun String.toInstruction(parameters: String = "", registers: Int = 1) = + this.toInstructions(parameters, registers).first() diff --git a/src/main/kotlin/app/revanced/patcher/smali/InstructionConverter.kt b/src/main/kotlin/app/revanced/patcher/util/smali/InstructionConverter.kt similarity index 99% rename from src/main/kotlin/app/revanced/patcher/smali/InstructionConverter.kt rename to src/main/kotlin/app/revanced/patcher/util/smali/InstructionConverter.kt index 57363d74..e4c5ae1b 100644 --- a/src/main/kotlin/app/revanced/patcher/smali/InstructionConverter.kt +++ b/src/main/kotlin/app/revanced/patcher/util/smali/InstructionConverter.kt @@ -1,4 +1,4 @@ -package app.revanced.patcher.smali +package app.revanced.patcher.util.smali import org.jf.dexlib2.Format import org.jf.dexlib2.builder.instruction.* diff --git a/src/test/kotlin/app/revanced/patcher/PatcherTest.kt b/src/test/kotlin/app/revanced/patcher/PatcherTest.kt index 1007aac5..d4b091f0 100644 --- a/src/test/kotlin/app/revanced/patcher/PatcherTest.kt +++ b/src/test/kotlin/app/revanced/patcher/PatcherTest.kt @@ -1,49 +1,46 @@ package app.revanced.patcher -import app.revanced.patcher.signature.PatternScanMethod -import app.revanced.patcher.usage.ExampleBytecodePatch -import app.revanced.patcher.usage.ExampleResourcePatch import org.junit.jupiter.api.Test -import java.io.File -import kotlin.test.assertTrue internal class PatcherTest { @Test fun testPatcher() { return // FIXME: create a proper resource to pass this test + /** val patcher = Patcher( - File(PatcherTest::class.java.getResource("/example.apk")!!.toURI()), - "exampleCacheDirectory", - patchResources = true + File(PatcherTest::class.java.getResource("/example.apk")!!.toURI()), + "exampleCacheDirectory", + patchResources = true ) patcher.addPatches(listOf(ExampleBytecodePatch(), ExampleResourcePatch())) for (signature in patcher.resolveSignatures()) { - if (!signature.resolved) { - throw Exception("Signature ${signature.metadata.name} was not resolved!") - } - val patternScanMethod = signature.metadata.patternScanMethod - if (patternScanMethod is PatternScanMethod.Fuzzy) { - val warnings = patternScanMethod.warnings - if (warnings != null) { - println("Signature ${signature.metadata.name} had ${warnings.size} warnings!") - for (warning in warnings) { - println(warning.toString()) - } - } else { - println("Signature ${signature.metadata.name} used the fuzzy resolver, but the warnings list is null!") - } - } + if (!signature.resolved) { + throw Exception("Signature ${signature.metadata.name} was not resolved!") + } + val patternScanMethod = signature.metadata.patternScanMethod + if (patternScanMethod is PatternScanMethod.Fuzzy) { + val warnings = patternScanMethod.warnings + if (warnings != null) { + println("Signature ${signature.metadata.name} had ${warnings.size} warnings!") + for (warning in warnings) { + println(warning.toString()) + } + } else { + println("Signature ${signature.metadata.name} used the fuzzy resolver, but the warnings list is null!") + } + } } for ((metadata, result) in patcher.applyPatches()) { - if (result.isFailure) { - throw Exception("Patch ${metadata.shortName} failed", result.exceptionOrNull()!!) - } else { - println("Patch ${metadata.shortName} applied successfully!") - } + if (result.isFailure) { + throw Exception("Patch ${metadata.shortName} failed", result.exceptionOrNull()!!) + } else { + println("Patch ${metadata.shortName} applied successfully!") + } } val out = patcher.save() assertTrue(out.isNotEmpty(), "Expected the output of Patcher#save() to not be empty.") + */ } } \ No newline at end of file diff --git a/src/test/kotlin/app/revanced/patcher/usage/bytecode/annotation/ExampleBytecodeCompatibility.kt b/src/test/kotlin/app/revanced/patcher/usage/bytecode/annotation/ExampleBytecodeCompatibility.kt new file mode 100644 index 00000000..842e2ce6 --- /dev/null +++ b/src/test/kotlin/app/revanced/patcher/usage/bytecode/annotation/ExampleBytecodeCompatibility.kt @@ -0,0 +1,14 @@ +package app.revanced.patcher.usage.bytecode.annotation + +import app.revanced.patcher.annotation.Compatibility +import app.revanced.patcher.annotation.Package + +@Compatibility( + [Package( + "com.example.examplePackage", arrayOf("0.0.1", "0.0.2") + )] +) +@Target(AnnotationTarget.CLASS) +@Retention(AnnotationRetention.RUNTIME) +internal annotation class ExampleBytecodeCompatibility + diff --git a/src/test/kotlin/app/revanced/patcher/usage/ExampleBytecodePatch.kt b/src/test/kotlin/app/revanced/patcher/usage/bytecode/patch/ExampleBytecodePatch.kt similarity index 78% rename from src/test/kotlin/app/revanced/patcher/usage/ExampleBytecodePatch.kt rename to src/test/kotlin/app/revanced/patcher/usage/bytecode/patch/ExampleBytecodePatch.kt index 18745c59..1a286951 100644 --- a/src/test/kotlin/app/revanced/patcher/usage/ExampleBytecodePatch.kt +++ b/src/test/kotlin/app/revanced/patcher/usage/bytecode/patch/ExampleBytecodePatch.kt @@ -1,21 +1,21 @@ -package app.revanced.patcher.usage +package app.revanced.patcher.usage.bytecode.patch +import app.revanced.patcher.annotation.Description +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version import app.revanced.patcher.data.implementation.BytecodeData import app.revanced.patcher.extensions.addInstructions import app.revanced.patcher.extensions.or +import app.revanced.patcher.patch.annotations.Patch import app.revanced.patcher.patch.implementation.BytecodePatch -import app.revanced.patcher.patch.implementation.metadata.PackageMetadata -import app.revanced.patcher.patch.implementation.metadata.PatchMetadata import app.revanced.patcher.patch.implementation.misc.PatchResult import app.revanced.patcher.patch.implementation.misc.PatchResultSuccess -import app.revanced.patcher.proxy.mutableTypes.MutableField.Companion.toMutable -import app.revanced.patcher.proxy.mutableTypes.MutableMethod.Companion.toMutable -import app.revanced.patcher.signature.MethodMetadata -import app.revanced.patcher.signature.MethodSignature -import app.revanced.patcher.signature.MethodSignatureMetadata -import app.revanced.patcher.signature.PatternScanMethod -import app.revanced.patcher.smali.toInstruction -import app.revanced.patcher.smali.toInstructions +import app.revanced.patcher.usage.bytecode.signatures.ExampleSignature +import app.revanced.patcher.usage.resource.annotation.ExampleResourceCompatibility +import app.revanced.patcher.util.proxy.mutableTypes.MutableField.Companion.toMutable +import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMutable +import app.revanced.patcher.util.smali.toInstruction +import app.revanced.patcher.util.smali.toInstructions import com.google.common.collect.ImmutableList import org.jf.dexlib2.AccessFlags import org.jf.dexlib2.Format @@ -32,45 +32,15 @@ import org.jf.dexlib2.immutable.reference.ImmutableStringReference import org.jf.dexlib2.immutable.value.ImmutableFieldEncodedValue import org.jf.dexlib2.util.Preconditions -val packageMetadata = listOf( - PackageMetadata( - "com.example.examplePackage", - listOf("0.0.1", "0.0.2") - ) -) - +@Patch +@Name("example-bytecode-patch") +@Description("Example demonstration of a bytecode patch.") +@ExampleResourceCompatibility +@Version("0.0.1") class ExampleBytecodePatch : BytecodePatch( - PatchMetadata( - "example-patch", - "ReVanced example patch", - "A demonstrative patch to feature the core features of the ReVanced patcher", - packageMetadata, - "0.0.1" - ), - setOf( - MethodSignature( - MethodSignatureMetadata( - "Example signature", - MethodMetadata( - "TestClass", - "main", - ), - PatternScanMethod.Fuzzy(1), - packageMetadata, - "The main method of TestClass", - "1.0.0" - ), - "V", - AccessFlags.PUBLIC or AccessFlags.STATIC, - listOf("[L"), - listOf( - Opcode.SGET_OBJECT, - null, // Testing unknown opcodes. - Opcode.INVOKE_STATIC, // This is intentionally wrong to test the Fuzzy resolver. - Opcode.RETURN_VOID - ), - null - ) + + listOf( + ExampleSignature ) ) { // This function will be executed by the patcher. diff --git a/src/test/kotlin/app/revanced/patcher/usage/bytecode/signatures/ExampleSignature.kt b/src/test/kotlin/app/revanced/patcher/usage/bytecode/signatures/ExampleSignature.kt new file mode 100644 index 00000000..d0983b71 --- /dev/null +++ b/src/test/kotlin/app/revanced/patcher/usage/bytecode/signatures/ExampleSignature.kt @@ -0,0 +1,32 @@ +package app.revanced.patcher.usage.bytecode.signatures + +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.extensions.or +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 +import app.revanced.patcher.usage.bytecode.annotation.ExampleBytecodeCompatibility +import org.jf.dexlib2.AccessFlags +import org.jf.dexlib2.Opcode + +@Name("example-signature") +@MatchingMethod( + "LexampleClass;", + "exampleMehod" +) +@FuzzyPatternScanMethod(2) +@ExampleBytecodeCompatibility +@Version("0.0.1") +object ExampleSignature : MethodSignature( + "V", + AccessFlags.PUBLIC or AccessFlags.STATIC, + listOf("[L"), + listOf( + Opcode.SGET_OBJECT, + null, // Testing unknown opcodes. + Opcode.INVOKE_STATIC, // This is intentionally wrong to test the Fuzzy resolver. + Opcode.RETURN_VOID + ), + null +) \ No newline at end of file diff --git a/src/test/kotlin/app/revanced/patcher/usage/resource/annotation/ExampleResourceCompatibility.kt b/src/test/kotlin/app/revanced/patcher/usage/resource/annotation/ExampleResourceCompatibility.kt new file mode 100644 index 00000000..d8154c66 --- /dev/null +++ b/src/test/kotlin/app/revanced/patcher/usage/resource/annotation/ExampleResourceCompatibility.kt @@ -0,0 +1,14 @@ +package app.revanced.patcher.usage.resource.annotation + +import app.revanced.patcher.annotation.Compatibility +import app.revanced.patcher.annotation.Package + +@Compatibility( + [Package( + "com.example.examplePackage", arrayOf("0.0.1", "0.0.2") + )] +) +@Target(AnnotationTarget.CLASS) +@Retention(AnnotationRetention.RUNTIME) +internal annotation class ExampleResourceCompatibility + diff --git a/src/test/kotlin/app/revanced/patcher/usage/ExampleResourcePatch.kt b/src/test/kotlin/app/revanced/patcher/usage/resource/patch/ExampleResourcePatch.kt similarity index 68% rename from src/test/kotlin/app/revanced/patcher/usage/ExampleResourcePatch.kt rename to src/test/kotlin/app/revanced/patcher/usage/resource/patch/ExampleResourcePatch.kt index ae41181d..dc99de95 100644 --- a/src/test/kotlin/app/revanced/patcher/usage/ExampleResourcePatch.kt +++ b/src/test/kotlin/app/revanced/patcher/usage/resource/patch/ExampleResourcePatch.kt @@ -1,21 +1,22 @@ -package app.revanced.patcher.usage +package app.revanced.patcher.usage.resource.patch +import app.revanced.patcher.annotation.Description +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version import app.revanced.patcher.data.implementation.ResourceData +import app.revanced.patcher.patch.annotations.Patch import app.revanced.patcher.patch.implementation.ResourcePatch -import app.revanced.patcher.patch.implementation.metadata.PatchMetadata import app.revanced.patcher.patch.implementation.misc.PatchResult import app.revanced.patcher.patch.implementation.misc.PatchResultSuccess +import app.revanced.patcher.usage.resource.annotation.ExampleResourceCompatibility import org.w3c.dom.Element -class ExampleResourcePatch : ResourcePatch( - PatchMetadata( - "example-patch", - "Example Resource Patch", - "Example demonstration of a resource patch.", - packageMetadata, - "0.0.1" - ) -) { +@Patch +@Name("example-resource-patch") +@Description("Example demonstration of a resource patch.") +@ExampleResourceCompatibility +@Version("0.0.1") +class ExampleResourcePatch : ResourcePatch() { override fun execute(data: ResourceData): PatchResult { val editor = data.getXmlEditor("AndroidManifest.xml")