refactorrfb

This commit is contained in:
citronneur
2014-06-19 22:59:23 +02:00
parent eaf7569f1a
commit 3d9deca110
5 changed files with 58 additions and 16 deletions

View File

@@ -1,4 +1,6 @@
# RDPY Remote Desktop Protoc in Python # RDPY
## Remote Desktop Protoc in Python
## Requirements ## Requirements
* python2.7 * python2.7

13
README.md~ Normal file
View File

@@ -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.

View File

@@ -701,7 +701,7 @@ class PDU(LayerAutomata):
Global channel for mcs that handle session Global channel for mcs that handle session
identification user, licensing management, and capabilities exchange identification user, licensing management, and capabilities exchange
''' '''
def __init__(self, mode, dispatcher): def __init__(self, mode, ordersManager):
''' '''
Constructor Constructor
''' '''
@@ -743,7 +743,7 @@ class PDU(LayerAutomata):
self._shareId = UInt32Le() self._shareId = UInt32Le()
#rdp observer #rdp observer
self._dispatcher = dispatcher self._ordersManager = ordersManager
def connect(self): def connect(self):
''' '''
@@ -871,7 +871,7 @@ class PDU(LayerAutomata):
''' '''
dataPDU = self.readDataPDU(data) dataPDU = self.readDataPDU(data)
if dataPDU.shareDataHeader.pduType2 == PDUType2.PDUTYPE2_UPDATE and dataPDU.pduData._value.updateType == UpdateType.UPDATETYPE_BITMAP: 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): def sendConfirmActivePDU(self):

View File

@@ -5,7 +5,7 @@ from twisted.internet import protocol
import tpkt, tpdu, mcs, pdu import tpkt, tpdu, mcs, pdu
from rdpy.network.layer import LayerMode from rdpy.network.layer import LayerMode
class RDP(object): class RDPOrdersManager(object):
''' '''
use to decode and dispatch to observer PDU messages and orders 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 Function call from twisted and build rdp protocol stack
''' '''
rdp = RDP() rdpOrdersManager = RDPOrdersManager()
rdp.addObserver(self._observer) rdpOrdersManager.addObserver(self._observer)
return tpkt.TPKT(tpdu.TPDU(mcs.MCS(pdu.PDU(LayerMode.CLIENT, rdp)))); return tpkt.TPKT(tpdu.TPDU(mcs.MCS(pdu.PDU(LayerMode.CLIENT, rdpOrdersManager))));
class RDPObserver(object): class RDPObserver(object):
''' '''

View File

@@ -152,7 +152,7 @@ class Rfb(RawLayer):
implements rfb protocol implements rfb protocol
''' '''
def __init__(self, mode): def __init__(self, mode, ordersManager):
''' '''
constructor constructor
''' '''
@@ -177,7 +177,7 @@ class Rfb(RawLayer):
#current rectangle header #current rectangle header
self._currentRect = Rectangle() self._currentRect = Rectangle()
#client or server adaptor #client or server adaptor
self._observer = [] self._ordersManager = ordersManager
def addObserver(self, observer): def addObserver(self, observer):
''' '''
@@ -355,8 +355,7 @@ class Rfb(RawLayer):
''' '''
read body of rect read body of rect
''' '''
for observer in self._observer: self._ordersManager.recvRectangle(self._currentRect, self._pixelFormat, data.getvalue())
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._nbRect = self._nbRect - 1 self._nbRect = self._nbRect - 1
#if there is another rect to read #if there is another rect to read
@@ -411,6 +410,33 @@ class Rfb(RawLayer):
''' '''
self.send((ClientToServerMessages.CUT_TEXT, ClientCutText(text))) 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): class ClientFactory(protocol.Factory):
''' '''
Factory of RFB protocol Factory of RFB protocol
@@ -427,8 +453,9 @@ class ClientFactory(protocol.Factory):
function call by twisted on connection function call by twisted on connection
@param addr: adress where client try to connect @param addr: adress where client try to connect
''' '''
protocol = Rfb(LayerMode.CLIENT) orderManager = RFBOrderManager()
protocol.addObserver(self._observer) orderManager.addObserver(self._observer)
protocol = Rfb(LayerMode.CLIENT, orderManager)
self._observer.setProtocol(protocol) self._observer.setProtocol(protocol)
return protocol return protocol