예제 #1
0
    def parseClientCoreData(self, stream):
        stream = StrictStream(stream)

        # 128 bytes minimum (excluding header)
        version = RDPVersion(Uint32LE.unpack(stream))
        desktopWidth = Uint16LE.unpack(stream)
        desktopHeight = Uint16LE.unpack(stream)
        colorDepth = ColorDepth(Uint16LE.unpack(stream))
        sasSequence = Uint16LE.unpack(stream)
        keyboardLayout = Uint32LE.unpack(stream)
        clientBuild = Uint32LE.unpack(stream)
        clientName = decodeUTF16LE(stream.read(32))
        keyboardType = Uint32LE.unpack(stream)
        keyboardSubType = Uint32LE.unpack(stream)
        keyboardFunctionKey = Uint32LE.unpack(stream)
        imeFileName = stream.read(64)

        core = ClientCoreData(version, desktopWidth, desktopHeight, colorDepth, sasSequence, keyboardLayout, clientBuild, clientName, keyboardType, keyboardSubType, keyboardFunctionKey, imeFileName)

        # Optional data
        # The optional fields are read in order. If one of them is not present, then all subsequent fields are also not present.
        try:
            core.postBeta2ColorDepth = Uint16LE.unpack(stream)
            core.clientProductId = Uint16LE.unpack(stream)
            core.serialNumber = Uint32LE.unpack(stream)
            core.highColorDepth = HighColorDepth(Uint16LE.unpack(stream))
            core.supportedColorDepths = Uint16LE.unpack(stream)
            core.earlyCapabilityFlags = Uint16LE.unpack(stream)
            core.clientDigProductId = decodeUTF16LE(stream.read(64))
            core.connectionType = ConnectionType(Uint8.unpack(stream))
            core.pad1octet = stream.read(1)
            core.serverSelectedProtocol = Uint32LE.unpack(stream)
            core.desktopPhysicalWidth = Uint32LE.unpack(stream)
            core.desktopPhysicalHeight = Uint32LE.unpack(stream)
            core.desktopOrientation = DesktopOrientation(Uint16LE.unpack(stream))
            core.desktopScaleFactor = Uint32LE.unpack(stream)
            core.deviceScaleFactor = Uint32LE.unpack(stream)
        except EOFError:
            # The stream has reached the end, we don't have any more optional fields. This exception can be ignored.
            pass

        return core
예제 #2
0
 def parseControl(self, stream: BytesIO, header):
     action = Uint16LE.unpack(stream)
     grantID = Uint16LE.unpack(stream)
     controlID = Uint32LE.unpack(stream)
     return ControlPDU(header, action, grantID, controlID)
예제 #3
0
 def parsePlaySound(self, stream: BytesIO, header):
     duration = Uint32LE.unpack(stream)
     frequency = Uint32LE.unpack(stream)
     return PlaySoundPDU(header, duration, frequency)
예제 #4
0
 def writeDeviceReadResponse(self, pdu: DeviceReadResponsePDU, stream: BytesIO):
     Uint32LE.pack(len(pdu.payload), stream)
     stream.write(pdu.payload)
예제 #5
0
 def parseError(self, stream: BytesIO, header):
     errorInfo = Uint32LE.unpack(stream)
     return SetErrorInfoPDU(header, ErrorInfo(errorInfo))
예제 #6
0
 def writeDeviceCreateResponse(self, pdu: DeviceCreateResponsePDU, stream: BytesIO):
     Uint32LE.pack(pdu.fileID, stream)
     Uint8.pack(pdu.information)
예제 #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
예제 #8
0
 def parseSynchronizeEvent(self, stream, eventTime):
     stream.read(2)
     flags = Uint32LE.unpack(stream)
     return SynchronizeEvent(eventTime, flags)
예제 #9
0
 def writeSynchronizeEvent(self, stream, event):
     stream.write(b"\x00" * 2)
     Uint32LE.pack(event.flags, stream)
예제 #10
0
    def parse(s: BytesIO) -> 'FrameMarker':
        self = FrameMarker()
        self.action = Uint32LE.unpack(s)

        return self
예제 #11
0
 def writeHeader(self, stream, pdu):
     # Make sure the header contains the flags for encryption and salted signatures.
     header = pdu.header | SecurityFlags.SEC_ENCRYPT | SecurityFlags.SEC_SECURE_CHECKSUM
     Uint32LE.pack(header, stream)
예제 #12
0
파일: player.py 프로젝트: yuraxdrumz/pyrdp
    def parseFileDescription(self, stream: BytesIO) -> PlayerFileDescription:
        length = Uint32LE.unpack(stream)
        path = stream.read(length).decode()
        isDirectory = bool(Uint8.unpack(stream))

        return PlayerFileDescription(path, isDirectory)
예제 #13
0
파일: player.py 프로젝트: yuraxdrumz/pyrdp
 def writeBitmap(self, pdu: PlayerBitmapPDU, stream: BytesIO):
     Uint32LE.pack(pdu.width, stream)
     Uint32LE.pack(pdu.height, stream)
     stream.write(pdu.pixels)
예제 #14
0
파일: player.py 프로젝트: yuraxdrumz/pyrdp
 def parseBitmap(self, stream: BytesIO, timestamp: int) -> PlayerBitmapPDU:
     width = Uint32LE.unpack(stream)
     height = Uint32LE.unpack(stream)
     pixels = stream.read(width * height * 4)
     return PlayerBitmapPDU(timestamp, width, height, pixels)
예제 #15
0
    def writeGeneralCapability(self, capability: DeviceRedirectionGeneralCapability, stream: BytesIO):
        Uint32LE.pack(capability.osType, stream)
        Uint32LE.pack(capability.osVersion, stream)
        Uint16LE.pack(capability.protocolMajorVersion, stream)
        Uint16LE.pack(capability.protocolMinorVersion, stream)
        Uint32LE.pack(capability.ioCode1, stream)
        Uint32LE.pack(capability.ioCode2, stream)
        Uint32LE.pack(capability.extendedPDU, stream)
        Uint32LE.pack(capability.extraFlags1, stream)
        Uint32LE.pack(capability.extraFlags2, stream)

        if capability.version == GeneralCapabilityVersion.GENERAL_CAPABILITY_VERSION_02:
            Uint32LE.pack(capability.specialTypeDeviceCap or 0, stream)
예제 #16
0
 def parseFileContentsResponse(self, payload, msgFlags):
     stream = BytesIO(payload)
     streamId = Uint32LE.unpack(stream)
     # FIXME: Need to grab the actual file size from the reply.
     data = stream.read()
     return FileContentsResponsePDU(payload, msgFlags, streamId, data)
예제 #17
0
    def writeDeviceCreateRequest(self, pdu: DeviceCreateRequestPDU, stream: BytesIO):
        path = (pdu.path + "\x00").encode("utf-16le")

        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(path), stream)
        stream.write(path)
예제 #18
0
 def parseFormatDataRequest(self, payload, msgFlags):
     s = BytesIO(payload)
     out = FormatDataRequestPDU(Uint32LE.unpack(s))
     self.req = out
     return out
예제 #19
0
    def parseDeviceReadRequest(self, deviceID: int, fileID: int, completionID: int, minorFunction: int, stream: BytesIO) -> DeviceReadRequestPDU:
        length = Uint32LE.unpack(stream)
        offset = Uint64LE.unpack(stream)
        stream.read(20)  # Padding

        return DeviceReadRequestPDU(deviceID, fileID, completionID, minorFunction, length, offset)
예제 #20
0
 def writeSingleDeviceAnnounce(self, pdu: DeviceAnnounce, stream: BytesIO):
     Uint32LE.pack(pdu.deviceType, stream)
     Uint32LE.pack(pdu.deviceId, stream)
     stream.write(pdu.preferredDosName)
     Uint32LE.pack(len(pdu.deviceData), stream)
     stream.write(pdu.deviceData)
예제 #21
0
    def parseDeviceReadResponse(self, deviceID: int, completionID: int, ioStatus: int, stream: BytesIO) -> DeviceReadResponsePDU:
        length = Uint32LE.unpack(stream)
        payload = stream.read(length)

        return DeviceReadResponsePDU(deviceID, completionID, ioStatus, payload)
예제 #22
0
 def parseDeviceListAnnounce(self, stream: BytesIO) -> DeviceListAnnounceRequest:
     deviceCount = Uint32LE.unpack(stream)
     deviceList = []
     for i in range(deviceCount):
         deviceList.append(self.parseSingleDeviceAnnounce(stream))
     return DeviceListAnnounceRequest(deviceList)
예제 #23
0
 def doParse(self, data: bytes) -> VirtualChannelPDU:
     stream = BytesIO(data)
     length = Uint32LE.unpack(stream)
     flags = Uint32LE.unpack(stream)
     payload = stream.read(length)
     return VirtualChannelPDU(flags, payload)
예제 #24
0
 def parseDeviceListAnnounce(self, stream: BytesIO) -> DeviceListAnnounceRequest:
     deviceCount = Uint32LE.unpack(stream)
     deviceList = [self.parseDeviceAnnounce(stream) for _ in range(deviceCount)]
     return DeviceListAnnounceRequest(deviceList)
예제 #25
0
 def writeError(self, stream: BytesIO, pdu):
     Uint32LE.pack(pdu.errorInfo, stream)
예제 #26
0
    def writeDeviceListAnnounce(self, pdu: DeviceListAnnounceRequest, stream: BytesIO):
        Uint32LE.pack(len(pdu.deviceList), stream)

        for device in pdu.deviceList:
            self.writeDeviceAnnounce(device, stream)
예제 #27
0
 def writeControl(self, stream: BytesIO, pdu):
     Uint16LE.pack(pdu.action, stream)
     Uint16LE.pack(pdu.grantID, stream)
     Uint32LE.pack(pdu.grantID, stream)
예제 #28
0
 def writeDeviceAnnounce(self, pdu: DeviceAnnounce, stream: BytesIO):
     Uint32LE.pack(pdu.deviceType, stream)
     Uint32LE.pack(pdu.deviceID, stream)
     stream.write(pdu.preferredDOSName.encode().ljust(7, b"\x00")[: 7] + b"\x00")
     Uint32LE.pack(len(pdu.deviceData), stream)
     stream.write(pdu.deviceData)
예제 #29
0
 def writePlaySound(self, stream: BytesIO, pdu):
     Uint32LE.pack(pdu.duration, stream)
     Uint32LE.pack(pdu.frequency, stream)
예제 #30
0
 def writeClientClusterData(self, stream, cluster):
     stream.write(Uint32LE.pack(cluster.flags))
     stream.write(Uint32LE.pack(cluster.redirectedSessionID))