Beispiel #1
0
    def getEq(self):

        src = (self.read_operands)[0]
        if src.isVar():
            srcs = map(lambda b: z3.BitVec(b, 8), src.get_bytes())
        else:
            srcs = map(lambda b: z3.BitVecVal(int(b, 16), 8), src.get_bytes())

        srcs.reverse()

        conds = []
        offset = Memvars.getOffset(self.write_operands[0])
        old_sname, new_sname, offset = Memvars.write(self.write_operands[0])

        old_array = mkArray(old_sname)
        array = mkArray(new_sname)

        #for (i,src) in zip(range(offset,offset-(src.size),-1), srcs):
        #for (i,src) in zip(range(offset,offset+(src.size)+1), srcs):
        for (i, src) in zip(range(src.size), srcs):
            array = z3.Store(array, offset + i, src)

        conds = [(old_array == array)]

        return conds
Beispiel #2
0
  def getEq(self):
    
    src = (self.read_operands)[0]
    if src.isVar():
      srcs = map(lambda b: z3.BitVec(b,8), src.get_bytes())
    else:
      srcs = map(lambda b: z3.BitVecVal(int(b,16),8), src.get_bytes())
      
    srcs.reverse()
    
    conds = []
    offset = Memvars.getOffset(self.write_operands[0])
    old_sname, new_sname, offset = Memvars.write(self.write_operands[0])
      
    old_array = mkArray(old_sname)
    array = mkArray(new_sname)

    #for (i,src) in zip(range(offset,offset-(src.size),-1), srcs):
    #for (i,src) in zip(range(offset,offset+(src.size)+1), srcs):
    for (i,src) in zip(range(src.size), srcs):
      array = z3.Store(array, offset + i, src)
      
    conds = [(old_array == array)]

    return conds
Beispiel #3
0
  def getEq(self, mvars):
    
    r = []
    
    #print self.src, self.dst
    
    if (self.src.isReg()):
      src = self.src.name
    #  self.src.size = self.size
    #  srcs = self.getOperands([self.src])
    #  print srcs
    else:
      assert(0)
  
    old_sname, new_sname, offset = Memvars.write(self.dst)
      
    old_array = mkArray(old_sname)
    array = mkArray(new_sname)
    
    for i in range(self.size):
      
      dst_op = Operand(self.dst.mem_source+"@"+str(offset+i), "BYTE")
      src_var = z3.BitVec(src+":"+str(i)+"(0)",8)
      
      if (dst_op in mvars):
        array = z3.Store(array, offset+i, src_var)

      r.append(src_var <> 0)
      
    r.append((old_array == array))

    return r
Beispiel #4
0
  def getEq(self, mlocs):
    
    src = InputOp("stdin", 1)
    src.size_in_bytes = self.size

    srcs = mkByteListVar(src)    
       
    dst = self.dst #self.func.write_operands[0]
    dsts = dst.getLocations()
    
    conds = []
    
    old_sname, new_sname = Memvars.write(dsts[0])

    #array = mkArray(old_sname)
    #new_array = mkArray(new_sname)

    old_array = mkArray(old_sname)
    array = mkArray(new_sname)

    for (src,dst) in zip(srcs, dsts):
      if dst in mlocs:
        array = z3.Store(array, dst.getIndex(), src)
      
      conds.append(src <> 10)
      conds.append(src <> 0)
 
    conds.append((old_array == array))
    return conds
Beispiel #5
0
  def getEq(self):
    
    src = self.read_operands[0]
    
    if src.isVar():
      srcs = mkByteListVar(src)    
    else:
      srcs = mkByteListConst(src)
    
    #endianness
    srcs.reverse()

    dst = self.write_operands[0]
    dsts = dst.getLocations()
    
    conds = []
    
    old_sname, new_sname = Memvars.write(dsts[0])

    #array = mkArray(old_sname)
    #new_array = mkArray(new_sname)

    old_array = mkArray(old_sname)
    array = mkArray(new_sname)

    for (src,dst) in zip(srcs, dsts):
      array = z3.Store(array, dst.getIndex(), src)
      
    conds = [(old_array == array)]

    return conds
Beispiel #6
0
    def getEq(self):

        src = self.read_operands[0]

        if src.isVar():
            srcs = mkByteListVar(src)
        else:
            srcs = mkByteListConst(src)

        #endianness
        srcs.reverse()

        dst = self.write_operands[0]
        dsts = dst.getLocations()

        conds = []

        old_sname, new_sname = Memvars.write(dsts[0])

        #array = mkArray(old_sname)
        #new_array = mkArray(new_sname)

        old_array = mkArray(old_sname)
        array = mkArray(new_sname)

        for (src, dst) in zip(srcs, dsts):
            array = z3.Store(array, dst.getIndex(), src)

        conds = [(old_array == array)]

        return conds
Beispiel #7
0
    def getEq(self, mlocs):

        src = InputOp("stdin", 1)
        src.size_in_bytes = self.size

        srcs = mkByteListVar(src)

        dst = self.dst  #self.func.write_operands[0]
        dsts = dst.getLocations()

        conds = []

        old_sname, new_sname = Memvars.write(dsts[0])

        #array = mkArray(old_sname)
        #new_array = mkArray(new_sname)

        old_array = mkArray(old_sname)
        array = mkArray(new_sname)

        for (src, dst) in zip(srcs, dsts):
            if dst in mlocs:
                array = z3.Store(array, dst.getIndex(), src)

            conds.append(src <> 10)
            conds.append(src <> 0)

        conds.append((old_array == array))
        return conds
Beispiel #8
0
    def getEq(self, mvars):

        r = []

        #print self.src, self.dst

        if (self.src.isReg()):
            src = self.src.name
        #  self.src.size = self.size
        #  srcs = self.getOperands([self.src])
        #  print srcs
        else:
            assert (0)

        old_sname, new_sname, offset = Memvars.write(self.dst)

        old_array = mkArray(old_sname)
        array = mkArray(new_sname)

        for i in range(self.size):

            dst_op = Operand(self.dst.mem_source + "@" + str(offset + i),
                             "BYTE")
            src_var = z3.BitVec(src + ":" + str(i) + "(0)", 8)

            if (dst_op in mvars):
                array = z3.Store(array, offset + i, src_var)

            r.append(src_var <> 0)

        r.append((old_array == array))

        return r
Beispiel #9
0
    def getEq(self, x, y):

        assert (x.getSizeInBytes() == y.getSizeInBytes())

        conds = []

        if x.isMem() and y.isMem():

            srcs = x.getLocations()
            dsts = y.getLocations()

            for (src, dst) in zip(srcs, dsts):
                sname = Memvars.read(src)
                src_array = mkArray(sname)

                sname = Memvars.read(dst)
                dst_array = mkArray(sname)

                conds.append(
                    src_array[src.getIndex()] == dst_array[dst.getIndex()])

            return conds

        elif x.isMem() and y | iss | ImmOp:
            #assert(0)
            srcs = x.getLocations()
            dsts = mkByteListConst(y)

            #endiannes
            dsts.reverse()

            for (src, dst) in zip(srcs, dsts):
                #print str(x)
                sname = Memvars.read(src)
                src_array = mkArray(sname)
                conds.append(src_array[src.getIndex()] == dst)

            return conds
        else:

            src, dst = self.getOperands([x, y])
            return [src == dst]
Beispiel #10
0
  def getEq(self, x, y):
    
    assert(x.getSizeInBytes() == y.getSizeInBytes())
    
    conds = []
    
    if x.isMem() and y.isMem():
      
      srcs = x.getLocations()
      dsts = y.getLocations()
      
      for (src,dst) in zip(srcs, dsts):
        sname = Memvars.read(src)
        src_array = mkArray(sname)
        
        sname = Memvars.read(dst)
        dst_array = mkArray(sname)
        
        conds.append(src_array[src.getIndex()] == dst_array[dst.getIndex()])
      
      return conds
    
    elif x.isMem() and y |iss| ImmOp:
      #assert(0)
      srcs = x.getLocations()
      dsts = mkByteListConst(y)

      #endiannes
      dsts.reverse()
    
      for (src,dst) in zip(srcs, dsts):
        #print str(x)
        sname = Memvars.read(src)
        src_array = mkArray(sname)
        conds.append(src_array[src.getIndex()] == dst)
    
      return conds
    else:

      src, dst = self.getOperands([x,y])      
      return [src == dst]  
Beispiel #11
0
 def getEq(self, x, y):
   
   if x.isMem() and y.isMem():
     src_name, src_offset = Memvars.read(x)
     src_array = mkArray(src_name)
     
     dst_name, dst_offset = Memvars.read(y)
     dst_array = mkArray(dst_name)
     return [src_array[src_offset] == dst_array[dst_offset]]
   
   elif x.isMem() and y.isImm():
     
     assert(y.size == 1) # y should be a BYTE
     
     src_name, src_offset = Memvars.read(x)
     src_array = mkArray(src_name)
     
     dst = self.getOperands([y])
     return [src_array[src_offset] == dst[0]]
   else:
     src, dst = self.getOperands([x,y])
     return [src == dst]  
Beispiel #12
0
    def getEq(self, x, y):

        if x.isMem() and y.isMem():
            src_name, src_offset = Memvars.read(x)
            src_array = mkArray(src_name)

            dst_name, dst_offset = Memvars.read(y)
            dst_array = mkArray(dst_name)
            return [src_array[src_offset] == dst_array[dst_offset]]

        elif x.isMem() and y.isImm():

            assert (y.size == 1)  # y should be a BYTE

            src_name, src_offset = Memvars.read(x)
            src_array = mkArray(src_name)

            dst = self.getOperands([y])
            return [src_array[src_offset] == dst[0]]
        else:
            src, dst = self.getOperands([x, y])
            return [src == dst]
Beispiel #13
0
    def getEq(self):
        sname, offset = Memvars.read(self.ins.getReadMemOperands()[0])
        array = mkArray(sname)

        dst = (self.write_operands)[0]
        dsts = map(lambda b: z3.BitVec(b, 8), dst.get_bytes())
        dsts.reverse()

        conds = []

        for (i, dst) in zip(range(dst.size), dsts):
            conds.append(array[offset + i] == dst)

        return conds
Beispiel #14
0
  def getEq(self):
    sname, offset = Memvars.read(self.ins.getReadMemOperands()[0])
    array = mkArray(sname)
    
    dst = (self.write_operands)[0]
    dsts = map(lambda b: z3.BitVec(b,8), dst.get_bytes())
    dsts.reverse()    

    conds = []
    
    for (i,dst) in zip(range(dst.size), dsts):
      conds.append(array[offset+i] == dst)

    return conds
Beispiel #15
0
    def getEq(self):

        conds = []

        src = self.ins.getReadMemOperands()[0]
        srcs = src.getLocations()

        dst = (self.write_operands)[0]
        if dst.isVar():
            dsts = mkByteListVar(dst)
        else:
            dsts = mkByteListConst(dst)

        #endianness
        dsts.reverse()

        for (src, dst) in zip(srcs, dsts):
            sname = Memvars.read(src)
            array = mkArray(sname)
            conds.append(array[src.getIndex()] == dst)

        return conds
Beispiel #16
0
  def getEq(self):
    
    conds = []
    
    src = self.ins.getReadMemOperands()[0]
    srcs = src.getLocations()
    
    dst = (self.write_operands)[0]
    if dst.isVar():
      dsts = mkByteListVar(dst)    
    else:
      dsts = mkByteListConst(dst)
    
    #endianness
    dsts.reverse()

    for (src,dst) in zip(srcs, dsts):
      sname = Memvars.read(src)
      array = mkArray(sname)
      conds.append(array[src.getIndex()] == dst)
    
    return conds
Beispiel #17
0
  def getEq(self, mvars):
    
    r = []

    old_sname, new_sname, offset = Memvars.write(self.dst)
      
    old_array = mkArray(old_sname)
    array = mkArray(new_sname)

    for i in range(self.size):
      
      op = Operand(self.dst.mem_source+"@"+str(offset+i), "BYTE")
      
      if (op in mvars):
        array = z3.Store(array, offset+i, z3.BitVec("stdin:"+str(i)+"(0)",8))
        
      r.append(z3.BitVec("stdin:"+str(i)+"(0)",8) <> 10)
      r.append(z3.BitVec("stdin:"+str(i)+"(0)",8) <> 0)
      
    r.append((old_array == array))

    return r
Beispiel #18
0
    def getEq(self, mvars):

        r = []

        old_sname, new_sname, offset = Memvars.write(self.dst)

        old_array = mkArray(old_sname)
        array = mkArray(new_sname)

        for i in range(self.size):

            op = Operand(self.dst.mem_source + "@" + str(offset + i), "BYTE")

            if (op in mvars):
                array = z3.Store(array, offset + i,
                                 z3.BitVec("stdin:" + str(i) + "(0)", 8))

            r.append(z3.BitVec("stdin:" + str(i) + "(0)", 8) <> 10)
            r.append(z3.BitVec("stdin:" + str(i) + "(0)", 8) <> 0)

        r.append((old_array == array))

        return r
Beispiel #19
0
    def getEq(self, mlocs):
        #assert(0)
        #for loc in mlocs:
        #  print loc, "--",
        #print ""
        r = []
        src = self.src
        srcs = src.getLocations()
        sname = Memvars.read(srcs[0])

        read_array = mkArray(sname)

        dst = self.dst
        dsts = dst.getLocations()

        old_sname, new_sname = Memvars.write(dsts[0])

        old_array = mkArray(old_sname)
        array = mkArray(new_sname)

        for (src_loc, dst_loc) in zip(srcs, dsts):

            read_val = z3.Select(read_array, src_loc.getIndex())
            if dst_loc in mlocs:
                array = z3.Store(array, dst_loc.getIndex(), read_val)

            r.append(read_val <> 0)

        r.append((old_array == array))
        #print r
        #assert(0)
        return r

        #print self.src, self.dst

        #if (self.src.isReg()):
        #  src = self.src.name
        #  self.src.size = self.size
        #  srcs = self.getOperands([self.src])
        #  print srcs
        #else:
        #  assert(0)

        #old_sname, new_sname, offset = Memvars.write(self.dst)

        #old_array = mkArray(old_sname)
        #array = mkArray(new_sname)

        #for i in range(self.size):

        #  dst_op = Operand(self.dst.mem_source+"@"+str(offset+i), "BYTE")
        #  src_var = z3.BitVec(src+":"+str(i)+"(0)",8)

        #  if (dst_op in mvars):
        #    array = z3.Store(array, offset+i, src_var)

        #  r.append(src_var <> 0)

        #r.append((old_array == array))

        return r
Beispiel #20
0
  def getEq(self, mlocs):
    #assert(0)
    #for loc in mlocs:
    #  print loc, "--",
    #print ""
    r = []
    src = self.src
    srcs = src.getLocations()
    sname = Memvars.read(srcs[0])

    read_array = mkArray(sname)

    dst = self.dst 
    dsts = dst.getLocations()
    
    old_sname, new_sname = Memvars.write(dsts[0])
    
    old_array = mkArray(old_sname)
    array = mkArray(new_sname)

    for (src_loc,dst_loc) in zip(srcs, dsts):

      read_val = z3.Select(read_array, src_loc.getIndex()) 
      if dst_loc in mlocs:
        array = z3.Store(array, dst_loc.getIndex(), read_val)
      
      r.append(read_val <> 0)
 
    r.append((old_array == array))
    #print r
    #assert(0)
    return r


    #print self.src, self.dst
    
    #if (self.src.isReg()):
    #  src = self.src.name
    #  self.src.size = self.size
    #  srcs = self.getOperands([self.src])
    #  print srcs
    #else:
    #  assert(0)
  
    #old_sname, new_sname, offset = Memvars.write(self.dst)
      
    #old_array = mkArray(old_sname)
    #array = mkArray(new_sname)
    
    #for i in range(self.size):
      
    #  dst_op = Operand(self.dst.mem_source+"@"+str(offset+i), "BYTE")
    #  src_var = z3.BitVec(src+":"+str(i)+"(0)",8)
      
    #  if (dst_op in mvars):
    #    array = z3.Store(array, offset+i, src_var)

    #  r.append(src_var <> 0)
      
    #r.append((old_array == array))

    return r