Ejemplo n.º 1
0
 def __init__(self, sink):
     BaseEventHandler.__init__(self)
     self._fastPath = FastPathOutputParser()
     self._bitmap = BitmapParser()
     self._orders: OrdersParser = None
     self.log = logging.getLogger(__name__)
     self.sink = sink
Ejemplo n.º 2
0
 def __init__(self, imageHandler: ImageHandler):
     BaseEventHandler.__init__(self)
     self._fastPath = FastPathOutputParser()
     self._bitmap = BitmapParser()
     self.gdi: GdiQtFrontend = None
     self._orders: OrdersParser = None
     self.log = logging.getLogger(__name__)
     self.imageHandler = imageHandler
Ejemplo n.º 3
0
class RenderingEventHandler(BaseEventHandler):
    """Abstract class for rendering handlers."""
    def __init__(self, imageHandler: ImageHandler):
        BaseEventHandler.__init__(self)
        self._fastPath = FastPathOutputParser()
        self._bitmap = BitmapParser()
        self.gdi: GdiQtFrontend = None
        self._orders: OrdersParser = None
        self.log = logging.getLogger(__name__)
        self.imageHandler = imageHandler

    def onCapabilities(self, caps):
        if CapabilityType.CAPSTYPE_ORDER in caps:
            self.gdi = GdiQtFrontend(self.imageHandler)
            self._orders = OrdersParser(self.gdi)
            self._orders.onCapabilities(caps)

    # Generic Parsing Routines.
    def onFastPathOutput(self, event: FastPathOutputEvent):
        self.onBeginRender()
        if isinstance(event, FastPathBitmapEvent):
            parsed = self._fastPath.parseBitmapEvent(event)
            for bmp in parsed.bitmapUpdateData:
                self.onBitmap(bmp)

        elif isinstance(event, FastPathOrdersEvent):
            if self._orders is None:
                self.log.error('Received Unexpected Drawing Orders!')
                return
            self.onBeginRender()
            self._orders.parse(event)

        self.onFinishRender()

    def onSlowPathUpdate(self, pdu: UpdatePDU):
        if pdu.updateType == SlowPathUpdateType.SLOWPATH_UPDATETYPE_BITMAP:
            self.onBeginRender()

            updates = self._bitmap.parseBitmapUpdateData(pdu.updateData)
            for bmp in updates:
                self.onBitmap(bmp)

            self.onFinishRender()

    def onBitmap(self, bitmapData: BitmapUpdateData):
        image, _ = RDPBitmapToQtImage(
            bitmapData.width, bitmapData.heigth, bitmapData.bitsPerPixel,
            bitmapData.flags & BitmapFlags.BITMAP_COMPRESSION != 0,
            bitmapData.bitmapData)

        self.imageHandler.notifyImage(
            bitmapData.destLeft, bitmapData.destTop, image,
            bitmapData.destRight - bitmapData.destLeft + 1,
            bitmapData.destBottom - bitmapData.destTop + 1)

    def onBeginRender(self):
        pass

    def onFinishRender(self):
        pass
Ejemplo n.º 4
0
    def onSlowPathPDU(self, pdu: PlayerPDU):
        parser = SlowPathParser()
        pdu = parser.parse(pdu.payload)

        if isinstance(pdu, ConfirmActivePDU):
            bitmapCapability = pdu.parsedCapabilitySets[
                CapabilityType.CAPSTYPE_BITMAP]
            self.viewer.resize(bitmapCapability.desktopWidth,
                               bitmapCapability.desktopHeight)
        elif isinstance(
                pdu, UpdatePDU
        ) and pdu.updateType == SlowPathUpdateType.SLOWPATH_UPDATETYPE_BITMAP:
            updates = BitmapParser().parseBitmapUpdateData(pdu.updateData)

            for bitmap in updates:
                self.handleBitmap(bitmap)
        elif isinstance(pdu, InputPDU):
            for event in pdu.events:
                if isinstance(event, MouseEvent):
                    self.onMousePosition(event.x, event.y)
                elif isinstance(event, KeyboardEvent):
                    self.onScanCode(
                        event.keyCode,
                        event.flags & KeyboardFlag.KBDFLAGS_DOWN == 0,
                        event.flags & KeyboardFlag.KBDFLAGS_EXTENDED != 0)
Ejemplo n.º 5
0
    def handleBitmap(self, pdu: PlayerBitmapPDU):
        bpp = 32
        flags = 0

        # RDP expects bitmap data in bottom-up, left-to-right
        # See: https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-rdpbcgr/84a3d4d2-5523-4e49-9a48-33952c559485
        for y in range(pdu.height):
            pixels = pdu.pixels[y * pdu.width * 4 : (y + 1) * pdu.width * 4]
            bitmap = BitmapUpdateData(0, y, pdu.width, y + 1, pdu.width, 1, bpp, flags, pixels)
            bitmapData = BitmapParser().writeBitmapUpdateData([bitmap])
            event = FastPathBitmapEvent(FastPathOutputType.FASTPATH_UPDATETYPE_BITMAP, None, [], bitmapData)
            self.sendOutputEvents([event])