From 8b833268bb64711ebd3f41ad15975a2680a24b13 Mon Sep 17 00:00:00 2001 From: Pun Butrach Date: Mon, 12 Jan 2026 15:40:35 +0700 Subject: [PATCH] refactor(baconreader): SpoofClientPatch --- .../baconreader/api/Fingerprints.kt | 27 +++++++++--------- .../baconreader/api/SpoofClientPatch.kt | 28 +++++++++++-------- 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/baconreader/api/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/baconreader/api/Fingerprints.kt index bb87c2114..0626439cf 100644 --- a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/baconreader/api/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/baconreader/api/Fingerprints.kt @@ -1,19 +1,20 @@ package app.revanced.patches.reddit.customclients.baconreader.api -import app.revanced.patcher.fingerprint +import app.revanced.patcher.BytecodePatchContextMethodMatching.gettingFirstMutableMethodDeclaratively +import app.revanced.patcher.definingClass +import app.revanced.patcher.name +import app.revanced.patcher.patch.BytecodePatchContext -internal val getAuthorizationUrlFingerprint = fingerprint { - strings("client_id=zACVn0dSFGdWqQ") -} -internal val getClientIdFingerprint = fingerprint { - strings("client_id=zACVn0dSFGdWqQ") - custom { method, classDef -> - if (!classDef.endsWith("RedditOAuth;")) return@custom false +internal val BytecodePatchContext.getAuthorizationUrlMethod by gettingFirstMutableMethodDeclaratively( + "client_id=zACVn0dSFGdWqQ" +) - method.name == "getAuthorizeUrl" - } +internal val BytecodePatchContext.getClientIdMethod by gettingFirstMutableMethodDeclaratively("client_id=zACVn0dSFGdWqQ") { + name("getAuthorizeUrl") + definingClass { endsWith("RedditOAuth;") } } -internal val requestTokenFingerprint = fingerprint { - strings("zACVn0dSFGdWqQ", "kDm2tYpu9DqyWFFyPlNcXGEni4k") // App ID and secret. -} +internal val BytecodePatchContext.requestTokenMethod by gettingFirstMutableMethodDeclaratively( + "zACVn0dSFGdWqQ", + "kDm2tYpu9DqyWFFyPlNcXGEni4k" +) diff --git a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/baconreader/api/SpoofClientPatch.kt b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/baconreader/api/SpoofClientPatch.kt index 588af2338..e0485dacd 100644 --- a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/baconreader/api/SpoofClientPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/baconreader/api/SpoofClientPatch.kt @@ -1,11 +1,15 @@ package app.revanced.patches.reddit.customclients.baconreader.api -import app.revanced.patcher.Fingerprint import app.revanced.patcher.extensions.getInstruction import app.revanced.patcher.extensions.replaceInstruction import app.revanced.patches.reddit.customclients.spoofClientPatch import app.revanced.patches.shared.misc.string.replaceStringPatch +import app.revanced.util.getReference +import app.revanced.util.indexOfFirstInstructionOrThrow +import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction +import com.android.tools.smali.dexlib2.iface.reference.StringReference +import com.android.tools.smali.dexlib2.mutable.MutableMethod val spoofClientPatch = spoofClientPatch(redirectUri = "http://baconreader.com/auth") { clientIdOption -> dependsOn( @@ -22,22 +26,22 @@ val spoofClientPatch = spoofClientPatch(redirectUri = "http://baconreader.com/au val clientId by clientIdOption apply { - fun Fingerprint.patch(replacementString: String) { - val clientIdIndex = stringMatches.first().index - - method.apply { - val clientIdRegister = getInstruction(clientIdIndex).registerA - replaceInstruction( - clientIdIndex, - "const-string v$clientIdRegister, \"$replacementString\"", - ) + fun MutableMethod.patch(targetString: String, replacementString: String) { + val clientIdIndex = indexOfFirstInstructionOrThrow { + opcode == Opcode.CONST_STRING && getReference()?.string == targetString } + + val clientIdRegister = getInstruction(clientIdIndex).registerA + replaceInstruction( + clientIdIndex, + "const-string v$clientIdRegister, \"$replacementString\"", + ) } // Patch client id in authorization url. - getAuthorizationUrlFingerprint.patch("client_id=$clientId") + getAuthorizationUrlMethod.patch("client_id=zACVn0dSFGdWqQ", "client_id=$clientId") // Patch client id for access token request. - requestTokenFingerprint.patch(clientId!!) + requestTokenMethod.patch("zACVn0dSFGdWqQ", clientId!!) } }