Exemple #1
0
 def sstore(self, key: BitVecRef, value: BitVecRef):
     checkBitVecRef256(key)
     checkBitVecRef256(value)
     # # concrete value
     # if type(key) == BitVecNumRef:
     #     key = key.as_long()
     # # symbolic variable
     # else:
     #     key = str(key)
     self.__storage_data[str(key)] = value
Exemple #2
0
 def pop(self) -> BitVecRef:
     if len(self.__stackdata) >= 1:
         return checkBitVecRef256(self.__stackdata.pop())
     else:
         # generate a symbolic variable
         # TODO this may cause stack underflow
         return self.generateStackVar()
Exemple #3
0
 def push(self, w: BitVecRef):
     if len(self.__stackdata) < 1024:
         self.__stackdata.append(checkBitVecRef256(w))
         # self.__stackdata.append(w)
     else:
         # TODO stack limit reached 1024
         pass
Exemple #4
0
 def sload(self, key: BitVecRef) -> BitVecRef:
     key = str(checkBitVecRef256(key))
     if key in self.__storage_data.keys():
         return self.__storage_data[key]
     else:
         newvar = self.__generate_storage_var(key)
         self.__storage_data[key] = newvar
         return newvar
Exemple #5
0
    def mstore8(self, offset: BitVecNumRef, value: BitVecRef):
        if isinstance(offset, BitVecNumRef):
            offset = checkBitVecRef256(offset).as_long()
        elif not isinstance(offset, int):
            raise DevelopmentErorr(
                'Does not support memory operations indexed by symbol variables.'
            )

        #checkBitVecRef256(value)

        if offset >= len(self.__immediate_data):
            d = offset - len(self.__immediate_data) + 1
            self.__immediate_data.extend([zero8bit() for _ in range(d)])
        self.__immediate_data[offset] = simplify(Extract(7, 0, value))
Exemple #6
0
    def mstore(self, offset: BitVecNumRef, value: BitVecRef):
        if not isinstance(offset, BitVecNumRef) and not isinstance(
                offset, int):
            raise DevelopmentErorr(
                'Does not support memory operations indexed by symbol variables.'
            )

        offset = offset.as_long() if isinstance(offset,
                                                BitVecNumRef) else offset
        checkBitVecRef256(value)

        if offset + WORDBYTESIZE > len(self.__immediate_data):
            d = offset + WORDBYTESIZE - len(self.__immediate_data)
            self.__immediate_data.extend([zero8bit() for _ in range(d)])

        #  for dict
        #
        # for i in range(self.__size(), offset + WORDBYTESIZE):
        #     self.__memdata[str(i)] = zero8bit()
        #
        for i in range(WORDBYTESIZE):
            self.__immediate_data[offset + (WORDBYTESIZE - 1 - i)] = Extract(
                i * 8 + 7, i * 8, value)