Template
mirror of
https://github.com/MorpheApp/morphe-patches-template.git
synced 2026-12-01 00:19:34 +00:00
chore: Add example code from patch docs, add missing context parameter compiler argument
This commit is contained in:
1 parent
4b62e7fe8c
commit
01b9822788
5 files changed
+97
-14
No files matched your search
@@ -2,12 +2,18 @@ group = "app.morphe"
|
||||
|
||||
patches {
|
||||
about {
|
||||
name = "Morphe Patches template"
|
||||
description = "Patches template for Morphe"
|
||||
name = "XYZ Patches for use with Morphe"
|
||||
description = "Example patches"
|
||||
source = "[email protected]:MorpheApp/morphe-patches-template.git"
|
||||
author = "Morphe"
|
||||
contact = "[email protected]"
|
||||
author = "Awesome dev"
|
||||
contact = "na"
|
||||
website = "https://morphe.software"
|
||||
license = "Additional conditions under GPL section 7 apply: attribution and project name restrictions. See LICENSE file."
|
||||
license = "GPLv3"
|
||||
}
|
||||
}
|
||||
|
||||
kotlin {
|
||||
compilerOptions {
|
||||
freeCompilerArgs.add("-Xcontext-parameters")
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,28 @@
|
||||
package app.morphe.patches.example
|
||||
|
||||
import app.morphe.patcher.extensions.InstructionExtensions.addInstructions
|
||||
import app.morphe.patcher.patch.bytecodePatch
|
||||
|
||||
private const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/morphe/extension/ExamplePatch;"
|
||||
|
||||
@Suppress("unused")
|
||||
val examplePatch = bytecodePatch(
|
||||
name = "Example Patch",
|
||||
description = "This is an example patch to start with.",
|
||||
description = "Example patch to start with."
|
||||
) {
|
||||
compatibleWith("com.example.app"("1.0.0"))
|
||||
|
||||
extendWith("extensions/extension.rve")
|
||||
|
||||
// Business logic of the patch to disable ads in the app.
|
||||
execute {
|
||||
// TODO("Not yet implemented")
|
||||
AdLoaderFingerprint.method.addInstructions(
|
||||
0,
|
||||
"""
|
||||
invoke-static {}, $EXTENSION_CLASS_DESCRIPTOR;->showAds()Z
|
||||
move-result v0
|
||||
return v0
|
||||
"""
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package app.morphe.patches.example
|
||||
|
||||
import app.morphe.patcher.Fingerprint
|
||||
import app.morphe.patcher.InstructionLocation.*
|
||||
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 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.
|
||||
object AdLoaderFingerprint : Fingerprint(
|
||||
// Exact access flags
|
||||
accessFlags = listOf(AccessFlags.PUBLIC, AccessFlags.FINAL),
|
||||
// Return type is matched using String.startsWith()
|
||||
returnType = "Z",
|
||||
// Declared parameters are matched using String.startsWith()
|
||||
// Non obfuscated classes should be declared using the full class name.
|
||||
// While 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 = listOf("Ljava/lang/String;", "I", "L"),
|
||||
|
||||
// Instruction filters.
|
||||
filters = listOf(
|
||||
// Filter 1.
|
||||
fieldAccess(
|
||||
// Restrict to field get operation.
|
||||
opcode = Opcode.IGET,
|
||||
// "this" refers to the class the method was declared in.
|
||||
// It does not include superclasses or subclasses.
|
||||
definingClass = "this",
|
||||
type = "Ljava/util/Map;"
|
||||
),
|
||||
|
||||
// Filter 2.
|
||||
string("showBannerAds"),
|
||||
|
||||
// Filter 3.
|
||||
methodCall(
|
||||
definingClass = "Ljava/lang/String;",
|
||||
name = "equals",
|
||||
),
|
||||
|
||||
// Filter 4.
|
||||
// MatchAfterImmediately() means this must match immediately after the last filter.
|
||||
opcode(Opcode.MOVE_RESULT, MatchAfterImmediately()),
|
||||
|
||||
// Filter 5.
|
||||
literal(1337),
|
||||
|
||||
// Filter 6.
|
||||
opcode(Opcode.IF_EQ),
|
||||
),
|
||||
|
||||
custom = { _, classDef ->
|
||||
classDef.type == "Lcom/some/app/ads/AdsLoader;"
|
||||
}
|
||||
)
|
||||
Reference in new issue
Block a user