How to use the claripy.FSORT_FLOAT function in claripy

To help you get started, we’ve selected a few claripy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github angr / angr / angr / calling_conventions.py View on Github external
def get_value(self, state, size=None, endness=None, **kwargs):  # pylint:disable=arguments-differ
        #val = super(SimLyingRegArg, self).get_value(state, **kwargs)
        val = getattr(state.regs, self.reg_name)
        if endness and endness != state.arch.register_endness:
            val = val.reversed
        if size == 4:
            val = claripy.fpToFP(claripy.fp.RM.RM_NearestTiesEven, val.raw_to_fp(), claripy.FSORT_FLOAT)
        return val
github angr / angr / angr / engines / vex / claripy / datalayer.py View on Github external
def value(ty, val):
    if ty == 'Ity_F32':
        return claripy.FPV(float(val), claripy.FSORT_FLOAT)
    elif ty == 'Ity_F64':
        return claripy.FPV(float(val), claripy.FSORT_DOUBLE)
    else:
        return claripy.BVV(int(val), pyvex.get_type_size(ty))
github angr / angr / angr / sim_type.py View on Github external
def _init_str(self):
        return "%s(size=%d)" % (
            self.__class__.__name__,
            self.size
        )


class SimTypeFloat(SimTypeReg):
    """
    An IEEE754 single-precision floating point number
    """
    def __init__(self, size=32):
        super(SimTypeFloat, self).__init__(size)

    sort = claripy.FSORT_FLOAT
    signed = True

    def extract(self, state, addr, concrete=False):
        itype = claripy.fpToFP(super(SimTypeFloat, self).extract(state, addr, False), self.sort)
        if concrete:
            return state.solver.eval(itype)
        return itype

    def store(self, state, addr, value):
        if type(value) in (int, float):
            value = claripy.FPV(float(value), self.sort)
        return super(SimTypeFloat, self).store(state, addr, value)

    def __repr__(self):
        return 'float'
github angr / angr / angr / simos / javavm.py View on Github external
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
github angr / angr / angr / simos / javavm.py View on Github external
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()
github angr / angr / angr / calling_conventions.py View on Github external
for sarg, sty
                                        in zip(arg, ty.fields.values())])
            else:
                return claripy.Concat(*[SimCC._standardize_value(sarg, None, state, alloc) for sarg in arg])

        elif isinstance(arg, int):
            if check and isinstance(ty, SimTypeFloat):
                return SimCC._standardize_value(float(arg), ty, state, alloc)

            val = state.solver.BVV(arg, ty.size if check else state.arch.bits)
            if state.arch.memory_endness == 'Iend_LE':
                val = val.reversed
            return val

        elif isinstance(arg, float):
            sort = claripy.FSORT_FLOAT
            if check:
                if isinstance(ty, SimTypeDouble):
                    sort = claripy.FSORT_DOUBLE
                elif isinstance(ty, SimTypeFloat):
                    pass
                else:
                    raise TypeError("Type mismatch: expectd %s, got float" % ty.name)
            else:
                sort = claripy.FSORT_DOUBLE if state.arch.bits == 64 else claripy.FSORT_FLOAT

            val = claripy.fpToIEEEBV(claripy.FPV(arg, sort))
            if state.arch.memory_endness == 'Iend_LE':
                val = val.reversed      # pylint: disable=no-member
            return val

        elif isinstance(arg, claripy.ast.FP):