protocol buffer is now raw layer
This commit is contained in:
@@ -31,6 +31,6 @@ if __name__ == '__main__':
|
|||||||
#w.show()
|
#w.show()
|
||||||
from twisted.internet import reactor
|
from twisted.internet import reactor
|
||||||
#reactor.connectTCP("127.0.0.1", 5901, factory.RfbFactory(protocol))
|
#reactor.connectTCP("127.0.0.1", 5901, factory.RfbFactory(protocol))
|
||||||
reactor.connectTCP("192.168.122.184", 3389, factory.RfbFactory(tpkt.TPKT(tpdu.TPDU())))
|
reactor.connectTCP("192.168.135.160", 3389, factory.RfbFactory(tpkt.TPKT(tpdu.TPDU())))
|
||||||
reactor.run()
|
reactor.run()
|
||||||
sys.exit(app.exec_())
|
sys.exit(app.exec_())
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
'''
|
'''
|
||||||
@author: sylvain
|
@author: sylvain
|
||||||
'''
|
'''
|
||||||
|
|
||||||
class Layer(object):
|
class Layer(object):
|
||||||
'''
|
'''
|
||||||
Network abstraction for protocol
|
Network abstraction for protocol
|
||||||
@@ -43,4 +44,71 @@ class Layer(object):
|
|||||||
default pass data to transport layer
|
default pass data to transport layer
|
||||||
'''
|
'''
|
||||||
if not self._transport is None:
|
if not self._transport is None:
|
||||||
self._transport.write(data)
|
self._transport.write(data)
|
||||||
|
|
||||||
|
class LayerAutomata(Layer):
|
||||||
|
'''
|
||||||
|
layer with automata state
|
||||||
|
we can set next recv function used
|
||||||
|
'''
|
||||||
|
def __init__(self, presentation = None):
|
||||||
|
'''
|
||||||
|
Constructor
|
||||||
|
'''
|
||||||
|
#call parent constructor
|
||||||
|
Layer.__init__(self, presentation)
|
||||||
|
|
||||||
|
def setNextState(self, callback = None):
|
||||||
|
'''
|
||||||
|
set recv function to next callback or
|
||||||
|
'''
|
||||||
|
if callback is None:
|
||||||
|
callback = self.__class__.recv
|
||||||
|
|
||||||
|
self.recv = callback
|
||||||
|
|
||||||
|
#twitsed layer concept
|
||||||
|
from twisted.internet import protocol
|
||||||
|
#first that handle stream
|
||||||
|
from stream import Stream
|
||||||
|
|
||||||
|
class RawLayer(protocol.Protocol, LayerAutomata):
|
||||||
|
'''
|
||||||
|
Inherit from protocol twisted class
|
||||||
|
allow this protocol to wait until expected size of packet
|
||||||
|
and use Layer automata to call next automata state
|
||||||
|
'''
|
||||||
|
def __init__(self, presentation = None):
|
||||||
|
'''
|
||||||
|
Constructor
|
||||||
|
'''
|
||||||
|
#call parent automata
|
||||||
|
LayerAutomata.__init__(self, presentation)
|
||||||
|
#data buffer received from twisted network layer
|
||||||
|
self._buffer = ""
|
||||||
|
#len of next packet pass to next state function
|
||||||
|
self._expectedLen = 0
|
||||||
|
|
||||||
|
def dataReceived(self, data):
|
||||||
|
'''
|
||||||
|
inherit from protocol class
|
||||||
|
main event of received data
|
||||||
|
'''
|
||||||
|
#add in buffer
|
||||||
|
self._buffer += data
|
||||||
|
#while buffer have expected size call local callback
|
||||||
|
while len(self._buffer) >= self._expectedLen:
|
||||||
|
#expected data is first expected bytes
|
||||||
|
expectedData = Stream(self._buffer[0:self._expectedLen])
|
||||||
|
#rest is for next event of automata
|
||||||
|
self._buffer = self._buffer[self._expectedLen:]
|
||||||
|
#call recv function
|
||||||
|
self.recv(expectedData)
|
||||||
|
|
||||||
|
def expect(self, expectedLen, callback = None):
|
||||||
|
'''
|
||||||
|
new expected len
|
||||||
|
'''
|
||||||
|
self._expectedLen = expectedLen
|
||||||
|
#default callback is recv from LayerAutomata
|
||||||
|
self.setNextState(callback)
|
||||||
@@ -1,11 +1,10 @@
|
|||||||
'''
|
'''
|
||||||
@author: sylvain
|
@author: sylvain
|
||||||
'''
|
'''
|
||||||
from rdpy.protocol.common.protocolbuffer import ProtocolBuffer
|
from rdpy.protocol.common.layer import RawLayer
|
||||||
from rdpy.protocol.common.layer import Layer
|
|
||||||
from rdpy.protocol.common.stream import Stream
|
from rdpy.protocol.common.stream import Stream
|
||||||
|
|
||||||
class TPKT(ProtocolBuffer, Layer):
|
class TPKT(RawLayer):
|
||||||
'''
|
'''
|
||||||
TPKT layer in RDP protocol stack
|
TPKT layer in RDP protocol stack
|
||||||
this layer only handle size of packet
|
this layer only handle size of packet
|
||||||
@@ -15,8 +14,7 @@ class TPKT(ProtocolBuffer, Layer):
|
|||||||
'''
|
'''
|
||||||
Constructor
|
Constructor
|
||||||
'''
|
'''
|
||||||
ProtocolBuffer.__init__(self)
|
RawLayer.__init__(self, presentation)
|
||||||
Layer.__init__(self, presentation)
|
|
||||||
#last packet version read from header
|
#last packet version read from header
|
||||||
self._lastPacketVersion = 0
|
self._lastPacketVersion = 0
|
||||||
#length may be coded on more than 1 bytes
|
#length may be coded on more than 1 bytes
|
||||||
@@ -25,7 +23,7 @@ class TPKT(ProtocolBuffer, Layer):
|
|||||||
def connectionMade(self):
|
def connectionMade(self):
|
||||||
'''
|
'''
|
||||||
call when transport layer connection
|
call when transport layer connection
|
||||||
is made (inherit from ProtocolBuffer)
|
is made (inherit from RawLayer)
|
||||||
'''
|
'''
|
||||||
#header is on two bytes
|
#header is on two bytes
|
||||||
self.expect(2, self.readHeader)
|
self.expect(2, self.readHeader)
|
||||||
|
|||||||
@@ -5,10 +5,10 @@ Created on 12 aout 2013
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
from rdpy.protocol.common.stream import Stream
|
from rdpy.protocol.common.stream import Stream
|
||||||
from rdpy.protocol.common.protocolbuffer import ProtocolBuffer
|
from rdpy.protocol.common.layer import RawLayer
|
||||||
from types import PixelFormat,ProtocolVersion,SecurityType, Rectangle, Encoding
|
from types import PixelFormat,ProtocolVersion,SecurityType, Rectangle, Encoding
|
||||||
|
|
||||||
class Rfb(ProtocolBuffer):
|
class Rfb(RawLayer):
|
||||||
'''
|
'''
|
||||||
implements rfb protocol message
|
implements rfb protocol message
|
||||||
'''
|
'''
|
||||||
@@ -20,7 +20,7 @@ class Rfb(ProtocolBuffer):
|
|||||||
constructor
|
constructor
|
||||||
mode can be only client or server mode
|
mode can be only client or server mode
|
||||||
'''
|
'''
|
||||||
ProtocolBuffer.__init__(self)
|
RawLayer.__init__(self)
|
||||||
#usefull for rfb protocol
|
#usefull for rfb protocol
|
||||||
self._callbackBody = None
|
self._callbackBody = None
|
||||||
#mode of automata
|
#mode of automata
|
||||||
|
|||||||
Reference in New Issue
Block a user