diff --git a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/redditisfun/api/SpoofClientPatch.kt b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/redditisfun/api/SpoofClientPatch.kt index 325cbac6c..99c2a697e 100644 --- a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/redditisfun/api/SpoofClientPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/redditisfun/api/SpoofClientPatch.kt @@ -61,7 +61,7 @@ val spoofClientPatch = spoofClientPatch(redirectUri = "redditisfun://auth") { cl // region Patch miscellaneous. // Reddit messed up and does not append a redirect uri to the authorization url to old.reddit.com/login. - // Replace old.reddit.com with ssl.reddit.com to fix this. + // Replace old.reddit.com with www.reddit.com to fix this. buildAuthorizationStringFingerprint.method.apply { val index = indexOfFirstInstructionOrThrow { getReference()?.contains("old.reddit.com") == true @@ -70,7 +70,7 @@ val spoofClientPatch = spoofClientPatch(redirectUri = "redditisfun://auth") { cl val targetRegister = getInstruction(index).registerA replaceInstruction( index, - "const-string v$targetRegister, \"https://ssl.reddit.com/api/v1/authorize.compact\"", + "const-string v$targetRegister, \"https://www.reddit.com/api/v1/authorize.compact\"", ) } diff --git a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/sync/syncforreddit/api/SpoofClientPatch.kt b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/sync/syncforreddit/api/SpoofClientPatch.kt index 64d6ca111..0246ce711 100644 --- a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/sync/syncforreddit/api/SpoofClientPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/sync/syncforreddit/api/SpoofClientPatch.kt @@ -4,6 +4,7 @@ import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction import app.revanced.patches.reddit.customclients.spoofClientPatch import app.revanced.patches.reddit.customclients.sync.detection.piracy.disablePiracyDetectionPatch +import app.revanced.patches.shared.misc.string.replaceStringPatch import app.revanced.util.returnEarly import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction @@ -13,7 +14,12 @@ import java.util.Base64 val spoofClientPatch = spoofClientPatch( redirectUri = "http://redditsync/auth", ) { clientIdOption -> - dependsOn(disablePiracyDetectionPatch) + dependsOn( + disablePiracyDetectionPatch, + // Redirects from SSL to WWW domain are bugged causing auth problems. + // Manually rewrite the URLs to fix this. + replaceStringPatch("ssl.reddit.com", "www.reddit.com") + ) compatibleWith( "com.laurencedawson.reddit_sync", diff --git a/patches/src/main/kotlin/app/revanced/patches/shared/misc/string/ReplaceStringPatch.kt b/patches/src/main/kotlin/app/revanced/patches/shared/misc/string/ReplaceStringPatch.kt new file mode 100644 index 000000000..2e83a6d93 --- /dev/null +++ b/patches/src/main/kotlin/app/revanced/patches/shared/misc/string/ReplaceStringPatch.kt @@ -0,0 +1,39 @@ +package app.revanced.patches.shared.misc.string + +import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction +import app.revanced.patcher.patch.bytecodePatch +import app.revanced.patches.all.misc.transformation.transformInstructionsPatch +import app.revanced.util.getReference +import com.android.tools.smali.dexlib2.ReferenceType +import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction +import com.android.tools.smali.dexlib2.iface.reference.StringReference +import kotlin.text.contains + +fun replaceStringPatch( + from: String, + to: String +) = bytecodePatch( + description = "Replaces occurrences of '$from' with '$to' in string references.", +) { + dependsOn( + transformInstructionsPatch( + filterMap = filterMap@{ _, _, instruction, instructionIndex -> + if (instruction.opcode.referenceType != ReferenceType.STRING) return@filterMap null + + val stringReference = instruction.getReference()!!.string + if (from !in stringReference) return@filterMap null + + Triple(instructionIndex, instruction as OneRegisterInstruction, stringReference) + }, + transform = transform@{ mutableMethod, entry -> + val (instructionIndex, instruction, stringReference) = entry + + val newString = stringReference.replace(from, to) + mutableMethod.replaceInstruction( + instructionIndex, + "${instruction.opcode.name} v${instruction.registerA}, \"$newString\"", + ) + }, + ) + ) +}