mirror of
https://github.com/ReVanced/revanced-patcher.git
synced 2024-11-10 01:02:22 +01:00
Fix tests (stupid mistake) & add logging
This commit is contained in:
parent
a9e7f19d51
commit
ae5007ebd1
3 changed files with 33 additions and 9 deletions
|
@ -16,6 +16,8 @@ dependencies {
|
|||
implementation("org.ow2.asm:asm-util:9.2")
|
||||
implementation("org.ow2.asm:asm-tree:9.2")
|
||||
implementation("org.ow2.asm:asm-commons:9.2")
|
||||
implementation("ch.qos.logback:logback-classic:1.2.11")
|
||||
implementation("io.github.microutils:kotlin-logging:2.1.21")
|
||||
testImplementation(kotlin("test"))
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package net.revanced.patcher.resolver
|
||||
|
||||
import mu.KotlinLogging
|
||||
import net.revanced.patcher.cache.PatchData
|
||||
import net.revanced.patcher.signature.Signature
|
||||
import org.objectweb.asm.Type
|
||||
|
@ -7,6 +8,8 @@ import org.objectweb.asm.tree.ClassNode
|
|||
import org.objectweb.asm.tree.InsnList
|
||||
import org.objectweb.asm.tree.MethodNode
|
||||
|
||||
private val logger = KotlinLogging.logger("MethodResolver")
|
||||
|
||||
internal class MethodResolver(private val classList: List<ClassNode>, private val signatures: Array<Signature>) {
|
||||
fun resolve(): MutableMap<String, PatchData> {
|
||||
val patchData = mutableMapOf<String, PatchData>()
|
||||
|
@ -14,8 +17,16 @@ internal class MethodResolver(private val classList: List<ClassNode>, private va
|
|||
for ((classNode, methods) in classList) {
|
||||
for (method in methods) {
|
||||
for (signature in signatures) {
|
||||
if (patchData.containsKey(signature.name)) continue // method already found for this sig
|
||||
if (!this.cmp(method, signature)) continue
|
||||
if (patchData.containsKey(signature.name)) { // method already found for this sig
|
||||
logger.debug { "Sig ${signature.name} already found, skipping." }
|
||||
continue
|
||||
}
|
||||
logger.debug { "Resolving sig ${signature.name}: ${classNode.name} / ${method.name}" }
|
||||
if (!this.cmp(method, signature)) {
|
||||
logger.debug { "Compare result for sig ${signature.name} has failed!" }
|
||||
continue
|
||||
}
|
||||
logger.debug { "Method for sig ${signature.name} found!" }
|
||||
patchData[signature.name] = PatchData(classNode, method)
|
||||
}
|
||||
}
|
||||
|
@ -23,20 +34,31 @@ internal class MethodResolver(private val classList: List<ClassNode>, private va
|
|||
|
||||
for (signature in signatures) {
|
||||
if (patchData.containsKey(signature.name)) continue
|
||||
// not found
|
||||
// TODO log error or whatever
|
||||
logger.error { "Could not find method for sig ${signature.name}!" }
|
||||
}
|
||||
|
||||
return patchData
|
||||
}
|
||||
|
||||
private fun cmp(method: MethodNode, signature: Signature): Boolean {
|
||||
if (signature.returns != Type.getReturnType(method.desc)) return false
|
||||
if (signature.accessors != method.access) return false
|
||||
if (!signature.parameters.contentEquals(Type.getArgumentTypes(method.desc))) return false
|
||||
if (signature.returns != Type.getReturnType(method.desc)) {
|
||||
logger.debug { "Comparing sig ${signature.name}: invalid return type:\nexpected ${signature.returns},\ngot ${Type.getReturnType(method.desc)}" }
|
||||
return false
|
||||
}
|
||||
if (signature.accessors != method.access) {
|
||||
logger.debug { "Comparing sig ${signature.name}: invalid accessors:\nexpected ${signature.accessors},\ngot ${method.access}" }
|
||||
return false
|
||||
}
|
||||
if (!signature.parameters.contentEquals(Type.getArgumentTypes(method.desc))) {
|
||||
logger.debug { "Comparing sig ${signature.name}: invalid parameter types:\nexpected ${signature.parameters},\ngot ${Type.getArgumentTypes(method.desc)}" }
|
||||
return false
|
||||
}
|
||||
|
||||
val result = method.instructions.scanFor(signature.opcodes)
|
||||
if (!result.found) return false
|
||||
if (!result.found) {
|
||||
logger.debug { "Comparing sig ${signature.name}: invalid opcode pattern" }
|
||||
return false
|
||||
}
|
||||
// TODO make use of the startIndex and endIndex we have from the result
|
||||
|
||||
return true
|
||||
|
|
|
@ -12,7 +12,7 @@ internal class PatcherTest {
|
|||
private val testSigs: Array<Signature> = arrayOf(
|
||||
Signature(
|
||||
"testMethod",
|
||||
Type.BOOLEAN_TYPE,
|
||||
Type.VOID_TYPE,
|
||||
ACC_PUBLIC or ACC_STATIC,
|
||||
arrayOf(
|
||||
ExtraTypes.ArrayAny,
|
||||
|
|
Loading…
Reference in a new issue