From 14809cd4510ad9514b4a4820187a81681669374c Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Fri, 30 Jun 2023 02:30:41 +0200 Subject: [PATCH] feat(redditisfun): add `change-oauth-client-id` patch --- .../AbstractClientIdFingerprint.kt | 7 +++ .../BasicAuthorizationFingerprint.kt | 5 ++ .../BuildAuthorizationStringFingerprint.kt | 5 ++ .../api/patch/ChangeOAuthClientIdPatch.kt | 57 +++++++++++++++++++ 4 files changed, 74 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/reddit/customclients/redditisfun/api/fingerprints/AbstractClientIdFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/reddit/customclients/redditisfun/api/fingerprints/BasicAuthorizationFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/reddit/customclients/redditisfun/api/fingerprints/BuildAuthorizationStringFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/reddit/customclients/redditisfun/api/patch/ChangeOAuthClientIdPatch.kt diff --git a/src/main/kotlin/app/revanced/patches/reddit/customclients/redditisfun/api/fingerprints/AbstractClientIdFingerprint.kt b/src/main/kotlin/app/revanced/patches/reddit/customclients/redditisfun/api/fingerprints/AbstractClientIdFingerprint.kt new file mode 100644 index 0000000000..fe166b91d8 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/reddit/customclients/redditisfun/api/fingerprints/AbstractClientIdFingerprint.kt @@ -0,0 +1,7 @@ +package app.revanced.patches.reddit.customclients.redditisfun.api.fingerprints + +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint + +abstract class AbstractClientIdFingerprint(string: String) : MethodFingerprint( + strings = listOfNotNull("yyOCBp.RHJhDKd", string), +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/reddit/customclients/redditisfun/api/fingerprints/BasicAuthorizationFingerprint.kt b/src/main/kotlin/app/revanced/patches/reddit/customclients/redditisfun/api/fingerprints/BasicAuthorizationFingerprint.kt new file mode 100644 index 0000000000..9e4b3530a4 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/reddit/customclients/redditisfun/api/fingerprints/BasicAuthorizationFingerprint.kt @@ -0,0 +1,5 @@ +package app.revanced.patches.reddit.customclients.redditisfun.api.fingerprints + +object BasicAuthorizationFingerprint : AbstractClientIdFingerprint( + string = "fJOxVwBUyo*=f:.patch(context: BytecodeContext): PatchResult { + /** + * Replaces a one register instruction with a const-string instruction + * at the index returned by [getReplacementIndex]. + * + * @param string The string to replace the instruction with. + * @param getReplacementIndex A function that returns the index of the instruction to replace + * using the [StringMatch] list from the [MethodFingerprintResult]. + */ + fun MethodFingerprintResult.replaceWith( + string: String, + getReplacementIndex: List.() -> Int, + ) = mutableMethod.apply { + val replacementIndex = scanResult.stringsScanResult!!.matches.getReplacementIndex() + val clientIdRegister = getInstruction(replacementIndex).registerA + + replaceInstruction(replacementIndex, "const-string v$clientIdRegister, \"$string\"") + } + + // Patch OAuth authorization. + first().replaceWith(clientId!!) { first().index + 4 } + + // Path basic authorization. + last().replaceWith("$clientId:") { last().index + 7 } + + return PatchResultSuccess() + } + + companion object Options : AbstractChangeOAuthClientIdPatch.Options.ChangeOAuthClientIdOptionsContainer() +} \ No newline at end of file