mirror of
https://github.com/ReVanced/revanced-patcher.git
synced 2024-11-10 01:02:22 +01:00
fix(MethodResolver): strip labels nodes so opcode patterns match
this commit is also a fix for 8d1bb5f3d9
because it corrupted the stack by completely removing the nodes
This commit is contained in:
parent
81d0cf20f3
commit
82c530650f
1 changed files with 13 additions and 5 deletions
|
@ -8,6 +8,8 @@ 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.*
|
import org.objectweb.asm.tree.*
|
||||||
|
import kotlin.reflect.KType
|
||||||
|
import kotlin.reflect.typeOf
|
||||||
|
|
||||||
private val logger = KotlinLogging.logger("MethodResolver")
|
private val logger = KotlinLogging.logger("MethodResolver")
|
||||||
|
|
||||||
|
@ -108,7 +110,7 @@ internal class MethodResolver(private val classList: List<ClassNode>, private va
|
||||||
}
|
}
|
||||||
|
|
||||||
signature.opcodes?.let { _ ->
|
signature.opcodes?.let { _ ->
|
||||||
val result = method.instructions.stripLabels().scanFor(signature.opcodes)
|
val result = method.instructions.scanFor(signature.opcodes)
|
||||||
if (!result.found) {
|
if (!result.found) {
|
||||||
logger.trace { "Comparing sig ${signature.name}: invalid opcode pattern" }
|
logger.trace { "Comparing sig ${signature.name}: invalid opcode pattern" }
|
||||||
return@cmp false to null
|
return@cmp false to null
|
||||||
|
@ -128,7 +130,14 @@ private fun InsnList.scanFor(pattern: IntArray): ScanResult {
|
||||||
for (i in 0 until this.size()) {
|
for (i in 0 until this.size()) {
|
||||||
var occurrence = 0
|
var occurrence = 0
|
||||||
while (i + occurrence < this.size()) {
|
while (i + occurrence < this.size()) {
|
||||||
if (this[i + occurrence].opcode != pattern[occurrence]) break
|
val n = this[i + occurrence]
|
||||||
|
if (
|
||||||
|
!n.anyOf(
|
||||||
|
typeOf<LabelNode>(),
|
||||||
|
typeOf<LineNumberNode>()
|
||||||
|
) &&
|
||||||
|
n.opcode != pattern[occurrence]
|
||||||
|
) break
|
||||||
if (++occurrence >= pattern.size) {
|
if (++occurrence >= pattern.size) {
|
||||||
val current = i + occurrence
|
val current = i + occurrence
|
||||||
return ScanResult(true, current - pattern.size, current)
|
return ScanResult(true, current - pattern.size, current)
|
||||||
|
@ -151,7 +160,6 @@ private fun Array<Type>.convertObjects(): Array<Type> {
|
||||||
return this.map { it.convertObject() }.toTypedArray()
|
return this.map { it.convertObject() }.toTypedArray()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun InsnList.stripLabels(): InsnList {
|
private fun AbstractInsnNode.anyOf(vararg types: KType): Boolean {
|
||||||
this.removeAll { it is LabelNode || it is LineNumberNode }
|
return types.any { it.javaClass.isAssignableFrom(this.javaClass) }
|
||||||
return this
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue