add error file and TPDU layer is connected
This commit is contained in:
20
rdpy/protocol/common/error.py
Normal file
20
rdpy/protocol/common/error.py
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
'''
|
||||||
|
@author: sylvain
|
||||||
|
'''
|
||||||
|
|
||||||
|
class InvalidExpectedDataException(Exception):
|
||||||
|
'''
|
||||||
|
raise when expected data on network is invalid
|
||||||
|
'''
|
||||||
|
def __init__(self, message):
|
||||||
|
'''
|
||||||
|
constructor with message
|
||||||
|
'''
|
||||||
|
self._message = message
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
'''
|
||||||
|
return string representation of exception
|
||||||
|
'''
|
||||||
|
return "%s"%self._message
|
||||||
|
|
||||||
@@ -5,6 +5,7 @@ Created on 5 sept. 2013
|
|||||||
'''
|
'''
|
||||||
from rdpy.protocol.common.layer import Layer
|
from rdpy.protocol.common.layer import Layer
|
||||||
from rdpy.protocol.common.stream import Stream
|
from rdpy.protocol.common.stream import Stream
|
||||||
|
from rdpy.protocol.common.error import InvalidExpectedDataException
|
||||||
class TPDU(Layer):
|
class TPDU(Layer):
|
||||||
'''
|
'''
|
||||||
classdocs
|
classdocs
|
||||||
@@ -24,7 +25,34 @@ class TPDU(Layer):
|
|||||||
def connect(self):
|
def connect(self):
|
||||||
self.writeMessage(TPDU.X224_TPDU_CONNECTION_REQUEST)
|
self.writeMessage(TPDU.X224_TPDU_CONNECTION_REQUEST)
|
||||||
|
|
||||||
|
def recv(self, data):
|
||||||
|
'''
|
||||||
|
main receive function
|
||||||
|
layer complexity doesn't need automata
|
||||||
|
'''
|
||||||
|
#unused length
|
||||||
|
len = data.read_uint8()
|
||||||
|
code = data.read_uint8()
|
||||||
|
|
||||||
|
if code == TPDU.X224_TPDU_DATA:
|
||||||
|
data.read_uint8()
|
||||||
|
self._presentation.recv(data)
|
||||||
|
else:
|
||||||
|
#padding
|
||||||
|
data.read_leuint32()
|
||||||
|
if code == TPDU.X224_TPDU_CONNECTION_CONFIRM:
|
||||||
|
self._presentation.connect()
|
||||||
|
elif code == TPDU.X224_TPDU_CONNECTION_REQUEST:
|
||||||
|
self.writeMessage(TPDU.X224_TPDU_CONNECTION_CONFIRM)
|
||||||
|
self._presentation.connect()
|
||||||
|
else:
|
||||||
|
raise InvalidExpectedDataException("invalid TPDU header code %d"%code)
|
||||||
|
|
||||||
def write(self, data):
|
def write(self, data):
|
||||||
|
'''
|
||||||
|
write message packet for TPDU layer
|
||||||
|
add TPDU header
|
||||||
|
'''
|
||||||
s = Stream()
|
s = Stream()
|
||||||
s.write_uint8(2)
|
s.write_uint8(2)
|
||||||
s.write_uint8(TPDU.X224_TPDU_DATA)
|
s.write_uint8(TPDU.X224_TPDU_DATA)
|
||||||
@@ -33,10 +61,14 @@ class TPDU(Layer):
|
|||||||
self._transport.write(data)
|
self._transport.write(data)
|
||||||
|
|
||||||
def writeMessage(self, code):
|
def writeMessage(self, code):
|
||||||
|
'''
|
||||||
|
special write function
|
||||||
|
that packet TPDU message
|
||||||
|
'''
|
||||||
s = Stream()
|
s = Stream()
|
||||||
s.write_uint8(6);
|
s.write_uint8(6)
|
||||||
s.write_uint8(code);
|
s.write_uint8(code)
|
||||||
s.write_beuint16(0);
|
s.write_beuint16(0)
|
||||||
s.write_beuint16(0);
|
s.write_beuint16(0)
|
||||||
s.write_uint8(0);
|
s.write_uint8(0)
|
||||||
self.write(s)
|
self.write(s)
|
||||||
@@ -78,7 +78,7 @@ class TPKT(RawLayer):
|
|||||||
read classic TPKT packet
|
read classic TPKT packet
|
||||||
'''
|
'''
|
||||||
#next state is pass to
|
#next state is pass to
|
||||||
self.recv(data)
|
self._presentation.recv(data)
|
||||||
self.expect(2, self.readHeader)
|
self.expect(2, self.readHeader)
|
||||||
|
|
||||||
def write(self, data):
|
def write(self, data):
|
||||||
|
|||||||
Reference in New Issue
Block a user