mirror of
https://github.com/revanced/revanced-patcher.git
synced 2025-05-12 09:54:24 +02:00
fix(MethodResolver): strip labels and line numbers so opcode patterns match
This commit is contained in:
parent
c8a017a4c0
commit
8d1bb5f3d9
@ -7,9 +7,7 @@ import app.revanced.patcher.cache.PatternScanData
|
|||||||
import app.revanced.patcher.signature.Signature
|
import app.revanced.patcher.signature.Signature
|
||||||
import app.revanced.patcher.util.ExtraTypes
|
import app.revanced.patcher.util.ExtraTypes
|
||||||
import org.objectweb.asm.Type
|
import org.objectweb.asm.Type
|
||||||
import org.objectweb.asm.tree.ClassNode
|
import org.objectweb.asm.tree.*
|
||||||
import org.objectweb.asm.tree.InsnList
|
|
||||||
import org.objectweb.asm.tree.MethodNode
|
|
||||||
|
|
||||||
private val logger = KotlinLogging.logger("MethodResolver")
|
private val logger = KotlinLogging.logger("MethodResolver")
|
||||||
|
|
||||||
@ -110,7 +108,7 @@ internal class MethodResolver(private val classList: List<ClassNode>, private va
|
|||||||
}
|
}
|
||||||
|
|
||||||
signature.opcodes?.let { _ ->
|
signature.opcodes?.let { _ ->
|
||||||
val result = method.instructions.scanFor(signature.opcodes)
|
val result = method.instructions.stripLabels().scanFor(signature.opcodes)
|
||||||
if (!result.found) {
|
if (!result.found) {
|
||||||
logger.debug { "Comparing sig ${signature.name}: invalid opcode pattern" }
|
logger.debug { "Comparing sig ${signature.name}: invalid opcode pattern" }
|
||||||
return@cmp false to null
|
return@cmp false to null
|
||||||
@ -123,13 +121,8 @@ internal class MethodResolver(private val classList: List<ClassNode>, private va
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private operator fun ClassNode.component1(): ClassNode {
|
private operator fun ClassNode.component1() = this
|
||||||
return this
|
private operator fun ClassNode.component2() = this.methods
|
||||||
}
|
|
||||||
|
|
||||||
private operator fun ClassNode.component2(): List<MethodNode> {
|
|
||||||
return this.methods
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun InsnList.scanFor(pattern: IntArray): ScanResult {
|
private fun InsnList.scanFor(pattern: IntArray): ScanResult {
|
||||||
for (i in 0 until this.size()) {
|
for (i in 0 until this.size()) {
|
||||||
@ -157,3 +150,8 @@ private fun Type.convertObject(): Type {
|
|||||||
private fun Array<Type>.convertObjects(): Array<Type> {
|
private fun Array<Type>.convertObjects(): Array<Type> {
|
||||||
return this.map { it.convertObject() }.toTypedArray()
|
return this.map { it.convertObject() }.toTypedArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun InsnList.stripLabels(): InsnList {
|
||||||
|
this.removeAll { it is LabelNode || it is LineNumberNode }
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
@ -38,7 +38,8 @@ private class NodeStringBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
|
if (sb.isEmpty()) return ""
|
||||||
val s = sb.toString()
|
val s = sb.toString()
|
||||||
return s.substring(0 until s.length - 2) // remove the last ", "
|
return s.substring(0 .. (s.length - 2).coerceAtLeast(0)) // remove the last ", "
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user