From 400a10f8d2044fd1689ba521a6f88c7e8cdb7ae9 Mon Sep 17 00:00:00 2001 From: Graham Date: Mon, 27 Jan 2020 21:25:07 +0000 Subject: [PATCH] Add live variable analysis --- .../deob/analysis/LiveVariableAnalyzer.kt | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 deob/src/main/java/dev/openrs2/deob/analysis/LiveVariableAnalyzer.kt diff --git a/deob/src/main/java/dev/openrs2/deob/analysis/LiveVariableAnalyzer.kt b/deob/src/main/java/dev/openrs2/deob/analysis/LiveVariableAnalyzer.kt new file mode 100644 index 0000000000..924d154e20 --- /dev/null +++ b/deob/src/main/java/dev/openrs2/deob/analysis/LiveVariableAnalyzer.kt @@ -0,0 +1,30 @@ +package dev.openrs2.deob.analysis + +import org.objectweb.asm.Opcodes +import org.objectweb.asm.tree.AbstractInsnNode +import org.objectweb.asm.tree.IincInsnNode +import org.objectweb.asm.tree.MethodNode +import org.objectweb.asm.tree.VarInsnNode + +class LiveVariableAnalyzer(owner: String, method: MethodNode) : + DataFlowAnalyzer>(owner, method, backwards = true) { + override fun createInitialSet(): Set { + return emptySet() + } + + override fun join(set1: Set, set2: Set): Set { + return set1 union set2 + } + + override fun transfer(set: Set, insn: AbstractInsnNode): Set { + return when (insn) { + is VarInsnNode -> when (insn.opcode) { + Opcodes.ILOAD, Opcodes.LLOAD, Opcodes.FLOAD, Opcodes.DLOAD, Opcodes.ALOAD -> set.plus(insn.`var`) + Opcodes.ISTORE, Opcodes.LSTORE, Opcodes.FSTORE, Opcodes.DSTORE, Opcodes.ASTORE -> set.minus(insn.`var`) + else -> set + } + is IincInsnNode -> set.plus(insn.`var`) + else -> set + } + } +}