Esempio n. 1
0
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()
Esempio n. 2
0
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()