refactor(boostforreddit): FixRedgifsApiPatch

This commit is contained in:
Pun Butrach
2026-01-12 15:54:35 +07:00
parent 24cb9d987b
commit 7787268bed
2 changed files with 23 additions and 13 deletions

View File

@@ -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() }
}

View File

@@ -19,7 +19,7 @@ val fixRedgifsApi = fixRedgifsApiPatch(
apply {
// region Patch Redgifs OkHttp3 client.
createOkHttpClientFingerprint.method.apply {
createOkHttpClientMethod.apply {
val index = indexOfFirstInstructionOrThrow {
val reference = getReference<MethodReference>()
reference?.name == "build" && reference.definingClass == "Lokhttp3/OkHttpClient\$Builder;"