def _get_default_concrete_value_by_type(type_, state=None): # pylint: disable=unused-argument if type_ in ['byte', 'char', 'short', 'int', 'boolean']: return BVV(0, 32) elif type_ == "long": return BVV(0, 64) elif type_ == 'float': return FPV(0, FSORT_FLOAT) elif type_ == 'double': return FPV(0, FSORT_DOUBLE) # not a primitive type # => treat it as a reference return SootNullConstant()
def cast_primitive(state, value, to_type): """ Cast the value of primtive types. :param value: Bitvector storing the primitive value. :param to_type: Name of the targeted type. :return: Resized value. """ if to_type in ['float', 'double']: if value.symbolic: # TODO extend support for floating point types l.warning('No support for symbolic floating-point arguments.' 'Value gets concretized.') value = float(state.solver.eval(value)) sort = FSORT_FLOAT if to_type == 'float' else FSORT_DOUBLE return FPV(value, sort) elif to_type == 'int' and isinstance(value, FP): # TODO fix fpToIEEEBV in claripty l.warning('Converting FP to BV might provide incorrect results.') return fpToIEEEBV(value)[63:32] elif to_type == 'long' and isinstance(value, FP): # TODO fix fpToIEEEBV in claripty l.warning('Converting FP to BV might provide incorrect results.') return fpToIEEEBV(value) else: # lookup the type size and extract value value_size = ArchSoot.sizeof[to_type] value_extracted = value.reversed.get_bytes(index=0, size=value_size // 8).reversed # determine size of Soot bitvector and resize bitvector # Note: smaller types than int's are stored in a 32-bit BV value_soot_size = value_size if value_size >= 32 else 32 if to_type in ['char', 'boolean']: # unsigned extend return value_extracted.zero_extend(value_soot_size - value_extracted.size()) # signed extend return value_extracted.sign_extend(value_soot_size - value_extracted.size())