mirror of
https://github.com/revanced/revanced-patcher.git
synced 2025-04-30 21:34:25 +02:00
Fix tests (stupid mistake) & add logging
This commit is contained in:
parent
a9e7f19d51
commit
ae5007ebd1
@ -16,6 +16,8 @@ dependencies {
|
|||||||
implementation("org.ow2.asm:asm-util:9.2")
|
implementation("org.ow2.asm:asm-util:9.2")
|
||||||
implementation("org.ow2.asm:asm-tree:9.2")
|
implementation("org.ow2.asm:asm-tree:9.2")
|
||||||
implementation("org.ow2.asm:asm-commons: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"))
|
testImplementation(kotlin("test"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package net.revanced.patcher.resolver
|
package net.revanced.patcher.resolver
|
||||||
|
|
||||||
|
import mu.KotlinLogging
|
||||||
import net.revanced.patcher.cache.PatchData
|
import net.revanced.patcher.cache.PatchData
|
||||||
import net.revanced.patcher.signature.Signature
|
import net.revanced.patcher.signature.Signature
|
||||||
import org.objectweb.asm.Type
|
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.InsnList
|
||||||
import org.objectweb.asm.tree.MethodNode
|
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>) {
|
internal class MethodResolver(private val classList: List<ClassNode>, private val signatures: Array<Signature>) {
|
||||||
fun resolve(): MutableMap<String, PatchData> {
|
fun resolve(): MutableMap<String, PatchData> {
|
||||||
val patchData = mutableMapOf<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 ((classNode, methods) in classList) {
|
||||||
for (method in methods) {
|
for (method in methods) {
|
||||||
for (signature in signatures) {
|
for (signature in signatures) {
|
||||||
if (patchData.containsKey(signature.name)) continue // method already found for this sig
|
if (patchData.containsKey(signature.name)) { // method already found for this sig
|
||||||
if (!this.cmp(method, signature)) continue
|
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)
|
patchData[signature.name] = PatchData(classNode, method)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -23,20 +34,31 @@ internal class MethodResolver(private val classList: List<ClassNode>, private va
|
|||||||
|
|
||||||
for (signature in signatures) {
|
for (signature in signatures) {
|
||||||
if (patchData.containsKey(signature.name)) continue
|
if (patchData.containsKey(signature.name)) continue
|
||||||
// not found
|
logger.error { "Could not find method for sig ${signature.name}!" }
|
||||||
// TODO log error or whatever
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return patchData
|
return patchData
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun cmp(method: MethodNode, signature: Signature): Boolean {
|
private fun cmp(method: MethodNode, signature: Signature): Boolean {
|
||||||
if (signature.returns != Type.getReturnType(method.desc)) return false
|
if (signature.returns != Type.getReturnType(method.desc)) {
|
||||||
if (signature.accessors != method.access) return false
|
logger.debug { "Comparing sig ${signature.name}: invalid return type:\nexpected ${signature.returns},\ngot ${Type.getReturnType(method.desc)}" }
|
||||||
if (!signature.parameters.contentEquals(Type.getArgumentTypes(method.desc))) return false
|
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)
|
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
|
// TODO make use of the startIndex and endIndex we have from the result
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
@ -12,7 +12,7 @@ internal class PatcherTest {
|
|||||||
private val testSigs: Array<Signature> = arrayOf(
|
private val testSigs: Array<Signature> = arrayOf(
|
||||||
Signature(
|
Signature(
|
||||||
"testMethod",
|
"testMethod",
|
||||||
Type.BOOLEAN_TYPE,
|
Type.VOID_TYPE,
|
||||||
ACC_PUBLIC or ACC_STATIC,
|
ACC_PUBLIC or ACC_STATIC,
|
||||||
arrayOf(
|
arrayOf(
|
||||||
ExtraTypes.ArrayAny,
|
ExtraTypes.ArrayAny,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user