Beispiel #1
0
 def sendMessage(self, data: bytes, messageType: PlayerMessageType,
                 timeStamp: int):
     stream = BytesIO()
     Uint8.pack(messageType, stream)
     Uint64LE.pack(timeStamp, stream)
     stream.write(data)
     self.previous.send(stream.getvalue())
Beispiel #2
0
 def writeCreateRequest(self, pdu: DeviceCreateRequestPDU, stream: BytesIO):
     Uint32LE.pack(pdu.desiredAccess, stream)
     Uint64LE.pack(pdu.allocationSize, stream)
     Uint32LE.pack(pdu.fileAttributes, stream)
     Uint32LE.pack(pdu.sharedAccess, stream)
     Uint32LE.pack(pdu.createDisposition, stream)
     Uint32LE.pack(pdu.createOptions, stream)
     Uint32LE.pack(len(pdu.path), stream)
     stream.write(pdu.path)
Beispiel #3
0
    def writeFileDownloadResponse(self, pdu: PlayerFileDownloadResponsePDU,
                                  stream: BytesIO):
        path = pdu.path.encode()

        Uint32LE.pack(pdu.deviceID, stream)
        Uint32LE.pack(len(path), stream)
        stream.write(path)
        Uint64LE.pack(pdu.offset, stream)
        Uint32LE.pack(len(pdu.payload), stream)
        stream.write(pdu.payload)
Beispiel #4
0
    def write(self, pdu: PlayerMessagePDU) -> bytes:
        stream = BytesIO()

        # 18 bytes of header + the payload
        Uint64LE.pack(len(pdu.payload) + 18, stream)
        Uint16LE.pack(pdu.header, stream)
        Uint64LE.pack(pdu.timestamp, stream)
        stream.write(pdu.payload)

        return stream.getvalue()
Beispiel #5
0
    def write(self, pdu: PlayerPDU) -> bytes:
        substream = BytesIO()

        Uint16LE.pack(pdu.header, substream)
        Uint64LE.pack(pdu.timestamp, substream)

        if pdu.header in self.writers:
            self.writers[pdu.header](pdu, substream)

        substream.write(pdu.payload)
        substreamValue = substream.getvalue()

        stream = BytesIO()
        Uint64LE.pack(len(substreamValue) + 8, stream)
        stream.write(substreamValue)

        return stream.getvalue()
Beispiel #6
0
    def writeFileBothDirectoryInformation(self, information: List[FileBothDirectoryInformation], stream: BytesIO):
        dataList: [bytes] = []

        for info in information:
            substream = BytesIO()
            fileName = info.fileName.encode("utf-16le")
            shortName = info.shortName.encode("utf-16le")

            Uint32LE.pack(info.fileIndex, substream)
            Uint64LE.pack(info.creationTime, substream)
            Uint64LE.pack(info.lastAccessTime, substream)
            Uint64LE.pack(info.lastWriteTime, substream)
            Uint64LE.pack(info.lastChangeTime, substream)
            Uint64LE.pack(info.endOfFilePosition, substream)
            Uint64LE.pack(info.allocationSize, substream)
            Uint32LE.pack(info.fileAttributes, substream)
            Uint32LE.pack(len(fileName), substream)
            Uint32LE.pack(info.eaSize, substream)
            Uint8.pack(len(shortName), substream)
            # stream.write(b"\x00") # reserved
            substream.write(shortName.ljust(24, b"\x00")[: 24])
            substream.write(fileName)

            dataList.append(substream.getvalue())

        self.writeFileInformationList(dataList, stream)
Beispiel #7
0
 def writeDeviceReadRequest(self, pdu: DeviceReadRequestPDU, stream: BytesIO):
     Uint32LE.pack(pdu.length, stream)
     Uint64LE.pack(pdu.offset, stream)
     stream.write(b"\x00" * 20)  # Padding