Template
mirror of
https://github.com/MorpheApp/morphe-patches-template.git
synced 2026-12-01 00:19:34 +00:00
chore: Change template packages to template naming
This commit is contained in:
1 parent
6551d39a3d
commit
0fac28586e
7 files changed
+11
-20
No files matched your search
@@ -0,0 +1,28 @@
|
||||
package app.template.patches.example
|
||||
|
||||
import app.morphe.patcher.extensions.InstructionExtensions.addInstructions
|
||||
import app.morphe.patcher.patch.bytecodePatch
|
||||
|
||||
private const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/template/extension/ExamplePatch;"
|
||||
|
||||
@Suppress("unused")
|
||||
val examplePatch = bytecodePatch(
|
||||
name = "Example Patch",
|
||||
description = "Example patch to start with."
|
||||
) {
|
||||
compatibleWith("com.example.app"("1.0.0"))
|
||||
|
||||
extendWith("extensions/extension.mpp")
|
||||
|
||||
// Business logic of the patch to disable ads in the app.
|
||||
execute {
|
||||
AdLoaderFingerprint.method.addInstructions(
|
||||
0,
|
||||
"""
|
||||
invoke-static {}, $EXTENSION_CLASS_DESCRIPTOR;->showAds()Z
|
||||
move-result v0
|
||||
return v0
|
||||
"""
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package app.template.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;"
|
||||
}
|
||||
)
|
||||
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* Copyright 2025 Morphe.
|
||||
* https://github.com/morpheapp/morphe-patches
|
||||
*
|
||||
* File-Specific License Notice (GPLv3 Section 7 Additional Permission).
|
||||
*
|
||||
* This file is part of the Morphe patches project and is licensed under
|
||||
* the GNU General Public License version 3 (GPLv3), with the Additional
|
||||
* Terms under Section 7 described in the Morphe patches LICENSE file.
|
||||
*
|
||||
* https://www.gnu.org/licenses/gpl-3.0.html
|
||||
*
|
||||
* File-Specific Exception to Section 7b:
|
||||
* -------------------------------------
|
||||
* Section 7b (Attribution Requirement) of the Morphe patches LICENSE
|
||||
* does not apply to THIS FILE. Use of this file does NOT require any
|
||||
* user-facing, in-application, or UI-visible attribution.
|
||||
*
|
||||
* For this file only, attribution under Section 7b is satisfied by
|
||||
* retaining this comment block in the source code of this file.
|
||||
*
|
||||
* Distribution and Derivative Works:
|
||||
* ----------------------------------
|
||||
* This comment block MUST be preserved in all copies, distributions,
|
||||
* and derivative works of this file, whether in source or modified
|
||||
* form.
|
||||
*
|
||||
* All other terms of the Morphe Patches LICENSE, including Section 7c
|
||||
* (Project Name Restriction) and the GPLv3 itself, remain fully
|
||||
* applicable to this file.
|
||||
*/
|
||||
|
||||
package app.template.util
|
||||
|
||||
import app.morphe.patcher.patch.Patch
|
||||
import app.morphe.patcher.patch.loadPatchesFromJar
|
||||
import com.google.gson.GsonBuilder
|
||||
import com.google.gson.JsonObject
|
||||
import java.io.File
|
||||
import java.net.URLClassLoader
|
||||
import java.util.jar.Manifest
|
||||
|
||||
typealias PackageName = String
|
||||
typealias VersionName = String
|
||||
|
||||
internal fun main() {
|
||||
val patchFiles = setOf(
|
||||
File("build/libs/").listFiles { file ->
|
||||
val fileName = file.name
|
||||
!fileName.contains("javadoc") &&
|
||||
!fileName.contains("sources") &&
|
||||
fileName.endsWith(".mpp")
|
||||
}!!.first()
|
||||
)
|
||||
val loadedPatches = loadPatchesFromJar(patchFiles)
|
||||
val patchClassLoader = URLClassLoader(patchFiles.map { it.toURI().toURL() }.toTypedArray())
|
||||
val manifest = patchClassLoader.getResources("META-INF/MANIFEST.MF")
|
||||
|
||||
while (manifest.hasMoreElements()) {
|
||||
Manifest(manifest.nextElement().openStream())
|
||||
.mainAttributes
|
||||
.getValue("Version")
|
||||
?.let {
|
||||
generatePatchList(it, loadedPatches)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
private fun generatePatchList(version: String, patches: Set<Patch<*>>) {
|
||||
val listJson = File("../patches-list.json")
|
||||
|
||||
val patchesMap = patches.sortedBy { it.name }.map {
|
||||
JsonPatch(
|
||||
it.name!!,
|
||||
it.description,
|
||||
it.use,
|
||||
it.dependencies.map { dependency -> dependency.javaClass.simpleName },
|
||||
it.compatiblePackages?.associate { (packageName, versions) -> packageName to versions },
|
||||
it.options.values.map { option ->
|
||||
JsonPatch.Option(
|
||||
option.key,
|
||||
option.title,
|
||||
option.description,
|
||||
option.required,
|
||||
option.type.toString(),
|
||||
option.default,
|
||||
option.values,
|
||||
)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
val gsonBuilder = GsonBuilder()
|
||||
.serializeNulls()
|
||||
.disableHtmlEscaping()
|
||||
.setPrettyPrinting()
|
||||
.create()
|
||||
|
||||
val jsonObject = JsonObject()
|
||||
jsonObject.addProperty("version", "v$version")
|
||||
jsonObject.add("patches", gsonBuilder.toJsonTree(patchesMap))
|
||||
|
||||
listJson.writeText(
|
||||
gsonBuilder.toJson(jsonObject)
|
||||
)
|
||||
}
|
||||
|
||||
@Suppress("unused")
|
||||
private class JsonPatch(
|
||||
val name: String? = null,
|
||||
val description: String? = null,
|
||||
val use: Boolean = true,
|
||||
val dependencies: List<String>,
|
||||
val compatiblePackages: Map<PackageName, Set<VersionName>?>? = null,
|
||||
val options: List<Option>,
|
||||
) {
|
||||
class Option(
|
||||
val key: String,
|
||||
val title: String?,
|
||||
val description: String?,
|
||||
val required: Boolean,
|
||||
val type: String,
|
||||
val default: Any?,
|
||||
val values: Map<String, Any?>?,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user