Open-source multiplayer game server compatible with the RuneScape client
https://www.openrs2.org/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
3.4 KiB
89 lines
3.4 KiB
3 years ago
|
package org.openrs2.deob.bytecode.analysis
|
||
5 years ago
|
|
||
|
import org.objectweb.asm.Opcodes
|
||
|
import org.objectweb.asm.Type
|
||
|
import org.objectweb.asm.tree.AbstractInsnNode
|
||
|
import org.objectweb.asm.tree.analysis.BasicInterpreter
|
||
|
import org.objectweb.asm.tree.analysis.Interpreter
|
||
4 years ago
|
import org.openrs2.asm.intConstant
|
||
5 years ago
|
|
||
4 years ago
|
public class ConstSourceInterpreter : Interpreter<ConstSourceValue>(Opcodes.ASM9) {
|
||
5 years ago
|
private val basicInterpreter = BasicInterpreter()
|
||
|
|
||
|
override fun newValue(type: Type?): ConstSourceValue? {
|
||
|
val basicValue = basicInterpreter.newValue(type) ?: return null
|
||
4 years ago
|
return ConstSourceValue.Unknown(basicValue)
|
||
5 years ago
|
}
|
||
|
|
||
4 years ago
|
override fun newParameterValue(isInstanceMethod: Boolean, local: Int, type: Type): ConstSourceValue {
|
||
|
val basicValue = basicInterpreter.newParameterValue(isInstanceMethod, local, type)
|
||
|
return ConstSourceValue.Arg(basicValue)
|
||
|
}
|
||
|
|
||
5 years ago
|
override fun newOperation(insn: AbstractInsnNode): ConstSourceValue {
|
||
|
val basicValue = basicInterpreter.newOperation(insn)
|
||
|
return if (insn.intConstant != null) {
|
||
4 years ago
|
ConstSourceValue.Insn(basicValue, insn)
|
||
5 years ago
|
} else {
|
||
4 years ago
|
ConstSourceValue.Unknown(basicValue)
|
||
5 years ago
|
}
|
||
|
}
|
||
|
|
||
|
override fun copyOperation(insn: AbstractInsnNode, value: ConstSourceValue): ConstSourceValue {
|
||
|
val basicValue = basicInterpreter.copyOperation(insn, value.basicValue)
|
||
4 years ago
|
return ConstSourceValue.Unknown(basicValue)
|
||
5 years ago
|
}
|
||
|
|
||
|
override fun unaryOperation(insn: AbstractInsnNode, value: ConstSourceValue): ConstSourceValue? {
|
||
|
val basicValue = basicInterpreter.unaryOperation(insn, value.basicValue) ?: return null
|
||
4 years ago
|
return ConstSourceValue.Unknown(basicValue)
|
||
5 years ago
|
}
|
||
|
|
||
|
override fun binaryOperation(
|
||
|
insn: AbstractInsnNode,
|
||
|
value1: ConstSourceValue,
|
||
|
value2: ConstSourceValue
|
||
|
): ConstSourceValue? {
|
||
5 years ago
|
val basicValue = basicInterpreter.binaryOperation(insn, value1.basicValue, value2.basicValue)
|
||
|
?: return null
|
||
4 years ago
|
return ConstSourceValue.Unknown(basicValue)
|
||
5 years ago
|
}
|
||
|
|
||
|
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
|
||
4 years ago
|
return ConstSourceValue.Unknown(basicValue)
|
||
5 years ago
|
}
|
||
|
|
||
|
override fun naryOperation(
|
||
|
insn: AbstractInsnNode,
|
||
|
values: List<ConstSourceValue>
|
||
|
): ConstSourceValue? {
|
||
4 years ago
|
val args = values.map(ConstSourceValue::basicValue)
|
||
5 years ago
|
val basicValue = basicInterpreter.naryOperation(insn, args) ?: return null
|
||
4 years ago
|
return ConstSourceValue.Unknown(basicValue)
|
||
5 years ago
|
}
|
||
|
|
||
|
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)
|
||
4 years ago
|
return when {
|
||
|
value1 is ConstSourceValue.Arg || value2 is ConstSourceValue.Arg -> ConstSourceValue.Arg(basicValue)
|
||
|
value1 == value2 -> value1
|
||
|
else -> ConstSourceValue.Unknown(basicValue)
|
||
5 years ago
|
}
|
||
|
}
|
||
|
}
|