refactor: finalize Signature Checker

This commit is contained in:
Lucaskyy 2022-04-14 21:47:43 +02:00
parent 0077e26d23
commit e5a609f716
No known key found for this signature in database
GPG key ID: 1530BFF96D1EEB89

View file

@ -3,6 +3,7 @@ package app.revanced.patches
import app.revanced.patcher.Patcher
import app.revanced.patcher.signature.MethodSignature
import app.revanced.patcher.signature.PatternScanMethod
import org.jf.dexlib2.iface.Method
import org.junit.Test
import java.io.File
@ -26,16 +27,20 @@ internal class SignatureChecker {
if (patternScanMethod is PatternScanMethod.Fuzzy) {
val warnings = patternScanMethod.warnings!!
println("Signature ${signature.metadata.name} had ${warnings.size} warnings!")
val method = signature.result!!.method
val instructions = method.implementation!!.instructions
println("class = ${method.definingClass}, method = ${printMethod(method)}")
for (warning in warnings) {
val instructions = signature.result!!.method.implementation!!.instructions
for (i in warning.expectedIndex - 5 until warning.expectedIndex) {
println(instructions[i].opcode)
println("-".repeat(10))
for (i in (warning.actualIndex - 5).coerceAtLeast(0) until warning.actualIndex) {
println("$i: ${instructions[i].opcode}")
}
println(warning.toString())
for (i in warning.expectedIndex - 5 .. warning.expectedIndex + 1) {
println(instructions[i].opcode)
for (i in warning.actualIndex + 1 until (warning.actualIndex + 5).coerceAtMost(instructions.size)) {
println("$i: ${instructions[i].opcode}")
}
}
println("=".repeat(20))
}
}
if (unresolved.isNotEmpty()) {
@ -46,4 +51,8 @@ internal class SignatureChecker {
throw base
}
}
private fun printMethod(method: Method): String {
return "${method.name}(${method.parameterTypes.joinToString("")})${method.returnType}"
}
}