From 0423a7cc0fcc6ca6c85fc8b697eba8c42d418f94 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Tue, 27 Jun 2023 04:46:05 +0200 Subject: [PATCH] fix(relay/change-client-id): patch client id instead of developer key --- ...rint.kt => AbstractClientIdFingerprint.kt} | 4 +-- .../GetLoggedInBearerTokenFingerprint.kt | 4 +++ .../GetLoggedOutBearerTokenFingerprint.kt | 3 ++ .../GetRefreshTokenFingerprint.kt | 3 ++ .../LoginActivityClientIdFingerprint.kt | 3 ++ .../api/patch/ChangeOAuthClientIdPatch.kt | 28 +++++++++++++++++-- 6 files changed, 40 insertions(+), 5 deletions(-) rename src/main/kotlin/app/revanced/patches/reddit/customclients/relayforreddit/api/fingerprints/{GetClientIdFingerprint.kt => AbstractClientIdFingerprint.kt} (53%) create mode 100644 src/main/kotlin/app/revanced/patches/reddit/customclients/relayforreddit/api/fingerprints/GetLoggedInBearerTokenFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/reddit/customclients/relayforreddit/api/fingerprints/GetLoggedOutBearerTokenFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/reddit/customclients/relayforreddit/api/fingerprints/GetRefreshTokenFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/reddit/customclients/relayforreddit/api/fingerprints/LoginActivityClientIdFingerprint.kt 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/AbstractClientIdFingerprint.kt similarity index 53% rename from src/main/kotlin/app/revanced/patches/reddit/customclients/relayforreddit/api/fingerprints/GetClientIdFingerprint.kt rename to src/main/kotlin/app/revanced/patches/reddit/customclients/relayforreddit/api/fingerprints/AbstractClientIdFingerprint.kt index 212eb979e5..8cb5161f5c 100644 --- 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/AbstractClientIdFingerprint.kt @@ -2,6 +2,6 @@ package app.revanced.patches.reddit.customclients.relayforreddit.api.fingerprint import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -object GetClientIdFingerprint : MethodFingerprint( - strings = listOf("AIzaSyCTQfRx9fHnDpfcfiI5pmwyGUBjDVTNvX8") +abstract class AbstractClientIdFingerprint(string: String) : MethodFingerprint( + strings = listOfNotNull("dj-xCIZQYiLbEg", string), ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/reddit/customclients/relayforreddit/api/fingerprints/GetLoggedInBearerTokenFingerprint.kt b/src/main/kotlin/app/revanced/patches/reddit/customclients/relayforreddit/api/fingerprints/GetLoggedInBearerTokenFingerprint.kt new file mode 100644 index 0000000000..3c0ab8ade9 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/reddit/customclients/relayforreddit/api/fingerprints/GetLoggedInBearerTokenFingerprint.kt @@ -0,0 +1,4 @@ +package app.revanced.patches.reddit.customclients.relayforreddit.api.fingerprints + +object GetLoggedInBearerTokenFingerprint : + AbstractClientIdFingerprint("authorization_code") \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/reddit/customclients/relayforreddit/api/fingerprints/GetLoggedOutBearerTokenFingerprint.kt b/src/main/kotlin/app/revanced/patches/reddit/customclients/relayforreddit/api/fingerprints/GetLoggedOutBearerTokenFingerprint.kt new file mode 100644 index 0000000000..74e479c586 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/reddit/customclients/relayforreddit/api/fingerprints/GetLoggedOutBearerTokenFingerprint.kt @@ -0,0 +1,3 @@ +package app.revanced.patches.reddit.customclients.relayforreddit.api.fingerprints + +object GetLoggedOutBearerTokenFingerprint : AbstractClientIdFingerprint("https://oauth.reddit.com/grants/installed_client") \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/reddit/customclients/relayforreddit/api/fingerprints/GetRefreshTokenFingerprint.kt b/src/main/kotlin/app/revanced/patches/reddit/customclients/relayforreddit/api/fingerprints/GetRefreshTokenFingerprint.kt new file mode 100644 index 0000000000..492a5554c9 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/reddit/customclients/relayforreddit/api/fingerprints/GetRefreshTokenFingerprint.kt @@ -0,0 +1,3 @@ +package app.revanced.patches.reddit.customclients.relayforreddit.api.fingerprints + +object GetRefreshTokenFingerprint : AbstractClientIdFingerprint("refresh_token") \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/reddit/customclients/relayforreddit/api/fingerprints/LoginActivityClientIdFingerprint.kt b/src/main/kotlin/app/revanced/patches/reddit/customclients/relayforreddit/api/fingerprints/LoginActivityClientIdFingerprint.kt new file mode 100644 index 0000000000..ba260ee195 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/reddit/customclients/relayforreddit/api/fingerprints/LoginActivityClientIdFingerprint.kt @@ -0,0 +1,3 @@ +package app.revanced.patches.reddit.customclients.relayforreddit.api.fingerprints + +object LoginActivityClientIdFingerprint : AbstractClientIdFingerprint("&duration=permanent") \ 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 index b4587b9f5a..2bdeed0b95 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/ChangeOAuthClientIdPatch.kt @@ -3,21 +3,43 @@ 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.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.patches.reddit.customclients.AbstractChangeOAuthClientIdPatch import app.revanced.patches.reddit.customclients.ChangeOAuthClientIdPatchAnnotation -import app.revanced.patches.reddit.customclients.relayforreddit.api.fingerprints.GetClientIdFingerprint +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.LoginActivityClientIdFingerprint +import app.revanced.patches.reddit.customclients.relayforreddit.api.fingerprints.GetRefreshTokenFingerprint +import org.jf.dexlib2.iface.instruction.OneRegisterInstruction @ChangeOAuthClientIdPatchAnnotation @Compatibility([Package("free.reddit.news"), Package("reddit.news")]) class ChangeOAuthClientIdPatch : AbstractChangeOAuthClientIdPatch( - "dbrady://relay", Options, listOf(GetClientIdFingerprint) + "dbrady://relay", + Options, + listOf( + LoginActivityClientIdFingerprint, + GetLoggedInBearerTokenFingerprint, + GetLoggedOutBearerTokenFingerprint, + GetRefreshTokenFingerprint + ) ) { override fun List.patch(context: BytecodeContext): PatchResult { - first().mutableMethod.replaceInstruction(0, "const-string v0, \"$clientId\"") + forEach { + val clientIdIndex = it.scanResult.stringsScanResult!!.matches.first().index + it.mutableMethod.apply { + val clientIdRegister = getInstruction(clientIdIndex).registerA + + it.mutableMethod.replaceInstruction( + clientIdIndex, + "const-string v$clientIdRegister, \"$clientId\"" + ) + } + } return PatchResultSuccess() }