Esempio n. 1
0
 def unserialize(self, toUnpack):
     bu = BinaryUnpacker(toUnpack)
     self.messageType = bu.get(VAR_STR)
     self.rejectCode = bu.get(INT8)
     self.message = bu.get(VAR_STR)
     self.data = bu.get(BINARY_CHUNK, bu.getRemainingSize())
     self.serializedData = toUnpack
     return self
Esempio n. 2
0
 def unserialize(self, toUnpack):
    bu = BinaryUnpacker(toUnpack)
    self.messageType = bu.get(VAR_STR)
    self.rejectCode = bu.get(INT8)
    self.message = bu.get(VAR_STR)
    self.data = bu.get(BINARY_CHUNK, bu.getRemainingSize())
    self.serializedData = toUnpack
    return self
Esempio n. 3
0
    def unserialize(self, toUnpack):
        if isinstance(toUnpack, BinaryUnpacker):
            invData = toUnpack
        else:
            invData = BinaryUnpacker(toUnpack)

        numInv = invData.get(VAR_INT)
        for i in range(numInv):
            invType = invData.get(UINT32)
            invHash = invData.get(BINARY_CHUNK, 32)
            self.invList.append([invType, invHash])
        return self
Esempio n. 4
0
    def unserialize(self, toUnpack):
        if isinstance(toUnpack, BinaryUnpacker):
            gbData = toUnpack
        else:
            gbData = BinaryUnpacker(toUnpack)

        self.version = gbData.get(UINT32)
        nhash = gbData.get(VAR_INT)
        for i in range(nhash):
            self.hashList.append(gbData.get(BINARY_CHUNK, 32))
        self.hashStop = gbData.get(BINARY_CHUNK, 32)
        return self
Esempio n. 5
0
   def unserialize(self, toUnpack):
      if isinstance(toUnpack, BinaryUnpacker):
         gbData = toUnpack
      else:
         gbData = BinaryUnpacker( toUnpack )

      self.version = gbData.get(UINT32)
      nhash = gbData.get(VAR_INT)
      for i in range(nhash):
         self.hashList.append(gbData.get(BINARY_CHUNK, 32))
      self.hashStop = gbData.get(BINARY_CHUNK, 32)
      return self
Esempio n. 6
0
   def unserialize(self, toUnpack):
      if isinstance(toUnpack, BinaryUnpacker):
         invData = toUnpack
      else:
         invData = BinaryUnpacker( toUnpack )

      numInv = invData.get(VAR_INT)
      for i in range(numInv):
         invType = invData.get(UINT32)
         invHash = invData.get(BINARY_CHUNK, 32)
         self.invList.append( [invType, invHash] )
      return self
Esempio n. 7
0
   def unserialize(self, toUnpack):
      if isinstance(toUnpack, BinaryUnpacker):
         headerData = toUnpack
      else:
         headerData = BinaryUnpacker( toUnpack )

      self.headerList = []
      self.header.unserialize(headerData)
      numHeader = headerData.get(VAR_INT)
      for i in range(numHeader):
         self.headerList.append(PyBlockHeader().unserialize(headerData))
      headerData.get(VAR_INT) # Not sure if this is even used, ever
      return self
Esempio n. 8
0
    def unserialize(self, toUnpack):
        if isinstance(toUnpack, BinaryUnpacker):
            headerData = toUnpack
        else:
            headerData = BinaryUnpacker(toUnpack)

        self.headerList = []
        self.header.unserialize(headerData)
        numHeader = headerData.get(VAR_INT)
        for i in range(numHeader):
            self.headerList.append(PyBlockHeader().unserialize(headerData))
        headerData.get(VAR_INT)  # Not sure if this is even used, ever
        return self
Esempio n. 9
0
   def unserialize(self, toUnpack):
      if isinstance(toUnpack, BinaryUnpacker):
         blkData = toUnpack
      else:
         blkData = BinaryUnpacker( toUnpack )

      self.version     = blkData.get(UINT32)
      self.prevBlkHash = blkData.get(BINARY_CHUNK, 32)
      self.merkleRoot  = blkData.get(BINARY_CHUNK, 32)
      self.timestamp   = blkData.get(UINT32)
      self.diffBits    = blkData.get(BINARY_CHUNK, 4)
      self.nonce       = blkData.get(UINT32)
      self.theHash     = hash256(self.serialize())
      return self
Esempio n. 10
0
   def unserialize(self, toUnpack):
      if isinstance(toUnpack, BinaryUnpacker):
         blkData = toUnpack
      else:
         blkData = BinaryUnpacker( toUnpack )

      self.version     = blkData.get(UINT32)
      self.prevBlkHash = blkData.get(BINARY_CHUNK, 32)
      self.merkleRoot  = blkData.get(BINARY_CHUNK, 32)
      self.timestamp   = blkData.get(UINT32)
      self.diffBits    = blkData.get(BINARY_CHUNK, 4)
      self.nonce       = blkData.get(UINT32)
      self.theHash     = hash256(self.serialize())
      return self
Esempio n. 11
0
   def unserialize(self, toUnpack, hasTimeField=True):
      if isinstance(toUnpack, BinaryUnpacker):
         addrData = toUnpack
      else:
         addrData = BinaryUnpacker( toUnpack )

      if hasTimeField:
         self.time     = addrData.get(UINT32)

      self.services = addrData.get(UINT64)
      self.addrQuad = addrData.get(BINARY_CHUNK,16)[-4:]
      self.port     = addrData.get(UINT16, endianness=NETWORKENDIAN)

      self.services = int_to_bitset(self.services)
      self.addrQuad = binary_to_quad(self.addrQuad)
      return self
Esempio n. 12
0
    def executeScript(self, binaryScript, stack=[]):
        self.stack = stack
        self.stackAlt = []
        scriptData = BinaryUnpacker(binaryScript)
        self.lastOpCodeSepPos = None

        while scriptData.getRemainingSize() > 0:
            opcode = scriptData.get(UINT8)
            exitCode = self.executeOpCode(opcode, scriptData, self.stack,
                                          self.stackAlt)
            if not exitCode == SCRIPT_NO_ERROR:
                if exitCode == OP_NOT_IMPLEMENTED:
                    LOGERROR(
                        '***ERROR: OpCodes OP_IF, OP_NOTIF, OP_ELSE, OP_ENDIF,'
                    )
                    LOGERROR(
                        '          have not been implemented, yet.  This script'
                    )
                    LOGERROR('          could not be evaluated.')
                if exitCode == OP_DISABLED:
                    LOGERROR(
                        '***ERROR: This script included an op code that has been'
                    )
                    LOGERROR(
                        '          disabled for security reasons.  Script eval'
                    )
                    LOGERROR('          failed.')
                return exitCode

        return SCRIPT_NO_ERROR
Esempio n. 13
0
    def unserialize(self, toUnpack, hasTimeField=True):
        if isinstance(toUnpack, BinaryUnpacker):
            addrData = toUnpack
        else:
            addrData = BinaryUnpacker(toUnpack)

        if hasTimeField:
            self.time = addrData.get(UINT32)

        self.services = addrData.get(UINT64)
        self.addrQuad = addrData.get(BINARY_CHUNK, 16)[-4:]
        self.port = addrData.get(UINT16, endianness=NETWORKENDIAN)

        self.services = int_to_bitset(self.services)
        self.addrQuad = binary_to_quad(self.addrQuad)
        return self
Esempio n. 14
0
    def unserialize(self, toUnpack):
        if isinstance(toUnpack, BinaryUnpacker):
            msgData = toUnpack
        else:
            msgData = BinaryUnpacker(toUnpack)

        self.magic = msgData.get(BINARY_CHUNK, 4)
        self.cmd = msgData.get(BINARY_CHUNK, 12).strip('\x00')
        length = msgData.get(UINT32)
        chksum = msgData.get(BINARY_CHUNK, 4)
        payload = msgData.get(BINARY_CHUNK, length)
        payload = verifyChecksum(payload, chksum)

        self.payload = PayloadMap[self.cmd]().unserialize(payload)

        if self.magic != MAGIC_BYTES:
            raise NetworkIDError, 'Message has wrong network bytes!'
        return self
Esempio n. 15
0
   def unserialize(self, toUnpack):
      if isinstance(toUnpack, BinaryUnpacker):
         msgData = toUnpack
      else:
         msgData = BinaryUnpacker( toUnpack )


      self.magic = msgData.get(BINARY_CHUNK, 4)
      self.cmd   = msgData.get(BINARY_CHUNK, 12).strip('\x00')
      length     = msgData.get(UINT32)
      chksum     = msgData.get(BINARY_CHUNK, 4)
      payload    = msgData.get(BINARY_CHUNK, length)
      payload    = verifyChecksum(payload, chksum)

      self.payload = PayloadMap[self.cmd]().unserialize(payload)

      if self.magic != MAGIC_BYTES:
         raise NetworkIDError, 'Message has wrong network bytes!'
      return self
Esempio n. 16
0
    def unserialize(self, toUnpack):
        if isinstance(toUnpack, BinaryUnpacker):
            addrData = toUnpack
        else:
            addrData = BinaryUnpacker(toUnpack)

        self.addrList = []
        naddr = addrData.get(VAR_INT)
        for i in range(naddr):
            self.addrList.append(PyNetAddress().unserialize(addrData))
        return self
Esempio n. 17
0
   def unserialize(self, toUnpack):
      if isinstance(toUnpack, BinaryUnpacker):
         addrData = toUnpack
      else:
         addrData = BinaryUnpacker( toUnpack )

      self.addrList = []
      naddr = addrData.get(VAR_INT)
      for i in range(naddr):
         self.addrList.append( PyNetAddress().unserialize(addrData) )
      return self
Esempio n. 18
0
   def unserialize(self, toUnpack):
      if isinstance(toUnpack, BinaryUnpacker):
         blkData = toUnpack
      else:
         blkData = BinaryUnpacker( toUnpack )

      self.txList = []
      self.header.unserialize(blkData)
      numTx = blkData.get(VAR_INT)
      for i in range(numTx):
         self.txList.append(PyTx().unserialize(blkData))
      return self
Esempio n. 19
0
    def unserialize(self, toUnpack):
        if isinstance(toUnpack, BinaryUnpacker):
            blkData = toUnpack
        else:
            blkData = BinaryUnpacker(toUnpack)

        self.txList = []
        self.header.unserialize(blkData)
        numTx = blkData.get(VAR_INT)
        for i in range(numTx):
            self.txList.append(PyTx().unserialize(blkData))
        return self
Esempio n. 20
0
    def unserialize(self, toUnpack):
        if isinstance(toUnpack, BinaryUnpacker):
            blkData = toUnpack
        else:
            blkData = BinaryUnpacker(toUnpack)

        self.txList = []
        self.numTx = blkData.get(VAR_INT)
        for i in xrange(self.numTx):
            self.txList.append(PyTx().unserialize(blkData))
        self.merkleTree = []
        self.merkleRoot = ''
        return self
Esempio n. 21
0
   def unserialize(self, toUnpack):
      if isinstance(toUnpack, BinaryUnpacker):
         blkData = toUnpack
      else:
         blkData = BinaryUnpacker( toUnpack )

      self.txList = []
      self.numTx  = blkData.get(VAR_INT)
      for i in xrange(self.numTx):
         self.txList.append( PyTx().unserialize(blkData) )
      self.merkleTree = []
      self.merkleRoot = ''
      return self
Esempio n. 22
0
    def unserialize(self, toUnpack):
        if isinstance(toUnpack, BinaryUnpacker):
            verData = toUnpack
        else:
            verData = BinaryUnpacker(toUnpack)

        self.version = verData.get(INT32)
        self.services = int_to_bitset(verData.get(UINT64), widthBytes=8)
        self.time = verData.get(INT64)
        self.addrRecv = PyNetAddress().unserialize(verData, hasTimeField=False)
        self.addrFrom = PyNetAddress().unserialize(verData, hasTimeField=False)
        self.nonce = verData.get(UINT64)
        self.subver = verData.get(VAR_STR)
        self.height0 = verData.get(INT32)
        return self
Esempio n. 23
0
   def unserialize(self, toUnpack):
      if isinstance(toUnpack, BinaryUnpacker):
         verData = toUnpack
      else:
         verData = BinaryUnpacker( toUnpack )

      self.version  = verData.get(INT32)
      self.services = int_to_bitset(verData.get(UINT64), widthBytes=8)
      self.time     = verData.get(INT64)
      self.addrRecv = PyNetAddress().unserialize(verData, hasTimeField=False)
      self.addrFrom = PyNetAddress().unserialize(verData, hasTimeField=False)
      self.nonce    = verData.get(UINT64)
      self.subver   = verData.get(VAR_STR)
      self.height0  = verData.get(INT32)
      return self
Esempio n. 24
0
   def executeScript(self, binaryScript, stack=[]):
      self.stack = stack
      self.stackAlt  = []
      scriptData = BinaryUnpacker(binaryScript)
      self.lastOpCodeSepPos = None

      while scriptData.getRemainingSize() > 0:
         opcode = scriptData.get(UINT8)
         exitCode = self.executeOpCode(opcode, scriptData, self.stack, self.stackAlt)
         if not exitCode == SCRIPT_NO_ERROR:
            if exitCode==OP_NOT_IMPLEMENTED:
               LOGERROR('***ERROR: OpCodes OP_IF, OP_NOTIF, OP_ELSE, OP_ENDIF,')
               LOGERROR('          have not been implemented, yet.  This script')
               LOGERROR('          could not be evaluated.')
            if exitCode==OP_DISABLED:
               LOGERROR('***ERROR: This script included an op code that has been')
               LOGERROR('          disabled for security reasons.  Script eval')
               LOGERROR('          failed.')
            return exitCode

      return SCRIPT_NO_ERROR
Esempio n. 25
0
    def unserialize(self, toUnpack):
        alertData = BinaryUnpacker(toUnpack)
        self.nonSigLength = alertData.get(INT8)
        self.version = alertData.get(UINT32)
        self.relayUntil = alertData.get(UINT64)
        self.expiration = alertData.get(UINT64)
        self.uniqueID = alertData.get(UINT32)
        self.cancelVal = alertData.get(UINT32)
        numCancel = alertData.get(INT8)
        for i in range(numCancel):
            self.cancelSet.append(alertData.get(UINT32))
        self.minVersion = alertData.get(UINT32)
        self.maxVersion = alertData.get(UINT32)
        numSubVer = alertData.get(INT8)
        for i in range(numSubVer):
            self.subVerSet.append(alertData.get(VAR_STR))
        self.priority = alertData.get(UINT32)
        self.comment = alertData.get(VAR_STR)
        self.statusBar = alertData.get(VAR_STR)
        self.reserved = alertData.get(VAR_STR)
        self.signature = alertData.get(VAR_STR)

        return self
Esempio n. 26
0
   def unserialize(self, toUnpack):
      alertData = BinaryUnpacker( toUnpack )
      self.nonSigLength = alertData.get(INT8)
      self.version = alertData.get(UINT32)
      self.relayUntil = alertData.get(UINT64)
      self.expiration = alertData.get(UINT64)
      self.uniqueID = alertData.get(UINT32)
      self.cancelVal = alertData.get(UINT32)
      numCancel = alertData.get(INT8)
      for i in range(numCancel):
         self.cancelSet.append(alertData.get(UINT32))
      self.minVersion = alertData.get(UINT32)
      self.maxVersion = alertData.get(UINT32)
      numSubVer = alertData.get(INT8)
      for i in range(numSubVer):
         self.subVerSet.append(alertData.get(VAR_STR))
      self.priority = alertData.get(UINT32)
      self.comment = alertData.get(VAR_STR)
      self.statusBar = alertData.get(VAR_STR)
      self.reserved = alertData.get(VAR_STR)
      self.signature = alertData.get(VAR_STR)

      return self