From 5477e8edbe3b5a764b0aef3af3ce8b1580ee1f50 Mon Sep 17 00:00:00 2001 From: Pun Butrach Date: Mon, 12 Jan 2026 16:46:43 +0700 Subject: [PATCH] refactor(sync): DisablePiracyDetectionPatch --- .../piracy/DisablePiracyDetectionPatch.kt | 6 ++-- .../sync/detection/piracy/Fingerprints.kt | 34 +++++++++---------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/sync/detection/piracy/DisablePiracyDetectionPatch.kt b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/sync/detection/piracy/DisablePiracyDetectionPatch.kt index fc0e976ef..05215d133 100644 --- a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/sync/detection/piracy/DisablePiracyDetectionPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/sync/detection/piracy/DisablePiracyDetectionPatch.kt @@ -1,15 +1,15 @@ package app.revanced.patches.reddit.customclients.sync.detection.piracy import app.revanced.patcher.extensions.addInstruction -import app.revanced.patcher.patch.bytecodePatch +import app.revanced.patcher.patch.creatingBytecodePatch -val disablePiracyDetectionPatch = bytecodePatch( +val `Disable privacy detection` = creatingBytecodePatch( description = "Disables detection of modified versions.", ) { apply { // Do not throw an error if the fingerprint is not resolved. // This is fine because new versions of the target app do not need this patch. - piracyDetectionFingerprint.methodOrNull?.addInstruction(0, "return-void") + piracyDetectionMethod.addInstruction(0, "return-void") } } diff --git a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/sync/detection/piracy/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/sync/detection/piracy/Fingerprints.kt index 801a5ecaf..df2d43249 100644 --- a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/sync/detection/piracy/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/sync/detection/piracy/Fingerprints.kt @@ -1,26 +1,24 @@ package app.revanced.patches.reddit.customclients.sync.detection.piracy -import app.revanced.patcher.extensions.instructions -import app.revanced.patcher.fingerprint -import app.revanced.util.getReference +import app.revanced.patcher.BytecodePatchContextMethodMatching.gettingFirstMutableMethodDeclaratively +import app.revanced.patcher.accessFlags +import app.revanced.patcher.instructions +import app.revanced.patcher.invoke +import app.revanced.patcher.patch.BytecodePatchContext +import app.revanced.patcher.returnType import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.Opcode -import com.android.tools.smali.dexlib2.iface.reference.Reference -internal val piracyDetectionFingerprint = fingerprint { +internal val BytecodePatchContext.piracyDetectionMethod by gettingFirstMutableMethodDeclaratively( + "Lcom/github/javiersantos/piracychecker/PiracyChecker;" +) { accessFlags(AccessFlags.PRIVATE, AccessFlags.FINAL) - returns("V") - opcodes( - Opcode.NEW_INSTANCE, - Opcode.INVOKE_DIRECT, - Opcode.NEW_INSTANCE, - Opcode.INVOKE_DIRECT, - Opcode.INVOKE_VIRTUAL, + returnType("V") + instructions( + Opcode.NEW_INSTANCE(), + Opcode.INVOKE_DIRECT(), + Opcode.NEW_INSTANCE(), + Opcode.INVOKE_DIRECT(), + Opcode.INVOKE_VIRTUAL(), ) - custom { method, _ -> - method.implementation ?: return@custom false - method.instructions.any { - it.getReference()?.toString() == "Lcom/github/javiersantos/piracychecker/PiracyChecker;" - } - } }