fix: breaking changes by revanced-patcher dependency

Signed-off-by: oSumAtrIX <johan.melkonyan1@web.de>
This commit is contained in:
oSumAtrIX
2022-05-18 23:58:54 +02:00
parent 96e7aed843
commit 113637183a
67 changed files with 3709 additions and 3563 deletions
@@ -1,17 +1,18 @@
package app.revanced.patches
import app.revanced.patcher.Patcher
import app.revanced.patcher.signature.MethodMetadata
import app.revanced.patcher.signature.MethodSignature
import app.revanced.patcher.signature.PatternScanMethod
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.signature.implementation.method.annotation.FuzzyPatternScanMethod
import app.revanced.patcher.signature.implementation.method.annotation.MatchingMethod
import app.revanced.patcher.signature.implementation.method.annotation.PatternScanMethod
import org.jf.dexlib2.iface.Method
import org.junit.Test
import java.io.File
internal class SignatureChecker {
@Test
fun checkSignatures() {
return
fun checkMethodSignatures() {
// FIXME: instead of having this as a test, it should be turned into a task which can be ran manually
val file = File("stock.apk")
if (!file.exists()) {
@@ -19,24 +20,26 @@ internal class SignatureChecker {
}
val patcher = Patcher(file, "signatureCheckerCache", false)
patcher.addPatches(Index.patches.map { it() })
val unresolved = mutableListOf<MethodSignature>()
val unresolved = mutableListOf<String>()
for (signature in patcher.resolveSignatures()) {
val signatureAnnotations = signature::class.annotations
val nameAnnotation = signatureAnnotations.find { it is Name } as Name
if (!signature.resolved) {
unresolved.add(signature)
unresolved.add(nameAnnotation.name)
continue
}
val patternScanMethod = signature.metadata.patternScanMethod
if (patternScanMethod is PatternScanMethod.Fuzzy) {
val warnings = patternScanMethod.warnings!!
val patternScanMethod =
signatureAnnotations.find { it::class.annotations.any { method -> method is PatternScanMethod } }
if (patternScanMethod is FuzzyPatternScanMethod) {
val warnings = signature.result!!.scanData.warnings!!
val method = signature.result!!.method
val methodFromMetadata =
if (signature.metadata.methodMetadata != null) signature.metadata.methodMetadata!! else MethodMetadata(
null,
null
)
println("Signature: ${signature.metadata.name}.\nMethod: ${methodFromMetadata.definingClass}->${methodFromMetadata.name} (Signature matches: ${method.definingClass}->${method.toStr()})\nWarnings: ${warnings.count()}")
val methodFromMetadata =
signatureAnnotations.find { it is MatchingMethod } as MatchingMethod? ?: MatchingMethod()
println("Signature: ${nameAnnotation}.\nMethod: ${methodFromMetadata.definingClass}->${methodFromMetadata.name} (Signature matches: ${method.definingClass}->${method.toStr()})\nWarnings: ${warnings.count()}")
for (warning in warnings) {
println("${warning.instructionIndex} / ${warning.patternIndex}: ${warning.wrongOpcode} (expected: ${warning.correctOpcode})")
}
@@ -46,8 +49,8 @@ internal class SignatureChecker {
}
if (unresolved.isNotEmpty()) {
val base = Exception("${unresolved.size} signatures were not resolved.")
for (signature in unresolved) {
base.addSuppressed(Exception("Signature ${signature.metadata.name} was not resolved!"))
for (name in unresolved) {
base.addSuppressed(Exception("Signature $name was not resolved!"))
}
throw base
}