From d5915aa115b713d723e10beb2340114f0296c325 Mon Sep 17 00:00:00 2001 From: LisoUseInAIKyrios <118716522+LisoUseInAIKyrios@users.noreply.github.com> Date: Sat, 4 Jul 2026 20:06:56 +0300 Subject: [PATCH] chore: Add internal patch example. Update fingerprint examples. --- .../template/patches/example/ExamplePatch.kt | 2 + .../template/patches/example/Fingerprints.kt | 62 +++++++++++++------ .../template/patches/example/InternalPatch.kt | 27 ++++++++ .../app/template/patches/shared/Constants.kt | 33 ++++++++-- 4 files changed, 99 insertions(+), 25 deletions(-) create mode 100644 patches/src/main/kotlin/app/template/patches/example/InternalPatch.kt diff --git a/patches/src/main/kotlin/app/template/patches/example/ExamplePatch.kt b/patches/src/main/kotlin/app/template/patches/example/ExamplePatch.kt index 22fee46de..e9eba9f5f 100644 --- a/patches/src/main/kotlin/app/template/patches/example/ExamplePatch.kt +++ b/patches/src/main/kotlin/app/template/patches/example/ExamplePatch.kt @@ -14,6 +14,8 @@ val examplePatch = bytecodePatch( ) { compatibleWith(COMPATIBILITY_EXAMPLE) + dependsOn(internalPatch) + extendWith("extensions/extension.mpe") // Business logic of the patch to disable ads in the app. diff --git a/patches/src/main/kotlin/app/template/patches/example/Fingerprints.kt b/patches/src/main/kotlin/app/template/patches/example/Fingerprints.kt index fd4285b8a..a59f674a9 100644 --- a/patches/src/main/kotlin/app/template/patches/example/Fingerprints.kt +++ b/patches/src/main/kotlin/app/template/patches/example/Fingerprints.kt @@ -1,32 +1,58 @@ package app.template.patches.example import app.morphe.patcher.Fingerprint -import app.morphe.patcher.InstructionLocation.* -import app.morphe.patcher.StringComparisonType +import app.morphe.patcher.InstructionLocation.MatchAfterImmediately import app.morphe.patcher.fieldAccess import app.morphe.patcher.literal import app.morphe.patcher.methodCall import app.morphe.patcher.opcode import app.morphe.patcher.string -import app.template.patches.example.AdLoaderFingerprint.classDef import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.Opcode -// Declaring fingerprints as classes is not required, but if a fingerprint fails -// to match then the exception stack trace will include the fingerprint name. +/** + * See: + * https://github.com/MorpheApp/morphe-patcher/blob/main/docs + * https://github.com/MorpheApp/morphe-patcher/blob/main/docs/2_2_1_fingerprinting.md + * + * Declaring fingerprints as classes is not required, but if a fingerprint fails + * to match then the exception stack trace will include the fingerprint name. + */ object AdLoaderFingerprint : Fingerprint( - // Exact access flags + /** + * Defining class type is matched using implicit comparison depending on how the type is declared. + * + * This can be a package without a class: ":com/some/app/ads/" + * A class without a package: "/AdsLoader;" + * Or a full class if the full class name is not obfuscated: "Lcom/some/app/ads/AdsLoader;" + * + * See [app.morphe.patcher.StringComparisonType] for more. + */ + definingClass = "Lcom/some/app/ads/AdsLoader;", + /** + * Exact method name. + */ + name = "showAds", + /** + * Exact access flags. + */ accessFlags = listOf(AccessFlags.PUBLIC, AccessFlags.FINAL), - // Return type is matched using implicit coparison depending on how the type is declared. - // See StringComparisonType for more. + /** + * Return type. Partial matches are allowed and follows the same rules as [definingClass] + * and [app.morphe.patcher.StringComparisonType]. + */ returnType = "Z", - // Declared parameters are matched using StringComparisonType implicit comparison. - // Obfuscated class names must be declared only using the object type - // Since obfuscated names change between releases. - // Last parameter is simply `L` since it's an obfuscated class object. + /** + * Parameters. Partial matches are allowed and follows the same rules as + * [app.morphe.patcher.StringComparisonType]. + * + * Obfuscated class names must be declared only using the object type: "L" + * Since obfuscated names change between app targets. + */ parameters = listOf("Ljava/lang/String;", "I", "L"), - - // Instruction filters. + /** + * Instruction filters. See [app.morphe.patcher.InstructionFilter]. + */ filters = listOf( // Filter 1. fieldAccess( @@ -55,10 +81,6 @@ object AdLoaderFingerprint : Fingerprint( literal(1337), // Filter 6. - opcode(Opcode.IF_EQ), - ), - - custom = { _, classDef -> - classDef.type == "Lcom/some/app/ads/AdsLoader;" - } + opcode(Opcode.IF_EQ) + ) ) \ No newline at end of file diff --git a/patches/src/main/kotlin/app/template/patches/example/InternalPatch.kt b/patches/src/main/kotlin/app/template/patches/example/InternalPatch.kt new file mode 100644 index 000000000..10d216f14 --- /dev/null +++ b/patches/src/main/kotlin/app/template/patches/example/InternalPatch.kt @@ -0,0 +1,27 @@ +package app.template.patches.example + +import app.morphe.patcher.Fingerprint +import app.morphe.patcher.extensions.InstructionExtensions.addInstruction +import app.morphe.patcher.patch.bytecodePatch + +// Internal patch that is not shown in Morphe Manager or CLI patch list, +// but this patch is required for other patches to function. +val internalPatch = bytecodePatch { + execute { + Fingerprint( + /** + * Class fingerprint finds any methods in the class, + * and the rest of this fingerprint finds the method to use. + */ + classFingerprint = AdLoaderFingerprint, + name = "unrelatedMethod", + parameters = listOf("Ljava/lang/String;"), + ).method.addInstruction( + 0, + // Override string parameter with a constant value. + """ + const-string p1, "dummy.value.overide" + """ + ) + } +} diff --git a/patches/src/main/kotlin/app/template/patches/shared/Constants.kt b/patches/src/main/kotlin/app/template/patches/shared/Constants.kt index 5d3881563..4e5be42ea 100644 --- a/patches/src/main/kotlin/app/template/patches/shared/Constants.kt +++ b/patches/src/main/kotlin/app/template/patches/shared/Constants.kt @@ -6,19 +6,42 @@ import app.morphe.patcher.patch.Compatibility object Constants { val COMPATIBILITY_EXAMPLE = Compatibility( - name = "XYZ app", + name = "XYZ app", // App name as it appears in the Android launcher. packageName = "com.example.app", - apkFileType = ApkFileType.APK, - appIconColor = 0xFF0045, // Icon color in Morphe Manager + apkFileType = ApkFileType.APK, // Preferred or recommended file type. + appIconColor = 0xFF0045, // Icon color in Morphe Manager. Usually the same color as the icon background. targets = listOf( // "version = null" means the patch works with the latest app target - // and is expected to work with all future app targets + // and is expected to work with all future app targets. + // + // It is highly recommended to always include the exact app version you developed your patches for + // or the last version you have confirmed as 100% working. AppTarget( version = "2.0.0" ), AppTarget( - version = "1.0.2", + version = "1.0.2" ) ) ) + + + val COMPATIBILITY_EXAMPLE_2 = Compatibility( + name = "ABC app", + packageName = "com.example.app", + apkFileType = ApkFileType.APKM, + appIconColor = 0x00FF45, // Icon color in Morphe Manager. Usually the same color as the icon background. + targets = listOf( + // 'any' version supported experimentally. + AppTarget( + version = null, + isExperimental = true + ), + // App version confirmed 100% working. + AppTarget( + version = "1.0.2" + ) + ) + ) + }