From fe66f4089d6365564c8097d3c7a1bc842c343194 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0mundur=20=C3=93li?= Date: Sun, 25 Jun 2023 03:13:34 +0000 Subject: [PATCH] feat(relayforreddit): add `change-oauth-client-id` patch (#2491) Co-authored-by: oSumAtrIX --- .../ChangeOAuthClientIdPatchAnnotation.kt | 11 ++++++++ .../api/patch/ChangeOAuthClientIdPatch.kt | 28 ++++++++----------- .../api/patch/ChangeOAuthClientIdPatch.kt | 10 +++---- .../fingerprints/GetClientIdFingerprint.kt | 7 +++++ .../api/patch/ChangeOAuthClientIdPatch.kt | 26 +++++++++++++++++ .../api/patch/ChangeOAuthClientIdPatch.kt | 14 ++++------ 6 files changed, 64 insertions(+), 32 deletions(-) create mode 100644 src/main/kotlin/app/revanced/patches/reddit/customclients/ChangeOAuthClientIdPatchAnnotation.kt create mode 100644 src/main/kotlin/app/revanced/patches/reddit/customclients/relayforreddit/api/fingerprints/GetClientIdFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/reddit/customclients/relayforreddit/api/patch/ChangeOAuthClientIdPatch.kt diff --git a/src/main/kotlin/app/revanced/patches/reddit/customclients/ChangeOAuthClientIdPatchAnnotation.kt b/src/main/kotlin/app/revanced/patches/reddit/customclients/ChangeOAuthClientIdPatchAnnotation.kt new file mode 100644 index 000000000..270fc3405 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/reddit/customclients/ChangeOAuthClientIdPatchAnnotation.kt @@ -0,0 +1,11 @@ +package app.revanced.patches.reddit.customclients + +import app.revanced.patcher.annotation.Description +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.patch.annotations.Patch + +@Target(AnnotationTarget.CLASS) +@Patch +@Name("change-oauth-client-id") +@Description("Changes the OAuth client ID.") +annotation class ChangeOAuthClientIdPatchAnnotation \ No newline at end of file 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/ChangeOAuthClientIdPatch.kt index d6c286d6a..f088f2e36 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/ChangeOAuthClientIdPatch.kt @@ -1,35 +1,29 @@ package app.revanced.patches.reddit.customclients.boostforreddit.api.patch -import app.revanced.patcher.annotation.* +import app.revanced.patcher.annotation.Compatibility +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.patcher.patch.annotations.Patch import app.revanced.patches.reddit.customclients.AbstractChangeOAuthClientIdPatch +import app.revanced.patches.reddit.customclients.ChangeOAuthClientIdPatchAnnotation import app.revanced.patches.reddit.customclients.boostforreddit.api.fingerprints.GetClientIdFingerprint -@Patch -@Name("change-oauth-client-id") -@Description("Changes the OAuth client ID in Boost for Reddit.") +@ChangeOAuthClientIdPatchAnnotation @Compatibility([Package("com.rubenmayayo.reddit")]) -@Version("0.0.1") class ChangeOAuthClientIdPatch : AbstractChangeOAuthClientIdPatch( - "http://rubenmayayo.com", - Options, - listOf(GetClientIdFingerprint) + "http://rubenmayayo.com", Options, listOf(GetClientIdFingerprint) ) { override fun List.patch(context: BytecodeContext): PatchResult { - forEach { - it.mutableMethod.addInstructions( - 0, + first().mutableMethod.addInstructions( + 0, + """ + const-string v0, "$clientId" + return-object v0 """ - const-string v0, "$clientId" - return-object v0 - """ - ) - } + ) return PatchResultSuccess() } 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/ChangeOAuthClientIdPatch.kt index ac6d76d3b..36d136b9b 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/ChangeOAuthClientIdPatch.kt @@ -1,23 +1,21 @@ package app.revanced.patches.reddit.customclients.infinityforreddit.api.patch -import app.revanced.patcher.annotation.* +import app.revanced.patcher.annotation.Compatibility +import app.revanced.patcher.annotation.Package import app.revanced.patcher.data.BytecodeContext 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.patch.PatchResult import app.revanced.patcher.patch.PatchResultSuccess -import app.revanced.patcher.patch.annotations.Patch import app.revanced.patches.reddit.customclients.AbstractChangeOAuthClientIdPatch +import app.revanced.patches.reddit.customclients.ChangeOAuthClientIdPatchAnnotation 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 -@Patch -@Name("change-oauth-client-id") -@Description("Changes the OAuth client ID.") +@ChangeOAuthClientIdPatchAnnotation @Compatibility([Package("ml.docilealligator.infinityforreddit")]) -@Version("0.0.1") class ChangeOAuthClientIdPatch : AbstractChangeOAuthClientIdPatch( "infinity://localhost", Options, diff --git a/src/main/kotlin/app/revanced/patches/reddit/customclients/relayforreddit/api/fingerprints/GetClientIdFingerprint.kt b/src/main/kotlin/app/revanced/patches/reddit/customclients/relayforreddit/api/fingerprints/GetClientIdFingerprint.kt new file mode 100644 index 000000000..212eb979e --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/reddit/customclients/relayforreddit/api/fingerprints/GetClientIdFingerprint.kt @@ -0,0 +1,7 @@ +package app.revanced.patches.reddit.customclients.relayforreddit.api.fingerprints + +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint + +object GetClientIdFingerprint : MethodFingerprint( + strings = listOf("AIzaSyCTQfRx9fHnDpfcfiI5pmwyGUBjDVTNvX8") +) \ 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/ChangeOAuthClientIdPatch.kt new file mode 100644 index 000000000..b4587b9f5 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/reddit/customclients/relayforreddit/api/patch/ChangeOAuthClientIdPatch.kt @@ -0,0 +1,26 @@ +package app.revanced.patches.reddit.customclients.relayforreddit.api.patch + +import app.revanced.patcher.annotation.Compatibility +import app.revanced.patcher.annotation.Package +import app.revanced.patcher.data.BytecodeContext +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.relayforreddit.api.fingerprints.GetClientIdFingerprint + +@ChangeOAuthClientIdPatchAnnotation +@Compatibility([Package("free.reddit.news"), Package("reddit.news")]) +class ChangeOAuthClientIdPatch : AbstractChangeOAuthClientIdPatch( + "dbrady://relay", Options, listOf(GetClientIdFingerprint) +) { + override fun List.patch(context: BytecodeContext): PatchResult { + first().mutableMethod.replaceInstruction(0, "const-string v0, \"$clientId\"") + + return PatchResultSuccess() + } + + companion object Options : AbstractChangeOAuthClientIdPatch.Options.ChangeOAuthClientIdOptionsContainer() +} \ No newline at end of file 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/ChangeOAuthClientIdPatch.kt index 0fd161891..0e33b6920 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/ChangeOAuthClientIdPatch.kt @@ -1,7 +1,8 @@ package app.revanced.patches.reddit.customclients.syncforreddit.api.patch import app.revanced.extensions.toErrorResult -import app.revanced.patcher.annotation.* +import app.revanced.patcher.annotation.Compatibility +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 @@ -10,8 +11,8 @@ import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion. 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.Patch import app.revanced.patches.reddit.customclients.AbstractChangeOAuthClientIdPatch +import app.revanced.patches.reddit.customclients.ChangeOAuthClientIdPatchAnnotation import app.revanced.patches.reddit.customclients.syncforreddit.api.fingerprints.GetAuthorizationStringFingerprint import app.revanced.patches.reddit.customclients.syncforreddit.api.fingerprints.GetBearerTokenFingerprint import org.jf.dexlib2.iface.instruction.OneRegisterInstruction @@ -19,15 +20,10 @@ import org.jf.dexlib2.iface.instruction.ReferenceInstruction import org.jf.dexlib2.iface.reference.StringReference import java.util.* -@Patch -@Name("change-oauth-client-id") -@Description("Changes the OAuth client ID.") +@ChangeOAuthClientIdPatchAnnotation @Compatibility([Package("com.laurencedawson.reddit_sync"), Package("com.laurencedawson.reddit_sync.pro")]) -@Version("0.0.1") class ChangeOAuthClientIdPatch : AbstractChangeOAuthClientIdPatch( - "http://redditsync/auth", - Options, - listOf(GetAuthorizationStringFingerprint) + "http://redditsync/auth", Options, listOf(GetAuthorizationStringFingerprint) ) { override fun List.patch(context: BytecodeContext): PatchResult { forEach { fingerprintResult ->