mirror of
https://github.com/ReVanced/revanced-cli.git
synced 2026-01-23 03:11:02 +00:00
add: signature checker and compatibility filters
Signed-off-by: oSumAtrIX <johan.melkonyan1@web.de>
This commit is contained in:
@@ -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