def get_ast(self): fields = [get_field_ast(f) for f in self.fields] methods = [] for m in self.methods: if isinstance(m, DvMethod) and m.ast: methods.append(m.get_ast()) isInterface = 'interface' in self.access return { 'rawname': self.thisclass[1:-1], 'name': parse_descriptor(self.thisclass), 'super': parse_descriptor(self.superclass), 'flags': self.access, 'isInterface': isInterface, 'interfaces': list(map(parse_descriptor, self.interfaces)), 'fields': fields, 'methods': methods, }
def get_field_ast(field): triple = field.get_class_name()[1:-1], field.get_name( ), field.get_descriptor() expr = None if field.init_value: val = field.init_value.value expr = dummy(str(val)) if val is not None: if field.get_descriptor() == 'Ljava/lang/String;': expr = literal_string(val) elif field.proto == 'B': expr = literal_hex_int(struct.unpack('<b', struct.pack("B", val))[0]) return { 'triple': triple, 'type': parse_descriptor(field.get_descriptor()), 'flags': util.get_access_field(field.get_access_flags()), 'expr': expr, }
def get_field_ast(field, annotations): triple = field.get_class_name()[1:-1], field.get_name( ), field.get_descriptor() expr = None if field.init_value: val = field.init_value.value expr = None if val is not None: descriptor = str(field.get_descriptor()) if descriptor == 'Ljava/lang/String;': expr = literal_string(val) elif descriptor == 'Z': expr = literal_bool(val == 'True') elif descriptor in 'ISC': expr = literal_int(val) elif field.proto == 'B': expr = literal_hex_int( struct.unpack('<b', struct.pack("B", val))[0]) elif descriptor in 'J': expr = literal_long(val) elif descriptor in 'F': expr = literal_float(val) elif descriptor in 'D': expr = literal_double(val) elif descriptor == 'Ljava/lang/Class;': expr = literal_class(val) else: expr = dummy(str(val)) return { 'triple': triple, 'type': parse_descriptor(field.get_descriptor()), 'flags': util.get_access_field(field.get_access_flags()), 'annotations': annotations, 'expr': expr, }