コード例 #1
0
ファイル: message.py プロジェクト: anees042/rdpy
 def __init__(self):
     CompositeType.__init__(self)
     self.x = UInt16Be()
     self.y = UInt16Be()
     self.width = UInt16Be()
     self.height = UInt16Be()
     self.encoding = SInt32Be()
コード例 #2
0
ファイル: message.py プロジェクト: anees042/rdpy
 def __init__(self, incremental=False, x=0, y=0, width=0, height=0):
     CompositeType.__init__(self)
     self.incremental = UInt8(incremental)
     self.x = UInt16Be(x)
     self.y = UInt16Be(y)
     self.width = UInt16Be(width)
     self.height = UInt16Be(height)
コード例 #3
0
ファイル: ber.py プロジェクト: anees042/rdpy
def readInteger(s):
    '''
    read integer structure from stream
    @param s: stream
    @return: int or long python
    '''
    if not readUniversalTag(s, Tag.BER_TAG_INTEGER, False):
        raise InvalidExpectedDataException("bad integer tag")
    
    size = readLength(s)
    
    if size == 1:
        integer = UInt8()
        s.readType(integer)
        return integer.value
    elif size == 2:
        integer = UInt16Be()
        s.readType(integer)
        return integer.value
    elif size == 3:
        integer1 = UInt8()
        integer2 = UInt16Be()
        s.readType(integer1)
        s.readType(integer2)
        return integer2.value + (integer1.value << 16)
    elif size == 4:
        integer = UInt32Be()
        s.readType(integer)
        return integer.value
    else:
        raise InvalidExpectedDataException("wrong integer size")
コード例 #4
0
 def __init__(self):
     CompositeType.__init__(self)
     self.len = UInt8(lambda:sizeof(self) - 1)
     self.code = UInt8()
     self.padding = (UInt16Be(), UInt16Be(), UInt8())
     #read if there is enought data
     self.protocolNeg = Negotiation(optional = True)
コード例 #5
0
ファイル: mcs.py プロジェクト: anees042/rdpy
 def send(self, channelId, data):
     '''
     specific send function for channelId
     @param data: message to send
     '''
     self._transport.send(
         (self.writeMCSPDUHeader(DomainMCSPDU.SEND_DATA_REQUEST),
          self._userId, channelId, UInt8(0x70),
          UInt16Be(sizeof(data)) | UInt16Be(0x8000), data))
コード例 #6
0
ファイル: message.py プロジェクト: anees042/rdpy
 def __init__(self):
     CompositeType.__init__(self)
     self.BitsPerPixel = UInt8(32)
     self.Depth = UInt8(24)
     self.BigEndianFlag = UInt8(False)
     self.TrueColorFlag = UInt8(True)
     self.RedMax = UInt16Be(255)
     self.GreenMax = UInt16Be(255)
     self.BlueMax = UInt16Be(255)
     self.RedShift = UInt8(16)
     self.GreenShift = UInt8(8)
     self.BlueShift = UInt8(0)
     self.padding = (UInt16Be(), UInt8())
コード例 #7
0
ファイル: tpkt.py プロジェクト: anees042/rdpy
 def readExtendedHeader(self, data):
     '''
     header may be on 4 bytes
     '''
     #next state is read data
     size = UInt16Be()
     data.readType(size)
     self.expect(size.value - 4, self.readData)
コード例 #8
0
ファイル: per.py プロジェクト: anees042/rdpy
def readLength(s):
    '''
    read length use in per specification
    @param s: Stream
    @return: int python
    '''
    byte = UInt8()
    s.readType(byte)
    size = None
    if (byte & UInt8(0x80)) == UInt8(0x80):
        byte &= ~UInt8(0x80)
        size = UInt16Be(byte.value << 8)
        s.readType(byte)
        size += s.value + byte
    else:
        size = UInt16Be(byte.value)
    return size.value
コード例 #9
0
ファイル: per.py プロジェクト: anees042/rdpy
def writeInteger16(value, minimum = 0):
    '''
    write UInt16Be minus minimum
    @param value: value to write
    @param minimum: value subtracted to real value
    @return: UInt16Be
    '''
    return UInt16Be(value - minimum)
コード例 #10
0
 def recvFrameBufferUpdateHeader(self, data):
     '''
     read frame buffer update packet header
     '''
     #padding
     nbRect = UInt16Be()
     self._nbRect = data.readType((UInt8(), nbRect))
     self._nbRect = nbRect.value
     self.expect(12, self.recvRectHeader)
コード例 #11
0
ファイル: per.py プロジェクト: anees042/rdpy
def writeLength(value):
    '''
    write length as expected in per specification
    @param value: int or long python
    @return: UInt8, UInt16Be depend on value
    '''
    if value > 0x7f:
        return UInt16Be(value | 0x8000)
    else:
        return UInt8(value)
コード例 #12
0
ファイル: per.py プロジェクト: anees042/rdpy
def readInteger16(s, minimum = 0):
    '''
    read UInt16Be from stream s and add minimum
    @param s: Stream
    @param minimum: minimum added to real value
    @return: int or long python value
    '''
    result = UInt16Be()
    s.readType(result)
    return result.value + minimum
コード例 #13
0
ファイル: ber.py プロジェクト: anees042/rdpy
def writeLength(size):
    '''
    return strcture length as expected in Ber specification
    @param size: int or python long
    @return: UInt8 or (UInt8(0x82), UInt16Be)
    '''
    if size > 0x7f:
        return (UInt8(0x82), UInt16Be(size))
    else:
        return UInt8(size)
コード例 #14
0
ファイル: per.py プロジェクト: anees042/rdpy
def writeInteger(value):
    '''
    write python long or int into per integer format
    @param value: int or long python value
    @return: UInt8, UInt16Be or UInt32Be
    '''
    if value <= 0xff:
        return (writeLength(1), UInt8(value))
    elif value < 0xffff:
        return (writeLength(2), UInt16Be(value))
    else:
        return (writeLength(4), UInt32Be(value))
コード例 #15
0
ファイル: ber.py プロジェクト: anees042/rdpy
def writeInteger(value):
    '''
    write integer value
    @param param: int or python long
    @return ber interger structure 
    '''
    if value <= 0xff:
        return (writeUniversalTag(Tag.BER_TAG_INTEGER, False), writeLength(1), UInt8(value))
    elif value <= 0xffff:
        return (writeUniversalTag(Tag.BER_TAG_INTEGER, False), writeLength(2), UInt16Be(value))
    else:
        return (writeUniversalTag(Tag.BER_TAG_INTEGER, False), writeLength(4), UInt32Be(value))
コード例 #16
0
ファイル: mcs.py プロジェクト: anees042/rdpy
    def recvData(self, data):
        '''
        main receive method
        @param data: Stream 
        '''
        opcode = UInt8()
        data.readType(opcode)

        if self.readMCSPDUHeader(opcode,
                                 DomainMCSPDU.DISCONNECT_PROVIDER_ULTIMATUM):
            print "receive DISCONNECT_PROVIDER_ULTIMATUM"
            self.close()

        elif not self.readMCSPDUHeader(opcode,
                                       DomainMCSPDU.SEND_DATA_INDICATION):
            raise InvalidExpectedDataException("invalid expected mcs opcode")

        userId = UInt16Be()
        channelId = UInt16Be()
        flags = UInt8()
        length = UInt8()

        data.readType((userId, channelId, flags, length))

        if length & UInt8(0x80) == UInt8(0x80):
            lengthP2 = UInt8()
            data.readType(lengthP2)
            length = UInt16Be(length.value & 0x7f << 8 | lengthP2.value)

        #channel id doesn't match a requested layer
        if not self._channelIdsRequest.has_key(channelId):
            print "receive data for an unrequested layer"
            return

        #channel id math an unconnected layer
        if not self._channelIdsRequest[channelId]:
            print "receive data for an unconnected layer"
            return

        self._channelIds[channelId].recv(data)
コード例 #17
0
ファイル: mcs.py プロジェクト: anees042/rdpy
    def recvChannelJoinConfirm(self, data):
        '''
        receive a channel join confirm from server
        @param data: Stream
        '''
        opcode = UInt8()
        confirm = UInt8()
        data.readType((opcode, confirm))
        if not self.readMCSPDUHeader(opcode,
                                     DomainMCSPDU.CHANNEL_JOIN_CONFIRM):
            raise InvalidExpectedDataException("invalid MCS PDU")
        userId = UInt16Be()
        channelId = UInt16Be()
        data.readType((userId, channelId))
        #save state of channel
        self._channelIdsRequest[channelId] = confirm == 0
        if confirm == 0:
            print "server accept channel %d" % channelId.value
        else:
            print "server refused channel %d" % channelId.value

        self.connectNextChannel()
コード例 #18
0
ファイル: mcs.py プロジェクト: anees042/rdpy
 def __init__(self, presentation):
     '''
     ctor call base class ctor
     @param presentation: presentation layer
     '''
     LayerAutomata.__init__(self, presentation._mode, presentation)
     self._clientSettings = gcc.ClientSettings()
     self._serverSettings = gcc.ServerSettings()
     #default user Id
     self._userId = UInt16Be(1)
     #list of channel use in this layer and connection state
     self._channelIds = {Channel.MCS_GLOBAL_CHANNEL: presentation}
     #use to record already requested channel
     self._channelIdsRequest = {}
コード例 #19
0
ファイル: per.py プロジェクト: anees042/rdpy
def readInteger(s):
    '''
    read interger per format from stream
    @param s: Stream
    @return: python int or long
    @raise InvalidValue: if size of integer is not correct
    '''
    result = None
    size = readLength(s)
    if size == 1:
        result = UInt8()
    elif size == 2:
        result = UInt16Be()
    elif size == 4:
        result = UInt32Be()
    else:
        raise InvalidValue("invalid integer size %d"%size)
    s.readType(result)
    return result.value
コード例 #20
0
 def expectedBody(self, data):
     '''
     read header and wait header value to call next state
     @param data: Stream that length are to header length (1|2|4 bytes)
     set next state to callBack body when length read from header
     are received
     '''
     bodyLen = None
     if data.len == 1:
         bodyLen = UInt8()
     elif data.len == 2:
         bodyLen = UInt16Be()
     elif data.len == 4:
         bodyLen = UInt32Be()
     else:
         print "invalid header length"
         return
     data.readType(bodyLen)
     self.expect(bodyLen.value, self._callbackBody)
コード例 #21
0
ファイル: ber.py プロジェクト: anees042/rdpy
def readLength(s):
    '''
    read length of ber structure
    length be on 1 2 or 3 bytes
    @param s: stream
    @return: int or python long
    '''
    size = None
    length = UInt8()
    s.readType(length)
    byte = length.value
    if (byte & 0x80):
        byte &= 0x80
        if byte == 1:
            size = UInt8()
        elif byte == 2:
            size = UInt16Be()
        else:
            raise InvalidExpectedDataException("ber length may be 1 or 2")
        s.readType(size)
    else:
        size = length
    return size.value
コード例 #22
0
 def sendPixelFormat(self, pixelFormat):
     '''
     send pixel format structure
     '''
     self.send((ClientToServerMessages.PIXEL_FORMAT, UInt16Be(), UInt8(),
                pixelFormat))
コード例 #23
0
ファイル: message.py プロジェクト: anees042/rdpy
 def __init__(self):
     CompositeType.__init__(self)
     self.width = UInt16Be()
     self.height = UInt16Be()
     self.pixelFormat = PixelFormat()
コード例 #24
0
ファイル: message.py プロジェクト: anees042/rdpy
 def __init__(self, text=""):
     CompositeType.__init__(self)
     self.padding = (UInt16Be(), UInt8())
     self.size = UInt32Be(len(text))
     self.message = String(text)
コード例 #25
0
ファイル: message.py プロジェクト: anees042/rdpy
 def __init__(self, mask=0, x=0, y=0):
     CompositeType.__init__(self)
     self.mask = UInt8(mask)
     self.x = UInt16Be(x)
     self.y = UInt16Be(y)
コード例 #26
0
ファイル: message.py プロジェクト: anees042/rdpy
 def __init__(self, downFlag=False, key=0):
     CompositeType.__init__(self)
     self.downFlag = UInt8(downFlag)
     self.padding = UInt16Be()
     self.key = UInt32Be(key)
コード例 #27
0
 def sendSetEncoding(self):
     '''
     send set encoding packet
     '''
     self.send((ClientToServerMessages.ENCODING, UInt8(), UInt16Be(1),
                Encoding.RAW))
コード例 #28
0
ファイル: tpkt.py プロジェクト: anees042/rdpy
 def send(self, message):
     '''
     send encapsuled data
     '''
     RawLayer.send(self, (TPKT.TPKT_PACKET, UInt8(0),
                          UInt16Be(sizeof(message) + 4), message))