diff --git a/README.md b/README.md index 0ee9e87..e5af741 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ -# RDPY Remote Desktop Protoc in Python +# RDPY + +## Remote Desktop Protoc in Python ## Requirements * python2.7 @@ -8,4 +10,4 @@ * python-qt4 * python-qt4reactor -this project is still in progress. +this project is still in progress. diff --git a/README.md~ b/README.md~ new file mode 100644 index 0000000..72aa78a --- /dev/null +++ b/README.md~ @@ -0,0 +1,13 @@ +# RDPY + +## Remote Desktop Protoc in Python + +## Requirements +* python2.7 +* python-twisted + +## Requirements for examples +* python-qt4 +* python-qt4reactor + +this project is still in progress. diff --git a/rdpy/protocol/rdp/pdu.py b/rdpy/protocol/rdp/pdu.py index b455b46..08ce76e 100644 --- a/rdpy/protocol/rdp/pdu.py +++ b/rdpy/protocol/rdp/pdu.py @@ -701,7 +701,7 @@ class PDU(LayerAutomata): Global channel for mcs that handle session identification user, licensing management, and capabilities exchange ''' - def __init__(self, mode, dispatcher): + def __init__(self, mode, ordersManager): ''' Constructor ''' @@ -743,7 +743,7 @@ class PDU(LayerAutomata): self._shareId = UInt32Le() #rdp observer - self._dispatcher = dispatcher + self._ordersManager = ordersManager def connect(self): ''' @@ -871,7 +871,7 @@ class PDU(LayerAutomata): ''' dataPDU = self.readDataPDU(data) if dataPDU.shareDataHeader.pduType2 == PDUType2.PDUTYPE2_UPDATE and dataPDU.pduData._value.updateType == UpdateType.UPDATETYPE_BITMAP: - self._dispatcher.recvBitmapUpdateDataPDU(dataPDU.pduData._value.updateData._value) + self._ordersManager.recvBitmapUpdateDataPDU(dataPDU.pduData._value.updateData._value) def sendConfirmActivePDU(self): diff --git a/rdpy/protocol/rdp/rdp.py b/rdpy/protocol/rdp/rdp.py index 3b451b6..3ec5486 100644 --- a/rdpy/protocol/rdp/rdp.py +++ b/rdpy/protocol/rdp/rdp.py @@ -5,7 +5,7 @@ from twisted.internet import protocol import tpkt, tpdu, mcs, pdu from rdpy.network.layer import LayerMode -class RDP(object): +class RDPOrdersManager(object): ''' use to decode and dispatch to observer PDU messages and orders ''' @@ -48,9 +48,9 @@ class ClientFactory(protocol.Factory): ''' Function call from twisted and build rdp protocol stack ''' - rdp = RDP() - rdp.addObserver(self._observer) - return tpkt.TPKT(tpdu.TPDU(mcs.MCS(pdu.PDU(LayerMode.CLIENT, rdp)))); + rdpOrdersManager = RDPOrdersManager() + rdpOrdersManager.addObserver(self._observer) + return tpkt.TPKT(tpdu.TPDU(mcs.MCS(pdu.PDU(LayerMode.CLIENT, rdpOrdersManager)))); class RDPObserver(object): ''' diff --git a/rdpy/protocol/rfb/rfb.py b/rdpy/protocol/rfb/rfb.py index dc8bfec..2149ddb 100644 --- a/rdpy/protocol/rfb/rfb.py +++ b/rdpy/protocol/rfb/rfb.py @@ -152,7 +152,7 @@ class Rfb(RawLayer): implements rfb protocol ''' - def __init__(self, mode): + def __init__(self, mode, ordersManager): ''' constructor ''' @@ -177,7 +177,7 @@ class Rfb(RawLayer): #current rectangle header self._currentRect = Rectangle() #client or server adaptor - self._observer = [] + self._ordersManager = ordersManager def addObserver(self, observer): ''' @@ -355,9 +355,8 @@ class Rfb(RawLayer): ''' read body of rect ''' - for observer in self._observer: - observer.notifyFramebufferUpdate(self._currentRect.width.value, self._currentRect.height.value, self._currentRect.x.value, self._currentRect.y.value, self._pixelFormat, self._currentRect.encoding, data.getvalue()) - + self._ordersManager.recvRectangle(self._currentRect, self._pixelFormat, data.getvalue()) + self._nbRect = self._nbRect - 1 #if there is another rect to read if self._nbRect == 0: @@ -410,6 +409,33 @@ class Rfb(RawLayer): write client cut text event packet ''' self.send((ClientToServerMessages.CUT_TEXT, ClientCutText(text))) + +class RFBOrderManager(object): + ''' + class use to manage rfb order and dispatch throw observers + ''' + def __init__(self): + ''' + ctor + ''' + self._observers = [] + + def addObserver(self, observer): + ''' + Add new observer for this protocol + @param observer: new observer + ''' + self._observers.append(observer) + + def recvRectangle(self, rectangle, pixelFormat, data): + ''' + receive rectangle order + @param rectangle: Rectangle type header of packet + @param pixelFormat: pixelFormat struct of current session + @param data: image data + ''' + for observer in self._observers: + observer.notifyFramebufferUpdate(rectangle.width.value, rectangle.height.value, rectangle.x.value, rectangle.y.value, self._pixelFormat, rectangle.encoding, data) class ClientFactory(protocol.Factory): ''' @@ -427,8 +453,9 @@ class ClientFactory(protocol.Factory): function call by twisted on connection @param addr: adress where client try to connect ''' - protocol = Rfb(LayerMode.CLIENT) - protocol.addObserver(self._observer) + orderManager = RFBOrderManager() + orderManager.addObserver(self._observer) + protocol = Rfb(LayerMode.CLIENT, orderManager) self._observer.setProtocol(protocol) return protocol