From 7d3054178187bed294d156d3858613fa63a626ef Mon Sep 17 00:00:00 2001 From: badawoll <129878899+badawoll@users.noreply.github.com> Date: Tue, 18 Apr 2023 23:47:17 +0000 Subject: [PATCH] feat(memegenerator): `unlock-pro` patch (#1902) Co-authored-by: oSumAtrIX --- .../LicenseValidationFingerprint.kt | 24 ++++++++++ .../license/patch/LicenseValidationPatch.kt | 31 +++++++++++++ .../fingerprint/VerifySignatureFingerprint.kt | 35 +++++++++++++++ .../patch/SignatureVerificationPatch.kt | 31 +++++++++++++ .../pro/annotations/UnlockProCompatibility.kt | 8 ++++ .../fingerprint/IsFreeVersionFingerprint.kt | 22 +++++++++ .../misc/pro/patch/UnlockProVersionPatch.kt | 45 +++++++++++++++++++ 7 files changed, 196 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/memegenerator/detection/license/fingerprint/LicenseValidationFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/memegenerator/detection/license/patch/LicenseValidationPatch.kt create mode 100644 src/main/kotlin/app/revanced/patches/memegenerator/detection/signature/fingerprint/VerifySignatureFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/memegenerator/detection/signature/patch/SignatureVerificationPatch.kt create mode 100644 src/main/kotlin/app/revanced/patches/memegenerator/misc/pro/annotations/UnlockProCompatibility.kt create mode 100644 src/main/kotlin/app/revanced/patches/memegenerator/misc/pro/fingerprint/IsFreeVersionFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/memegenerator/misc/pro/patch/UnlockProVersionPatch.kt diff --git a/src/main/kotlin/app/revanced/patches/memegenerator/detection/license/fingerprint/LicenseValidationFingerprint.kt b/src/main/kotlin/app/revanced/patches/memegenerator/detection/license/fingerprint/LicenseValidationFingerprint.kt new file mode 100644 index 00000000..205bca30 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/memegenerator/detection/license/fingerprint/LicenseValidationFingerprint.kt @@ -0,0 +1,24 @@ +package app.revanced.patches.memegenerator.detection.license.fingerprint + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import org.jf.dexlib2.AccessFlags +import org.jf.dexlib2.Opcode + +object LicenseValidationFingerprint : MethodFingerprint( + returnType = "Z", + access = AccessFlags.PUBLIC or AccessFlags.STATIC, + parameters = listOf("Landroid/content/Context;"), + opcodes = listOf( + Opcode.INVOKE_STATIC, + Opcode.MOVE_RESULT_WIDE, + Opcode.INVOKE_STATIC, + Opcode.MOVE_RESULT_WIDE, + Opcode.CMP_LONG, + Opcode.IF_GEZ, + Opcode.CONST_4, + Opcode.RETURN, + Opcode.CONST_4, + Opcode.RETURN + ) +) diff --git a/src/main/kotlin/app/revanced/patches/memegenerator/detection/license/patch/LicenseValidationPatch.kt b/src/main/kotlin/app/revanced/patches/memegenerator/detection/license/patch/LicenseValidationPatch.kt new file mode 100644 index 00000000..6e514ff7 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/memegenerator/detection/license/patch/LicenseValidationPatch.kt @@ -0,0 +1,31 @@ +package app.revanced.patches.memegenerator.detection.license.patch + +import app.revanced.extensions.toErrorResult +import app.revanced.patcher.annotation.Description +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.replaceInstructions +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patches.memegenerator.detection.license.fingerprint.LicenseValidationFingerprint + +@Description("Disables Firebase license validation.") +@Version("0.0.1") +class LicenseValidationPatch : BytecodePatch( + listOf(LicenseValidationFingerprint) +) { + override fun execute(context: BytecodeContext): PatchResult { + LicenseValidationFingerprint.result?.apply { + mutableMethod.replaceInstructions( + 0, + """ + const/4 p0, 0x1 + return p0 + """ + ) + } ?: throw LicenseValidationFingerprint.toErrorResult() + + return PatchResultSuccess() + } +} \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/memegenerator/detection/signature/fingerprint/VerifySignatureFingerprint.kt b/src/main/kotlin/app/revanced/patches/memegenerator/detection/signature/fingerprint/VerifySignatureFingerprint.kt new file mode 100644 index 00000000..7c0304eb --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/memegenerator/detection/signature/fingerprint/VerifySignatureFingerprint.kt @@ -0,0 +1,35 @@ +package app.revanced.patches.memegenerator.detection.signature.fingerprint + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.method.annotation.FuzzyPatternScanMethod +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import org.jf.dexlib2.AccessFlags +import org.jf.dexlib2.Opcode + +@FuzzyPatternScanMethod(2) +object VerifySignatureFingerprint : MethodFingerprint( + returnType = "Z", + access = AccessFlags.PUBLIC or AccessFlags.STATIC, + parameters = listOf("Landroid/app/Activity;"), + opcodes = listOf( + Opcode.SGET_OBJECT, + Opcode.IF_NEZ, + Opcode.INVOKE_STATIC, + Opcode.CONST_4, + Opcode.CONST_4, + Opcode.SGET_OBJECT, + Opcode.ARRAY_LENGTH, + Opcode.IF_GE, + Opcode.AGET_OBJECT, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT_OBJECT, + Opcode.SGET_OBJECT, + Opcode.IF_EQZ, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT, + Opcode.IF_EQZ, + Opcode.CONST_4, + Opcode.RETURN, + Opcode.ADD_INT_LIT8 + ), +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/memegenerator/detection/signature/patch/SignatureVerificationPatch.kt b/src/main/kotlin/app/revanced/patches/memegenerator/detection/signature/patch/SignatureVerificationPatch.kt new file mode 100644 index 00000000..1b9ca306 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/memegenerator/detection/signature/patch/SignatureVerificationPatch.kt @@ -0,0 +1,31 @@ +package app.revanced.patches.memegenerator.detection.signature.patch + +import app.revanced.extensions.toErrorResult +import app.revanced.patcher.annotation.Description +import app.revanced.patcher.annotation.Version +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.replaceInstructions +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patches.memegenerator.detection.signature.fingerprint.VerifySignatureFingerprint + +@Description("Disables detection of incorrect signature.") +@Version("0.0.1") +class SignatureVerificationPatch : BytecodePatch( + listOf(VerifySignatureFingerprint) +) { + override fun execute(context: BytecodeContext): PatchResult { + VerifySignatureFingerprint.result?.apply { + mutableMethod.replaceInstructions( + 0, + """ + const/4 p0, 0x1 + return p0 + """ + ) + } ?: throw VerifySignatureFingerprint.toErrorResult() + + return PatchResultSuccess() + } +} \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/memegenerator/misc/pro/annotations/UnlockProCompatibility.kt b/src/main/kotlin/app/revanced/patches/memegenerator/misc/pro/annotations/UnlockProCompatibility.kt new file mode 100644 index 00000000..bf92bcca --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/memegenerator/misc/pro/annotations/UnlockProCompatibility.kt @@ -0,0 +1,8 @@ +package app.revanced.patches.memegenerator.misc.pro.annotations + +import app.revanced.patcher.annotation.Compatibility +import app.revanced.patcher.annotation.Package + +@Compatibility([Package("com.zombodroid.MemeGenerator", arrayOf("4.6364"))]) +@Target(AnnotationTarget.CLASS) +internal annotation class UnlockProCompatibility diff --git a/src/main/kotlin/app/revanced/patches/memegenerator/misc/pro/fingerprint/IsFreeVersionFingerprint.kt b/src/main/kotlin/app/revanced/patches/memegenerator/misc/pro/fingerprint/IsFreeVersionFingerprint.kt new file mode 100644 index 00000000..be9b266b --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/memegenerator/misc/pro/fingerprint/IsFreeVersionFingerprint.kt @@ -0,0 +1,22 @@ +package app.revanced.patches.memegenerator.misc.pro.fingerprint + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import org.jf.dexlib2.AccessFlags +import org.jf.dexlib2.Opcode + +object IsFreeVersionFingerprint : MethodFingerprint( + returnType = "Ljava/lang/Boolean;", + access = AccessFlags.PUBLIC or AccessFlags.STATIC, + strings = listOf("free"), + parameters = listOf("Landroid/content/Context;"), + opcodes = listOf( + Opcode.SGET, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT_OBJECT, + Opcode.CONST_STRING, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT, + Opcode.IF_EQZ + ) +) diff --git a/src/main/kotlin/app/revanced/patches/memegenerator/misc/pro/patch/UnlockProVersionPatch.kt b/src/main/kotlin/app/revanced/patches/memegenerator/misc/pro/patch/UnlockProVersionPatch.kt new file mode 100644 index 00000000..c0c928e2 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/memegenerator/misc/pro/patch/UnlockProVersionPatch.kt @@ -0,0 +1,45 @@ +package app.revanced.patches.memegenerator.misc.pro.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.replaceInstructions +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.patch.annotations.DependsOn +import app.revanced.patcher.patch.annotations.Patch +import app.revanced.patches.memegenerator.detection.license.patch.LicenseValidationPatch +import app.revanced.patches.memegenerator.detection.signature.patch.SignatureVerificationPatch +import app.revanced.patches.memegenerator.misc.pro.annotations.UnlockProCompatibility +import app.revanced.patches.memegenerator.misc.pro.fingerprint.IsFreeVersionFingerprint + +@Patch +@Name("unlock-pro") +@Description("Unlocks pro features.") +@DependsOn([ + SignatureVerificationPatch::class, + LicenseValidationPatch::class +]) +@UnlockProCompatibility +@Version("0.0.1") +class UnlockProVersionPatch : BytecodePatch( + listOf( + IsFreeVersionFingerprint + ) +) { + override fun execute(context: BytecodeContext): PatchResult { + IsFreeVersionFingerprint.result?.apply { + mutableMethod.replaceInstructions(0, + """ + sget-object p0, Ljava/lang/Boolean;->FALSE:Ljava/lang/Boolean; + return-object p0 + """ + ) + } ?: throw IsFreeVersionFingerprint.toErrorResult() + + return PatchResultSuccess() + } +} \ No newline at end of file