From a23ae25a1fd1fa8372e67b83f389ce6900818f32 Mon Sep 17 00:00:00 2001 From: speyrefitte Date: Thu, 21 May 2015 10:29:32 +0200 Subject: [PATCH] fix issue on unhandle upadte --- bin/rdpy-rdphoneypot.py | 2 +- rdpy/protocol/rdp/lic.py | 2 +- rdpy/protocol/rdp/pdu/data.py | 43 +++++++++++++++++++++++----------- rdpy/protocol/rdp/pdu/layer.py | 4 ++-- rdpy/ui/qt4.py | 3 --- setup.py | 2 +- 6 files changed, 34 insertions(+), 22 deletions(-) diff --git a/bin/rdpy-rdphoneypot.py b/bin/rdpy-rdphoneypot.py index 3f1e898..3ceb42a 100755 --- a/bin/rdpy-rdphoneypot.py +++ b/bin/rdpy-rdphoneypot.py @@ -70,7 +70,7 @@ class HoneyPotServer(rdp.RDPServerObserver): def onClose(self): """ HoneyPot """ - def onKeyEventScancode(self, code, isPressed): + def onKeyEventScancode(self, code, isPressed, isExtended): """ HoneyPot """ def onKeyEventUnicode(self, code, isPressed): diff --git a/rdpy/protocol/rdp/lic.py b/rdpy/protocol/rdp/lic.py index 3acdb74..f22f4d4 100644 --- a/rdpy/protocol/rdp/lic.py +++ b/rdpy/protocol/rdp/lic.py @@ -234,7 +234,7 @@ class LicPacket(CompositeType): if self.bMsgtype.value == c._MESSAGE_TYPE_: return c(readLen = self.wMsgSize - 4) log.debug("unknown license message : %s"%self.bMsgtype.value) - return String() + return String(readLen = self.wMsgSize - 4) if message is None: message = FactoryType(LicensingMessageFactory) diff --git a/rdpy/protocol/rdp/pdu/data.py b/rdpy/protocol/rdp/pdu/data.py index e7caf36..385ae63 100644 --- a/rdpy/protocol/rdp/pdu/data.py +++ b/rdpy/protocol/rdp/pdu/data.py @@ -202,6 +202,16 @@ class Display(object): SUPPRESS_DISPLAY_UPDATES = 0x00 ALLOW_DISPLAY_UPDATES = 0x01 +class ToogleFlag(object): + """ + @summary: Use to known state of keyboard + @see: https://msdn.microsoft.com/en-us/library/cc240588.aspx + """ + TS_SYNC_SCROLL_LOCK = 0x00000001 + TS_SYNC_NUM_LOCK = 0x00000002 + TS_SYNC_CAPS_LOCK = 0x00000004 + TS_SYNC_KANA_LOCK = 0x00000008 + class ErrorInfo(object): """ @summary: Error code use in Error info PDU @@ -542,9 +552,9 @@ class DataPDU(CompositeType): """ for c in [UpdateDataPDU, SynchronizeDataPDU, ControlDataPDU, ErrorInfoDataPDU, FontListDataPDU, FontMapDataPDU, PersistentListPDU, ClientInputEventPDU, ShutdownDeniedPDU, ShutdownRequestPDU, SupressOutputDataPDU, SaveSessionInfoPDU]: if self.shareDataHeader.pduType2.value == c._PDUTYPE2_: - return c(readLen = CallableValue(self.shareDataHeader.uncompressedLength.value - 18)) + return c(readLen = CallableValue(readLen.value - sizeof(self.shareDataHeader))) log.debug("unknown PDU data type : %s"%hex(self.shareDataHeader.pduType2.value)) - return String(readLen = CallableValue(self.shareDataHeader.uncompressedLength.value - 18)) + return String(readLen = CallableValue(readLen.value - sizeof(self.shareDataHeader))) if pduData is None: pduData = FactoryType(PDUDataFactory) @@ -759,15 +769,9 @@ class UpdateDataPDU(CompositeType): """ for c in [BitmapUpdateDataPDU]: if self.updateType.value == c._UPDATE_TYPE_: - if not readLen is None: - return c(readLen = CallableValue(readLen.value - 2)) - else: - return c() + return c(readLen = CallableValue(readLen.value - 2)) log.debug("unknown PDU update data type : %s"%hex(self.updateType.value)) - if not readLen is None: - return String(readLen = CallableValue(readLen.value - 2)) - else: - return String() + return String(readLen = CallableValue(readLen.value - 2)) if updateData is None: updateData = FactoryType(UpdateDataFactory, conditional = lambda:(self.updateType.value != UpdateType.UPDATETYPE_SYNCHRONIZE)) @@ -915,11 +919,10 @@ class SlowPathInputEvent(CompositeType): self.messageType = UInt16Le(lambda:self.slowPathInputData.__class__._INPUT_MESSAGE_TYPE_) def SlowPathInputDataFactory(): - for c in [PointerEvent, ScancodeKeyEvent, UnicodeKeyEvent]: + for c in [PointerEvent, ScancodeKeyEvent, UnicodeKeyEvent, SynchronizeEvent]: if self.messageType.value == c._INPUT_MESSAGE_TYPE_: return c() - log.debug("unknown slow path input : %s"%hex(self.messageType.value)) - return String() + raise InvalidExpectedDataException("unknown slow path input : %s"%hex(self.messageType.value)) if messageData is None: messageData = FactoryType(SlowPathInputDataFactory) @@ -927,7 +930,19 @@ class SlowPathInputEvent(CompositeType): raise InvalidExpectedDataException("try to send an invalid Slow Path Input Event") self.slowPathInputData = messageData - + +class SynchronizeEvent(CompositeType): + """ + @summary: Synchronize keyboard + @see: https://msdn.microsoft.com/en-us/library/cc240588.aspx + """ + _INPUT_MESSAGE_TYPE_ = InputMessageType.INPUT_EVENT_SYNC + + def __init__(self): + CompositeType.__init__(self) + self.pad2Octets = UInt16Le() + self.toggleFlags = UInt32Le() + class PointerEvent(CompositeType): """ @summary: Event use to communicate mouse position diff --git a/rdpy/protocol/rdp/pdu/layer.py b/rdpy/protocol/rdp/pdu/layer.py index dcf68e9..aebcd15 100644 --- a/rdpy/protocol/rdp/pdu/layer.py +++ b/rdpy/protocol/rdp/pdu/layer.py @@ -332,8 +332,8 @@ class Client(PDULayer): generalCapability.osMajorType.value = caps.MajorType.OSMAJORTYPE_WINDOWS generalCapability.osMinorType.value = caps.MinorType.OSMINORTYPE_WINDOWS_NT generalCapability.extraFlags.value = caps.GeneralExtraFlag.LONG_CREDENTIALS_SUPPORTED | caps.GeneralExtraFlag.NO_BITMAP_COMPRESSION_HDR | caps.GeneralExtraFlag.ENC_SALTED_CHECKSUM - #if not self._fastPathSender is None: - # generalCapability.extraFlags.value |= caps.GeneralExtraFlag.FASTPATH_OUTPUT_SUPPORTED + if not self._fastPathSender is None: + generalCapability.extraFlags.value |= caps.GeneralExtraFlag.FASTPATH_OUTPUT_SUPPORTED #init bitmap capability bitmapCapability = self._clientCapabilities[caps.CapsType.CAPSTYPE_BITMAP].capability diff --git a/rdpy/ui/qt4.py b/rdpy/ui/qt4.py index 63a3b14..237f974 100644 --- a/rdpy/ui/qt4.py +++ b/rdpy/ui/qt4.py @@ -241,7 +241,6 @@ class RDPClientQt(RDPClientObserver, QAdaptor): self._widget = QRemoteDesktop(width, height, self) #set widget screen to RDP stack controller.setScreen(width, height) - self._i = 0 def getWidget(self): """ @@ -305,8 +304,6 @@ class RDPClientQt(RDPClientObserver, QAdaptor): @param data: {str} bitmap data """ image = RDPBitmapToQtImage(width, height, bitsPerPixel, isCompress, data) - image.save("/tmp/%s.png"%self._i) - self._i += 1 #if image need to be cut #For bit alignement server may send more than image pixel self._widget.notifyImage(destLeft, destTop, image, destRight - destLeft + 1, destBottom - destTop + 1) diff --git a/setup.py b/setup.py index e8a1bee..d3136f2 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ import setuptools from distutils.core import setup, Extension setup(name='rdpy', - version='1.3.1', + version='1.3.2', description='Remote Desktop Protocol in Python', long_description=""" RDPY is a pure Python implementation of the Microsoft RDP (Remote Desktop Protocol) protocol (Client and Server side). RDPY is built over the event driven network engine Twisted.