def get_field_ast(field): triple = field.get_class_name()[1:-1], field.get_name(), field.get_descriptor() expr = None if field.init_value: vt = field.init_value.get_value_type() val = field.init_value.value # TODO: Add other types once dvm.EncodedValue parses them correctly if vt == dvm.VALUE_STRING: expr = literal_string(val) # elif vt in (dvm.VALUE_INT, dvm.VALUE_SHORT, dvm.VALUE_CHAR): # expr = literal_int(val) elif vt == dvm.VALUE_BYTE: x = ord(val) expr = literal_int(x - 256 if x >= 128 else x) # elif vt == dvm.VALUE_LONG: # expr = literal_long(val) # elif vt == dvm.VALUE_DOUBLE: # expr = literal_double(val) # elif vt == dvm.VALUE_FLOAT: # expr = literal_float(val) elif vt == dvm.VALUE_NULL: expr = literal_null() elif vt == dvm.VALUE_BOOLEAN: expr = literal_bool(val) else: expr = dummy('???') 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): 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', 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): 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", val)[0]) return { "triple": triple, "type": parse_descriptor(field.get_descriptor()), "flags": util.get_access_field(field.get_access_flags()), "expr": expr, }