refactor(boostforreddit): SpoofClientPatch

This commit is contained in:
Pun Butrach 2026-01-12 15:44:53 +07:00
parent 968dfde7a8
commit e2bc428b29
2 changed files with 25 additions and 17 deletions

View file

@ -1,15 +1,15 @@
package app.revanced.patches.reddit.customclients.boostforreddit.api 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 { internal val BytecodePatchContext.buildUserAgentMethod by gettingFirstMutableMethodDeclaratively(
strings("%s:%s:%s (by /u/%s)") "%s:%s:%s (by /u/%s)"
} )
internal val getClientIdFingerprint = fingerprint { internal val BytecodePatchContext.getClientIdMethod by gettingFirstMutableMethodDeclaratively {
custom { method, classDef -> name("getClientId")
if (!classDef.endsWith("Credentials;")) return@custom false definingClass { endsWith("Credentials;") }
method.name == "getClientId"
}
} }

View file

@ -3,9 +3,14 @@ package app.revanced.patches.reddit.customclients.boostforreddit.api
import app.revanced.patcher.extensions.getInstruction import app.revanced.patcher.extensions.getInstruction
import app.revanced.patcher.extensions.replaceInstruction import app.revanced.patcher.extensions.replaceInstruction
import app.revanced.patches.reddit.customclients.spoofClientPatch import app.revanced.patches.reddit.customclients.spoofClientPatch
import app.revanced.util.getReference
import app.revanced.util.indexOfFirstInstructionOrThrow
import app.revanced.util.returnEarly 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.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.reference.StringReference
@Suppress("unused")
val spoofClientPatch = spoofClientPatch(redirectUri = "http://rubenmayayo.com") { clientIdOption -> val spoofClientPatch = spoofClientPatch(redirectUri = "http://rubenmayayo.com") { clientIdOption ->
compatibleWith("com.rubenmayayo.reddit") compatibleWith("com.rubenmayayo.reddit")
@ -14,7 +19,7 @@ val spoofClientPatch = spoofClientPatch(redirectUri = "http://rubenmayayo.com")
apply { apply {
// region Patch client id. // region Patch client id.
getClientIdFingerprint.method.returnEarly(clientId!!) getClientIdMethod.returnEarly(clientId!!)
// endregion // endregion
@ -23,11 +28,14 @@ val spoofClientPatch = spoofClientPatch(redirectUri = "http://rubenmayayo.com")
// Use a random user agent. // Use a random user agent.
val randomName = (0..100000).random() val randomName = (0..100000).random()
val userAgent = "$randomName:app.revanced.$randomName:v1.0.0 (by /u/revanced)" val userAgent = "$randomName:app.revanced.$randomName:v1.0.0 (by /u/revanced)"
buildUserAgentFingerprint.let {
val userAgentTemplateIndex = it.stringMatches.first().index buildUserAgentMethod.apply {
val register = it.method.getInstruction<OneRegisterInstruction>(userAgentTemplateIndex).registerA val userAgentTemplateIndex = indexOfFirstInstructionOrThrow {
opcode == Opcode.CONST_STRING && getReference<StringReference>()?.string == "%s:%s:%s (by /u/%s)"
it.method.replaceInstruction(userAgentTemplateIndex, "const-string v$register, \"$userAgent\"") }
val register = getInstruction<OneRegisterInstruction>(userAgentTemplateIndex).registerA
replaceInstruction(userAgentTemplateIndex, "const-string v$register, \"$userAgent\"")
} }
// endregion // endregion