Template
mirror of
https://github.com/MorpheApp/morphe-patches-template.git
synced 2026-12-01 01:29:34 +00:00
chore: Add internal patch example. Update fingerprint examples.
This commit is contained in:
1 parent
0fafb19448
commit
d5915aa115
4 files changed
+99
-25
No files matched your search
@@ -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.
|
||||
|
||||
@@ -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)
|
||||
)
|
||||
)
|
||||
@@ -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"
|
||||
"""
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -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"
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user