Skip to content

Commit 6fea672

Browse files
committed
fix(Sync for Reddit - Spoof client): Use www instead of ssl API to fix auth related issues
1 parent 501f19a commit 6fea672

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

patches/src/main/kotlin/app/revanced/patches/reddit/customclients/redditisfun/api/SpoofClientPatch.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ val spoofClientPatch = spoofClientPatch(redirectUri = "redditisfun://auth") { cl
6161
// region Patch miscellaneous.
6262

6363
// Reddit messed up and does not append a redirect uri to the authorization url to old.reddit.com/login.
64-
// Replace old.reddit.com with ssl.reddit.com to fix this.
64+
// Replace old.reddit.com with www.reddit.com to fix this.
6565
buildAuthorizationStringFingerprint.method.apply {
6666
val index = indexOfFirstInstructionOrThrow {
6767
getReference<StringReference>()?.contains("old.reddit.com") == true
@@ -70,7 +70,7 @@ val spoofClientPatch = spoofClientPatch(redirectUri = "redditisfun://auth") { cl
7070
val targetRegister = getInstruction<OneRegisterInstruction>(index).registerA
7171
replaceInstruction(
7272
index,
73-
"const-string v$targetRegister, \"https://ssl.reddit.com/api/v1/authorize.compact\"",
73+
"const-string v$targetRegister, \"https://www.reddit.com/api/v1/authorize.compact\"",
7474
)
7575
}
7676

patches/src/main/kotlin/app/revanced/patches/reddit/customclients/sync/syncforreddit/api/SpoofClientPatch.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
44
import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction
55
import app.revanced.patches.reddit.customclients.spoofClientPatch
66
import app.revanced.patches.reddit.customclients.sync.detection.piracy.disablePiracyDetectionPatch
7+
import app.revanced.patches.shared.misc.string.replaceStringPatch
78
import app.revanced.util.returnEarly
89
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
910
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
@@ -13,7 +14,12 @@ import java.util.Base64
1314
val spoofClientPatch = spoofClientPatch(
1415
redirectUri = "http://redditsync/auth",
1516
) { clientIdOption ->
16-
dependsOn(disablePiracyDetectionPatch)
17+
dependsOn(
18+
disablePiracyDetectionPatch,
19+
// Redirects from SSL to WWW domain are bugged causing auth problems.
20+
// Manually rewrite the URLs to fix this.
21+
replaceStringPatch("ssl.reddit.com", "www.reddit.com")
22+
)
1723

1824
compatibleWith(
1925
"com.laurencedawson.reddit_sync",
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package app.revanced.patches.shared.misc.string
2+
3+
import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction
4+
import app.revanced.patcher.patch.bytecodePatch
5+
import app.revanced.patches.all.misc.transformation.transformInstructionsPatch
6+
import app.revanced.util.getReference
7+
import com.android.tools.smali.dexlib2.ReferenceType
8+
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
9+
import com.android.tools.smali.dexlib2.iface.reference.StringReference
10+
import kotlin.text.contains
11+
12+
fun replaceStringPatch(
13+
from: String,
14+
to: String
15+
) = bytecodePatch(
16+
description = "Replaces occurrences of '$from' with '$to' in string references.",
17+
) {
18+
dependsOn(
19+
transformInstructionsPatch(
20+
filterMap = filterMap@{ _, _, instruction, instructionIndex ->
21+
if (instruction.opcode.referenceType != ReferenceType.STRING) return@filterMap null
22+
23+
val stringReference = instruction.getReference<StringReference>()!!.string
24+
if (from !in stringReference) return@filterMap null
25+
26+
Triple(instructionIndex, instruction as OneRegisterInstruction, stringReference)
27+
},
28+
transform = transform@{ mutableMethod, entry ->
29+
val (instructionIndex, instruction, stringReference) = entry
30+
31+
val newString = stringReference.replace(from, to)
32+
mutableMethod.replaceInstruction(
33+
instructionIndex,
34+
"${instruction.opcode.name} v${instruction.registerA}, \"$newString\"",
35+
)
36+
},
37+
)
38+
)
39+
}

0 commit comments

Comments
 (0)