From 1e8dcae6f540455b8698703bbded5f52fd0c6300 Mon Sep 17 00:00:00 2001 From: johnconner122 <107796137+johnconner122@users.noreply.github.com> Date: Sun, 21 May 2023 22:27:50 +0500 Subject: [PATCH] feat(trakt): add `unlock-pro` patch (#2210) Co-authored-by: oSumAtrIX --- .../annotations/UnlockProCompatibility.kt | 8 +++ .../trakt/fingerprints/IsVIPEPFingerprint.kt | 11 ++++ .../trakt/fingerprints/IsVIPFingerprint.kt | 11 ++++ .../RealmUserSettingsFingerprint.kt | 9 ++++ .../patches/trakt/patch/UnlockProPatch.kt | 52 +++++++++++++++++++ 5 files changed, 91 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/trakt/annotations/UnlockProCompatibility.kt create mode 100644 src/main/kotlin/app/revanced/patches/trakt/fingerprints/IsVIPEPFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/trakt/fingerprints/IsVIPFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/trakt/fingerprints/RealmUserSettingsFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/trakt/patch/UnlockProPatch.kt diff --git a/src/main/kotlin/app/revanced/patches/trakt/annotations/UnlockProCompatibility.kt b/src/main/kotlin/app/revanced/patches/trakt/annotations/UnlockProCompatibility.kt new file mode 100644 index 00000000..aa619bd8 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/trakt/annotations/UnlockProCompatibility.kt @@ -0,0 +1,8 @@ +package app.revanced.patches.trakt.annotations + +import app.revanced.patcher.annotation.Compatibility +import app.revanced.patcher.annotation.Package + +@Compatibility([Package("tv.trakt.trakt")]) +@Target(AnnotationTarget.CLASS) +internal annotation class UnlockProCompatibility \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/trakt/fingerprints/IsVIPEPFingerprint.kt b/src/main/kotlin/app/revanced/patches/trakt/fingerprints/IsVIPEPFingerprint.kt new file mode 100644 index 00000000..f62cfe5f --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/trakt/fingerprints/IsVIPEPFingerprint.kt @@ -0,0 +1,11 @@ +package app.revanced.patches.trakt.fingerprints + +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint + +object IsVIPEPFingerprint : MethodFingerprint( + customFingerprint = custom@{ methodDef, _ -> + if (!methodDef.definingClass.endsWith("RealmUserSettings;")) return@custom false + + methodDef.name == "isVIPEP" + } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/trakt/fingerprints/IsVIPFingerprint.kt b/src/main/kotlin/app/revanced/patches/trakt/fingerprints/IsVIPFingerprint.kt new file mode 100644 index 00000000..eb678d26 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/trakt/fingerprints/IsVIPFingerprint.kt @@ -0,0 +1,11 @@ +package app.revanced.patches.trakt.fingerprints + +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint + +object IsVIPFingerprint : MethodFingerprint( + customFingerprint = custom@{ methodDef, _ -> + if (!methodDef.definingClass.endsWith("RealmUserSettings;")) return@custom false + + methodDef.name == "isVIP" + } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/trakt/fingerprints/RealmUserSettingsFingerprint.kt b/src/main/kotlin/app/revanced/patches/trakt/fingerprints/RealmUserSettingsFingerprint.kt new file mode 100644 index 00000000..dd8c8198 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/trakt/fingerprints/RealmUserSettingsFingerprint.kt @@ -0,0 +1,9 @@ +package app.revanced.patches.trakt.fingerprints + +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint + +object RealmUserSettingsFingerprint : MethodFingerprint( + customFingerprint = { methodDef, _ -> + methodDef.definingClass.endsWith("RealmUserSettings;") + } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/trakt/patch/UnlockProPatch.kt b/src/main/kotlin/app/revanced/patches/trakt/patch/UnlockProPatch.kt new file mode 100644 index 00000000..362b9133 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/trakt/patch/UnlockProPatch.kt @@ -0,0 +1,52 @@ +package app.revanced.patches.trakt.patch + +import app.revanced.extensions.toErrorResult +import app.revanced.patcher.annotation.Description +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.addInstructions +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.patch.annotations.Patch +import app.revanced.patches.trakt.annotations.UnlockProCompatibility +import app.revanced.patches.trakt.fingerprints.IsVIPEPFingerprint +import app.revanced.patches.trakt.fingerprints.IsVIPFingerprint +import app.revanced.patches.trakt.fingerprints.RealmUserSettingsFingerprint + +@Patch +@Name("unlock-pro") +@Description("Unlocks pro features.") +@UnlockProCompatibility +@Version("0.0.1") +class UnlockProPatch : BytecodePatch( + listOf(RealmUserSettingsFingerprint) +) { + override fun execute(context: BytecodeContext): PatchResult { + RealmUserSettingsFingerprint.result?.classDef?.let { realUserSettingsClass -> + arrayOf(IsVIPFingerprint, IsVIPEPFingerprint).onEach { fingerprint -> + // Resolve both fingerprints on the same class. + if (!fingerprint.resolve(context, realUserSettingsClass)) + throw fingerprint.toErrorResult() + }.forEach { fingerprint -> + // Return true for both VIP check methods. + fingerprint.result?.mutableMethod?.addInstructions(0, RETURN_TRUE_INSTRUCTIONS) + ?: return fingerprint.toErrorResult() + } + } ?: return RealmUserSettingsFingerprint.toErrorResult() + + return PatchResultSuccess() + } + + private companion object { + const val RETURN_TRUE_INSTRUCTIONS = + """ + const/4 v0, 0x1 + invoke-static {v0}, Ljava/lang/Boolean;->valueOf(Z)Ljava/lang/Boolean; + move-result-object v1 + return-object v1 + """ + } +} \ No newline at end of file