From 8cd60eea36bd49514ed1c42bf362dce7e9675fca Mon Sep 17 00:00:00 2001 From: Valerio Mazza <92364106+vlemazza@users.noreply.github.com> Date: Wed, 5 Jul 2023 22:19:44 +0200 Subject: [PATCH] feat(slideforreddit): add `change-oauth-client-id` patch (#2571) --- .../fingerprints/GetClientIdFingerprint.kt | 11 ++++++ .../api/patch/ChangeOAuthClientIdPatch.kt | 36 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/reddit/customclients/slide/api/fingerprints/GetClientIdFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/reddit/customclients/slide/api/patch/ChangeOAuthClientIdPatch.kt diff --git a/src/main/kotlin/app/revanced/patches/reddit/customclients/slide/api/fingerprints/GetClientIdFingerprint.kt b/src/main/kotlin/app/revanced/patches/reddit/customclients/slide/api/fingerprints/GetClientIdFingerprint.kt new file mode 100644 index 0000000000..9caed98521 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/reddit/customclients/slide/api/fingerprints/GetClientIdFingerprint.kt @@ -0,0 +1,11 @@ +package app.revanced.patches.reddit.customclients.slide.api.fingerprints + +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint + +object GetClientIdFingerprint : MethodFingerprint( + customFingerprint = custom@{ methodDef, classDef -> + if (!classDef.type.endsWith("Credentials;")) return@custom false + + methodDef.name == "getClientId" + } +) \ 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/ChangeOAuthClientIdPatch.kt new file mode 100644 index 0000000000..90a9372fcc --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/reddit/customclients/slide/api/patch/ChangeOAuthClientIdPatch.kt @@ -0,0 +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() +}