Example #1
0
def invokespecial(frame):
    index = (ord(frame.code[frame.pc]) << 8) + ord(frame.code[frame.pc + 1])
    frame.pc += 2
    cp_item = frame.this_class.constant_pool[index]
    assert cp_item[0] == 10  # CONSTANT_Methodref
    klass_info = frame.this_class.constant_pool[cp_item[1]]
    assert klass_info[0] == 7  # CONSTANT_Class_info
    name_and_type = frame.this_class.constant_pool[cp_item[2]]
    assert name_and_type[0] == 12  # name_and_type_index
    klass_name = frame.this_class.constant_pool[klass_info[1]][1]
    klass = frame.vm.get_class(klass_name)
    method_name = frame.this_class.constant_pool[name_and_type[1]][1]
    method_signature = frame.this_class.constant_pool[name_and_type[2]][1]
    method = klass.find_method(method_name, method_signature)

    logger.debug(klass_name)
    logger.debug(method_name)
    logger.debug(method_signature)
    logger.debug(frame.stack)

    if is_spec_lookup(frame.this_class, klass, method_name):
        method = None
        c = frame.this_class.super_class
        while method is None:
            if c is None:
                break
            if (method_name in c.methods
                    and method_signature in c.methods[method_name]):
                method = c.methods[method_name][method_signature]
                klass = c
                break
            c = c.super_class

    assert method is not None

    nargs = args_count(method_signature) + 1
    args = [None] * nargs
    while nargs > 0:
        value = frame.stack.pop()
        if type(value) is tuple and value[0] in ('long', 'double'):
            nargs -= 1
        args[nargs - 1] = value
        nargs -= 1

    assert len(args[0]) > 0
    jassert_ref(args[0])

    if args[0] is None:
        frame.vm.raise_exception(frame, "java/lang/NullPointerException")
        return

    if method[0] & 0x0100 > 0:  # is native?
        exec_native(frame, args, klass, method_name, method_signature)
        return

    obj_mon = None
    if method[0] & 0x0020 > 0:  # is sync
        obj_mon = frame.vm.heap[args[0][1]]
        if "@monitor" in obj_mon.fields:
            if obj_mon.fields["@monitor"] == frame.thread:
                obj_mon.fields["@monitor_count"] += 1
            else:
                index = 0
                while index < len(args):
                    a = args[index]
                    if type(a) is tuple and a[0] in ('long', 'double'):
                        index += 1
                    else:
                        frame.stack.append(a)
                    index += 1
                raise SkipThreadCycle()
        else:
            obj_mon.fields["@monitor"] = frame.thread
            obj_mon.fields["@monitor_count"] = 1

    m_args = [''] * method[1]
    m_args[0:len(args)] = args[0:len(args)]

    instance = frame.vm.heap[args[0][1]]
    logger.debug("InvokeSpec: %s:%s %s", method_name, method_signature,
                 instance)
    sub = Frame(frame.thread, klass, method, m_args,
                "%s:%s %s" % (method_name, method_signature, instance))
    if obj_mon is not None:
        sub.monitor = obj_mon
    frame.thread.frame_stack.append(sub)
Example #2
0
def invokevirtual(frame):
    index = (ord(frame.code[frame.pc]) << 8) + ord(frame.code[frame.pc + 1])
    frame.pc += 2
    cp_item = frame.this_class.constant_pool[index]
    assert cp_item[0] == 10  # CONSTANT_Methodref
    klass_info = frame.this_class.constant_pool[cp_item[1]]
    assert klass_info[0] == 7  # CONSTANT_Class_info
    name_and_type = frame.this_class.constant_pool[cp_item[2]]
    assert name_and_type[0] == 12  # name_and_type_index
    klass_name = frame.this_class.constant_pool[klass_info[1]][1]
    method_name = frame.this_class.constant_pool[name_and_type[1]][1]
    method_signature = frame.this_class.constant_pool[name_and_type[2]][1]

    logger.debug("%s %s %s", klass_name, method_name, method_signature)

    klass = frame.vm.get_class(klass_name)
    method = klass.find_method(method_name, method_signature)

    nargs = args_count(method_signature) + 1
    args = [None] * nargs
    while nargs > 0:
        value = frame.stack.pop()
        if type(value) is tuple and value[0] in ('long', 'double'):
            nargs -= 1
        args[nargs - 1] = value
        nargs -= 1

    logger.debug(frame.id)
    logger.debug(args)
    logger.debug(method_signature)
    jassert_ref(args[0])

    if args[0] is None:
        frame.vm.raise_exception(frame, "java/lang/NullPointerException")
        return

    if args[0][0] == "vm_ref":  # vm owned object call
        vm_obj_call(frame, args, method_name, method_signature)
        return

    # ignore signute polimorphic method
    instance = frame.vm.heap[args[0][1]]
    klass = instance.java_class
    method = None
    while method is None and klass is not None:
        if method_name in klass.methods:
            if method_signature in klass.methods[method_name]:
                method = klass.methods[method_name][method_signature]
                break
        klass = klass.super_class

    assert method is not None
    assert klass is not None

    if method[0] & 0x0100 > 0:  # is native?
        exec_native(frame, args, klass, method_name, method_signature)
        return

    obj_mon = None
    if method[0] & 0x0020 > 0:  # is sync
        obj_mon = frame.vm.heap[args[0][1]]
        if "@monitor" in obj_mon.fields:
            if obj_mon.fields["@monitor"] == frame.thread:
                obj_mon.fields["@monitor_count"] += 1
            else:
                index = 0
                while index < len(args):
                    a = args[index]
                    if type(a) is tuple and a[0] in ('long', 'double'):
                        index += 1
                    else:
                        frame.stack.append(a)
                    index += 1
                raise SkipThreadCycle()
        else:
            obj_mon.fields["@monitor"] = frame.thread
            obj_mon.fields["@monitor_count"] = 1

    m_args = [''] * method[1]
    m_args[0:len(args)] = args[0:len(args)]

    sub = Frame(
        frame.thread, klass, method, m_args, "InvVirt: %s %s in %s" %
        (method_name, method_signature, instance.java_class.this_name))
    if obj_mon is not None:
        sub.monitor = obj_mon
    frame.thread.frame_stack.append(sub)
Example #3
0
def invokespecial(frame):
    index = (ord(frame.code[frame.pc]) << 8) + ord(frame.code[frame.pc + 1])
    frame.pc += 2
    cp_item = frame.this_class.constant_pool[index]
    assert cp_item[0] == 10  # CONSTANT_Methodref
    klass_info = frame.this_class.constant_pool[cp_item[1]]
    assert klass_info[0] == 7  # CONSTANT_Class_info
    name_and_type = frame.this_class.constant_pool[cp_item[2]]
    assert name_and_type[0] == 12  # name_and_type_index
    klass_name = frame.this_class.constant_pool[klass_info[1]][1]
    klass = frame.vm.get_class(klass_name)
    method_name = frame.this_class.constant_pool[name_and_type[1]][1]
    method_signature = frame.this_class.constant_pool[name_and_type[2]][1]
    method = klass.find_method(method_name, method_signature)

    logger.debug(klass_name)
    logger.debug(method_name)
    logger.debug(method_signature)
    logger.debug(frame.stack)

    if is_spec_lookup(frame.this_class, klass, method_name):
        method = None
        c = frame.this_class.super_class
        while method is None:
            if c is None:
                break
            if (method_name in c.methods and
                    method_signature in c.methods[method_name]):
                method = c.methods[method_name][method_signature]
                klass = c
                break
            c = c.super_class

    assert method is not None

    nargs = args_count(method_signature) + 1
    args = [None] * nargs
    while nargs > 0:
        value = frame.stack.pop()
        if type(value) is tuple and value[0] in ('long', 'double'):
            nargs -= 1
        args[nargs - 1] = value
        nargs -= 1

    assert len(args[0]) > 0
    jassert_ref(args[0])

    if args[0] is None:
        frame.vm.raise_exception(frame, "java/lang/NullPointerException")
        return

    if method[0] & 0x0100 > 0:  # is native?
        exec_native(frame, args, klass, method_name, method_signature)
        return

    obj_mon = None
    if method[0] & 0x0020 > 0:  # is sync
        obj_mon = frame.vm.heap[args[0][1]]
        if "@monitor" in obj_mon.fields:
            if obj_mon.fields["@monitor"] == frame.thread:
                obj_mon.fields["@monitor_count"] += 1
            else:
                index = 0
                while index < len(args):
                    a = args[index]
                    if type(a) is tuple and a[0] in ('long', 'double'):
                        index += 1
                    else:
                        frame.stack.append(a)
                    index += 1
                raise SkipThreadCycle()
        else:
            obj_mon.fields["@monitor"] = frame.thread
            obj_mon.fields["@monitor_count"] = 1

    m_args = [''] * method[1]
    m_args[0:len(args)] = args[0:len(args)]

    instance = frame.vm.heap[args[0][1]]
    logger.debug("InvokeSpec: %s:%s %s", method_name, method_signature,
                 instance)
    sub = Frame(frame.thread, klass, method, m_args,
                "%s:%s %s" % (method_name, method_signature, instance))
    if obj_mon is not None:
        sub.monitor = obj_mon
    frame.thread.frame_stack.append(sub)
Example #4
0
def op_0xb9(frame):  # invokeinterface
    index = (ord(frame.code[frame.pc]) << 8) + ord(frame.code[frame.pc + 1])
    frame.pc += 2
    count = ord(frame.code[frame.pc])
    assert count > 0
    frame.pc += 1
    zero = ord(frame.code[frame.pc])
    assert zero == 0
    frame.pc += 1
    cp_item = frame.this_class.constant_pool[index]
    assert cp_item[0] == 11  # CONSTANT_Methodref
    klass_info = frame.this_class.constant_pool[cp_item[1]]
    assert klass_info[0] == 7  # CONSTANT_Class_info
    name_and_type = frame.this_class.constant_pool[cp_item[2]]
    assert name_and_type[0] == 12  # name_and_type_index
    klass_name = frame.this_class.constant_pool[klass_info[1]][1]
    method_name = frame.this_class.constant_pool[name_and_type[1]][1]
    method_signature = frame.this_class.constant_pool[name_and_type[2]][1]

    logger.debug("%s %s %s", klass_name, method_name, method_signature)

    frame.vm.get_class(klass_name)

    nargs = args_count(method_signature) + 1
    args = [None] * nargs
    while nargs > 0:
        value = frame.stack.pop()
        if type(value) is tuple and value[0] in ('long', 'double'):
            nargs -= 1
        args[nargs - 1] = value
        nargs -= 1

    logger.debug(args)
    logger.debug(method_signature)
    assert len(args[0]) > 0
    jassert_ref(args[0])

    if args[0] is None:
        frame.vm.raise_exception(frame, "java/lang/NullPointerException")
        return

    if args[0][0] == "vm_ref":  # vm owned object call
        vm_obj_call(frame, args, method_name, method_signature)
        return

    # ignore signute polimorphic method
    instance = frame.vm.heap[args[0][1]]
    klass = instance.java_class
    method = None
    while method is None and klass is not None:
        if method_name in klass.methods:
            if method_signature in klass.methods[method_name]:
                method = klass.methods[method_name][method_signature]
                break
        klass = klass.super_class

    assert method is not None

    if method[0] & 0x0100 > 0:  # is native?
        exec_native(frame, args, klass, method_name, method_signature)
        return

    obj_mon = None
    if method[0] & 0x0020 > 0:  # is sync
        obj_mon = frame.vm.heap[args[0][1]]
        if "@monitor" in obj_mon.fields:
            if obj_mon.fields["@monitor"] == frame.thread:
                obj_mon.fields["@monitor_count"] += 1
            else:
                index = 0
                while index < len(args):
                    a = args[index]
                    if type(a) is tuple and a[0] in ('long', 'double'):
                        index += 1
                    else:
                        frame.stack.append(a)
                    index += 1
                raise SkipThreadCycle()
        else:
            obj_mon.fields["@monitor"] = frame.thread
            obj_mon.fields["@monitor_count"] = 1

    m_args = [''] * method[1]
    m_args[0:len(args)] = args[0:len(args)]

    sub = Frame(frame.thread, klass, method, m_args,
                "InvInt: %s %s in %s" % (method_name, method_signature,
                                         instance.java_class.this_name))
    if obj_mon is not None:
        sub.monitor = obj_mon
    frame.thread.frame_stack.append(sub)
    return
Example #5
0
def invokestatic(frame):
    index = (ord(frame.code[frame.pc]) << 8) + ord(frame.code[frame.pc + 1])
    frame.pc += 2
    cp_methodref = frame.this_class.constant_pool[index]
    assert cp_methodref[0] == 10  # CONSTANT_Methodref
    klass_info = frame.this_class.constant_pool[cp_methodref[1]]
    assert klass_info[0] == 7  # CONSTANT_Class_info
    name_and_type = frame.this_class.constant_pool[cp_methodref[2]]
    assert name_and_type[0] == 12  # name_and_type_index
    klass_name = frame.this_class.constant_pool[klass_info[1]][1]
    method_name = frame.this_class.constant_pool[name_and_type[1]][1]
    method_signature = frame.this_class.constant_pool[name_and_type[2]][1]
    assert klass_name is not None
    assert method_name is not None
    assert method_signature is not None

    if klass_name == "sun/misc/VM" and method_name == "isBooted":
        # shortcut, to be remvoed
        frame.stack.append(1)
        return

    if (klass_name == "sun/reflect/Reflection" and
            method_name == "registerMethodsToFilter"):
        logger.debug("Ignoring registerMethodsToFilter")
        frame.stack.pop()
        frame.stack.pop()
        return

    if (klass_name == "sun/misc/SharedSecrets" and
            method_name == "getJavaLangAccess"):
        # use vm owned object instead of constructing real one
        frame.vm.get_class("sun/misc/JavaLangAccess")
        frame.stack.append(("vm_ref", VM_OBJECTS["JavaLangAccess"]))
        return

    logger.debug("%s %s %s", klass_name, method_name, method_signature)

    klass = frame.vm.get_class(klass_name)
    method = klass.find_method(method_name, method_signature)
    assert method is not None
    assert method[0] & 0x0008 > 0  # make sure this is static method

    obj_mon = None
    if method[0] & 0x0020:
        obj_mon = frame.vm.heap[klass.heap_ref[1]]
        if "@monitor" in obj_mon.fields:
            if obj_mon.fields["@monitor"] == frame.thread:
                obj_mon.fields["@monitor_count"] += 1
            else:
                raise SkipThreadCycle()
        else:
            obj_mon.fields["@monitor"] = frame.thread
            obj_mon.fields["@monitor_count"] = 1

    nargs = args_count(method_signature)
    args = [None] * nargs
    while nargs > 0:
        value = frame.stack.pop()
        if type(value) is tuple and value[0] in ('long', 'double'):
            nargs -= 1
        args[nargs - 1] = value
        nargs -= 1

    if method[0] & 0x0100 > 0:  # is native?
        exec_native(frame, args, klass, method_name, method_signature)
        return

    m_args = [''] * method[1]
    m_args[0:len(args)] = args[0:len(args)]

    logger.debug("InvStatic: %s %s in %s", method_name, method_signature,
                 klass_name)
    if method_name == "countBits":
        frame.stack.append(5)
        return

    sub = Frame(frame.thread, klass, method, m_args,
                "InvStatic: %s %s in %s" % (method_name, method_signature,
                                            klass_name))
    if obj_mon is not None:
        sub.monitor = obj_mon
    frame.thread.frame_stack.append(sub)
Example #6
0
def invokestatic(frame):
    index = (ord(frame.code[frame.pc]) << 8) + ord(frame.code[frame.pc + 1])
    frame.pc += 2
    cp_methodref = frame.this_class.constant_pool[index]
    assert cp_methodref[0] == 10  # CONSTANT_Methodref
    klass_info = frame.this_class.constant_pool[cp_methodref[1]]
    assert klass_info[0] == 7  # CONSTANT_Class_info
    name_and_type = frame.this_class.constant_pool[cp_methodref[2]]
    assert name_and_type[0] == 12  # name_and_type_index
    klass_name = frame.this_class.constant_pool[klass_info[1]][1]
    method_name = frame.this_class.constant_pool[name_and_type[1]][1]
    method_signature = frame.this_class.constant_pool[name_and_type[2]][1]
    assert klass_name is not None
    assert method_name is not None
    assert method_signature is not None

    if klass_name == "sun/misc/VM" and method_name == "isBooted":
        # shortcut, to be remvoed
        frame.stack.append(1)
        return

    if (klass_name == "sun/reflect/Reflection"
            and method_name == "registerMethodsToFilter"):
        logger.debug("Ignoring registerMethodsToFilter")
        frame.stack.pop()
        frame.stack.pop()
        return

    if (klass_name == "sun/misc/SharedSecrets"
            and method_name == "getJavaLangAccess"):
        # use vm owned object instead of constructing real one
        frame.vm.get_class("sun/misc/JavaLangAccess")
        frame.stack.append(("vm_ref", VM_OBJECTS["JavaLangAccess"]))
        return

    logger.debug("%s %s %s", klass_name, method_name, method_signature)

    klass = frame.vm.get_class(klass_name)
    method = klass.find_method(method_name, method_signature)
    assert method is not None
    assert method[0] & 0x0008 > 0  # make sure this is static method

    obj_mon = None
    if method[0] & 0x0020:
        obj_mon = frame.vm.heap[klass.heap_ref[1]]
        if "@monitor" in obj_mon.fields:
            if obj_mon.fields["@monitor"] == frame.thread:
                obj_mon.fields["@monitor_count"] += 1
            else:
                raise SkipThreadCycle()
        else:
            obj_mon.fields["@monitor"] = frame.thread
            obj_mon.fields["@monitor_count"] = 1

    nargs = args_count(method_signature)
    args = [None] * nargs
    while nargs > 0:
        value = frame.stack.pop()
        if type(value) is tuple and value[0] in ('long', 'double'):
            nargs -= 1
        args[nargs - 1] = value
        nargs -= 1

    if method[0] & 0x0100 > 0:  # is native?
        exec_native(frame, args, klass, method_name, method_signature)
        return

    m_args = [''] * method[1]
    m_args[0:len(args)] = args[0:len(args)]

    logger.debug("InvStatic: %s %s in %s", method_name, method_signature,
                 klass_name)
    if method_name == "countBits":
        frame.stack.append(5)
        return

    sub = Frame(
        frame.thread, klass, method, m_args,
        "InvStatic: %s %s in %s" % (method_name, method_signature, klass_name))
    if obj_mon is not None:
        sub.monitor = obj_mon
    frame.thread.frame_stack.append(sub)