mirror of
https://github.com/revanced/revanced-cli.git
synced 2025-01-10 19:25:51 +01:00
fix: migrate to latest patcher api changes
This commit is contained in:
parent
735dbc9149
commit
ace70e417f
@ -24,7 +24,7 @@ repositories {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.6.21")
|
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.6.21")
|
||||||
implementation("app.revanced:revanced-patcher:1.0.0-dev.16")
|
implementation("app.revanced:revanced-patcher:1.0.0-dev.17")
|
||||||
|
|
||||||
implementation("info.picocli:picocli:4.6.3")
|
implementation("info.picocli:picocli:4.6.3")
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package app.revanced.cli
|
package app.revanced.cli
|
||||||
|
|
||||||
|
import app.revanced.patcher.PatcherOptions
|
||||||
import app.revanced.patcher.annotation.Name
|
import app.revanced.patcher.annotation.Name
|
||||||
import app.revanced.patcher.extensions.findAnnotationRecursively
|
|
||||||
import app.revanced.patcher.util.patch.implementation.JarPatchBundle
|
import app.revanced.patcher.util.patch.implementation.JarPatchBundle
|
||||||
import app.revanced.utils.adb.Adb
|
import app.revanced.utils.adb.Adb
|
||||||
import app.revanced.utils.patcher.addPatchesFiltered
|
import app.revanced.utils.patcher.addPatchesFiltered
|
||||||
@ -54,21 +54,18 @@ internal object MainCommand : Runnable {
|
|||||||
|
|
||||||
override fun run() {
|
override fun run() {
|
||||||
if (listOnly) {
|
if (listOnly) {
|
||||||
for (patchBundlePath in patchBundles)
|
for (patchBundlePath in patchBundles) for (it in JarPatchBundle(patchBundlePath).loadPatches()) {
|
||||||
for (it in JarPatchBundle(patchBundlePath).loadPatches())
|
|
||||||
println(
|
// TODO: adjust extension methods to be able to do this
|
||||||
"[available] ${
|
val name = (it.annotations.find { it is Name } as? Name)?.name ?: it.simpleName
|
||||||
it.findAnnotationRecursively(
|
println(
|
||||||
Name::class.java
|
"[available] $name"
|
||||||
)?.name ?: it::class.java.name
|
)
|
||||||
}"
|
}
|
||||||
)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val patcher = app.revanced.patcher.Patcher(
|
val patcher = app.revanced.patcher.Patcher(PatcherOptions(inputFile, cacheDirectory, patchResources))
|
||||||
inputFile, cacheDirectory, patchResources
|
|
||||||
)
|
|
||||||
|
|
||||||
if (signatureCheck) {
|
if (signatureCheck) {
|
||||||
patcher.addPatchesFiltered()
|
patcher.addPatchesFiltered()
|
||||||
|
@ -31,7 +31,8 @@ internal class Patcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (MainCommand.patchResources) {
|
if (MainCommand.patchResources) {
|
||||||
for (file in File(MainCommand.cacheDirectory).resolve("build/").listFiles(FileFilter { it.isDirectory })?.first()?.listFiles()!!) {
|
for (file in File(MainCommand.cacheDirectory).resolve("build/").listFiles(FileFilter { it.isDirectory })
|
||||||
|
?.first()?.listFiles()!!) {
|
||||||
if (!file.isDirectory) {
|
if (!file.isDirectory) {
|
||||||
zipFileSystem.replaceFile(file.name, file.readBytes())
|
zipFileSystem.replaceFile(file.name, file.readBytes())
|
||||||
continue
|
continue
|
||||||
|
@ -2,29 +2,23 @@ package app.revanced.utils.patcher
|
|||||||
|
|
||||||
import app.revanced.cli.MainCommand
|
import app.revanced.cli.MainCommand
|
||||||
import app.revanced.patcher.Patcher
|
import app.revanced.patcher.Patcher
|
||||||
import app.revanced.patcher.annotation.Compatibility
|
|
||||||
import app.revanced.patcher.annotation.Name
|
|
||||||
import app.revanced.patcher.data.base.Data
|
import app.revanced.patcher.data.base.Data
|
||||||
import app.revanced.patcher.extensions.findAnnotationRecursively
|
import app.revanced.patcher.extensions.PatchExtensions.compatiblePackages
|
||||||
|
import app.revanced.patcher.extensions.PatchExtensions.patchName
|
||||||
import app.revanced.patcher.patch.base.Patch
|
import app.revanced.patcher.patch.base.Patch
|
||||||
import app.revanced.patcher.util.patch.implementation.JarPatchBundle
|
import app.revanced.patcher.util.patch.implementation.JarPatchBundle
|
||||||
|
|
||||||
fun Patcher.addPatchesFiltered(
|
fun Patcher.addPatchesFiltered(
|
||||||
packageCompatibilityFilter: Boolean = true,
|
|
||||||
packageVersionCompatibilityFilter: Boolean = true,
|
|
||||||
includeFilter: Boolean = false
|
includeFilter: Boolean = false
|
||||||
) {
|
) {
|
||||||
val packageName = this.packageName
|
val packageName = this.packageName
|
||||||
val packageVersion = this.packageVersion
|
val packageVersion = this.packageVersion
|
||||||
|
|
||||||
MainCommand.patchBundles.forEach { bundle ->
|
MainCommand.patchBundles.forEach { bundle ->
|
||||||
val includedPatches = mutableListOf<Patch<Data>>()
|
val includedPatches = mutableListOf<Class<out Patch<Data>>>()
|
||||||
JarPatchBundle(bundle).loadPatches().forEach patch@{ p ->
|
JarPatchBundle(bundle).loadPatches().forEach patch@{ patch ->
|
||||||
val patch = p.getDeclaredConstructor().newInstance()
|
val compatiblePackages = patch.compatiblePackages
|
||||||
|
val patchName = patch.patchName
|
||||||
val compatibilityAnnotation = patch.javaClass.findAnnotationRecursively(Compatibility::class.java)
|
|
||||||
|
|
||||||
val patchName = patch.javaClass.findAnnotationRecursively(Name::class.java)?.name ?: patch.javaClass.name
|
|
||||||
|
|
||||||
val prefix = "[skipped] $patchName"
|
val prefix = "[skipped] $patchName"
|
||||||
|
|
||||||
@ -33,24 +27,16 @@ fun Patcher.addPatchesFiltered(
|
|||||||
return@patch
|
return@patch
|
||||||
}
|
}
|
||||||
|
|
||||||
if (packageVersionCompatibilityFilter || packageCompatibilityFilter) {
|
if (compatiblePackages == null) println("$prefix: Missing compatibility annotation. Continuing.")
|
||||||
|
else compatiblePackages.forEach { compatiblePackage ->
|
||||||
if (compatibilityAnnotation == null) {
|
if (compatiblePackage.name != packageName) {
|
||||||
println("$prefix: Missing compatibility annotation.")
|
println("$prefix: Package name not matching ${compatiblePackage.name}.")
|
||||||
return@patch
|
return@patch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!compatiblePackage.versions.any { it == packageVersion }) {
|
||||||
compatibilityAnnotation.compatiblePackages.forEach { compatiblePackage ->
|
println("$prefix: Unsupported version.")
|
||||||
if (packageCompatibilityFilter && compatiblePackage.name != packageName) {
|
return@patch
|
||||||
println("$prefix: Package name not matching ${compatiblePackage.name}.")
|
|
||||||
return@patch
|
|
||||||
}
|
|
||||||
|
|
||||||
if (packageVersionCompatibilityFilter && !compatiblePackage.versions.any { it == packageVersion }) {
|
|
||||||
println("$prefix: Unsupported version.")
|
|
||||||
return@patch
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,55 +1,52 @@
|
|||||||
package app.revanced.utils.signature
|
package app.revanced.utils.signature
|
||||||
|
|
||||||
import app.revanced.patcher.Patcher
|
import app.revanced.patcher.Patcher
|
||||||
import app.revanced.patcher.extensions.findAnnotationRecursively
|
|
||||||
import app.revanced.patcher.signature.implementation.method.annotation.FuzzyPatternScanMethod
|
|
||||||
import app.revanced.patcher.signature.implementation.method.annotation.MatchingMethod
|
|
||||||
import org.jf.dexlib2.iface.Method
|
import org.jf.dexlib2.iface.Method
|
||||||
|
|
||||||
object Signature {
|
object Signature {
|
||||||
|
|
||||||
fun checkSignatures(patcher: Patcher) {
|
fun checkSignatures(patcher: Patcher) {
|
||||||
|
TODO()
|
||||||
|
/**
|
||||||
val failed = mutableListOf<String>()
|
val failed = mutableListOf<String>()
|
||||||
for (signature in patcher.resolveSignatures()) {
|
for (signature in patcher.resolveSignatures()) {
|
||||||
val signatureClass = signature::class.java
|
val signatureClass = signature::class.java
|
||||||
val signatureName =
|
val signatureName = signature.name ?: signatureClass.simpleName
|
||||||
signatureClass.findAnnotationRecursively(app.revanced.patcher.annotation.Name::class.java)?.name
|
if (!signature.resolved) {
|
||||||
?: signatureClass.name
|
failed.add(signatureName)
|
||||||
if (!signature.resolved) {
|
continue
|
||||||
failed.add(signatureName)
|
}
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
val method = signature.result!!.method
|
val method = signature.result!!.method
|
||||||
val matchingMethod =
|
val matchingMethod = signature.matchingMethod ?: MatchingMethod()
|
||||||
signatureClass.findAnnotationRecursively(MatchingMethod::class.java) ?: MatchingMethod()
|
|
||||||
|
|
||||||
println(
|
println(
|
||||||
"""
|
"""
|
||||||
[Signature] $signatureName
|
[Signature] $signatureName
|
||||||
[Method] ${matchingMethod.definingClass}->${matchingMethod.name}
|
[Method] ${matchingMethod.definingClass}->${matchingMethod.name}
|
||||||
[Match] ${method.definingClass}->${method.toStr()}
|
[Match] ${method.definingClass}->${method.toStr()}
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
)
|
)
|
||||||
|
|
||||||
signatureClass.findAnnotationRecursively(FuzzyPatternScanMethod::class.java)?.let {
|
signature.fuzzyThreshold.let {
|
||||||
val warnings = signature.result!!.scanResult.warnings!!
|
val warnings = signature.result!!.scanResult.warnings!!
|
||||||
println(
|
println(
|
||||||
"""
|
"""
|
||||||
[Warnings: ${warnings.count()}]
|
[Warnings: ${warnings.count()}]
|
||||||
${warnings.joinToString(separator = "\n") { warning -> "${warning.instructionIndex} / ${warning.patternIndex}: ${warning.wrongOpcode} (expected: ${warning.correctOpcode})" }}
|
${warnings.joinToString(separator = "\n") { warning -> "${warning.instructionIndex} / ${warning.patternIndex}: ${warning.wrongOpcode} (expected: ${warning.correctOpcode})" }}
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
println(
|
println(
|
||||||
"""
|
"""
|
||||||
${"=".repeat(50)}
|
${"=".repeat(50)}
|
||||||
[Failed signatures: ${failed.size}]
|
[Failed signatures: ${failed.size}]
|
||||||
${failed.joinToString(separator = "\n") { it }}
|
${failed.joinToString(separator = "\n") { it }}
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
)
|
)
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Method.toStr(): String {
|
private fun Method.toStr(): String {
|
||||||
|
Loading…
Reference in New Issue
Block a user