def Execute(self, frame:rtda.Frame): currentClass = frame.Method().Class() cp = frame.Method().Class().ConstantPool() methodRef = cp.GetConstant(self.Index) resolvedMethod = methodRef.ResolvedMethod() if resolvedMethod.IsStatic(): raise ValueError("java.lang.IncompatibleClassChangeError") ref = frame.OperandStack().GetRefFromTop(resolvedMethod.ArgSlotCount() - 1) if ref == None: # hack System.out.println() if methodRef.Name() == "println": _println(frame.OperandStack(), methodRef.Descriptor()) return raise ValueError("java.lang.NullPointerException") if resolvedMethod.IsProtected() and \ resolvedMethod.Class().IsSuperClassOf(currentClass) and \ resolvedMethod.Class().GetPackageName() != currentClass.GetPackageName() and \ ref.Class() != currentClass and \ not ref.Class().IsSubClassOf(currentClass): raise ValueError("java.lang.IllegalAccessError") methodToBeInvoked = rtda.heap.lookupMethodInClass(ref.Class(), \ methodRef.Name(), methodRef.Descriptor()) if methodToBeInvoked == None or methodToBeInvoked.IsAbstract(): raise ValueError("java.lang.AbstractMethodError") instructions.base.InvokeMethod(frame, methodToBeInvoked)
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())
def Execute(self, frame:rtda.Frame): cp = frame.Method().Class().ConstantPool() fieldRef = cp.GetConstant(self.Index) field = fieldRef.ResolvedField() if field.IsStatic(): raise ValueError("java.lang.IncompatibleClassChangeError") stack = frame.OperandStack() ref = stack.PopRef() if ref == None: raise ValueError("java.lang.NullPointerException") descriptor = field.Descriptor() slotId = field.SlotId() slots = ref.Fields() 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))
def Execute(self, frame: rtda.Frame): stack = frame.OperandStack() slot1 = stack.PopSlot() slot2 = stack.PopSlot() stack.PushSlot(slot1) stack.PushSlot(slot2) stack.PushSLot(copy.deepcopy(slot1))
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))
def Execute(self, frame: rtda.Frame): stack = frame.OperandStack() v2 = stack.PopLong() v1 = statk.PopLong() if v2 == 0: raise ("java.lang.ArithmeticException: / by zero") result = v1 / v2 stack.PushLong(result)
def Execute(self, frame: rtda.Frame): stack = frame.OperandStack() v2 = stack.PopInt() v1 = stack.PopLong() bits = struct.pack('>i', v2) s = struct.unpack('>I', bits)[0] & 0x3f result = v1 >> s stack.PushLong(result)
def Execute(self, frame: rtda.Frame): key = frame.OperandStack().PopInt() for i in range(0, self.npairs * 2, 2): if self.matchOffsets[i] == key: offset = self.matchOffsets[i + 1] instructions.base.Branch(frame, int(offset)) return instructions.base.Branch(frame, int(self.defaultOffset))
def Execute(self, frame: rtda.Frame): index = frame.OperandStack().PopInt() offset = 0 if index >= self.low and index <= self.high: offset = int(self.jumpOffsets[index - self.low]) else: offset = int(self.defaultOffset) instructions.base.Branch(frame, offset)
def Execute(self, frame: rtda.Frame): stack = frame.OperandStack() v2 = stack.PopLong() v1 = stack.PopLong() if v1 > v2: stack.PushInt(1) elif v1 == v2: stack.PushInt(0) else: stack.PushInt(-1)
def Execute(self, frame: rtda.Frame): stack = frame.OperandStack() v2 = stack.PopInt() v1 = stack.PopLong() bits = struct.pack('>i', v2) s = struct.unpack('>I', bits)[0] & 0x1f bits1 = struct.pack('>l', v1) s1 = struct.unpack('>L', bits1)[0] result = struct.unpack('>l', struct.pack('>L', s1 >> s))[0] stack.PushInt(result)
def Execute(self, frame: rtda.Frame): stack = frame.OperandStack() cp = frame.Method().Class().ConstantPool() c = cp.GetConstant(self.Index) if isinstance(c, int): stack.PushLong(c) elif isinstance(c, float): stack.PushDouble(c) else: raise ValueError("java.lang.ClassFormatError")
def _ldc(frame: rtda.Frame, index: int): stack = frame.OperandStack() cp = frame.Method().Class().ConstantPool() c = cp.GetConstant(index) if isinstance(c, int): stack.PushInt(c) elif isinstance(c, float): stack.PushFloat(c) else: raise ValueError("todo: ldc!")
def _dcmp(frame: rtda.Frame, gFlag: bool): statck = frame.OperandStack() v2 = stack.PopDouble() v1 = stack.PopDouble() if v1 > v2: stack.PushInt(1) elif v1 == v2: stack.PushInt(0) elif v1 < v2: stack.PushInt(-1) else: stack.PushInt(-1)
def Execute(self, frame:rtda.Frame): stack = frame.OperandStack() ref = stack.PopRef() stack.PushRef(ref) if ref == None: return cp = frame.Method().Class().ConstantPool() classRef = cp.GetConstant(self.Index) _class = classRef.ResolvedClass() if not ref.IsInstanceOf(_class): raise ValueError("java.lang.ClassCastException")
def Execute(self, frame:rtda.Frame): stack = frame.OperandStack() ref = stack.PopRef() if ref == None: stack.PushInt(0) return cp = frame.Method().Class().ConstantPool() classRef = cp.GetConstant(self.Index) _class = classRef.ResolvedClass() if ref.IsInstanceOf(_class): stack.PushInt(1) else: stack.PushInt(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)
def Execute(self, frame:rtda.Frame): currentMethod = frame.Method() currentClass = currentMethod.Class() cp = currentClass.ConstantPool() fieldRef = cp.GetConstant(self.Index) field = fieldRef.ResolvedField() if field.IsStatic(): raise ValueError("java.lang.IncompatibleClassChangeError") if field.IsFinal(): if currentClass != field.Class() or currentMethod.Nmae() != "<init>": raise ValueError("java.lang.IllegalAccessError") descriptor = field.Descriptor() slotId = field.SlotId() stack = frame.OperandStack() if descriptor[0] in ['Z','B','C','S','I']: val = stack.PopInt() ref = stack.PopRef() if ref == None: raise ValueError("java.lang.NullPointerException") ref.Fields().SetInt(slotId, val) elif descriptor[0] == 'F': val = stack.PopFloat() ref = stack.PopFloat() if ref == None: raise ValueError("java.lang.NullPointerException") ref.Fields().SetFloat(slotId, val) elif descriptor[0] == 'J': val = stack.PopLong() ref = stack.PopLong() if ref == None: raise ValueError("java.lang.NullPointerException") ref.Fields().SetLong(slotId, val) elif descriptor[0] == 'D': val = stack.PopDouble() ref = stack.PopDouble() if ref == None: raise ValueError("java.lang.NullPointerException") ref.Fields().SetDouble(slotId, val) elif descriptor[0] in ['L', '[']: val = stack.PopRef() ref = stack.PopRef() if ref == None: raise ValueError("java.lang.NullPointerException") ref.Fields().SetRef(slotId, val)
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()}" )
def Execute(self, frame:rtda.Frame): cp = frame.Method().Class().ConstantPool() methodRef = cp.GetConstant(self.index) resolvedMethod = methodRef.ResolvedInterfaceMethod() if resolvedMethod.IsStatic() or resolvedMethod.IsPrivate(): raise ValueError(f"java.lang.IncompativleClassChangeError") ref = frame.OperandStack().GetRefFromTop(resolvedMethod.ArgSlotCount() - 1) if ref == None: raise ValueError("java.lang.NullPointerException") if not ref.Class().IsImplements(methodRef.ResolvedClass()): raise ValueError(f"java.lang.IncompativleClassChangeError") methodToBeInvoked = rtda.heap.lookupMethodInClass(ref.Class(), \ methodRef.Name(), methodRef.Descriptor()) if methodToBeInvoked == None or methodToBeInvoked.IsAbstract(): raise ValueError("java.lang.AbstractMethodError") if not methodToBeInvoked.IsPublic(): raise ValueError("java.lang.IllegalAccessError") instructions.base.InvokeMethod(frame, methodToBeInvoked)
def _icmpPop(frame: rtda.Frame): stack = frame.OperandStack() val2 = stack.PopInt() val1 = stack.PopInt() return val1, val2
def _acmp(frame: rtda.Frame) -> bool: stack = frame.OperandStack() ref2 = stack.PopRef() ref1 = stack.PopRef() return ref1 == ref2 #todo
def Execute(self, frame: rtda.Frame): val = frame.OperandStack().PopInt() if val >= 0: instructions.base.Branch(frame, self.Offset)
def _fstore(frame: rtda.Frame, index): val = frame.OperandStack().PopFloat() frame.LocalVars().SetFloat(index, val)
def _istore(frame: rtda.Frame, index): val = frame.OperandStack().PopInt() frame.LocalVars().SetInt(index, val)
def _astore(frame: rtda.Frame, index): ref = frame.OperandStack().PopRef() frame.LocalVars().SetRef(index, ref)
def _dstore(frame: rtda.Frame, index): val = frame.OperandStack().PopDouble() frame.LocalVars().SetDouble(index, val)
def _lstore(frame: rtda.Frame, index): val = frame.OperandStack().PopLong() frame.LocalVars().SetLong(index, val)
def Execute(self, frame: rtda.Frame): stack = frame.OperandStack() i = stack.PopInt() d = struct.unpack('>d', struct.pack('>i', i))[0] stack.pushInt(d)
def Execute(self, frame: rtda.Frame): stack = frame.OperandStack() d = stack.PopDoulbe() f = struct.unpack('>f', struct.pack('>d', d))[0] stack.pushFloat(f)