(self, *args, **kwargs)
Add some constraints to the state.

        You may pass in any number of symbolic booleans as variadic positional arguments.
Add some constraints to the state.
Add some constraints to the state .
def add_constraints(self, *args, **kwargs):
        """
        Add some constraints to the state.

        You may pass in any number of symbolic booleans as variadic positional arguments.
        """
        if len(args) > 0 and isinstance(args[0], (list, tuple)):
            raise Exception("Tuple or list passed to add_constraints!")

        if o.TRACK_CONSTRAINTS in self.options and len(args) > 0:
            if o.SIMPLIFY_CONSTRAINTS in self.options:
                constraints = [ self.simplify(a) for a in args ]
            else:
                constraints = args

            self._inspect('constraints', BP_BEFORE, added_constraints=constraints)
            constraints = self._inspect_getattr("added_constraints", constraints)
            added = self.solver.add(*constraints)
            self._inspect('constraints', BP_AFTER)

            # add actions for the added constraints
            if o.TRACK_CONSTRAINT_ACTIONS in self.options:
                for c in added:
                    sac = SimActionConstraint(self, c)
                    self.history.add_action(sac)
        else:
            # preserve the old action logic for when we don't track constraints (why?)
            if (
                'action' in kwargs and kwargs['action'] and
                o.TRACK_CONSTRAINT_ACTIONS in self.options and len(args) > 0
            ):
                for arg in args:
                    if self.solver.symbolic(arg):
                        sac = SimActionConstraint(self, arg)
                        self.history.add_action(sac)

        if o.ABSTRACT_SOLVER in self.options and len(args) > 0:
            for arg in args:
                if self.solver.is_false(arg):
                    self._satisfiable = False
                    return

                if self.solver.is_true(arg):
                    continue

                # `is_true` and `is_false` does not use VSABackend currently (see commits 97a75366 and 2dfba73e in
                # claripy). There is a chance that VSA backend can in fact handle it.
                # Therefore we try to resolve it with VSABackend again
                if claripy.backends.vsa.is_false(arg):
                    self._satisfiable = False
                    return

                if claripy.backends.vsa.is_true(arg):
                    continue

                # It's neither True or False. Let's try to apply the condition

                # We take the argument, extract a list of constrained SIs out of it (if we could, of course), and
                # then replace each original SI the intersection of original SI and the constrained one.

                _, converted = self.solver.constraint_to_si(arg)

                for original_expr, constrained_si in converted:
                    if not original_expr.variables:
                        l.error('Incorrect original_expression to replace in add_constraints(). '
                                'This is due to defects in VSA logics inside claripy. Please report '
                                'to Fish and he will fix it if he\'s free.')
                        continue

                    new_expr = constrained_si
                    self.registers.replace_all(original_expr, new_expr)
                    self.memory.replace_all(original_expr, new_expr)
                    # tmps
                    temps = self.scratch.temps
                    for idx in range(len(temps)):  # pylint:disable=consider-using-enumerate
                        t = temps[idx]
                        if t is None:
                            continue
                        if t.variables.intersection(original_expr.variables):
                            # replace
                            temps[idx] = t.replace(original_expr, new_expr)

                    l.debug("SimState.add_constraints: Applied to final state.")
        elif o.SYMBOLIC not in self.options and len(args) > 0:
            for arg in args:
                if self.solver.is_false(arg):
                    self._satisfiable = False
                    return
def add_constraints ( self , * args , * * kwargs ) : if len ( args ) > 0 and isinstance ( args [ 0 ] , ( list , tuple ) ) : raise Exception ( "Tuple or list passed to add_constraints!" ) if o . TRACK_CONSTRAINTS in self . options and len ( args ) > 0 : if o . SIMPLIFY_CONSTRAINTS in self . options : constraints = [ self . simplify ( a ) for a in args ] else : constraints = args self . _inspect ( 'constraints' , BP_BEFORE , added_constraints = constraints ) constraints = self . _inspect_getattr ( "added_constraints" , constraints ) added = self . solver . add ( * constraints ) self . _inspect ( 'constraints' , BP_AFTER ) # add actions for the added constraints if o . TRACK_CONSTRAINT_ACTIONS in self . options : for c in added : sac = SimActionConstraint ( self , c ) self . history . add_action ( sac ) else : # preserve the old action logic for when we don't track constraints (why?) if ( 'action' in kwargs and kwargs [ 'action' ] and o . TRACK_CONSTRAINT_ACTIONS in self . options and len ( args ) > 0 ) : for arg in args : if self . solver . symbolic ( arg ) : sac = SimActionConstraint ( self , arg ) self . history . add_action ( sac ) if o . ABSTRACT_SOLVER in self . options and len ( args ) > 0 : for arg in args : if self . solver . is_false ( arg ) : self . _satisfiable = False return if self . solver . is_true ( arg ) : continue # `is_true` and `is_false` does not use VSABackend currently (see commits 97a75366 and 2dfba73e in # claripy). There is a chance that VSA backend can in fact handle it. # Therefore we try to resolve it with VSABackend again if claripy . backends . vsa . is_false ( arg ) : self . _satisfiable = False return if claripy . backends . vsa . is_true ( arg ) : continue # It's neither True or False. Let's try to apply the condition # We take the argument, extract a list of constrained SIs out of it (if we could, of course), and # then replace each original SI the intersection of original SI and the constrained one. _ , converted = self . solver . constraint_to_si ( arg ) for original_expr , constrained_si in converted : if not original_expr . variables : l . error ( 'Incorrect original_expression to replace in add_constraints(). ' 'This is due to defects in VSA logics inside claripy. Please report ' 'to Fish and he will fix it if he\'s free.' ) continue new_expr = constrained_si self . registers . replace_all ( original_expr , new_expr ) self . memory . replace_all ( original_expr , new_expr ) # tmps temps = self . scratch . temps for idx in range ( len ( temps ) ) : # pylint:disable=consider-using-enumerate t = temps [ idx ] if t is None : continue if t . variables . intersection ( original_expr . variables ) : # replace temps [ idx ] = t . replace ( original_expr , new_expr ) l . debug ( "SimState.add_constraints: Applied to final state." ) elif o . SYMBOLIC not in self . options and len ( args ) > 0 : for arg in args : if self . solver . is_false ( arg ) : self . _satisfiable = False return