mirror of
https://github.com/ReVanced/revanced-cli.git
synced 2026-01-21 10:23:57 +00:00
add: signature checker and compatibility filters
Signed-off-by: oSumAtrIX <johan.melkonyan1@web.de>
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
package app.revanced.cli
|
||||
|
||||
import app.revanced.patch.Patches
|
||||
import app.revanced.patcher.annotation.Name
|
||||
import app.revanced.patcher.extensions.findAnnotationRecursively
|
||||
import app.revanced.patcher.util.patch.PatchLoader
|
||||
import app.revanced.utils.adb.Adb
|
||||
import app.revanced.utils.patcher.addPatchesFiltered
|
||||
import app.revanced.utils.signature.Signature
|
||||
import picocli.CommandLine.*
|
||||
import java.io.File
|
||||
|
||||
@@ -35,6 +37,9 @@ internal object MainCommand : Runnable {
|
||||
@Option(names = ["-l", "--list"], description = ["List patches only"])
|
||||
internal var listOnly: Boolean = false
|
||||
|
||||
@Option(names = ["-s", "--signature-checker"], description = ["Check signatures of all patches"])
|
||||
internal var signatureCheck: Boolean = false
|
||||
|
||||
@Option(names = ["-m", "--merge"], description = ["One or more dex file containers to merge"])
|
||||
internal var mergeFiles = listOf<File>()
|
||||
|
||||
@@ -49,22 +54,30 @@ internal object MainCommand : Runnable {
|
||||
|
||||
override fun run() {
|
||||
if (listOnly) {
|
||||
for (patchBundle in patchBundles) for (it in Patches.load(patchBundle)) println(
|
||||
"[available] ${
|
||||
it.javaClass.findAnnotationRecursively(
|
||||
Name::class.java
|
||||
)?.name ?: Name::class.java.name
|
||||
}"
|
||||
)
|
||||
for (patchBundle in patchBundles)
|
||||
for (it in PatchLoader.loadFromFile(patchBundle))
|
||||
println(
|
||||
"[available] ${
|
||||
it.javaClass.findAnnotationRecursively(
|
||||
Name::class.java
|
||||
)?.name ?: Name::class.java.name
|
||||
}"
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
val outputFile = File(outputPath)
|
||||
|
||||
val patcher = app.revanced.patcher.Patcher(
|
||||
inputFile, cacheDirectory, patchResources
|
||||
)
|
||||
|
||||
if (signatureCheck) {
|
||||
patcher.addPatchesFiltered()
|
||||
Signature.checkSignatures(patcher)
|
||||
return
|
||||
}
|
||||
|
||||
val outputFile = File(outputPath)
|
||||
|
||||
var adb: Adb? = null
|
||||
deploy?.let {
|
||||
adb = Adb(
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
package app.revanced.cli
|
||||
|
||||
import app.revanced.patch.Patches
|
||||
import app.revanced.patcher.annotation.Compatibility
|
||||
import app.revanced.patcher.annotation.Name
|
||||
import app.revanced.patcher.data.base.Data
|
||||
import app.revanced.patcher.extensions.findAnnotationRecursively
|
||||
import app.revanced.patcher.patch.base.Patch
|
||||
import app.revanced.utils.filesystem.FileSystemUtils
|
||||
import app.revanced.utils.patcher.addPatchesFiltered
|
||||
import app.revanced.utils.patcher.applyPatchesPrint
|
||||
import app.revanced.utils.patcher.mergeFiles
|
||||
import app.revanced.utils.signing.Signer
|
||||
import java.io.File
|
||||
|
||||
@@ -14,13 +11,11 @@ internal class Patcher {
|
||||
internal companion object {
|
||||
internal fun start(patcher: app.revanced.patcher.Patcher) {
|
||||
// merge files like necessary integrations
|
||||
patcher.addFiles(MainCommand.mergeFiles)
|
||||
patcher.mergeFiles()
|
||||
// add patches, but filter incompatible or excluded patches
|
||||
patcher.addPatchesFiltered()
|
||||
patcher.addPatchesFiltered(includeFilter = MainCommand.includedPatches.isNotEmpty())
|
||||
// apply patches
|
||||
for ((patch, result) in patcher.applyPatches()) {
|
||||
println("[error: ${result.isFailure}] $patch")
|
||||
}
|
||||
patcher.applyPatchesPrint()
|
||||
|
||||
// write output file
|
||||
val outFile = File(MainCommand.outputPath)
|
||||
@@ -53,47 +48,6 @@ internal class Patcher {
|
||||
println("[done]")
|
||||
}
|
||||
|
||||
private fun app.revanced.patcher.Patcher.addPatchesFiltered() {
|
||||
val packageName = this.packageName
|
||||
val packageVersion = this.packageVersion
|
||||
|
||||
val checkInclude = MainCommand.includedPatches.isNotEmpty()
|
||||
|
||||
MainCommand.patchBundles.forEach { bundle ->
|
||||
val includedPatches = mutableListOf<Patch<Data>>()
|
||||
Patches.load(bundle).forEach patch@{ it ->
|
||||
val patch = it.getDeclaredConstructor().newInstance()
|
||||
|
||||
val filterOutPatches = true
|
||||
|
||||
val compatibilityAnnotation = patch.javaClass.findAnnotationRecursively(Compatibility::class.java)
|
||||
|
||||
val patchName =
|
||||
patch.javaClass.findAnnotationRecursively(Name::class.java)?.name ?: Name::class.java.name
|
||||
|
||||
if (checkInclude && !MainCommand.includedPatches.contains(patchName)) {
|
||||
return@patch
|
||||
}
|
||||
|
||||
if (filterOutPatches) {
|
||||
if (compatibilityAnnotation == null || !(compatibilityAnnotation.compatiblePackages.any { packageMetadata ->
|
||||
packageMetadata.name == packageName && packageMetadata.versions.any {
|
||||
it == packageVersion
|
||||
}
|
||||
})) {
|
||||
// TODO: misleading error message
|
||||
println("[Skipped] $patchName: Incompatible with current package.")
|
||||
return@patch
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
println("[loaded] $patchName")
|
||||
includedPatches.add(patch)
|
||||
|
||||
}
|
||||
this.addPatches(includedPatches)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user