Code factoring + comments
This commit is contained in:
@@ -6,24 +6,31 @@ import tpkt, tpdu, mcs, pdu
|
||||
from rdpy.network.layer import LayerMode
|
||||
|
||||
class RDPController(object):
|
||||
'''
|
||||
"""
|
||||
use to decode and dispatch to observer PDU messages and orders
|
||||
'''
|
||||
def __init__(self, pduLayer):
|
||||
"""
|
||||
def __init__(self, mode):
|
||||
'''
|
||||
ctor
|
||||
@param mode: mode of generate layer by controller
|
||||
@param observer: observer
|
||||
'''
|
||||
#list of observer
|
||||
self._observers = []
|
||||
self._clientObserver = []
|
||||
#transport layer
|
||||
self._pduLayer = pduLayer
|
||||
self._pduLayer = pdu.PDU(mode, self)
|
||||
|
||||
def addObserver(self, observer):
|
||||
def getPDULayer(self):
|
||||
"""
|
||||
@return: pdu layer use by controller
|
||||
"""
|
||||
return self._pduLayer
|
||||
|
||||
def addClientObserver(self, observer):
|
||||
'''
|
||||
add observer to rdp protocol
|
||||
@param observer: new observer to add
|
||||
'''
|
||||
self._observers.append(observer)
|
||||
self._clientObserver.append(observer)
|
||||
observer._controller = self
|
||||
|
||||
def recvBitmapUpdateDataPDU(self, bitmapUpdateData):
|
||||
@@ -31,12 +38,12 @@ class RDPController(object):
|
||||
call when a bitmap data is received from update pdu
|
||||
@param bitmapData: pdu.BitmapData struct
|
||||
'''
|
||||
for observer in self._observers:
|
||||
for observer in self._clientObserver:
|
||||
#for each rectangle in update PDU
|
||||
for rectangle in bitmapUpdateData.rectangles._array:
|
||||
observer.onBitmapUpdate(rectangle.destLeft.value, rectangle.destTop.value, rectangle.destRight.value, rectangle.destBottom.value, rectangle.width.value, rectangle.height.value, rectangle.bitsPerPixel.value, (rectangle.flags & pdu.BitmapFlag.BITMAP_COMPRESSION).value, rectangle.bitmapDataStream.value)
|
||||
|
||||
class ClientFactory(protocol.Factory):
|
||||
class Factory(protocol.Factory):
|
||||
'''
|
||||
Factory of Client RDP protocol
|
||||
'''
|
||||
@@ -45,9 +52,7 @@ class ClientFactory(protocol.Factory):
|
||||
Function call from twisted and build rdp protocol stack
|
||||
@param addr: destination address
|
||||
'''
|
||||
pduLayer = pdu.PDU(LayerMode.CLIENT)
|
||||
pduLayer.getController().addObserver(self.buildObserver())
|
||||
return tpkt.TPKT(tpdu.createClient(mcs.MCS(pduLayer)));
|
||||
return tpkt.TPKT(tpdu.createClient(mcs.createClient(self.buildObserver().getController())));
|
||||
|
||||
def buildObserver(self):
|
||||
'''
|
||||
@@ -75,7 +80,7 @@ class ServerFactory(protocol.Factory):
|
||||
'''
|
||||
pduLayer = pdu.PDU(LayerMode.SERVER)
|
||||
#pduLayer.getController().addObserver(self.buildObserver())
|
||||
return tpkt.TPKT(tpdu.createServer(mcs.MCS(pduLayer), self._privateKeyFileName, self._certificateFileName));
|
||||
return tpkt.TPKT(tpdu.createServer(mcs.createServer(pduLayer), self._privateKeyFileName, self._certificateFileName));
|
||||
|
||||
def buildObserver(self):
|
||||
'''
|
||||
@@ -88,10 +93,14 @@ class RDPClientObserver(object):
|
||||
class use to inform all rdp event handle by RDPY
|
||||
'''
|
||||
def __init__(self):
|
||||
'''
|
||||
ctor
|
||||
'''
|
||||
self._controller = None
|
||||
self._controller = RDPController(LayerMode.CLIENT)
|
||||
self._controller.addClientObserver(self)
|
||||
|
||||
def getController(self):
|
||||
"""
|
||||
@return: RDP controller use by observer
|
||||
"""
|
||||
return self._controller
|
||||
|
||||
def onBitmapUpdate(self, destLeft, destTop, destRight, destBottom, width, height, bitsPerPixel, isCompress, data):
|
||||
'''
|
||||
|
||||
Reference in New Issue
Block a user