Example #1
0
    def read(self, class_reader):
        self.read_and_check_magic(class_reader)
        self.read_and_check_version(class_reader)

        self.constant_pool = ConstantPool()
        self.constant_pool.read_constant_pool(class_reader)

        self.access_flags = int.from_bytes(class_reader.read_unit16(), byteorder="big")
        self.this_class = int.from_bytes(class_reader.read_unit16(), byteorder="big")
        self.super_class = int.from_bytes(class_reader.read_unit16(), byteorder="big")
        self.interfaces = class_reader.read_unit16s()

        member_info = MemberInfo(self.constant_pool)
        self.fields = member_info.read_members(class_reader, self.constant_pool)
        self.methods = member_info.read_members(class_reader, self.constant_pool)
        self.attributes = AttributeInfo.read_attributes(class_reader, self.constant_pool)
Example #2
0
    def new_constant_pool(clazz, cfConstantPool: ConstantPool):
        from ch08.classfile.CpNumeric import ConstantDoubleInfo, ConstantLongInfo, ConstantFloatInfo, ConstantIntegerInfo
        from ch08.classfile.ConstantStringInfo import ConstantStringInfo
        from ch08.classfile.ConstantClassInfo import ConstantClassInfo
        from ch08.classfile.ConstantMemberRefInfo import ConstantFieldRefInfo, ConstantMethodRefInfo, \
            ConstantInterfaceMethodRefInfo
        from ch08.rtda.heap.CpClassRef import ClassRef
        from ch08.rtda.heap.CpFieldRef import FieldRef
        from ch08.rtda.heap.CpMethodRef import MethodRef
        from ch08.rtda.heap.CpInterfaceMethodRef import InterfaceMethodRef

        cp_count = len(cfConstantPool.cp)
        consts = [None for _ in range(cp_count)]
        rt_constant_pool = ConstantPool(clazz, consts)

        for i in range(1, cp_count):
            cp_info = cfConstantPool.cp[i]
            if isinstance(cp_info, ConstantIntegerInfo):
                consts[i] = cp_info.val
            elif isinstance(cp_info, ConstantFloatInfo):
                consts[i] = cp_info.val
            elif isinstance(cp_info, ConstantLongInfo):
                consts[i] = cp_info.val
            elif isinstance(cp_info, ConstantDoubleInfo):
                consts[i] = cp_info.val
            elif isinstance(cp_info, ConstantStringInfo):
                consts[i] = str(cp_info)
            elif isinstance(cp_info, ConstantClassInfo):
                consts[i] = ClassRef(rt_constant_pool, cp_info)
            elif isinstance(cp_info, ConstantFieldRefInfo):
                consts[i] = FieldRef(rt_constant_pool, cp_info)
            elif isinstance(cp_info, ConstantMethodRefInfo):
                consts[i] = MethodRef(rt_constant_pool, cp_info)
            elif isinstance(cp_info, ConstantInterfaceMethodRefInfo):
                consts[i] = InterfaceMethodRef(rt_constant_pool, cp_info)

        # rt_constant_pool.consts = consts
        return rt_constant_pool
 def __init__(self, constant_pool):
     from ch08.classfile.ConstantPool import ConstantPool
     self.cp = ConstantPool(constant_pool)
     self.class_index = 0
     self.name_and_type_index = 0
 def __init__(self, constant_pool):
     from ch08.classfile.ConstantPool import ConstantPool
     self.cp = ConstantPool(constant_pool)
     self.string_index = ""