eval4j: cleanup 'public', property access syntax
This commit is contained in:
@@ -25,25 +25,25 @@ import org.jetbrains.org.objectweb.asm.tree.analysis.Interpreter
|
|||||||
|
|
||||||
class UnsupportedByteCodeException(message: String) : RuntimeException(message)
|
class UnsupportedByteCodeException(message: String) : RuntimeException(message)
|
||||||
|
|
||||||
public interface Eval {
|
interface Eval {
|
||||||
public fun loadClass(classType: Type): Value
|
fun loadClass(classType: Type): Value
|
||||||
public fun loadString(str: String): Value
|
fun loadString(str: String): Value
|
||||||
public fun newInstance(classType: Type): Value
|
fun newInstance(classType: Type): Value
|
||||||
public fun isInstanceOf(value: Value, targetType: Type): Boolean
|
fun isInstanceOf(value: Value, targetType: Type): Boolean
|
||||||
|
|
||||||
public fun newArray(arrayType: Type, size: Int): Value
|
fun newArray(arrayType: Type, size: Int): Value
|
||||||
public fun newMultiDimensionalArray(arrayType: Type, dimensionSizes: List<Int>): Value
|
fun newMultiDimensionalArray(arrayType: Type, dimensionSizes: List<Int>): Value
|
||||||
public fun getArrayLength(array: Value): Value
|
fun getArrayLength(array: Value): Value
|
||||||
public fun getArrayElement(array: Value, index: Value): Value
|
fun getArrayElement(array: Value, index: Value): Value
|
||||||
public fun setArrayElement(array: Value, index: Value, newValue: Value)
|
fun setArrayElement(array: Value, index: Value, newValue: Value)
|
||||||
|
|
||||||
public fun getStaticField(fieldDesc: FieldDescription): Value
|
fun getStaticField(fieldDesc: FieldDescription): Value
|
||||||
public fun setStaticField(fieldDesc: FieldDescription, newValue: Value)
|
fun setStaticField(fieldDesc: FieldDescription, newValue: Value)
|
||||||
public fun invokeStaticMethod(methodDesc: MethodDescription, arguments: List<Value>): Value
|
fun invokeStaticMethod(methodDesc: MethodDescription, arguments: List<Value>): Value
|
||||||
|
|
||||||
public fun getField(instance: Value, fieldDesc: FieldDescription): Value
|
fun getField(instance: Value, fieldDesc: FieldDescription): Value
|
||||||
public fun setField(instance: Value, fieldDesc: FieldDescription, newValue: Value)
|
fun setField(instance: Value, fieldDesc: FieldDescription, newValue: Value)
|
||||||
public fun invokeMethod(instance: Value, methodDesc: MethodDescription, arguments: List<Value>, invokespecial: Boolean = false): Value
|
fun invokeMethod(instance: Value, methodDesc: MethodDescription, arguments: List<Value>, invokespecial: Boolean = false): Value
|
||||||
}
|
}
|
||||||
|
|
||||||
class SingleInstructionInterpreter(private val eval: Eval) : Interpreter<Value>(ASM5) {
|
class SingleInstructionInterpreter(private val eval: Eval) : Interpreter<Value>(ASM5) {
|
||||||
@@ -203,7 +203,7 @@ class SingleInstructionInterpreter(private val eval: Eval) : Interpreter<Value>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun checkUnaryCondition(value: Value, opcode: Int): Boolean {
|
fun checkUnaryCondition(value: Value, opcode: Int): Boolean {
|
||||||
return when (opcode) {
|
return when (opcode) {
|
||||||
IFEQ -> value.int == 0
|
IFEQ -> value.int == 0
|
||||||
IFNE -> value.int != 0
|
IFNE -> value.int != 0
|
||||||
@@ -312,7 +312,7 @@ class SingleInstructionInterpreter(private val eval: Eval) : Interpreter<Value>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun checkBinaryCondition(value1: Value, value2: Value, opcode: Int): Boolean {
|
fun checkBinaryCondition(value1: Value, value2: Value, opcode: Int): Boolean {
|
||||||
return when (opcode) {
|
return when (opcode) {
|
||||||
IF_ICMPEQ -> value1.int == value2.int
|
IF_ICMPEQ -> value1.int == value2.int
|
||||||
IF_ICMPNE -> value1.int != value2.int
|
IF_ICMPNE -> value1.int != value2.int
|
||||||
|
|||||||
@@ -24,29 +24,29 @@ import org.jetbrains.org.objectweb.asm.tree.analysis.Frame
|
|||||||
import org.jetbrains.org.objectweb.asm.util.Printer
|
import org.jetbrains.org.objectweb.asm.util.Printer
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
public interface InterpreterResult {
|
interface InterpreterResult {
|
||||||
override fun toString(): String
|
override fun toString(): String
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ExceptionThrown(public val exception: ObjectValue, public val kind: ExceptionKind): InterpreterResult {
|
class ExceptionThrown(val exception: ObjectValue, val kind: ExceptionKind): InterpreterResult {
|
||||||
override fun toString(): String = "Thrown $exception: $kind"
|
override fun toString(): String = "Thrown $exception: $kind"
|
||||||
|
|
||||||
public enum class ExceptionKind {
|
enum class ExceptionKind {
|
||||||
FROM_EVALUATED_CODE,
|
FROM_EVALUATED_CODE,
|
||||||
FROM_EVALUATOR,
|
FROM_EVALUATOR,
|
||||||
BROKEN_CODE
|
BROKEN_CODE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public data class ValueReturned(public val result: Value): InterpreterResult {
|
data class ValueReturned(val result: Value): InterpreterResult {
|
||||||
override fun toString(): String = "Returned $result"
|
override fun toString(): String = "Returned $result"
|
||||||
}
|
}
|
||||||
|
|
||||||
public class AbnormalTermination(public val message: String): InterpreterResult {
|
class AbnormalTermination(val message: String): InterpreterResult {
|
||||||
override fun toString(): String = "Terminated abnormally: $message"
|
override fun toString(): String = "Terminated abnormally: $message"
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface InterpretationEventHandler {
|
interface InterpretationEventHandler {
|
||||||
object NONE : InterpretationEventHandler {
|
object NONE : InterpretationEventHandler {
|
||||||
override fun instructionProcessed(insn: AbstractInsnNode): InterpreterResult? = null
|
override fun instructionProcessed(insn: AbstractInsnNode): InterpreterResult? = null
|
||||||
override fun exceptionThrown(currentState: Frame<Value>, currentInsn: AbstractInsnNode, exception: Value): InterpreterResult? = null
|
override fun exceptionThrown(currentState: Frame<Value>, currentInsn: AbstractInsnNode, exception: Value): InterpreterResult? = null
|
||||||
@@ -71,7 +71,7 @@ class ThrownFromEvaluatedCodeException(val exception: ObjectValue): RuntimeExcep
|
|||||||
override fun toString(): String = "Thrown from evaluated code: $exception"
|
override fun toString(): String = "Thrown from evaluated code: $exception"
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun interpreterLoop(
|
fun interpreterLoop(
|
||||||
m: MethodNode,
|
m: MethodNode,
|
||||||
initialState: Frame<Value>,
|
initialState: Frame<Value>,
|
||||||
eval: Eval,
|
eval: Eval,
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ val CLASS = Type.getType(Class::class.java)
|
|||||||
val OBJECT = Type.getType(Any::class.java)
|
val OBJECT = Type.getType(Any::class.java)
|
||||||
val BOOTSTRAP_CLASS_DESCRIPTORS = setOf("Ljava/lang/String;", "Ljava/lang/ClassLoader;", "Ljava/lang/Class;")
|
val BOOTSTRAP_CLASS_DESCRIPTORS = setOf("Ljava/lang/String;", "Ljava/lang/ClassLoader;", "Ljava/lang/Class;")
|
||||||
|
|
||||||
public class JDIEval(
|
class JDIEval(
|
||||||
private val vm: VirtualMachine,
|
private val vm: VirtualMachine,
|
||||||
private val defaultClassLoader: ClassLoaderReference?,
|
private val defaultClassLoader: ClassLoaderReference?,
|
||||||
private val thread: ThreadReference,
|
private val thread: ThreadReference,
|
||||||
@@ -251,7 +251,7 @@ public class JDIEval(
|
|||||||
mayThrow { obj.setValue(field, jdiValue) }
|
mayThrow { obj.setValue(field, jdiValue) }
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun unboxType(boxedValue: Value, type: Type): Value {
|
fun unboxType(boxedValue: Value, type: Type): Value {
|
||||||
val method = when (type) {
|
val method = when (type) {
|
||||||
Type.INT_TYPE -> MethodDescription("java/lang/Integer", "intValue", "()I", false)
|
Type.INT_TYPE -> MethodDescription("java/lang/Integer", "intValue", "()I", false)
|
||||||
Type.BOOLEAN_TYPE -> MethodDescription("java/lang/Boolean", "booleanValue", "()Z", false)
|
Type.BOOLEAN_TYPE -> MethodDescription("java/lang/Boolean", "booleanValue", "()Z", false)
|
||||||
@@ -266,7 +266,7 @@ public class JDIEval(
|
|||||||
return invokeMethod(boxedValue, method, listOf(), true)
|
return invokeMethod(boxedValue, method, listOf(), true)
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun boxType(value: Value): Value {
|
fun boxType(value: Value): Value {
|
||||||
val method = when (value.asmType) {
|
val method = when (value.asmType) {
|
||||||
Type.INT_TYPE -> MethodDescription("java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;", false)
|
Type.INT_TYPE -> MethodDescription("java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;", false)
|
||||||
Type.BYTE_TYPE -> MethodDescription("java/lang/Byte", "valueOf", "(B)Ljava/lang/Byte;", false)
|
Type.BYTE_TYPE -> MethodDescription("java/lang/Byte", "valueOf", "(B)Ljava/lang/Byte;", false)
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ import com.sun.jdi.Type as jdi_Type
|
|||||||
import com.sun.jdi.Value as jdi_Value
|
import com.sun.jdi.Value as jdi_Value
|
||||||
import com.sun.jdi.VoidValue as jdi_VoidValue
|
import com.sun.jdi.VoidValue as jdi_VoidValue
|
||||||
|
|
||||||
public fun makeInitialFrame(methodNode: MethodNode, arguments: List<Value>): Frame<Value> {
|
fun makeInitialFrame(methodNode: MethodNode, arguments: List<Value>): Frame<Value> {
|
||||||
val isStatic = (methodNode.access and ACC_STATIC) != 0
|
val isStatic = (methodNode.access and ACC_STATIC) != 0
|
||||||
|
|
||||||
val params = Type.getArgumentTypes(methodNode.desc)
|
val params = Type.getArgumentTypes(methodNode.desc)
|
||||||
@@ -64,14 +64,14 @@ public fun makeInitialFrame(methodNode: MethodNode, arguments: List<Value>): Fra
|
|||||||
|
|
||||||
class JDIFailureException(message: String?, cause: Throwable? = null): RuntimeException(message, cause)
|
class JDIFailureException(message: String?, cause: Throwable? = null): RuntimeException(message, cause)
|
||||||
|
|
||||||
public fun jdi_ObjectReference?.asValue(): ObjectValue {
|
fun jdi_ObjectReference?.asValue(): ObjectValue {
|
||||||
return when (this) {
|
return when (this) {
|
||||||
null -> NULL_VALUE
|
null -> NULL_VALUE
|
||||||
else -> ObjectValue(this, type().asType())
|
else -> ObjectValue(this, type().asType())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun jdi_Value?.asValue(): Value {
|
fun jdi_Value?.asValue(): Value {
|
||||||
return when (this) {
|
return when (this) {
|
||||||
null -> NULL_VALUE
|
null -> NULL_VALUE
|
||||||
is jdi_VoidValue -> VOID_VALUE
|
is jdi_VoidValue -> VOID_VALUE
|
||||||
@@ -96,7 +96,7 @@ val Value.jdiObj: jdi_ObjectReference?
|
|||||||
val Value.jdiClass: ClassObjectReference?
|
val Value.jdiClass: ClassObjectReference?
|
||||||
get() = this.jdiObj as ClassObjectReference?
|
get() = this.jdiObj as ClassObjectReference?
|
||||||
|
|
||||||
public fun Value.asJdiValue(vm: VirtualMachine, expectedType: Type): jdi_Value? {
|
fun Value.asJdiValue(vm: VirtualMachine, expectedType: Type): jdi_Value? {
|
||||||
return when (this) {
|
return when (this) {
|
||||||
NULL_VALUE -> null
|
NULL_VALUE -> null
|
||||||
VOID_VALUE -> vm.mirrorOfVoid()
|
VOID_VALUE -> vm.mirrorOfVoid()
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ val MethodDescription.parameterTypes: List<Type>
|
|||||||
get() = Type.getArgumentTypes(desc).toList()
|
get() = Type.getArgumentTypes(desc).toList()
|
||||||
|
|
||||||
|
|
||||||
public class FieldDescription(
|
class FieldDescription(
|
||||||
ownerInternalName: String,
|
ownerInternalName: String,
|
||||||
name: String,
|
name: String,
|
||||||
desc: String,
|
desc: String,
|
||||||
|
|||||||
@@ -19,9 +19,9 @@ package org.jetbrains.eval4j
|
|||||||
import org.jetbrains.org.objectweb.asm.Type
|
import org.jetbrains.org.objectweb.asm.Type
|
||||||
import org.jetbrains.org.objectweb.asm.tree.LabelNode
|
import org.jetbrains.org.objectweb.asm.tree.LabelNode
|
||||||
|
|
||||||
public interface Value : org.jetbrains.org.objectweb.asm.tree.analysis.Value {
|
interface Value : org.jetbrains.org.objectweb.asm.tree.analysis.Value {
|
||||||
public val asmType: Type
|
val asmType: Type
|
||||||
public val valid: Boolean
|
val valid: Boolean
|
||||||
override fun getSize(): Int = asmType.size
|
override fun getSize(): Int = asmType.size
|
||||||
|
|
||||||
override fun toString(): String
|
override fun toString(): String
|
||||||
@@ -57,7 +57,7 @@ abstract class AbstractValueBase<V>(
|
|||||||
override val asmType: Type
|
override val asmType: Type
|
||||||
) : Value {
|
) : Value {
|
||||||
override val valid = true
|
override val valid = true
|
||||||
public abstract val value: V
|
abstract val value: V
|
||||||
|
|
||||||
override fun toString() = "$value: $asmType"
|
override fun toString() = "$value: $asmType"
|
||||||
|
|
||||||
@@ -81,7 +81,7 @@ class IntValue(value: Int, asmType: Type): AbstractValue<Int>(value, asmType)
|
|||||||
class LongValue(value: Long): AbstractValue<Long>(value, Type.LONG_TYPE)
|
class LongValue(value: Long): AbstractValue<Long>(value, Type.LONG_TYPE)
|
||||||
class FloatValue(value: Float): AbstractValue<Float>(value, Type.FLOAT_TYPE)
|
class FloatValue(value: Float): AbstractValue<Float>(value, Type.FLOAT_TYPE)
|
||||||
class DoubleValue(value: Double): AbstractValue<Double>(value, Type.DOUBLE_TYPE)
|
class DoubleValue(value: Double): AbstractValue<Double>(value, Type.DOUBLE_TYPE)
|
||||||
public open class ObjectValue(value: Any?, asmType: Type): AbstractValue<Any?>(value, asmType)
|
open class ObjectValue(value: Any?, asmType: Type): AbstractValue<Any?>(value, asmType)
|
||||||
class NewObjectValue(asmType: Type): ObjectValue(null, asmType) {
|
class NewObjectValue(asmType: Type): ObjectValue(null, asmType) {
|
||||||
override var value: Any? = null
|
override var value: Any? = null
|
||||||
get(): Any? {
|
get(): Any? {
|
||||||
|
|||||||
Reference in New Issue
Block a user