diff --git a/deob/src/main/java/dev/openrs2/deob/analysis/ConstSourceInterpreter.java b/deob/src/main/java/dev/openrs2/deob/analysis/ConstSourceInterpreter.java deleted file mode 100644 index 72750abf21..0000000000 --- a/deob/src/main/java/dev/openrs2/deob/analysis/ConstSourceInterpreter.java +++ /dev/null @@ -1,117 +0,0 @@ -package dev.openrs2.deob.analysis; - -import java.util.List; - -import com.google.common.collect.ImmutableList; -import dev.openrs2.asm.InsnNodeUtilsKt; -import org.objectweb.asm.Opcodes; -import org.objectweb.asm.Type; -import org.objectweb.asm.tree.AbstractInsnNode; -import org.objectweb.asm.tree.analysis.AnalyzerException; -import org.objectweb.asm.tree.analysis.BasicInterpreter; -import org.objectweb.asm.tree.analysis.BasicValue; -import org.objectweb.asm.tree.analysis.Interpreter; - -public final class ConstSourceInterpreter extends Interpreter { - private final Interpreter basicInterpreter = new BasicInterpreter(); - - public ConstSourceInterpreter() { - super(Opcodes.ASM7); - } - - @Override - public ConstSourceValue newValue(Type type) { - var basicValue = basicInterpreter.newValue(type); - if (basicValue == null) { - return null; - } - - return ConstSourceValue.createUnknown(basicValue); - } - - @Override - public ConstSourceValue newOperation(AbstractInsnNode insn) throws AnalyzerException { - var basicValue = basicInterpreter.newOperation(insn); - if (basicValue == null) { - return null; - } - - if (InsnNodeUtilsKt.getIntConstant(insn) != null) { - return ConstSourceValue.createSingleSourceConstant(basicValue, insn); - } - - return ConstSourceValue.createUnknown(basicValue); - } - - @Override - public ConstSourceValue copyOperation(AbstractInsnNode insn, ConstSourceValue value) throws AnalyzerException { - var basicValue = basicInterpreter.copyOperation(insn, value.getBasicValue()); - if (basicValue == null) { - return null; - } - - return ConstSourceValue.createUnknown(basicValue); - } - - @Override - public ConstSourceValue unaryOperation(AbstractInsnNode insn, ConstSourceValue value) throws AnalyzerException { - var basicValue = basicInterpreter.unaryOperation(insn, value.getBasicValue()); - if (basicValue == null) { - return null; - } - - return ConstSourceValue.createUnknown(basicValue); - } - - @Override - public ConstSourceValue binaryOperation(AbstractInsnNode insn, ConstSourceValue value1, ConstSourceValue value2) throws AnalyzerException { - var basicValue = basicInterpreter.binaryOperation(insn, value1.getBasicValue(), value2.getBasicValue()); - if (basicValue == null) { - return null; - } - - return ConstSourceValue.createUnknown(basicValue); - } - - @Override - public ConstSourceValue ternaryOperation(AbstractInsnNode insn, ConstSourceValue value1, ConstSourceValue value2, ConstSourceValue value3) throws AnalyzerException { - var basicValue = basicInterpreter.ternaryOperation(insn, value1.getBasicValue(), value2.getBasicValue(), value3.getBasicValue()); - if (basicValue == null) { - return null; - } - - return ConstSourceValue.createUnknown(basicValue); - } - - @Override - public ConstSourceValue naryOperation(AbstractInsnNode insn, List values) throws AnalyzerException { - var args = values.stream() - .map(ConstSourceValue::getBasicValue) - .collect(ImmutableList.toImmutableList()); - var basicValue = basicInterpreter.naryOperation(insn, args); - if (basicValue == null) { - return null; - } - - return ConstSourceValue.createUnknown(basicValue); - } - - @Override - public void returnOperation(AbstractInsnNode insn, ConstSourceValue value, ConstSourceValue expected) throws AnalyzerException { - basicInterpreter.returnOperation(insn, value.getBasicValue(), expected.getBasicValue()); - } - - @Override - public ConstSourceValue merge(ConstSourceValue value1, ConstSourceValue value2) { - var basicValue = basicInterpreter.merge(value1.getBasicValue(), value2.getBasicValue()); - if (basicValue == null) { - return null; - } - - if (value1.isSingleSourceConstant() && value1.equals(value2)) { - return value1; - } - - return ConstSourceValue.createUnknown(basicValue); - } -} diff --git a/deob/src/main/java/dev/openrs2/deob/analysis/ConstSourceInterpreter.kt b/deob/src/main/java/dev/openrs2/deob/analysis/ConstSourceInterpreter.kt new file mode 100644 index 0000000000..da4706a997 --- /dev/null +++ b/deob/src/main/java/dev/openrs2/deob/analysis/ConstSourceInterpreter.kt @@ -0,0 +1,92 @@ +package dev.openrs2.deob.analysis + +import dev.openrs2.asm.intConstant +import org.objectweb.asm.Opcodes +import org.objectweb.asm.Type +import org.objectweb.asm.tree.AbstractInsnNode +import org.objectweb.asm.tree.analysis.AnalyzerException +import org.objectweb.asm.tree.analysis.BasicInterpreter +import org.objectweb.asm.tree.analysis.Interpreter + +class ConstSourceInterpreter : Interpreter(Opcodes.ASM7) { + private val basicInterpreter = BasicInterpreter() + + override fun newValue(type: Type?): ConstSourceValue? { + val basicValue = basicInterpreter.newValue(type) ?: return null + return ConstSourceValue.createUnknown(basicValue) + } + + @Throws(AnalyzerException::class) + override fun newOperation(insn: AbstractInsnNode): ConstSourceValue { + val basicValue = basicInterpreter.newOperation(insn) + return if (insn.intConstant != null) { + ConstSourceValue.createSingleSourceConstant(basicValue, insn) + } else { + ConstSourceValue.createUnknown(basicValue) + } + } + + @Throws(AnalyzerException::class) + override fun copyOperation(insn: AbstractInsnNode, value: ConstSourceValue): ConstSourceValue { + val basicValue = basicInterpreter.copyOperation(insn, value.basicValue) + return ConstSourceValue.createUnknown(basicValue) + } + + @Throws(AnalyzerException::class) + override fun unaryOperation(insn: AbstractInsnNode, value: ConstSourceValue): ConstSourceValue? { + val basicValue = basicInterpreter.unaryOperation(insn, value.basicValue) ?: return null + return ConstSourceValue.createUnknown(basicValue) + } + + @Throws(AnalyzerException::class) + override fun binaryOperation( + insn: AbstractInsnNode, + value1: ConstSourceValue, + value2: ConstSourceValue + ): ConstSourceValue? { + val basicValue = + basicInterpreter.binaryOperation(insn, value1.basicValue, value2.basicValue) + ?: return null + return ConstSourceValue.createUnknown(basicValue) + } + + @Throws(AnalyzerException::class) + override fun ternaryOperation( + insn: AbstractInsnNode, + value1: ConstSourceValue, + value2: ConstSourceValue, + value3: ConstSourceValue + ): ConstSourceValue? { + val basicValue = basicInterpreter.ternaryOperation( + insn, + value1.basicValue, + value2.basicValue, + value3.basicValue + ) ?: return null + return ConstSourceValue.createUnknown(basicValue) + } + + @Throws(AnalyzerException::class) + override fun naryOperation( + insn: AbstractInsnNode, + values: List + ): ConstSourceValue? { + val args = values.map { it.basicValue }.toList() + val basicValue = basicInterpreter.naryOperation(insn, args) ?: return null + return ConstSourceValue.createUnknown(basicValue) + } + + @Throws(AnalyzerException::class) + override fun returnOperation(insn: AbstractInsnNode, value: ConstSourceValue, expected: ConstSourceValue) { + basicInterpreter.returnOperation(insn, value.basicValue, expected.basicValue) + } + + override fun merge(value1: ConstSourceValue, value2: ConstSourceValue): ConstSourceValue { + val basicValue = basicInterpreter.merge(value1.basicValue, value2.basicValue) + return if (value1.isSingleSourceConstant && value1 == value2) { + value1 + } else { + ConstSourceValue.createUnknown(basicValue) + } + } +}