def __init__(self): super().__init__('str.suffixof', 2, (exprtypes.StringType(), exprtypes.StringType()), exprtypes.BoolType()) # self.smt_function = z3.SuffixOf # self.eval_children = str.endswith self.eval_children = lambda a, b: str.endswith(b, a)
def __init__(self): super().__init__( 'str.substr', 3, (exprtypes.StringType(), exprtypes.IntType(), exprtypes.IntType()), exprtypes.StringType()) # self.smt_function = z3.Extract self.eval_children = lambda a, b, c: a[b:(c + b)] if 0 <= b and len( a) >= (c + b) >= b else ''
def __init__(self): super().__init__( 'str.substr', 3, (exprtypes.StringType(), exprtypes.IntType(), exprtypes.IntType()), exprtypes.StringType()) # self.smt_function = z3.Extract def substr(string, start, offset): if start < 0 or offset < 0: return '' elif start + offset > len(string): return string[start:] else: return string[start:(start + offset)] self.eval_children = lambda a, b, c: substr(a, b, c)
def _constant_to_string(constant_type, constant_value): if constant_type == exprtypes.BoolType(): return str(constant_value).lower() elif constant_type == exprtypes.IntType(): return str(constant_value) elif constant_type == exprtypes.StringType(): return '"%s"' % constant_value else: return utils.bitvector_to_string(constant_value, constant_type.size)
def sexp_to_type(sexp): if type(sexp) == list and sexp[0] == 'BitVec': assert type(sexp[1]) == tuple and sexp[1][0] == 'Int' length = sexp[1][1] return exprtypes.BitVectorType(length) elif sexp == 'Int': return exprtypes.IntType() elif sexp == 'Bool': return exprtypes.BoolType() elif sexp == 'String': return exprtypes.StringType() else: raise Exception("Unknown type: %s" % str(sexp))
def __init__(self): super().__init__('str.to.int', 1, (exprtypes.StringType(), ), exprtypes.IntType()) # self.smt_function = z3.Stoi def eval_c(a): try: if all(map(lambda x: '0' <= x <= '9', a)): return int(a) else: return -1 except ValueError: return -1 self.eval_children = eval_c
def __init__(self): super().__init__('int.to.str', 1, (exprtypes.IntType(), ), exprtypes.StringType()) # self.smt_function = z3.Itos self.eval_children = lambda a: str(a) if a >= 0 else ''
def __init__(self): super().__init__('str.at', 2, (exprtypes.StringType(), exprtypes.IntType()), exprtypes.StringType()) # self.smt_function = lambda a,b: a[b] self.eval_children = lambda a, b: a[b] if 0 <= b < len(a) else ''
def __init__(self): super().__init__('str.replace', 3, (exprtypes.StringType(), exprtypes.StringType(), exprtypes.StringType()), exprtypes.StringType()) self.smt_function = z3.Replace self.eval_children = lambda a, b, c: str.replace(a, b, c, 1)
def __init__(self): super().__init__('str.++', 2, (exprtypes.StringType(), exprtypes.StringType()), exprtypes.StringType()) # self.smt_function = z3.Concat self.eval_children = str.__add__
def __init__(self): super().__init__('slia') self.lia_instantiator = semantics_lia.LIAInstantiator() self.function_types = { 'str.++': (exprtypes.StringType(), exprtypes.StringType()), 'str.replace': (exprtypes.StringType(), exprtypes.StringType(), exprtypes.StringType()), 'str.at': (exprtypes.StringType(), exprtypes.IntType()), 'int.to.str': (exprtypes.IntType(), ), 'str.substr': (exprtypes.StringType(), exprtypes.IntType(), exprtypes.IntType()), 'str.len': (exprtypes.StringType(), ), 'str.to.int': (exprtypes.StringType(), ), 'str.indexof': (exprtypes.StringType(), exprtypes.StringType(), exprtypes.IntType()), 'str.prefixof': (exprtypes.StringType(), exprtypes.StringType()), 'str.suffixof': (exprtypes.StringType(), exprtypes.StringType()), 'str.contains': (exprtypes.StringType(), exprtypes.StringType()) } self.function_instances = { 'str.++': StrConcat(), 'str.replace': StrReplace(), 'str.at': StrAt(), 'int.to.str': IntToStr(), 'str.substr': Substr(), 'str.len': StrLen(), 'str.to.int': StrToInt(), 'str.indexof': StrIndexOf(), 'str.prefixof': StrPrefixOf(), 'str.suffixof': StrSuffixOf(), 'str.contains': StrContains() }
def __init__(self): super().__init__('str.contains', 2, (exprtypes.StringType(), exprtypes.StringType()), exprtypes.BoolType()) # self.smt_function = z3.Contains self.eval_children = lambda a, b: str.find(a, b) != -1
def __init__(self): super().__init__('str.indexof', 3, (exprtypes.StringType(), exprtypes.StringType(), exprtypes.IntType()), exprtypes.IntType()) # self.smt_function = z3.IndexOf self.eval_children = str.find
def __init__(self): super().__init__('str.len', 1, (exprtypes.StringType(), ), exprtypes.IntType()) # self.smt_function = z3.Length self.eval_children = lambda a: len(a)
def __init__(self): super().__init__('str.prefixof', 2, (exprtypes.StringType(), exprtypes.StringType()), exprtypes.BoolType()) # self.smt_function = z3.PrefixOf self.eval_children = str.startswith