From 7159f867801300d4ae32937743de59421de76238 Mon Sep 17 00:00:00 2001 From: johnconner122 <107796137+johnconner122@users.noreply.github.com> Date: Tue, 16 May 2023 08:39:48 +0500 Subject: [PATCH] feat(candylinkvpn): add `unlock-pro` patch (#2157) Co-authored-by: oSumAtrIX --- .../annotations/UnlockProCompatibility.kt | 8 ++++ .../IsPremiumPurchasedFingerprint.kt | 11 ++++++ .../candylinkvpn/patch/UnlockProPatch.kt | 37 +++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/candylinkvpn/annotations/UnlockProCompatibility.kt create mode 100644 src/main/kotlin/app/revanced/patches/candylinkvpn/fingereprints/IsPremiumPurchasedFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/candylinkvpn/patch/UnlockProPatch.kt diff --git a/src/main/kotlin/app/revanced/patches/candylinkvpn/annotations/UnlockProCompatibility.kt b/src/main/kotlin/app/revanced/patches/candylinkvpn/annotations/UnlockProCompatibility.kt new file mode 100644 index 000000000..36c0f653c --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/candylinkvpn/annotations/UnlockProCompatibility.kt @@ -0,0 +1,8 @@ +package app.revanced.patches.candylinkvpn.annotations + +import app.revanced.patcher.annotation.Compatibility +import app.revanced.patcher.annotation.Package + +@Compatibility([Package("com.candylink.openvpn")]) +@Target(AnnotationTarget.CLASS) +internal annotation class UnlockProCompatibility diff --git a/src/main/kotlin/app/revanced/patches/candylinkvpn/fingereprints/IsPremiumPurchasedFingerprint.kt b/src/main/kotlin/app/revanced/patches/candylinkvpn/fingereprints/IsPremiumPurchasedFingerprint.kt new file mode 100644 index 000000000..394b3c1f4 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/candylinkvpn/fingereprints/IsPremiumPurchasedFingerprint.kt @@ -0,0 +1,11 @@ +package app.revanced.patches.candylinkvpn.fingereprints + +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint + +object IsPremiumPurchasedFingerprint : MethodFingerprint( + customFingerprint = { methodDef, _ -> + methodDef.definingClass.endsWith("PreferenceProvider;") && + methodDef.name == "isPremiumPurchased" + } +) { +} diff --git a/src/main/kotlin/app/revanced/patches/candylinkvpn/patch/UnlockProPatch.kt b/src/main/kotlin/app/revanced/patches/candylinkvpn/patch/UnlockProPatch.kt new file mode 100644 index 000000000..9905df4de --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/candylinkvpn/patch/UnlockProPatch.kt @@ -0,0 +1,37 @@ +package app.revanced.patches.candylinkvpn.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.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.candylinkvpn.annotations.UnlockProCompatibility +import app.revanced.patches.candylinkvpn.fingereprints.IsPremiumPurchasedFingerprint + +@Patch +@Name("unlock-pro") +@Description("Unlocks premium features.") +@UnlockProCompatibility +@Version("0.0.1") +class UnlockProPatch : BytecodePatch( + listOf(IsPremiumPurchasedFingerprint) +) { + override fun execute(context: BytecodeContext): PatchResult { + IsPremiumPurchasedFingerprint.result?.let { + it.mutableMethod.addInstructions( + 0, + """ + const/4 v0, 0x1 + return v0 + """ + ) + } ?: return IsPremiumPurchasedFingerprint.toErrorResult() + + return PatchResultSuccess() + } +} \ No newline at end of file