chore: Add example code from patch docs, add missing context parameter compiler argument

This commit is contained in:
LisoUseInAIKyrios committed 2026-01-20 15:14:35 +01:00
1 parent 4b62e7fe8c
commit 01b9822788
5 files changed
+97 -14

No files matched your search

@@ -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;"
}
)