fix(Boost for Reddit - Spoof client): Set user-agent for OAuth requests to fix login

This commit is contained in:
oSumAtrIX 2023-10-08 02:56:23 +02:00
parent a48c4a7cc1
commit 2223951fa1
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4
2 changed files with 35 additions and 1 deletions

View File

@ -6,7 +6,9 @@ import app.revanced.patcher.fingerprint.method.impl.MethodFingerprintResult
import app.revanced.patcher.patch.annotation.CompatiblePackage
import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patches.reddit.customclients.AbstractSpoofClientPatch
import app.revanced.patches.reddit.customclients.Constants.OAUTH_USER_AGENT
import app.revanced.patches.reddit.customclients.boostforreddit.api.fingerprints.GetClientIdFingerprint
import app.revanced.patches.reddit.customclients.boostforreddit.api.fingerprints.LoginActivityOnCreateFingerprint
@Patch(
name = "Spoof client",
@ -15,7 +17,9 @@ import app.revanced.patches.reddit.customclients.boostforreddit.api.fingerprints
)
@Suppress("unused")
object SpoofClientPatch : AbstractSpoofClientPatch(
"http://rubenmayayo.com", listOf(GetClientIdFingerprint)
"http://rubenmayayo.com",
clientIdFingerprints = listOf(GetClientIdFingerprint),
userAgentFingerprints = listOf(LoginActivityOnCreateFingerprint)
) {
override fun List<MethodFingerprintResult>.patchClientId(context: BytecodeContext) {
first().mutableMethod.addInstructions(
@ -26,4 +30,20 @@ object SpoofClientPatch : AbstractSpoofClientPatch(
"""
)
}
override fun List<MethodFingerprintResult>.patchUserAgent(context: BytecodeContext) {
first().let { result ->
result.mutableMethod.apply {
val insertIndex = result.scanResult.patternScanResult!!.endIndex
addInstructions(
insertIndex,
"""
const-string v7, "$OAUTH_USER_AGENT"
invoke-virtual {v4, v7}, Landroid/webkit/WebSettings;->setUserAgentString(Ljava/lang/String;)V
"""
)
}
}
}
}

View File

@ -0,0 +1,14 @@
package app.revanced.patches.reddit.customclients.boostforreddit.api.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import com.android.tools.smali.dexlib2.Opcode
object LoginActivityOnCreateFingerprint : MethodFingerprint(
opcodes = listOf(
Opcode.MOVE_RESULT_OBJECT,
Opcode.CONST_4
),
customFingerprint = { method, classDef ->
method.name == "onCreate" && classDef.type.endsWith("LoginActivity;")
}
)