Exemplo n.º 1
0
    def Execute(self, frame:rtda.Frame):
        cp = frame.Method().Class().ConstantPool()
        fieldRef = cp.GetConstant(self.Index)
        field = fieldRef.ResolvedField()
        _class = field.Class()
        if not _class.InitStarted():
            frame.RevertNextPC()
            instructions.base.InitClass(frame.Thread(), _class)
            return

        if not field.IsStatic():
            raise ValueError("java.lang.IncompatibleClassChangeError")

        descriptor = field.Descriptor()
        slotId = field.SlotId()
        slots = _class.StaticVars()
        stack = frame.OperandStack()

        if descriptor[0] in ['Z','B','C','S','I']:
            stack.PushInt(slots.GetInt(slotId))
        elif descriptor[0] == 'F':
            stack.PushFloat(slots.GetFloat(slotId))
        elif descriptor[0] == 'J':
            stack.PushLong(slots.GetLong(slotId))
        elif descriptor[0] == 'D':
            stack.PushDouble(slots.GetDouble(slotId))
        elif descriptor[0] in ['L', '[']:
            stack.PushRef(slots.GetRef(slotId))
Exemplo n.º 2
0
    def Execute(self, frame:rtda.Frame):
        currentMethod = frame.Method()
        currentClass = currentMethod.Class()
        cp = currentClass.ConstantPool()
        fieldRef = cp.GetConstant(self.Index)
        field = fieldRef.ResolvedField()
        _class = field.Class()
        if not _class.InitStarted():
            frame.RevertNextPC()
            instructions.base.InitClass(frame.Thread(), _class)
            return

        if not field.IsStatic():
            raise ValueError("java.lang.IncompatibleClassChangeError")
        if field.IsFinal():
            if currentClass != _class or currentMethod.Name() != "<clinit>":
                raise ValueError("java.lang.IllegalAccessError")

        descriptor = field.Descriptor()
        slotId = field.SlotId()
        slots = _class.StaticVars()
        stack = frame.OperandStack()

        if descriptor[0] in ['Z','B','C','S','I']:
            slots.SetInt(slotId, stack.PopInt())
        elif descriptor[0] == 'F':
            slots.SetFloat(slotId, stack.PopFloat())
        elif descriptor[0] == 'J':
            slots.SetLong(slotId, stack.PopLong())
        elif descriptor[0] == 'D':
            slots.SetDouble(slotId, stack.PopDouble())
        elif descriptor[0] in ['L', '[']:
            slots.SetRef(slotId, stack.PopRef())
Exemplo n.º 3
0
    def Execute(self, frame:rtda.Frame):
        cp = frame.Method().Class().ConstantPool()
        methodRef = cp.GetConstant(self.Index)
        resolvedMethod = methodRef.ResolvedMethod()
        if not resolvedMethod.IsStatic():
            raise ValueError(f"java.lang.IncompativleClassChangeError")

        _class = resolvedMethod.Class()
        if not _class.InitStarted():
            frame.RevertNextPC()
            instructions.base.InitClass(frame.Thread(), _class)
            return

        instructions.base.InvokeMethod(frame, resolvedMethod)
Exemplo n.º 4
0
    def Execute(self, frame:rtda.Frame):
        cp = frame.Method().Class().ConstantPool()
        classRef = cp.GetConstant(self.Index)
        _class = classRef.ResolvedClass()

        if not _class.InitStarted():
            frame.RevertNextPC()
            instructions.base.InitClass(frame.Thread(), _class)
            return

        if _class.IsInterface() or _class.IsAbstract():
            raise ValueError("java.lang.InstantiationError")

        ref = _class.NewObject()
        frame.OperandStack().PushRef(ref)
Exemplo n.º 5
0
def InvokeMethod(invokerFrame: rtda.Frame, method: rtda.heap.Method):
    thread = invokerFrame.Thread()
    newFrame = thread.NewFrame(method)
    thread.PushFrame(newFrame)

    argSlotCount = int(method.ArgSlotCount())
    if argSlotCount > 0:
        for i in range(argSlotCount - 1, -1, -1):
            slot = invokerFrame.OperandStack().PopSlot()
            newFrame.LocalVars().SetSlot(i, slot)

    # hack
    if method.IsNative():
        if method.Name() == "registerNatives":
            thread.PopFrame()
        else:
            raise ValueError(
                "native method {method.Class().Name()}.{method.Name()}{method.Descriptor()}"
            )
Exemplo n.º 6
0
 def Execute(self, frame: rtda.Frame):
     thread = frame.Thread()
     currentFrame = thread.PopFrame()
     invokerFrame = thread.TopFrame()
     retVal = currentFrame.OperandStack().PopLong()
     invokerFrame.OperandStack().PushLong(retVal)
Exemplo n.º 7
0
 def Execute(self, frame: rtda.Frame):
     thread = frame.Thread()
     currentFrame = thread.PopFrame()
     invokerFrame = thread.TopFrame()
     ref = currentFrame.OperandStack().PopRef()
     invokerFrame.OperandStack().PushRef(ref)
Exemplo n.º 8
0
 def Execute(self, frame: rtda.Frame):
     frame.Thread().PopFrame()
Exemplo n.º 9
0
def logInstruction(frame: rtda.Frame, inst: instructions.base.Instruction):
    method = frame.Method()
    className = method.Class().Name()
    methodName = method.Name()
    pc = frame.Thread().PC()
    print(f"{className}.{methodName} #{pc} {inst} {inst}")
Exemplo n.º 10
0
def Branch(frame: rtda.Frame, offset: int):
    pc = frame.Thread().PC()
    nextPC = pc + offset
    frame.SetNextPC(nextPC)