def _z3expr(self, printable): ## z3str has a weird way of encoding string constants. ## for printing, we make strings look like nice constants, ## but otherwise we use z3str's encoding plan. if printable: return z3.Const('"%s"' % self.v, z3str.StringSort()) enc = "__cOnStStR_" + "".join(["_x%02x" % ord(c) for c in self.v]) return z3.Const(enc, z3str.StringSort())
def fork_and_check_worker(constr, conn): z3e = z3expr(constr) (ok, z3m) = z3str.check_and_model(z3e) m = {} if ok == z3.sat: for k in z3m: v = z3m[k] if v.sort() == z3.IntSort(): m[str(k)] = v.as_long() elif v.sort() == z3str.StringSort(): # print "Model string %s: %s" % (k, v) vs = str(v) if not vs.startswith('__cOnStStR_'): if not str(k).startswith('_t_'): print 'Undecodable string constant (%s): %s' % (k, vs) continue hexbytes = vs.split('_x')[1:] bytes = [int(h, 16) for h in hexbytes] m[str(k)] = ''.join(chr(x) for x in bytes) else: raise Exception("Unknown sort for %s=%s: %s" % (k, v, v.sort())) conn.send((ok, m)) conn.close()
def _z3expr(self, printable): return z3.Const(self.id, z3str.StringSort())