From e2bc428b29e8a9c8b35eee5c9beb67ac3da36a0e Mon Sep 17 00:00:00 2001 From: Pun Butrach Date: Mon, 12 Jan 2026 15:44:53 +0700 Subject: [PATCH] refactor(boostforreddit): SpoofClientPatch --- .../boostforreddit/api/Fingerprints.kt | 22 +++++++++---------- .../boostforreddit/api/SpoofClientPatch.kt | 20 ++++++++++++----- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/api/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/api/Fingerprints.kt index cc06fd396..0067b7c3c 100644 --- a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/api/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/api/Fingerprints.kt @@ -1,15 +1,15 @@ package app.revanced.patches.reddit.customclients.boostforreddit.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 buildUserAgentFingerprint = fingerprint { - strings("%s:%s:%s (by /u/%s)") -} - -internal val getClientIdFingerprint = fingerprint { - custom { method, classDef -> - if (!classDef.endsWith("Credentials;")) return@custom false - - method.name == "getClientId" - } +internal val BytecodePatchContext.buildUserAgentMethod by gettingFirstMutableMethodDeclaratively( + "%s:%s:%s (by /u/%s)" +) + +internal val BytecodePatchContext.getClientIdMethod by gettingFirstMutableMethodDeclaratively { + name("getClientId") + definingClass { endsWith("Credentials;") } } diff --git a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/api/SpoofClientPatch.kt b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/api/SpoofClientPatch.kt index bc2c3b6c6..a977099da 100644 --- a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/api/SpoofClientPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/api/SpoofClientPatch.kt @@ -3,9 +3,14 @@ package app.revanced.patches.reddit.customclients.boostforreddit.api import app.revanced.patcher.extensions.getInstruction import app.revanced.patcher.extensions.replaceInstruction import app.revanced.patches.reddit.customclients.spoofClientPatch +import app.revanced.util.getReference +import app.revanced.util.indexOfFirstInstructionOrThrow import app.revanced.util.returnEarly +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 +@Suppress("unused") val spoofClientPatch = spoofClientPatch(redirectUri = "http://rubenmayayo.com") { clientIdOption -> compatibleWith("com.rubenmayayo.reddit") @@ -14,7 +19,7 @@ val spoofClientPatch = spoofClientPatch(redirectUri = "http://rubenmayayo.com") apply { // region Patch client id. - getClientIdFingerprint.method.returnEarly(clientId!!) + getClientIdMethod.returnEarly(clientId!!) // endregion @@ -23,11 +28,14 @@ val spoofClientPatch = spoofClientPatch(redirectUri = "http://rubenmayayo.com") // Use a random user agent. val randomName = (0..100000).random() val userAgent = "$randomName:app.revanced.$randomName:v1.0.0 (by /u/revanced)" - buildUserAgentFingerprint.let { - val userAgentTemplateIndex = it.stringMatches.first().index - val register = it.method.getInstruction(userAgentTemplateIndex).registerA - - it.method.replaceInstruction(userAgentTemplateIndex, "const-string v$register, \"$userAgent\"") + + buildUserAgentMethod.apply { + val userAgentTemplateIndex = indexOfFirstInstructionOrThrow { + opcode == Opcode.CONST_STRING && getReference()?.string == "%s:%s:%s (by /u/%s)" + } + val register = getInstruction(userAgentTemplateIndex).registerA + + replaceInstruction(userAgentTemplateIndex, "const-string v$register, \"$userAgent\"") } // endregion