From 21c2a86ec8d6a03ed87aaf49aed31873b5c08d64 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Tue, 30 Apr 2024 01:29:09 +0200 Subject: [PATCH] sync docs --- docs/2_2_1_fingerprinting.md | 16 +++-------- docs/2_2_patch_anatomy.md | 12 ++++---- .../patcher/fingerprint/MethodFingerprint.kt | 28 +++++++++---------- .../app/revanced/patcher/patch/Patch.kt | 2 +- 4 files changed, 24 insertions(+), 34 deletions(-) diff --git a/docs/2_2_1_fingerprinting.md b/docs/2_2_1_fingerprinting.md index 04d1f2ab..3c874213 100644 --- a/docs/2_2_1_fingerprinting.md +++ b/docs/2_2_1_fingerprinting.md @@ -73,16 +73,11 @@ Throughout the documentation, the following example will be used to demonstrate package app.revanced.patches.ads.fingerprints methodFingerprint { - returns("Z") - accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL) - + returns("Z") parameters("Z") - opcodes(Opcode.RETURN) - - strings("pro") - + strings("pro" custom { (methodDef, classDef) -> methodDef.definingClass == "Lcom/some/app/ads/AdsLoader;" } } ``` @@ -96,8 +91,8 @@ The fingerprint contains the following information: - Method signature: ```kt - returns("Z") accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL) + returns("Z") parameters("Z") ``` @@ -105,7 +100,7 @@ The fingerprint contains the following information: ```kt opcodes(Opcode.RETURN) - strings("pro"), + strings("pro") ``` - Package and class name: @@ -264,9 +259,6 @@ You can resolve a fingerprint in the following ways: ```kt execute { - val adsFingerprintResult = showAdsFingerprint.result - ?: throw PatchException("showAdsFingerprint not found") - val proStringsFingerprint = methodFingerprint { strings("free", "trial") } diff --git a/docs/2_2_patch_anatomy.md b/docs/2_2_patch_anatomy.md index 41c22b0a..0c084e70 100644 --- a/docs/2_2_patch_anatomy.md +++ b/docs/2_2_patch_anatomy.md @@ -71,13 +71,11 @@ val disableAdsPatch = bytecodePatch( name = "Disable ads", description = "Disable ads in the app.", ) { - compatibleWith { + compatibleWith( "com.some.app"("1.0.0") - } + ) - dependsOn { - disableAdsResourcePatch() - } + dependsOn(disableAdsResourcePatch) val showAdsFingerprintResult by methodFingerprint { // ... @@ -127,7 +125,7 @@ Patches can have a finalization block called after all patches have been execute ```kt val patch = bytecodePatch(name = "Patch") { - dependsOn { + dependsOn( bytecodePatch(name = "Dependency") { execute { print("1") @@ -137,7 +135,7 @@ val patch = bytecodePatch(name = "Patch") { print("4") } } - } + ) execute { print("2") diff --git a/src/main/kotlin/app/revanced/patcher/fingerprint/MethodFingerprint.kt b/src/main/kotlin/app/revanced/patcher/fingerprint/MethodFingerprint.kt index 46029f05..1f426721 100644 --- a/src/main/kotlin/app/revanced/patcher/fingerprint/MethodFingerprint.kt +++ b/src/main/kotlin/app/revanced/patcher/fingerprint/MethodFingerprint.kt @@ -21,8 +21,8 @@ import com.android.tools.smali.dexlib2.util.MethodUtil /** * A fingerprint to resolve methods. * - * @param returnType The return type compared using [String.startsWith]. * @param accessFlags The exact access flags using values of [AccessFlags]. + * @param returnType The return type compared using [String.startsWith]. * @param parameters The parameters of the method. Partial matches allowed and follow the same rules as [returnType]. * @param opcodes An opcode pattern of the instructions. Wildcard or unknown opcodes can be specified by `null`. * @param strings A list of the strings compared each using [String.contains]. @@ -31,8 +31,8 @@ import com.android.tools.smali.dexlib2.util.MethodUtil */ @Suppress("MemberVisibilityCanBePrivate") class MethodFingerprint internal constructor( - internal val returnType: String? = null, internal val accessFlags: Int? = null, + internal val returnType: String? = null, internal val parameters: List? = null, internal val opcodes: List? = null, internal val strings: List? = null, @@ -395,8 +395,8 @@ class MethodFingerprintResult( /** * A builder for [MethodFingerprint]. * - * @property returnType The return type compared using [String.startsWith]. * @property accessFlags The exact access flags using values of [AccessFlags]. + * @property returnType The return type compared using [String.startsWith]. * @property parameters The parameters of the method. Partial matches allowed and follow the same rules as [returnType]. * @property opcodes An opcode pattern of the instructions. Wildcard or unknown opcodes can be specified by `null`. * @property strings A list of the strings compared each using [String.contains]. @@ -408,22 +408,13 @@ class MethodFingerprintResult( class MethodFingerprintBuilder internal constructor( private val fuzzyPatternScanThreshold: Int = 0, ) { - private var returnType: String? = null private var accessFlags: Int? = null + private var returnType: String? = null private var parameters: List? = null private var opcodes: List? = null private var strings: List? = null private var customBlock: ((methodDef: Method, classDef: ClassDef) -> Boolean)? = null - /** - * Set the return type. - * - * @param returnType The return type compared using [String.startsWith]. - */ - infix fun returns(returnType: String) { - this.returnType = returnType - } - /** * Set the access flags. * @@ -442,6 +433,15 @@ class MethodFingerprintBuilder internal constructor( this.accessFlags = accessFlags.fold(0) { acc, it -> acc or it.value } } + /** + * Set the return type. + * + * @param returnType The return type compared using [String.startsWith]. + */ + infix fun returns(returnType: String) { + this.returnType = returnType + } + /** * Set the parameters. * @@ -502,7 +502,7 @@ class MethodFingerprintBuilder internal constructor( this.customBlock = customBlock } - internal fun build() = MethodFingerprint(returnType, accessFlags, parameters, opcodes, strings, customBlock) + internal fun build() = MethodFingerprint(accessFlags, returnType, parameters, opcodes, strings, customBlock) private companion object { val opcodesByName = Opcode.entries.associateBy { it.name } diff --git a/src/main/kotlin/app/revanced/patcher/patch/Patch.kt b/src/main/kotlin/app/revanced/patcher/patch/Patch.kt index 38025b19..c02cf6d6 100644 --- a/src/main/kotlin/app/revanced/patcher/patch/Patch.kt +++ b/src/main/kotlin/app/revanced/patcher/patch/Patch.kt @@ -339,7 +339,7 @@ class BytecodePatchBuilder internal constructor( * Add the fingerprint to the patch. */ operator fun MethodFingerprint.invoke() = apply { - fingerprints.add(MethodFingerprint(returnType, accessFlags, parameters, opcodes, strings, custom)) + fingerprints.add(MethodFingerprint(accessFlags, returnType, parameters, opcodes, strings, custom)) } operator fun MethodFingerprint.getValue(nothing: Nothing?, property: KProperty<*>) = result