diff --git a/extensions/extension/src/main/java/app/morphe/extension/ExampleExtension.java b/extensions/extension/src/main/java/app/morphe/extension/ExampleExtension.java deleted file mode 100644 index 458f061cc..000000000 --- a/extensions/extension/src/main/java/app/morphe/extension/ExampleExtension.java +++ /dev/null @@ -1,7 +0,0 @@ -package app.morphe.extension; - -public class ExampleExtension { - public static void get() { - // TODO("Not yet implemented") - } -} diff --git a/extensions/extension/src/main/java/app/morphe/extension/ExamplePatch.java b/extensions/extension/src/main/java/app/morphe/extension/ExamplePatch.java new file mode 100644 index 000000000..f25bc3fbb --- /dev/null +++ b/extensions/extension/src/main/java/app/morphe/extension/ExamplePatch.java @@ -0,0 +1,11 @@ +package app.morphe.extension; + +@SuppressWarnings("unused") +public class ExamplePatch { + + public static boolean showAds() { + // Complex Java logic goes here. + // Simple patches that override with fixed values do not need to use or call extension code. + return false; + } +} diff --git a/patches/build.gradle.kts b/patches/build.gradle.kts index 3b1b193be..4eadd4cd0 100644 --- a/patches/build.gradle.kts +++ b/patches/build.gradle.kts @@ -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 = "git@github.com:MorpheApp/morphe-patches-template.git" - author = "Morphe" - contact = "contact@morphe.software" + 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") } } diff --git a/patches/src/main/kotlin/app/morphe/patches/example/ExamplePatch.kt b/patches/src/main/kotlin/app/morphe/patches/example/ExamplePatch.kt index d1fce6048..fad6c65ba 100644 --- a/patches/src/main/kotlin/app/morphe/patches/example/ExamplePatch.kt +++ b/patches/src/main/kotlin/app/morphe/patches/example/ExamplePatch.kt @@ -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 + """ + ) } } diff --git a/patches/src/main/kotlin/app/morphe/patches/example/Fingerprints.kt b/patches/src/main/kotlin/app/morphe/patches/example/Fingerprints.kt new file mode 100644 index 000000000..7e65029bf --- /dev/null +++ b/patches/src/main/kotlin/app/morphe/patches/example/Fingerprints.kt @@ -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;" + } +) \ No newline at end of file