Replace Stream with Sequence

bzip2
Graham 5 years ago
parent 250062a72f
commit 06b8af41e2
  1. 9
      asm/src/main/java/dev/openrs2/asm/InsnMatcher.kt
  2. 4
      deob/src/main/java/dev/openrs2/deob/transform/OpaquePredicateTransformer.kt

@ -5,21 +5,18 @@ import org.objectweb.asm.tree.AbstractInsnNode
import org.objectweb.asm.tree.InsnList import org.objectweb.asm.tree.InsnList
import org.objectweb.asm.tree.MethodNode import org.objectweb.asm.tree.MethodNode
import org.objectweb.asm.util.Printer import org.objectweb.asm.util.Printer
import java.util.stream.Stream
import kotlin.streams.asStream
class InsnMatcher private constructor(private val regex: Regex) { class InsnMatcher private constructor(private val regex: Regex) {
// TODO(gpe): use Sequence<T> when the rest of the deobfuscator is ported to Kotlin fun match(method: MethodNode): Sequence<List<AbstractInsnNode>> {
fun match(method: MethodNode): Stream<List<AbstractInsnNode>> {
return match(method.instructions) return match(method.instructions)
} }
fun match(list: InsnList): Stream<List<AbstractInsnNode>> { fun match(list: InsnList): Sequence<List<AbstractInsnNode>> {
val insns = list.filter { it.opcode != -1 }.toList() val insns = list.filter { it.opcode != -1 }.toList()
val codepoints = insns.map { opcodeToCodepoint(it.opcode) }.toCharArray() val codepoints = insns.map { opcodeToCodepoint(it.opcode) }.toCharArray()
return regex.findAll(String(codepoints)).map { return regex.findAll(String(codepoints)).map {
insns.subList(it.range.first, it.range.last + 1) insns.subList(it.range.first, it.range.last + 1)
}.asStream() }
} }
companion object { companion object {

@ -67,10 +67,10 @@ class OpaquePredicateTransformer : Transformer() {
// flow obstructor loaded via local variable // flow obstructor loaded via local variable
val iload = load as VarInsnNode val iload = load as VarInsnNode
return STORE_MATCHER.match(method).anyMatch { return STORE_MATCHER.match(method).any {
val getstatic = it[0] as FieldInsnNode val getstatic = it[0] as FieldInsnNode
val istore = it[1] as VarInsnNode val istore = it[1] as VarInsnNode
return@anyMatch isFlowObstructor(getstatic) && iload.`var` == istore.`var` return@any isFlowObstructor(getstatic) && iload.`var` == istore.`var`
} }
} }

Loading…
Cancel
Save