Skip to content

Commit 8d1bb5f

Browse files
committed
fix(MethodResolver): strip labels and line numbers so opcode patterns match
1 parent c8a017a commit 8d1bb5f

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

src/main/kotlin/app/revanced/patcher/resolver/MethodResolver.kt

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ import app.revanced.patcher.cache.PatternScanData
77
import app.revanced.patcher.signature.Signature
88
import app.revanced.patcher.util.ExtraTypes
99
import org.objectweb.asm.Type
10-
import org.objectweb.asm.tree.ClassNode
11-
import org.objectweb.asm.tree.InsnList
12-
import org.objectweb.asm.tree.MethodNode
10+
import org.objectweb.asm.tree.*
1311

1412
private val logger = KotlinLogging.logger("MethodResolver")
1513

@@ -110,7 +108,7 @@ internal class MethodResolver(private val classList: List<ClassNode>, private va
110108
}
111109

112110
signature.opcodes?.let { _ ->
113-
val result = method.instructions.scanFor(signature.opcodes)
111+
val result = method.instructions.stripLabels().scanFor(signature.opcodes)
114112
if (!result.found) {
115113
logger.debug { "Comparing sig ${signature.name}: invalid opcode pattern" }
116114
return@cmp false to null
@@ -123,13 +121,8 @@ internal class MethodResolver(private val classList: List<ClassNode>, private va
123121
}
124122
}
125123

126-
private operator fun ClassNode.component1(): ClassNode {
127-
return this
128-
}
129-
130-
private operator fun ClassNode.component2(): List<MethodNode> {
131-
return this.methods
132-
}
124+
private operator fun ClassNode.component1() = this
125+
private operator fun ClassNode.component2() = this.methods
133126

134127
private fun InsnList.scanFor(pattern: IntArray): ScanResult {
135128
for (i in 0 until this.size()) {
@@ -157,3 +150,8 @@ private fun Type.convertObject(): Type {
157150
private fun Array<Type>.convertObjects(): Array<Type> {
158151
return this.map { it.convertObject() }.toTypedArray()
159152
}
153+
154+
private fun InsnList.stripLabels(): InsnList {
155+
this.removeAll { it is LabelNode || it is LineNumberNode }
156+
return this
157+
}

src/test/kotlin/app/revanced/patcher/util/TestUtil.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ private class NodeStringBuilder {
3838
}
3939

4040
override fun toString(): String {
41+
if (sb.isEmpty()) return ""
4142
val s = sb.toString()
42-
return s.substring(0 until s.length - 2) // remove the last ", "
43+
return s.substring(0 .. (s.length - 2).coerceAtLeast(0)) // remove the last ", "
4344
}
4445
}

0 commit comments

Comments
 (0)