コード例 #1
0
ファイル: ber.py プロジェクト: zha0/rdpy
def readInteger(s):
    """
    @summary: 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")
コード例 #2
0
 def __init__(self):
     CompositeType.__init__(self)
     self.len = UInt8(lambda:sizeof(self) - 1)
     self.code = UInt8(MessageType.X224_TPDU_CONNECTION_CONFIRM, constant = True)
     self.padding = (UInt16Be(), UInt16Be(), UInt8())
     #read if there is enough data
     self.protocolNeg = Negotiation(optional = True)
コード例 #3
0
ファイル: rfb.py プロジェクト: chushuai/rdpy
 def __init__(self):
     CompositeType.__init__(self)
     self.x = UInt16Be()
     self.y = UInt16Be()
     self.width = UInt16Be()
     self.height = UInt16Be()
     self.encoding = SInt32Be()
コード例 #4
0
ファイル: rfb.py プロジェクト: chushuai/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)
コード例 #5
0
 def __init__(self):
     CompositeType.__init__(self)
     self.len = UInt8(lambda:sizeof(self) - 1)
     self.code = UInt8(MessageType.X224_TPDU_CONNECTION_REQUEST, constant = True)
     self.padding = (UInt16Be(), UInt16Be(), UInt8())
     self.cookie = String(until = "\x0d\x0a", conditional = lambda:(self.len._is_readed and self.len.value > 14))
     #read if there is enough data
     self.protocolNeg = Negotiation(optional = True)
コード例 #6
0
ファイル: rfb.py プロジェクト: chushuai/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
    def readExtendedFastPathHeader(self, data):
        """
        @summary: Fast path header may be on 1 byte more
        @param data: {Stream} from twisted layer
        """

        if self._isClient:
            leftPart = UInt8()
            data.readType(leftPart)
            self._lastShortLength.value &= ~0x80
            packetSize = (self._lastShortLength.value << 8) + leftPart.value
            #next state is fast patn data
            self.expect(packetSize - 3, self.readFastPath)
            return
        if self._lastShortLength.value & 0xFF == 0x82:
            size = UInt16Be()
            data.readType(size)
            packetSize = size.value
        else:  #0x81 or other
            leftPart = UInt8()
            data.readType(leftPart)
            self._lastShortLength.value &= ~0x80
            packetSize = leftPart.value

        #next state is fast path data
        self.expect(packetSize, self.readFastPath)
コード例 #8
0
ファイル: tpkt.py プロジェクト: zha0/rdpy
 def send(self, message):
     """
     @summary: Send encompassed data
     @param message: {network.Type} message to send
     """
     RawLayer.send(self, (UInt8(Action.FASTPATH_ACTION_X224), UInt8(0),
                          UInt16Be(sizeof(message) + 4), message))
コード例 #9
0
 def sendPixelFormat(self, pixelFormat):
     """
     @summary:  Send pixel format structure
                 Very important packet that inform the image struct supported by the client
     @param pixelFormat: PixelFormat struct
     """
     self.send((UInt8(ClientToServerMessages.PIXEL_FORMAT), UInt16Be(), UInt8(), pixelFormat))
コード例 #10
0
def writeInteger16(value, minimum=0):
    """
    @summary: write UInt16Be minus minimum
    @param value: value to write
    @param minimum: value subtracted to real value
    @return: UInt16Be
    """
    return UInt16Be(value - minimum)
コード例 #11
0
ファイル: rfb.py プロジェクト: chushuai/rdpy
 def sendSetEncoding(self):
     """
     @summary:  Send set encoding packet
                 Actually only RAW bitmap encoding are used
     """
     self.send(
         (UInt8(ClientToServerMessages.ENCODING), UInt8(), UInt16Be(1),
          SInt32Be(Encoding.RAW)))
コード例 #12
0
ファイル: tpkt.py プロジェクト: zha0/rdpy
 def sendFastPath(self, secFlag, fastPathS):
     """
     @param fastPathS: type transform to stream and send as fastpath
     @param secFlag: {integer} Security flag for fastpath packet
     """
     RawLayer.send(
         self,
         (UInt8(Action.FASTPATH_ACTION_FASTPATH | ((secFlag & 0x3) << 6)),
          UInt16Be((sizeof(fastPathS) + 3) | 0x8000), fastPathS))
コード例 #13
0
ファイル: tpkt.py プロジェクト: zha0/rdpy
 def readExtendedHeader(self, data):
     """
     @summary: Header may be on 4 bytes
     @param data: {Stream} from twisted layer
     """
     #next state is read data
     size = UInt16Be()
     data.readType(size)
     self.expect(size.value - 4, self.readData)
コード例 #14
0
ファイル: ber.py プロジェクト: zha0/rdpy
def writeLength(size):
    """
    @summary: Return structure 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)
コード例 #15
0
def writeLength(value):
    """
    @summary: 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)
コード例 #16
0
def readInteger16(s, minimum=0):
    """
    @summary: 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
コード例 #17
0
ファイル: rfb.py プロジェクト: chushuai/rdpy
 def recvFrameBufferUpdateHeader(self, data):
     """
     @summary: Read frame buffer update packet header
     @param data: Stream that contains well formed packet
     """
     #padding
     nbRect = UInt16Be()
     self._nbRect = data.readType((UInt8(), nbRect))
     self._nbRect = nbRect.value
     self.expect(12, self.recvRectHeader)
コード例 #18
0
def writeInteger(value):
    """
    @summary: 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))
コード例 #19
0
ファイル: ber.py プロジェクト: zha0/rdpy
def writeInteger(value):
    """
    @summary: Write integer value
    @param param: INT or Python long
    @return: BER integer block 
    """
    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))
コード例 #20
0
def readInteger(s):
    """
    @summary: 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
コード例 #21
0
ファイル: rfb.py プロジェクト: chushuai/rdpy
 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:
         log.error("invalid header length")
         return
     data.readType(bodyLen)
     self.expect(bodyLen.value, self._callbackBody)
コード例 #22
0
ファイル: ber.py プロジェクト: zha0/rdpy
def readLength(s):
    """
    @summary: 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
コード例 #23
0
ファイル: rfb.py プロジェクト: chushuai/rdpy
 def __init__(self):
     CompositeType.__init__(self)
     self.width = UInt16Be()
     self.height = UInt16Be()
     self.pixelFormat = PixelFormat()
コード例 #24
0
ファイル: rfb.py プロジェクト: chushuai/rdpy
 def __init__(self):
     CompositeType.__init__(self)
     self.downFlag = UInt8(False)
     self.padding = UInt16Be()
     self.key = UInt32Be()
コード例 #25
0
ファイル: rfb.py プロジェクト: chushuai/rdpy
 def __init__(self):
     CompositeType.__init__(self)
     self.mask = UInt8()
     self.x = UInt16Be()
     self.y = UInt16Be()
コード例 #26
0
ファイル: rfb.py プロジェクト: chushuai/rdpy
 def __init__(self, text=""):
     CompositeType.__init__(self)
     self.padding = (UInt16Be(), UInt8())
     self.size = UInt32Be(len(text))
     self.message = String(text)
コード例 #27
0
ファイル: rfb.py プロジェクト: chushuai/rdpy
 def __init__(self):
     CompositeType.__init__(self)
     self.padding = (UInt16Be(), UInt8())
     self.size = UInt32Be()