Skip to content

Commit

Permalink
sync docs
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Apr 29, 2024
1 parent 503078e commit 21c2a86
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 34 deletions.
16 changes: 4 additions & 12 deletions docs/2_2_1_fingerprinting.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"

This comment has been minimized.

Copy link
@BholeyKaBhakt

BholeyKaBhakt May 29, 2024

) missing

custom { (methodDef, classDef) -> methodDef.definingClass == "Lcom/some/app/ads/AdsLoader;" }
}
```
Expand All @@ -96,16 +91,16 @@ The fingerprint contains the following information:
- Method signature:

```kt
returns("Z")
accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL)
returns("Z")
parameters("Z")
```

- Method implementation:

```kt
opcodes(Opcode.RETURN)
strings("pro"),
strings("pro")
```

- Package and class name:
Expand Down Expand Up @@ -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")
}
Expand Down
12 changes: 5 additions & 7 deletions docs/2_2_patch_anatomy.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
// ...
Expand Down Expand Up @@ -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")
Expand All @@ -137,7 +135,7 @@ val patch = bytecodePatch(name = "Patch") {
print("4")
}
}
}
)

execute {
print("2")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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].
Expand All @@ -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<String>? = null,
internal val opcodes: List<Opcode?>? = null,
internal val strings: List<String>? = null,
Expand Down Expand Up @@ -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].
Expand All @@ -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<String>? = null
private var opcodes: List<Opcode?>? = null
private var strings: List<String>? = 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.
*
Expand All @@ -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.
*
Expand Down Expand Up @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/app/revanced/patcher/patch/Patch.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 21c2a86

Please sign in to comment.