diff --git a/api/revanced-patcher.api b/api/revanced-patcher.api index ecb12e4..13017d1 100644 --- a/api/revanced-patcher.api +++ b/api/revanced-patcher.api @@ -175,6 +175,7 @@ public abstract class app/revanced/patcher/fingerprint/MethodFingerprint { public fun ()V public fun (Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/Iterable;Ljava/lang/Iterable;Ljava/lang/Iterable;Lkotlin/jvm/functions/Function2;)V public synthetic fun (Ljava/lang/String;Ljava/lang/Integer;Ljava/lang/Iterable;Ljava/lang/Iterable;Ljava/lang/Iterable;Lkotlin/jvm/functions/Function2;ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public final fun getFuzzyPatternScanMethod ()Lapp/revanced/patcher/fingerprint/annotation/FuzzyPatternScanMethod; public final fun getResult ()Lapp/revanced/patcher/fingerprint/MethodFingerprintResult; public final fun resolve (Lapp/revanced/patcher/data/BytecodeContext;Lcom/android/tools/smali/dexlib2/iface/ClassDef;)Z public final fun resolve (Lapp/revanced/patcher/data/BytecodeContext;Lcom/android/tools/smali/dexlib2/iface/Method;Lcom/android/tools/smali/dexlib2/iface/ClassDef;)Z diff --git a/src/main/kotlin/app/revanced/patcher/extensions/AnnotationExtensions.kt b/src/main/kotlin/app/revanced/patcher/extensions/AnnotationExtensions.kt index 3eff3af..e5bf9d8 100644 --- a/src/main/kotlin/app/revanced/patcher/extensions/AnnotationExtensions.kt +++ b/src/main/kotlin/app/revanced/patcher/extensions/AnnotationExtensions.kt @@ -1,18 +1,16 @@ package app.revanced.patcher.extensions -import kotlin.reflect.KClass - internal object AnnotationExtensions { /** - * Recursively find a given annotation on a class. + * Search for an annotation recursively. * - * @param targetAnnotation The annotation to find. - * @return The annotation. + * @param targetAnnotation The annotation to search for. + * @return The annotation if found, otherwise null. */ - fun Class<*>.findAnnotationRecursively(targetAnnotation: KClass): T? { + fun Class<*>.findAnnotationRecursively(targetAnnotation: Class): T? { fun Class<*>.findAnnotationRecursively( targetAnnotation: Class, - traversed: MutableSet, + searchedAnnotations: MutableSet, ): T? { val found = this.annotations.firstOrNull { it.annotationClass.java.name == targetAnnotation.name } @@ -20,16 +18,18 @@ internal object AnnotationExtensions { if (found != null) return found as T for (annotation in this.annotations) { - if (traversed.contains(annotation)) continue - traversed.add(annotation) + if (searchedAnnotations.contains(annotation)) continue + searchedAnnotations.add(annotation) - return (annotation.annotationClass.java.findAnnotationRecursively(targetAnnotation, traversed)) - ?: continue + return annotation.annotationClass.java.findAnnotationRecursively( + targetAnnotation, + searchedAnnotations + ) ?: continue } return null } - return this.findAnnotationRecursively(targetAnnotation.java, mutableSetOf()) + return this.findAnnotationRecursively(targetAnnotation, mutableSetOf()) } } diff --git a/src/main/kotlin/app/revanced/patcher/extensions/MethodFingerprintExtensions.kt b/src/main/kotlin/app/revanced/patcher/extensions/MethodFingerprintExtensions.kt index 25dc694..a9a958a 100644 --- a/src/main/kotlin/app/revanced/patcher/extensions/MethodFingerprintExtensions.kt +++ b/src/main/kotlin/app/revanced/patcher/extensions/MethodFingerprintExtensions.kt @@ -1,14 +1,16 @@ package app.revanced.patcher.extensions -import app.revanced.patcher.extensions.AnnotationExtensions.findAnnotationRecursively import app.revanced.patcher.fingerprint.MethodFingerprint import app.revanced.patcher.fingerprint.annotation.FuzzyPatternScanMethod object MethodFingerprintExtensions { - // TODO: Make this a property. /** * The [FuzzyPatternScanMethod] annotation of a [MethodFingerprint]. */ + @Deprecated( + message = "Use the property instead.", + replaceWith = ReplaceWith("this.fuzzyPatternScanMethod") + ) val MethodFingerprint.fuzzyPatternScanMethod - get() = javaClass.findAnnotationRecursively(FuzzyPatternScanMethod::class) + get() = this.fuzzyPatternScanMethod } diff --git a/src/main/kotlin/app/revanced/patcher/fingerprint/MethodFingerprint.kt b/src/main/kotlin/app/revanced/patcher/fingerprint/MethodFingerprint.kt index 40973d9..04e511d 100644 --- a/src/main/kotlin/app/revanced/patcher/fingerprint/MethodFingerprint.kt +++ b/src/main/kotlin/app/revanced/patcher/fingerprint/MethodFingerprint.kt @@ -1,7 +1,7 @@ package app.revanced.patcher.fingerprint import app.revanced.patcher.data.BytecodeContext -import app.revanced.patcher.extensions.MethodFingerprintExtensions.fuzzyPatternScanMethod +import app.revanced.patcher.extensions.AnnotationExtensions.findAnnotationRecursively import app.revanced.patcher.fingerprint.LookupMap.Maps.appendParameters import app.revanced.patcher.fingerprint.LookupMap.Maps.initializeLookupMaps import app.revanced.patcher.fingerprint.LookupMap.Maps.methodSignatureLookupMap @@ -28,6 +28,7 @@ import com.android.tools.smali.dexlib2.iface.reference.StringReference * @param strings A list of the method's strings compared each using [String.contains]. * @param customFingerprint A custom condition for this fingerprint. */ +@Suppress("MemberVisibilityCanBePrivate") abstract class MethodFingerprint( internal val returnType: String? = null, internal val accessFlags: Int? = null, @@ -42,6 +43,13 @@ abstract class MethodFingerprint( var result: MethodFingerprintResult? = null private set + /** + * The [FuzzyPatternScanMethod] annotation of the [MethodFingerprint]. + * + * If the annotation is not present, this property is null. + */ + val fuzzyPatternScanMethod = javaClass.findAnnotationRecursively(FuzzyPatternScanMethod::class.java) + /** * Resolve a [MethodFingerprint] using the lookup map built by [initializeLookupMaps]. *