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

This commit is contained in:
oSumAtrIX 2023-10-08 01:45:07 +02:00
parent 49a233d75f
commit a48c4a7cc1
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4
3 changed files with 33 additions and 0 deletions

View File

@ -0,0 +1,6 @@
package app.revanced.patches.reddit.customclients
object Constants {
const val OAUTH_USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) " +
"Chrome/117.0.0.0 Safari/537.36 Edg/117.0.2045.60"
}

View File

@ -10,9 +10,11 @@ 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.syncforreddit.api.fingerprints.GetAuthorizationStringFingerprint
import app.revanced.patches.reddit.customclients.syncforreddit.api.fingerprints.GetBearerTokenFingerprint
import app.revanced.patches.reddit.customclients.syncforreddit.api.fingerprints.ImgurImageAPIFingerprint
import app.revanced.patches.reddit.customclients.syncforreddit.api.fingerprints.LoadBrowserURLFingerprint
import app.revanced.patches.reddit.customclients.syncforreddit.detection.piracy.DisablePiracyDetectionPatch
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
@ -33,6 +35,7 @@ import java.util.*
object SpoofClientPatch : AbstractSpoofClientPatch(
"http://redditsync/auth",
clientIdFingerprints = listOf(GetAuthorizationStringFingerprint),
userAgentFingerprints = listOf(LoadBrowserURLFingerprint),
miscellaneousFingerprints = listOf(ImgurImageAPIFingerprint)
) {
override fun List<MethodFingerprintResult>.patchClientId(context: BytecodeContext) {
@ -79,4 +82,18 @@ object SpoofClientPatch : AbstractSpoofClientPatch(
"const-string v1, \"https://api.imgur.com/3/image\""
)
}
override fun List<MethodFingerprintResult>.patchUserAgent(context: BytecodeContext) {
first().let { result ->
val insertIndex = result.scanResult.patternScanResult!!.startIndex
result.mutableMethod.addInstructions(
insertIndex,
"""
const-string v0, "$OAUTH_USER_AGENT"
invoke-virtual {p1, v0}, Landroid/webkit/WebSettings;->setUserAgentString(Ljava/lang/String;)V
"""
)
}
}
}

View File

@ -0,0 +1,10 @@
package app.revanced.patches.reddit.customclients.syncforreddit.api.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import com.android.tools.smali.dexlib2.Opcode
object LoadBrowserURLFingerprint : MethodFingerprint(
parameters = listOf("Landroid/view/View;", "Landroid/os/Bundle;"),
opcodes = listOf(Opcode.CONST_4),
strings = listOf("CustomInterface")
)