From b9aaf610ad9f1f45a72265a3782d2cf996020139 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Thu, 3 Aug 2023 00:58:11 +0200 Subject: [PATCH] feat(Reddit is Fun - Spoof client): Spoof the user agent --- ...IdPatch.kt => AbstractSpoofClientPatch.kt} | 44 ++++++++++-- ...Annotation.kt => SpoofClientAnnotation.kt} | 4 +- ...thClientIdPatch.kt => SpoofClientPatch.kt} | 14 ++-- ...thClientIdPatch.kt => SpoofClientPatch.kt} | 22 +++--- ...thClientIdPatch.kt => SpoofClientPatch.kt} | 14 ++-- ...thClientIdPatch.kt => SpoofClientPatch.kt} | 14 ++-- .../fingerprints/GetUserAgentFingerprint.kt | 20 ++++++ ...thClientIdPatch.kt => SpoofClientPatch.kt} | 37 +++++++--- ...thClientIdPatch.kt => SpoofClientPatch.kt} | 14 ++-- ...thClientIdPatch.kt => SpoofClientPatch.kt} | 72 +++++++++---------- ...thClientIdPatch.kt => SpoofClientPatch.kt} | 14 ++-- 11 files changed, 167 insertions(+), 102 deletions(-) rename src/main/kotlin/app/revanced/patches/reddit/customclients/{AbstractChangeOAuthClientIdPatch.kt => AbstractSpoofClientPatch.kt} (54%) rename src/main/kotlin/app/revanced/patches/reddit/customclients/{ChangeOAuthClientIdPatchAnnotation.kt => SpoofClientAnnotation.kt} (69%) rename src/main/kotlin/app/revanced/patches/reddit/customclients/baconreader/api/patch/{ChangeOAuthClientIdPatch.kt => SpoofClientPatch.kt} (79%) rename src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/api/patch/{ChangeOAuthClientIdPatch.kt => SpoofClientPatch.kt} (61%) rename src/main/kotlin/app/revanced/patches/reddit/customclients/infinityforreddit/api/patch/{ChangeOAuthClientIdPatch.kt => SpoofClientPatch.kt} (76%) rename src/main/kotlin/app/revanced/patches/reddit/customclients/joeyforreddit/api/patch/{ChangeOAuthClientIdPatch.kt => SpoofClientPatch.kt} (74%) create mode 100644 src/main/kotlin/app/revanced/patches/reddit/customclients/redditisfun/api/fingerprints/GetUserAgentFingerprint.kt rename src/main/kotlin/app/revanced/patches/reddit/customclients/redditisfun/api/patch/{ChangeOAuthClientIdPatch.kt => SpoofClientPatch.kt} (66%) rename src/main/kotlin/app/revanced/patches/reddit/customclients/relayforreddit/api/patch/{ChangeOAuthClientIdPatch.kt => SpoofClientPatch.kt} (79%) rename src/main/kotlin/app/revanced/patches/reddit/customclients/slide/api/patch/{ChangeOAuthClientIdPatch.kt => SpoofClientPatch.kt} (66%) rename src/main/kotlin/app/revanced/patches/reddit/customclients/syncforreddit/api/patch/{ChangeOAuthClientIdPatch.kt => SpoofClientPatch.kt} (86%) diff --git a/src/main/kotlin/app/revanced/patches/reddit/customclients/AbstractChangeOAuthClientIdPatch.kt b/src/main/kotlin/app/revanced/patches/reddit/customclients/AbstractSpoofClientPatch.kt similarity index 54% rename from src/main/kotlin/app/revanced/patches/reddit/customclients/AbstractChangeOAuthClientIdPatch.kt rename to src/main/kotlin/app/revanced/patches/reddit/customclients/AbstractSpoofClientPatch.kt index 75607e794..972b6dd5a 100644 --- a/src/main/kotlin/app/revanced/patches/reddit/customclients/AbstractChangeOAuthClientIdPatch.kt +++ b/src/main/kotlin/app/revanced/patches/reddit/customclients/AbstractSpoofClientPatch.kt @@ -8,11 +8,15 @@ import app.revanced.patcher.fingerprint.method.impl.MethodFingerprintResult import app.revanced.patcher.patch.* import java.io.File -abstract class AbstractChangeOAuthClientIdPatch( +abstract class AbstractSpoofClientPatch( private val redirectUri: String, - private val options: ChangeOAuthClientIdOptionsContainer, - private val fingerprints: List -) : BytecodePatch(fingerprints) { + private val options: SpoofClientOptionsContainer, + private val clientIdFingerprints: List, + private val userAgentFingerprints: List? = null, +) : BytecodePatch(buildList { + addAll(clientIdFingerprints) + userAgentFingerprints?.let(::addAll) +}) { override fun execute(context: BytecodeContext): PatchResult { if (options.clientId == null) { // Ensure device runs Android. @@ -38,13 +42,39 @@ abstract class AbstractChangeOAuthClientIdPatch( }.let { options.clientId = it.readText().trim() } } - return fingerprints.map { it.result ?: throw it.toErrorResult() }.patch(context) + fun List?.executePatch( + patch: List.(BytecodeContext) -> PatchResult + ) { + when (val result = this?.map { it.result ?: throw it.toErrorResult() }?.patch(context)) { + is PatchResultError -> throw result + } + } + + clientIdFingerprints.executePatch { patchClientId(context) } + userAgentFingerprints.executePatch { patchUserAgent(context) } + + return PatchResultSuccess() } - abstract fun List.patch(context: BytecodeContext): PatchResult + /** + * Patch the client ID. The fingerprints are guaranteed to be in the same order as in [clientIdFingerprints]. + * + * @param context The current [BytecodeContext]. + * + */ + abstract fun List.patchClientId(context: BytecodeContext): PatchResult + + /** + * Patch the user agent. The fingerprints are guaranteed to be in the same order as in [userAgentFingerprints]. + * + * @param context The current [BytecodeContext]. + */ + // Not every client needs to patch the user agent. + open fun List.patchUserAgent(context: BytecodeContext): PatchResult = + PatchResultSuccess() companion object Options { - open class ChangeOAuthClientIdOptionsContainer : OptionsContainer() { + open class SpoofClientOptionsContainer : OptionsContainer() { var clientId by option( PatchOption.StringOption( "client-id", diff --git a/src/main/kotlin/app/revanced/patches/reddit/customclients/ChangeOAuthClientIdPatchAnnotation.kt b/src/main/kotlin/app/revanced/patches/reddit/customclients/SpoofClientAnnotation.kt similarity index 69% rename from src/main/kotlin/app/revanced/patches/reddit/customclients/ChangeOAuthClientIdPatchAnnotation.kt rename to src/main/kotlin/app/revanced/patches/reddit/customclients/SpoofClientAnnotation.kt index ea5fe5935..9aede0fe1 100644 --- a/src/main/kotlin/app/revanced/patches/reddit/customclients/ChangeOAuthClientIdPatchAnnotation.kt +++ b/src/main/kotlin/app/revanced/patches/reddit/customclients/SpoofClientAnnotation.kt @@ -5,5 +5,5 @@ import app.revanced.patcher.patch.annotations.Patch @Target(AnnotationTarget.CLASS) @Patch -@Name("Change OAuth client id") -annotation class ChangeOAuthClientIdPatchAnnotation \ No newline at end of file +@Name("Spoof client") +annotation class SpoofClientAnnotation \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/reddit/customclients/baconreader/api/patch/ChangeOAuthClientIdPatch.kt b/src/main/kotlin/app/revanced/patches/reddit/customclients/baconreader/api/patch/SpoofClientPatch.kt similarity index 79% rename from src/main/kotlin/app/revanced/patches/reddit/customclients/baconreader/api/patch/ChangeOAuthClientIdPatch.kt rename to src/main/kotlin/app/revanced/patches/reddit/customclients/baconreader/api/patch/SpoofClientPatch.kt index cad02a6ab..39b197c49 100644 --- a/src/main/kotlin/app/revanced/patches/reddit/customclients/baconreader/api/patch/ChangeOAuthClientIdPatch.kt +++ b/src/main/kotlin/app/revanced/patches/reddit/customclients/baconreader/api/patch/SpoofClientPatch.kt @@ -9,15 +9,15 @@ import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction import app.revanced.patcher.fingerprint.method.impl.MethodFingerprintResult import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResultSuccess -import app.revanced.patches.reddit.customclients.AbstractChangeOAuthClientIdPatch -import app.revanced.patches.reddit.customclients.ChangeOAuthClientIdPatchAnnotation +import app.revanced.patches.reddit.customclients.AbstractSpoofClientPatch +import app.revanced.patches.reddit.customclients.SpoofClientAnnotation import app.revanced.patches.reddit.customclients.baconreader.api.fingerprints.GetAuthorizationUrlFingerprint import app.revanced.patches.reddit.customclients.baconreader.api.fingerprints.RequestTokenFingerprint import org.jf.dexlib2.iface.instruction.OneRegisterInstruction -@ChangeOAuthClientIdPatchAnnotation -@Description("Changes the OAuth client ID. " + +@SpoofClientAnnotation +@Description("Spoofs the client in order to allow logging in. " + "The OAuth application type has to be \"Installed app\" " + "and the redirect URI has to be set to \"http://baconreader.com/auth\".") @Compatibility( @@ -26,11 +26,11 @@ import org.jf.dexlib2.iface.instruction.OneRegisterInstruction Package("com.onelouder.baconreader.premium") ] ) -class ChangeOAuthClientIdPatch : AbstractChangeOAuthClientIdPatch( +class SpoofClientPatch : AbstractSpoofClientPatch( "http://baconreader.com/auth", Options, listOf(GetAuthorizationUrlFingerprint, RequestTokenFingerprint) ) { - override fun List.patch(context: BytecodeContext): PatchResult { + override fun List.patchClientId(context: BytecodeContext): PatchResult { fun MethodFingerprintResult.patch(replacementString: String) { val clientIdIndex = scanResult.stringsScanResult!!.matches.first().index @@ -52,5 +52,5 @@ class ChangeOAuthClientIdPatch : AbstractChangeOAuthClientIdPatch( return PatchResultSuccess() } - companion object Options : AbstractChangeOAuthClientIdPatch.Options.ChangeOAuthClientIdOptionsContainer() + companion object Options : AbstractSpoofClientPatch.Options.SpoofClientOptionsContainer() } diff --git a/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/api/patch/ChangeOAuthClientIdPatch.kt b/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/api/patch/SpoofClientPatch.kt similarity index 61% rename from src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/api/patch/ChangeOAuthClientIdPatch.kt rename to src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/api/patch/SpoofClientPatch.kt index 4f9a5e9b8..1f721e55f 100644 --- a/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/api/patch/ChangeOAuthClientIdPatch.kt +++ b/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/api/patch/SpoofClientPatch.kt @@ -8,29 +8,29 @@ import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patcher.fingerprint.method.impl.MethodFingerprintResult import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResultSuccess -import app.revanced.patches.reddit.customclients.AbstractChangeOAuthClientIdPatch -import app.revanced.patches.reddit.customclients.ChangeOAuthClientIdPatchAnnotation +import app.revanced.patches.reddit.customclients.AbstractSpoofClientPatch +import app.revanced.patches.reddit.customclients.SpoofClientAnnotation import app.revanced.patches.reddit.customclients.boostforreddit.api.fingerprints.GetClientIdFingerprint -@ChangeOAuthClientIdPatchAnnotation -@Description("Changes the OAuth client ID. " + +@SpoofClientAnnotation +@Description("Spoofs the client in order to allow logging in. " + "The OAuth application type has to be \"Installed app\" " + "and the redirect URI has to be set to \"http://rubenmayayo.com\".") @Compatibility([Package("com.rubenmayayo.reddit")]) -class ChangeOAuthClientIdPatch : AbstractChangeOAuthClientIdPatch( +class SpoofClientPatch : AbstractSpoofClientPatch( "http://rubenmayayo.com", Options, listOf(GetClientIdFingerprint) ) { - override fun List.patch(context: BytecodeContext): PatchResult { + override fun List.patchClientId(context: BytecodeContext): PatchResult { first().mutableMethod.addInstructions( 0, - """ - const-string v0, "$clientId" - return-object v0 - """ + """ + const-string v0, "$clientId" + return-object v0 + """ ) return PatchResultSuccess() } - companion object Options : AbstractChangeOAuthClientIdPatch.Options.ChangeOAuthClientIdOptionsContainer() + companion object Options : AbstractSpoofClientPatch.Options.SpoofClientOptionsContainer() } diff --git a/src/main/kotlin/app/revanced/patches/reddit/customclients/infinityforreddit/api/patch/ChangeOAuthClientIdPatch.kt b/src/main/kotlin/app/revanced/patches/reddit/customclients/infinityforreddit/api/patch/SpoofClientPatch.kt similarity index 76% rename from src/main/kotlin/app/revanced/patches/reddit/customclients/infinityforreddit/api/patch/ChangeOAuthClientIdPatch.kt rename to src/main/kotlin/app/revanced/patches/reddit/customclients/infinityforreddit/api/patch/SpoofClientPatch.kt index a2fa1ad42..88c346981 100644 --- a/src/main/kotlin/app/revanced/patches/reddit/customclients/infinityforreddit/api/patch/ChangeOAuthClientIdPatch.kt +++ b/src/main/kotlin/app/revanced/patches/reddit/customclients/infinityforreddit/api/patch/SpoofClientPatch.kt @@ -9,23 +9,23 @@ import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction import app.revanced.patcher.fingerprint.method.impl.MethodFingerprintResult import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResultSuccess -import app.revanced.patches.reddit.customclients.AbstractChangeOAuthClientIdPatch -import app.revanced.patches.reddit.customclients.ChangeOAuthClientIdPatchAnnotation +import app.revanced.patches.reddit.customclients.AbstractSpoofClientPatch +import app.revanced.patches.reddit.customclients.SpoofClientAnnotation import app.revanced.patches.reddit.customclients.infinityforreddit.api.fingerprints.GetHttpBasicAuthHeaderFingerprint import app.revanced.patches.reddit.customclients.infinityforreddit.api.fingerprints.LoginActivityOnCreateFingerprint import org.jf.dexlib2.iface.instruction.OneRegisterInstruction -@ChangeOAuthClientIdPatchAnnotation -@Description("Changes the OAuth client ID. " + +@SpoofClientAnnotation +@Description("Spoofs the client in order to allow logging in. " + "The OAuth application type has to be \"Installed app\" " + "and the redirect URI has to be set to \"infinity://localhost\".") @Compatibility([Package("ml.docilealligator.infinityforreddit")]) -class ChangeOAuthClientIdPatch : AbstractChangeOAuthClientIdPatch( +class SpoofClientPatch : AbstractSpoofClientPatch( "infinity://localhost", Options, listOf(GetHttpBasicAuthHeaderFingerprint, LoginActivityOnCreateFingerprint) ) { - override fun List.patch(context: BytecodeContext): PatchResult { + override fun List.patchClientId(context: BytecodeContext): PatchResult { forEach { val clientIdIndex = it.scanResult.stringsScanResult!!.matches.first().index it.mutableMethod.apply { @@ -41,5 +41,5 @@ class ChangeOAuthClientIdPatch : AbstractChangeOAuthClientIdPatch( return PatchResultSuccess() } - companion object Options : AbstractChangeOAuthClientIdPatch.Options.ChangeOAuthClientIdOptionsContainer() + companion object Options : AbstractSpoofClientPatch.Options.SpoofClientOptionsContainer() } \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/reddit/customclients/joeyforreddit/api/patch/ChangeOAuthClientIdPatch.kt b/src/main/kotlin/app/revanced/patches/reddit/customclients/joeyforreddit/api/patch/SpoofClientPatch.kt similarity index 74% rename from src/main/kotlin/app/revanced/patches/reddit/customclients/joeyforreddit/api/patch/ChangeOAuthClientIdPatch.kt rename to src/main/kotlin/app/revanced/patches/reddit/customclients/joeyforreddit/api/patch/SpoofClientPatch.kt index fb25a390d..8bd8ce6d0 100644 --- a/src/main/kotlin/app/revanced/patches/reddit/customclients/joeyforreddit/api/patch/ChangeOAuthClientIdPatch.kt +++ b/src/main/kotlin/app/revanced/patches/reddit/customclients/joeyforreddit/api/patch/SpoofClientPatch.kt @@ -9,14 +9,14 @@ import app.revanced.patcher.fingerprint.method.impl.MethodFingerprintResult import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResultSuccess import app.revanced.patcher.patch.annotations.DependsOn -import app.revanced.patches.reddit.customclients.AbstractChangeOAuthClientIdPatch -import app.revanced.patches.reddit.customclients.ChangeOAuthClientIdPatchAnnotation +import app.revanced.patches.reddit.customclients.AbstractSpoofClientPatch +import app.revanced.patches.reddit.customclients.SpoofClientAnnotation import app.revanced.patches.reddit.customclients.joeyforreddit.api.fingerprints.GetClientIdFingerprint import app.revanced.patches.reddit.customclients.joeyforreddit.detection.piracy.patch.DisablePiracyDetectionPatch -@ChangeOAuthClientIdPatchAnnotation +@SpoofClientAnnotation @Description( - "Changes the OAuth client ID. " + + "Spoofs the client in order to allow logging in. " + "The OAuth application type has to be \"Installed app\" " + "and the redirect URI has to be set to \"https://127.0.0.1:65023/authorize_callback\"." ) @@ -28,10 +28,10 @@ import app.revanced.patches.reddit.customclients.joeyforreddit.detection.piracy. ] ) @DependsOn([DisablePiracyDetectionPatch::class]) -class ChangeOAuthClientIdPatch : AbstractChangeOAuthClientIdPatch( +class SpoofClientPatch : AbstractSpoofClientPatch( "https://127.0.0.1:65023/authorize_callback", Options, listOf(GetClientIdFingerprint) ) { - override fun List.patch(context: BytecodeContext): PatchResult { + override fun List.patchClientId(context: BytecodeContext): PatchResult { first().mutableMethod.addInstructions( 0, """ @@ -43,5 +43,5 @@ class ChangeOAuthClientIdPatch : AbstractChangeOAuthClientIdPatch( return PatchResultSuccess() } - companion object Options : AbstractChangeOAuthClientIdPatch.Options.ChangeOAuthClientIdOptionsContainer() + companion object Options : AbstractSpoofClientPatch.Options.SpoofClientOptionsContainer() } \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/reddit/customclients/redditisfun/api/fingerprints/GetUserAgentFingerprint.kt b/src/main/kotlin/app/revanced/patches/reddit/customclients/redditisfun/api/fingerprints/GetUserAgentFingerprint.kt new file mode 100644 index 000000000..24609d686 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/reddit/customclients/redditisfun/api/fingerprints/GetUserAgentFingerprint.kt @@ -0,0 +1,20 @@ +package app.revanced.patches.reddit.customclients.redditisfun.api.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import org.jf.dexlib2.AccessFlags +import org.jf.dexlib2.Opcode + +object GetUserAgentFingerprint : MethodFingerprint( + "Ljava/lang/String;", + AccessFlags.PUBLIC or AccessFlags.STATIC, + emptyList(), + listOf( + Opcode.NEW_ARRAY, + Opcode.CONST_4, + Opcode.INVOKE_STATIC, + Opcode.MOVE_RESULT_OBJECT, + Opcode.APUT_OBJECT, + Opcode.CONST, + ) +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/reddit/customclients/redditisfun/api/patch/ChangeOAuthClientIdPatch.kt b/src/main/kotlin/app/revanced/patches/reddit/customclients/redditisfun/api/patch/SpoofClientPatch.kt similarity index 66% rename from src/main/kotlin/app/revanced/patches/reddit/customclients/redditisfun/api/patch/ChangeOAuthClientIdPatch.kt rename to src/main/kotlin/app/revanced/patches/reddit/customclients/redditisfun/api/patch/SpoofClientPatch.kt index db00bedb7..b5228a2a8 100644 --- a/src/main/kotlin/app/revanced/patches/reddit/customclients/redditisfun/api/patch/ChangeOAuthClientIdPatch.kt +++ b/src/main/kotlin/app/revanced/patches/reddit/customclients/redditisfun/api/patch/SpoofClientPatch.kt @@ -4,32 +4,32 @@ import app.revanced.patcher.annotation.Compatibility import app.revanced.patcher.annotation.Description import app.revanced.patcher.annotation.Package import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction import app.revanced.patcher.fingerprint.method.impl.MethodFingerprintResult import app.revanced.patcher.fingerprint.method.impl.MethodFingerprintResult.MethodFingerprintScanResult.StringsScanResult.StringMatch import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResultSuccess -import app.revanced.patches.reddit.customclients.AbstractChangeOAuthClientIdPatch -import app.revanced.patches.reddit.customclients.ChangeOAuthClientIdPatchAnnotation +import app.revanced.patches.reddit.customclients.AbstractSpoofClientPatch +import app.revanced.patches.reddit.customclients.SpoofClientAnnotation import app.revanced.patches.reddit.customclients.redditisfun.api.fingerprints.BasicAuthorizationFingerprint import app.revanced.patches.reddit.customclients.redditisfun.api.fingerprints.BuildAuthorizationStringFingerprint +import app.revanced.patches.reddit.customclients.redditisfun.api.fingerprints.GetUserAgentFingerprint import org.jf.dexlib2.iface.instruction.OneRegisterInstruction -@ChangeOAuthClientIdPatchAnnotation -@Description("Changes the OAuth client ID. " + +@SpoofClientAnnotation +@Description("Spoofs the client in order to allow logging in. " + "The OAuth application type has to be \"Installed app\" " + "and the redirect URI has to be set to \"redditisfun://auth\".") @Compatibility([Package("com.andrewshu.android.reddit"), Package("com.andrewshu.android.redditdonation")]) -class ChangeOAuthClientIdPatch : AbstractChangeOAuthClientIdPatch( +class SpoofClientPatch : AbstractSpoofClientPatch( "redditisfun://auth", Options, - listOf( - BuildAuthorizationStringFingerprint, - BasicAuthorizationFingerprint, - ) + listOf(BuildAuthorizationStringFingerprint, BasicAuthorizationFingerprint), + listOf(GetUserAgentFingerprint) ) { - override fun List.patch(context: BytecodeContext): PatchResult { + override fun List.patchClientId(context: BytecodeContext): PatchResult { /** * Replaces a one register instruction with a const-string instruction * at the index returned by [getReplacementIndex]. @@ -57,5 +57,20 @@ class ChangeOAuthClientIdPatch : AbstractChangeOAuthClientIdPatch( return PatchResultSuccess() } - companion object Options : AbstractChangeOAuthClientIdPatch.Options.ChangeOAuthClientIdOptionsContainer() + override fun List.patchUserAgent(context: BytecodeContext): PatchResult { + // Use a random number as the user agent string. + val randomUserAgent = (0..100000).random() + + first().mutableMethod.addInstructions( + 0, + """ + const-string v0, "$randomUserAgent" + return-object v0 + """ + ) + + return PatchResultSuccess() + } + + companion object Options : AbstractSpoofClientPatch.Options.SpoofClientOptionsContainer() } \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/reddit/customclients/relayforreddit/api/patch/ChangeOAuthClientIdPatch.kt b/src/main/kotlin/app/revanced/patches/reddit/customclients/relayforreddit/api/patch/SpoofClientPatch.kt similarity index 79% rename from src/main/kotlin/app/revanced/patches/reddit/customclients/relayforreddit/api/patch/ChangeOAuthClientIdPatch.kt rename to src/main/kotlin/app/revanced/patches/reddit/customclients/relayforreddit/api/patch/SpoofClientPatch.kt index 55f6073ac..9c4fdfe54 100644 --- a/src/main/kotlin/app/revanced/patches/reddit/customclients/relayforreddit/api/patch/ChangeOAuthClientIdPatch.kt +++ b/src/main/kotlin/app/revanced/patches/reddit/customclients/relayforreddit/api/patch/SpoofClientPatch.kt @@ -9,20 +9,20 @@ import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction import app.revanced.patcher.fingerprint.method.impl.MethodFingerprintResult import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResultSuccess -import app.revanced.patches.reddit.customclients.AbstractChangeOAuthClientIdPatch -import app.revanced.patches.reddit.customclients.ChangeOAuthClientIdPatchAnnotation +import app.revanced.patches.reddit.customclients.AbstractSpoofClientPatch +import app.revanced.patches.reddit.customclients.SpoofClientAnnotation import app.revanced.patches.reddit.customclients.relayforreddit.api.fingerprints.GetLoggedInBearerTokenFingerprint import app.revanced.patches.reddit.customclients.relayforreddit.api.fingerprints.GetLoggedOutBearerTokenFingerprint import app.revanced.patches.reddit.customclients.relayforreddit.api.fingerprints.GetRefreshTokenFingerprint import app.revanced.patches.reddit.customclients.relayforreddit.api.fingerprints.LoginActivityClientIdFingerprint import org.jf.dexlib2.iface.instruction.OneRegisterInstruction -@ChangeOAuthClientIdPatchAnnotation -@Description("Changes the OAuth client ID. " + +@SpoofClientAnnotation +@Description("Spoofs the client in order to allow logging in. " + "The OAuth application type has to be \"Installed app\" " + "and the redirect URI has to be set to \"dbrady://relay\".") @Compatibility([Package("free.reddit.news"), Package("reddit.news")]) -class ChangeOAuthClientIdPatch : AbstractChangeOAuthClientIdPatch( +class SpoofClientPatch : AbstractSpoofClientPatch( "dbrady://relay", Options, listOf( @@ -32,7 +32,7 @@ class ChangeOAuthClientIdPatch : AbstractChangeOAuthClientIdPatch( GetRefreshTokenFingerprint ) ) { - override fun List.patch(context: BytecodeContext): PatchResult { + override fun List.patchClientId(context: BytecodeContext): PatchResult { forEach { val clientIdIndex = it.scanResult.stringsScanResult!!.matches.first().index it.mutableMethod.apply { @@ -48,5 +48,5 @@ class ChangeOAuthClientIdPatch : AbstractChangeOAuthClientIdPatch( return PatchResultSuccess() } - companion object Options : AbstractChangeOAuthClientIdPatch.Options.ChangeOAuthClientIdOptionsContainer() + companion object Options : AbstractSpoofClientPatch.Options.SpoofClientOptionsContainer() } \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/reddit/customclients/slide/api/patch/ChangeOAuthClientIdPatch.kt b/src/main/kotlin/app/revanced/patches/reddit/customclients/slide/api/patch/SpoofClientPatch.kt similarity index 66% rename from src/main/kotlin/app/revanced/patches/reddit/customclients/slide/api/patch/ChangeOAuthClientIdPatch.kt rename to src/main/kotlin/app/revanced/patches/reddit/customclients/slide/api/patch/SpoofClientPatch.kt index 90a9372fc..b21829169 100644 --- a/src/main/kotlin/app/revanced/patches/reddit/customclients/slide/api/patch/ChangeOAuthClientIdPatch.kt +++ b/src/main/kotlin/app/revanced/patches/reddit/customclients/slide/api/patch/SpoofClientPatch.kt @@ -1,36 +1,36 @@ -package app.revanced.patches.reddit.customclients.slide.api.patch - -import app.revanced.patcher.annotation.Compatibility -import app.revanced.patcher.annotation.Description -import app.revanced.patcher.annotation.Package -import app.revanced.patcher.data.BytecodeContext -import app.revanced.patcher.extensions.InstructionExtensions.addInstructions -import app.revanced.patcher.fingerprint.method.impl.MethodFingerprintResult -import app.revanced.patcher.patch.PatchResult -import app.revanced.patcher.patch.PatchResultSuccess -import app.revanced.patches.reddit.customclients.AbstractChangeOAuthClientIdPatch -import app.revanced.patches.reddit.customclients.ChangeOAuthClientIdPatchAnnotation -import app.revanced.patches.reddit.customclients.boostforreddit.api.fingerprints.GetClientIdFingerprint - -@ChangeOAuthClientIdPatchAnnotation -@Description("Changes the OAuth client ID. " + - "The OAuth application type has to be \"Installed app\" " + - "and the redirect URI has to be set to \"http://www.ccrama.me\".") -@Compatibility([Package("me.ccrama.redditslide")]) -class ChangeOAuthClientIdPatch : AbstractChangeOAuthClientIdPatch( - "http://www.ccrama.me", Options, listOf(GetClientIdFingerprint) -) { - override fun List.patch(context: BytecodeContext): PatchResult { - first().mutableMethod.addInstructions( - 0, - """ - const-string v0, "$clientId" - return-object v0 - """ - ) - - return PatchResultSuccess() - } - - companion object Options : AbstractChangeOAuthClientIdPatch.Options.ChangeOAuthClientIdOptionsContainer() -} +package app.revanced.patches.reddit.customclients.slide.api.patch + +import app.revanced.patcher.annotation.Compatibility +import app.revanced.patcher.annotation.Description +import app.revanced.patcher.annotation.Package +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.addInstructions +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprintResult +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patches.reddit.customclients.AbstractSpoofClientPatch +import app.revanced.patches.reddit.customclients.SpoofClientAnnotation +import app.revanced.patches.reddit.customclients.boostforreddit.api.fingerprints.GetClientIdFingerprint + +@SpoofClientAnnotation +@Description("Spoofs the client in order to allow logging in. " + + "The OAuth application type has to be \"Installed app\" " + + "and the redirect URI has to be set to \"http://www.ccrama.me\".") +@Compatibility([Package("me.ccrama.redditslide")]) +class SpoofClientPatch : AbstractSpoofClientPatch( + "http://www.ccrama.me", Options, listOf(GetClientIdFingerprint) +) { + override fun List.patchClientId(context: BytecodeContext): PatchResult { + first().mutableMethod.addInstructions( + 0, + """ + const-string v0, "$clientId" + return-object v0 + """ + ) + + return PatchResultSuccess() + } + + companion object Options : AbstractSpoofClientPatch.Options.SpoofClientOptionsContainer() +} diff --git a/src/main/kotlin/app/revanced/patches/reddit/customclients/syncforreddit/api/patch/ChangeOAuthClientIdPatch.kt b/src/main/kotlin/app/revanced/patches/reddit/customclients/syncforreddit/api/patch/SpoofClientPatch.kt similarity index 86% rename from src/main/kotlin/app/revanced/patches/reddit/customclients/syncforreddit/api/patch/ChangeOAuthClientIdPatch.kt rename to src/main/kotlin/app/revanced/patches/reddit/customclients/syncforreddit/api/patch/SpoofClientPatch.kt index 898110b23..2f1ec7a1b 100644 --- a/src/main/kotlin/app/revanced/patches/reddit/customclients/syncforreddit/api/patch/ChangeOAuthClientIdPatch.kt +++ b/src/main/kotlin/app/revanced/patches/reddit/customclients/syncforreddit/api/patch/SpoofClientPatch.kt @@ -13,8 +13,8 @@ import app.revanced.patcher.fingerprint.method.impl.MethodFingerprintResult import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResultSuccess import app.revanced.patcher.patch.annotations.DependsOn -import app.revanced.patches.reddit.customclients.AbstractChangeOAuthClientIdPatch -import app.revanced.patches.reddit.customclients.ChangeOAuthClientIdPatchAnnotation +import app.revanced.patches.reddit.customclients.AbstractSpoofClientPatch +import app.revanced.patches.reddit.customclients.SpoofClientAnnotation 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.detection.piracy.patch.DisablePiracyDetectionPatch @@ -23,8 +23,8 @@ import org.jf.dexlib2.iface.instruction.ReferenceInstruction import org.jf.dexlib2.iface.reference.StringReference import java.util.* -@ChangeOAuthClientIdPatchAnnotation -@Description("Changes the OAuth client ID. " + +@SpoofClientAnnotation +@Description("Spoofs the client in order to allow logging in. " + "The OAuth application type has to be \"Installed app\" " + "and the redirect URI has to be set to \"http://redditsync/auth\".") @Compatibility( @@ -35,10 +35,10 @@ import java.util.* ] ) @DependsOn([DisablePiracyDetectionPatch::class]) -class ChangeOAuthClientIdPatch : AbstractChangeOAuthClientIdPatch( +class SpoofClientPatch : AbstractSpoofClientPatch( "http://redditsync/auth", Options, listOf(GetAuthorizationStringFingerprint) ) { - override fun List.patch(context: BytecodeContext): PatchResult { + override fun List.patchClientId(context: BytecodeContext): PatchResult { forEach { fingerprintResult -> fingerprintResult.also { result -> GetBearerTokenFingerprint.also { it.resolve(context, result.classDef) }.result?.mutableMethod?.apply { @@ -75,5 +75,5 @@ class ChangeOAuthClientIdPatch : AbstractChangeOAuthClientIdPatch( return PatchResultSuccess() } - companion object Options : AbstractChangeOAuthClientIdPatch.Options.ChangeOAuthClientIdOptionsContainer() + companion object Options : AbstractSpoofClientPatch.Options.SpoofClientOptionsContainer() }