From 7787268bedd84dc08573697d27e6549ed983e3c2 Mon Sep 17 00:00:00 2001 From: Pun Butrach Date: Mon, 12 Jan 2026 15:54:35 +0700 Subject: [PATCH] refactor(boostforreddit): FixRedgifsApiPatch --- .../fix/redgifs/Fingerprints.kt | 34 ++++++++++++------- .../fix/redgifs/FixRedgifsApiPatch.kt | 2 +- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/fix/redgifs/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/fix/redgifs/Fingerprints.kt index 1f3560d73..27e5f81ca 100644 --- a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/fix/redgifs/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/fix/redgifs/Fingerprints.kt @@ -1,20 +1,30 @@ package app.revanced.patches.reddit.customclients.boostforreddit.fix.redgifs -import app.revanced.patcher.fingerprint +import app.revanced.patcher.BytecodePatchContextMethodMatching.gettingFirstMutableMethodDeclaratively +import app.revanced.patcher.accessFlags +import app.revanced.patcher.classDef +import app.revanced.patcher.custom +import app.revanced.patcher.instructions +import app.revanced.patcher.invoke +import app.revanced.patcher.patch.BytecodePatchContext import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.Opcode +import com.android.tools.smali.dexlib2.iface.Method -internal val createOkHttpClientFingerprint = fingerprint { +internal val BytecodePatchContext.createOkHttpClientMethod by gettingFirstMutableMethodDeclaratively { accessFlags(AccessFlags.PRIVATE) - opcodes( - Opcode.NEW_INSTANCE, - Opcode.INVOKE_DIRECT, - Opcode.NEW_INSTANCE, - Opcode.INVOKE_DIRECT, - Opcode.NEW_INSTANCE, - Opcode.INVOKE_DIRECT, - Opcode.INVOKE_VIRTUAL, - Opcode.MOVE_RESULT_OBJECT + instructions( + Opcode.NEW_INSTANCE(), + Opcode.INVOKE_DIRECT(), + Opcode.NEW_INSTANCE(), + Opcode.INVOKE_DIRECT(), + Opcode.NEW_INSTANCE(), + Opcode.INVOKE_DIRECT(), + Opcode.INVOKE_VIRTUAL(), + Opcode.MOVE_RESULT_OBJECT() ) - custom { _, classDef -> classDef.sourceFile == "RedGifsAPIv2.java" } + + // Helper to capture the BytecodePatchContext for classDef access + fun Method.isTargetSourceFile() = classDef.sourceFile == "RedGifsAPIv2.java" + custom { isTargetSourceFile() } } diff --git a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/fix/redgifs/FixRedgifsApiPatch.kt b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/fix/redgifs/FixRedgifsApiPatch.kt index be54ca33c..4db18ee72 100644 --- a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/fix/redgifs/FixRedgifsApiPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/fix/redgifs/FixRedgifsApiPatch.kt @@ -19,7 +19,7 @@ val fixRedgifsApi = fixRedgifsApiPatch( apply { // region Patch Redgifs OkHttp3 client. - createOkHttpClientFingerprint.method.apply { + createOkHttpClientMethod.apply { val index = indexOfFirstInstructionOrThrow { val reference = getReference() reference?.name == "build" && reference.definingClass == "Lokhttp3/OkHttpClient\$Builder;"