change project format
This commit is contained in:
120
rdpy/display/qt.py
Normal file
120
rdpy/display/qt.py
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
'''
|
||||||
|
@author: sylvain
|
||||||
|
'''
|
||||||
|
from PyQt4 import QtGui
|
||||||
|
from rdpy.protocol.rfb.rfb import RfbObserver
|
||||||
|
|
||||||
|
class QAdaptor(object):
|
||||||
|
'''
|
||||||
|
adaptor model with link beetween protocol
|
||||||
|
and qt widget
|
||||||
|
'''
|
||||||
|
def __init__(self):
|
||||||
|
'''
|
||||||
|
constructor
|
||||||
|
must set qRemoteDesktop attribute
|
||||||
|
'''
|
||||||
|
#qwidget use for render
|
||||||
|
self._qRemoteDesktop = None
|
||||||
|
|
||||||
|
def sendMouseEvent(self, e):
|
||||||
|
'''
|
||||||
|
interface to send mouse event
|
||||||
|
to protocol stack
|
||||||
|
@param e: qEvent
|
||||||
|
'''
|
||||||
|
pass
|
||||||
|
|
||||||
|
def sendKeyEvent(self, e):
|
||||||
|
'''
|
||||||
|
interface to send key event
|
||||||
|
to protocol stack
|
||||||
|
@param e: qEvent
|
||||||
|
'''
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class RfbAdaptor(RfbObserver, QAdaptor):
|
||||||
|
'''
|
||||||
|
QAdaptor for specific RFB protocol stack
|
||||||
|
is to an RFB observer
|
||||||
|
'''
|
||||||
|
def __init__(self, rfb):
|
||||||
|
'''
|
||||||
|
ctor
|
||||||
|
@param rfb: RFB protocol stack
|
||||||
|
'''
|
||||||
|
self._rfb = rfb
|
||||||
|
#set RFB observer to
|
||||||
|
self._rfb.addObserver(self)
|
||||||
|
|
||||||
|
def notifyFramebufferUpdate(self, width, height, x, y, pixelFormat, encoding, data):
|
||||||
|
'''
|
||||||
|
implement RfbAdaptor interface
|
||||||
|
@param width: width of new image
|
||||||
|
@param height: height of new image
|
||||||
|
@param x: xpositionof new image
|
||||||
|
@param y: y position of new image
|
||||||
|
@param pixelFormat: pixefFormat structure in rfb.message.PixelFormat
|
||||||
|
@param encoding: encoding typpe rfb.message.Encoding
|
||||||
|
@param data: image data in accordance with pixelformat and encoding
|
||||||
|
'''
|
||||||
|
imageFormat = None
|
||||||
|
if pixelFormat.BitsPerPixel.value == 32 and pixelFormat.RedShift.value == 16:
|
||||||
|
imageFormat = QtGui.QImage.Format_RGB32
|
||||||
|
else:
|
||||||
|
print "Receive image in bad format"
|
||||||
|
return
|
||||||
|
|
||||||
|
image = QtGui.QImage(data, width, height, imageFormat)
|
||||||
|
self._qRemoteDesktop.notifyImage(x, y, image)
|
||||||
|
|
||||||
|
def sendMouseEvent(self, e):
|
||||||
|
'''
|
||||||
|
convert qt mouse event to rfb mouse event
|
||||||
|
send mouse event to rfb protocol stack
|
||||||
|
@param e: qEvent
|
||||||
|
'''
|
||||||
|
self._rfb.sendPointerEvent(0, e.pos().x(), e.pos().y())
|
||||||
|
|
||||||
|
def sendKeyEvent(self, e):
|
||||||
|
'''
|
||||||
|
convert qt key press event to rfb press event
|
||||||
|
send key event to protocol stack
|
||||||
|
@param e: qevent
|
||||||
|
'''
|
||||||
|
self._rfb.sendKeyEvent(True, e.nativeVirtualKey())
|
||||||
|
|
||||||
|
|
||||||
|
class QRemoteDesktop(QtGui.QWidget):
|
||||||
|
'''
|
||||||
|
Class that represent the main
|
||||||
|
widget
|
||||||
|
'''
|
||||||
|
def __init__(self, adaptor):
|
||||||
|
super(QRemoteDesktop, self).__init__()
|
||||||
|
self._adaptor = adaptor
|
||||||
|
self._adaptor._qRemoteDesktop = self
|
||||||
|
self._refresh = []
|
||||||
|
self.setMouseTracking(True)
|
||||||
|
|
||||||
|
def notifyImage(self, x, y, qimage):
|
||||||
|
self._refresh.append({"x" : x, "y" : y, "image" : qimage})
|
||||||
|
self.update()
|
||||||
|
|
||||||
|
def paintEvent(self, e):
|
||||||
|
if self._refresh == []:
|
||||||
|
return
|
||||||
|
qp = QtGui.QPainter()
|
||||||
|
qp.begin(self)
|
||||||
|
for image in self._refresh:
|
||||||
|
qp.drawImage(image["x"], image["y"], image["image"])
|
||||||
|
qp.end()
|
||||||
|
|
||||||
|
self._lastReceive = []
|
||||||
|
|
||||||
|
def mouseMoveEvent(self, event):
|
||||||
|
self._adaptor.sendMouseEvent(event)
|
||||||
|
|
||||||
|
def keyPressEvent(self, event):
|
||||||
|
self._adaptor.sendKeyEvent(event)
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
'''
|
|
||||||
Created on 4 sept. 2013
|
|
||||||
@author: sylvain
|
|
||||||
'''
|
|
||||||
from PyQt4 import QtGui
|
|
||||||
from rdpy.protocol.rfb.observer import RfbObserver
|
|
||||||
|
|
||||||
class QAdaptor(object):
|
|
||||||
'''
|
|
||||||
Adaptor for all qt
|
|
||||||
'''
|
|
||||||
def __init__(self):
|
|
||||||
self._observers = []
|
|
||||||
|
|
||||||
def addObserver(self, observer):
|
|
||||||
self._observers.append(observer)
|
|
||||||
|
|
||||||
def notifyImage(self, x, y, qimage):
|
|
||||||
for observer in self._observers:
|
|
||||||
observer.notifyImage(x, y, qimage)
|
|
||||||
|
|
||||||
def sendMouseEvent(self, e):
|
|
||||||
pass
|
|
||||||
def sendKeyEvent(self, e):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class RfbAdaptor(RfbObserver, QAdaptor):
|
|
||||||
'''
|
|
||||||
classdocs
|
|
||||||
'''
|
|
||||||
|
|
||||||
def __init__(self, rfb):
|
|
||||||
QAdaptor.__init__(self)
|
|
||||||
self._rfb = rfb
|
|
||||||
self._rfb.addObserver(self)
|
|
||||||
|
|
||||||
def notifyFramebufferUpdate(self, width, height, x, y, pixelFormat, encoding, data):
|
|
||||||
'''
|
|
||||||
implement RfbAdaptor interface
|
|
||||||
'''
|
|
||||||
imageFormat = None
|
|
||||||
if pixelFormat.BitsPerPixel.value == 32 and pixelFormat.RedShift.value == 16:
|
|
||||||
imageFormat = QtGui.QImage.Format_RGB32
|
|
||||||
else:
|
|
||||||
print "Receive image in bad format"
|
|
||||||
return
|
|
||||||
|
|
||||||
image = QtGui.QImage(data, width, height, imageFormat)
|
|
||||||
self.notifyImage(x, y, image)
|
|
||||||
|
|
||||||
def sendMouseEvent(self, e):
|
|
||||||
'''
|
|
||||||
convert qt mouse event to rfb mouse event
|
|
||||||
'''
|
|
||||||
self._rfb.sendPointerEvent(0, e.pos().x(), e.pos().y())
|
|
||||||
|
|
||||||
def sendKeyEvent(self, e):
|
|
||||||
'''
|
|
||||||
convert qt key press event to rfb press event
|
|
||||||
'''
|
|
||||||
self._rfb.sendKeyEvent(True, e.nativeVirtualKey())
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
'''
|
|
||||||
Created on 4 sept. 2013
|
|
||||||
|
|
||||||
@author: sylvain
|
|
||||||
'''
|
|
||||||
|
|
||||||
class QObserver(object):
|
|
||||||
'''
|
|
||||||
classdocs
|
|
||||||
'''
|
|
||||||
def notifyImage(self, x, y, qimage):
|
|
||||||
pass
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
'''
|
|
||||||
Created on 4 sept. 2013
|
|
||||||
|
|
||||||
@author: sylvain
|
|
||||||
'''
|
|
||||||
|
|
||||||
from PyQt4 import QtGui
|
|
||||||
from observer import QObserver
|
|
||||||
|
|
||||||
class QRemoteDesktop(QtGui.QWidget, QObserver):
|
|
||||||
|
|
||||||
def __init__(self, adaptor):
|
|
||||||
super(QRemoteDesktop, self).__init__()
|
|
||||||
self._adaptor = adaptor
|
|
||||||
self._adaptor.addObserver(self)
|
|
||||||
self._refresh = []
|
|
||||||
self.setMouseTracking(True)
|
|
||||||
|
|
||||||
def notifyImage(self, x, y, qimage):
|
|
||||||
self._refresh.append({"x" : x, "y" : y, "image" : qimage})
|
|
||||||
self.update()
|
|
||||||
|
|
||||||
def paintEvent(self, e):
|
|
||||||
if self._refresh == []:
|
|
||||||
return
|
|
||||||
qp = QtGui.QPainter()
|
|
||||||
qp.begin(self)
|
|
||||||
for image in self._refresh:
|
|
||||||
qp.drawImage(image["x"], image["y"], image["image"])
|
|
||||||
qp.end()
|
|
||||||
|
|
||||||
self._lastReceive = []
|
|
||||||
|
|
||||||
def mouseMoveEvent(self, event):
|
|
||||||
self._adaptor.sendMouseEvent(event)
|
|
||||||
|
|
||||||
def keyPressEvent(self, event):
|
|
||||||
self._adaptor.sendKeyEvent(event)
|
|
||||||
29
rdpy/main.py
29
rdpy/main.py
@@ -1,29 +0,0 @@
|
|||||||
'''
|
|
||||||
Created on 4 sept. 2013
|
|
||||||
|
|
||||||
@author: sylvain
|
|
||||||
'''
|
|
||||||
import sys
|
|
||||||
from PyQt4 import QtGui
|
|
||||||
from rdpy.display.qt import adaptor, widget
|
|
||||||
from rdpy.protocol.rfb import rfb, factory
|
|
||||||
from rdpy.protocol.rdp import tpkt, tpdu, mcs
|
|
||||||
from twisted.internet import ssl
|
|
||||||
from OpenSSL import SSL
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
#app = QtGui.QApplication(sys.argv)
|
|
||||||
#import qt4reactor
|
|
||||||
#qt4reactor.install()
|
|
||||||
|
|
||||||
#protocol = rfb.Rfb(rfb.Rfb.CLIENT)
|
|
||||||
#w = widget.QRemoteDesktop(adaptor.RfbAdaptor(protocol))
|
|
||||||
#w.resize(1000, 700)
|
|
||||||
#w.setWindowTitle('QVNCViewer')
|
|
||||||
#w.show()
|
|
||||||
from twisted.internet import reactor
|
|
||||||
#reactor.connectTCP("127.0.0.1", 5901, factory.RfbFactory(protocol))
|
|
||||||
#reactor.connectTCP("192.168.1.90", 3389, factory.RfbFactory(tpkt.TPKT(tpdu.TPDU(mcs.MCS()))))
|
|
||||||
reactor.connectTCP("192.168.135.50", 3389, factory.RfbFactory(tpkt.TPKT(tpdu.TPDU(mcs.MCS()))))
|
|
||||||
reactor.run()
|
|
||||||
#sys.exit(app.exec_())
|
|
||||||
@@ -1,16 +1,14 @@
|
|||||||
'''
|
'''
|
||||||
Created on 22 aout 2013
|
|
||||||
|
|
||||||
@author: sylvain
|
@author: sylvain
|
||||||
'''
|
'''
|
||||||
from twisted.internet import protocol
|
from twisted.internet import protocol
|
||||||
|
import tpkt, tpdu, mcs
|
||||||
class RfbFactory(protocol.Factory):
|
class Factory(protocol.Factory):
|
||||||
'''
|
'''
|
||||||
classdocs
|
Factory of RFB protocol
|
||||||
'''
|
'''
|
||||||
def __init__(self, protocol):
|
def __init__(self):
|
||||||
self._protocol = protocol
|
self._protocol = tpkt.TPKT(tpdu.TPDU(mcs.MCS()))
|
||||||
|
|
||||||
def buildProtocol(self, addr):
|
def buildProtocol(self, addr):
|
||||||
return self._protocol;
|
return self._protocol;
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
'''
|
|
||||||
Created on 4 sept. 2013
|
|
||||||
|
|
||||||
@author: sylvain
|
|
||||||
'''
|
|
||||||
|
|
||||||
class RfbObserver(object):
|
|
||||||
'''
|
|
||||||
Rfb protocol obserser
|
|
||||||
'''
|
|
||||||
def notifyFramebufferUpdate(self, width, height, x, y, pixelFormat, encoding, data):
|
|
||||||
'''
|
|
||||||
recv framebuffer update
|
|
||||||
width : width of image
|
|
||||||
height : height of image
|
|
||||||
x : x position
|
|
||||||
y : y position
|
|
||||||
pixelFormat : pixel format struct from rfb.types
|
|
||||||
encoding : encoding struct from rfb.types
|
|
||||||
data : in respect of dataFormat and pixelFormat
|
|
||||||
'''
|
|
||||||
pass
|
|
||||||
|
|
||||||
@@ -1,24 +1,26 @@
|
|||||||
'''
|
'''
|
||||||
@author: sylvain
|
@author: sylvain
|
||||||
'''
|
'''
|
||||||
|
from twisted.internet import protocol
|
||||||
from rdpy.protocol.network.type import String, UInt8, UInt16Be, UInt32Be
|
from rdpy.protocol.network.type import String, UInt8, UInt16Be, UInt32Be
|
||||||
from rdpy.protocol.network.layer import RawLayer
|
from rdpy.protocol.network.layer import RawLayer
|
||||||
from message import *
|
from message import *
|
||||||
|
|
||||||
|
class ProtocolMode(object):
|
||||||
|
CLIENT = 0
|
||||||
|
SERVER = 1
|
||||||
|
|
||||||
class Rfb(RawLayer):
|
class Rfb(RawLayer):
|
||||||
'''
|
'''
|
||||||
implements rfb protocol
|
implements rfb protocol
|
||||||
'''
|
'''
|
||||||
CLIENT = 0
|
|
||||||
SERVER = 1
|
|
||||||
|
|
||||||
def __init__(self, mode):
|
def __init__(self, mode):
|
||||||
'''
|
'''
|
||||||
constructor
|
constructor
|
||||||
mode can be only client or server mode
|
mode can be only client or server mode
|
||||||
in this RDPY version only client mode is supported
|
in this RDPY version only client mode is supported
|
||||||
@param mode: Rfb.CLIENT | Rfb.SERVER
|
@param mode: ProtocolMode.CLIENT | ProtocolMode.SERVER
|
||||||
'''
|
'''
|
||||||
RawLayer.__init__(self)
|
RawLayer.__init__(self)
|
||||||
#usefull for rfb protocol
|
#usefull for rfb protocol
|
||||||
@@ -85,7 +87,7 @@ class Rfb(RawLayer):
|
|||||||
call when transport layer connection
|
call when transport layer connection
|
||||||
is made
|
is made
|
||||||
'''
|
'''
|
||||||
if self._mode == Rfb.CLIENT:
|
if self._mode == ProtocolMode.CLIENT:
|
||||||
self.expect(12, self.readProtocolVersion)
|
self.expect(12, self.readProtocolVersion)
|
||||||
else:
|
else:
|
||||||
self.send(self._version)
|
self.send(self._version)
|
||||||
@@ -267,4 +269,40 @@ class Rfb(RawLayer):
|
|||||||
'''
|
'''
|
||||||
write client cut text event packet
|
write client cut text event packet
|
||||||
'''
|
'''
|
||||||
self.send((ClientToServerMessages.CUT_TEXT, ClientCutText(text)))
|
self.send((ClientToServerMessages.CUT_TEXT, ClientCutText(text)))
|
||||||
|
|
||||||
|
class Factory(protocol.Factory):
|
||||||
|
'''
|
||||||
|
Factory of RFB protocol
|
||||||
|
'''
|
||||||
|
def __init__(self, mode):
|
||||||
|
self._protocol = Rfb(mode)
|
||||||
|
|
||||||
|
def buildProtocol(self, addr):
|
||||||
|
return self._protocol;
|
||||||
|
|
||||||
|
def startedConnecting(self, connector):
|
||||||
|
print 'Started to connect.'
|
||||||
|
|
||||||
|
def clientConnectionLost(self, connector, reason):
|
||||||
|
print 'Lost connection. Reason:', reason
|
||||||
|
|
||||||
|
def clientConnectionFailed(self, connector, reason):
|
||||||
|
print 'Connection failed. Reason:', reason
|
||||||
|
|
||||||
|
class RfbObserver(object):
|
||||||
|
'''
|
||||||
|
Rfb protocol obserser
|
||||||
|
'''
|
||||||
|
def notifyFramebufferUpdate(self, width, height, x, y, pixelFormat, encoding, data):
|
||||||
|
'''
|
||||||
|
recv framebuffer update
|
||||||
|
width : width of image
|
||||||
|
height : height of image
|
||||||
|
x : x position
|
||||||
|
y : y position
|
||||||
|
pixelFormat : pixel format struct from rfb.types
|
||||||
|
encoding : encoding struct from rfb.types
|
||||||
|
data : in respect of dataFormat and pixelFormat
|
||||||
|
'''
|
||||||
|
pass
|
||||||
13
rdpy/rdpclient.py
Normal file
13
rdpy/rdpclient.py
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
'''
|
||||||
|
Created on 4 sept. 2013
|
||||||
|
|
||||||
|
@author: sylvain
|
||||||
|
'''
|
||||||
|
from rdpy.protocol.rdp import rdp
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
from twisted.internet import reactor
|
||||||
|
#reactor.connectTCP("127.0.0.1", 5901, factory.RfbFactory(protocol))
|
||||||
|
#reactor.connectTCP("192.168.1.90", 3389, factory.RfbFactory(tpkt.TPKT(tpdu.TPDU(mcs.MCS()))))
|
||||||
|
reactor.connectTCP("192.168.135.50", 3389, rdp.Factory())
|
||||||
|
reactor.run()
|
||||||
13
rdpy/rdpserver.py
Normal file
13
rdpy/rdpserver.py
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
'''
|
||||||
|
@author: sylvain
|
||||||
|
'''
|
||||||
|
|
||||||
|
from rdpy.protocol.rfb import factory
|
||||||
|
from rdpy.protocol.rdp import tpkt, tpdu, mcs
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
from twisted.internet import reactor
|
||||||
|
#reactor.connectTCP("127.0.0.1", 5901, factory.RfbFactory(protocol))
|
||||||
|
#reactor.connectTCP("192.168.1.90", 3389, factory.RfbFactory(tpkt.TPKT(tpdu.TPDU(mcs.MCS()))))
|
||||||
|
reactor.listenTCP(33389, factory.RfbFactory(tpkt.TPKT(tpdu.TPDU(mcs.MCS()))))
|
||||||
|
reactor.run()
|
||||||
@@ -4,8 +4,8 @@
|
|||||||
|
|
||||||
import sys
|
import sys
|
||||||
from PyQt4 import QtGui
|
from PyQt4 import QtGui
|
||||||
from rdpy.display.qt import adaptor, widget
|
from rdpy.display.qt import RfbAdaptor, QRemoteDesktop
|
||||||
from rdpy.protocol.rfb import rfb, factory
|
from rdpy.protocol.rfb import rfb
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
#create application
|
#create application
|
||||||
@@ -16,12 +16,12 @@ if __name__ == '__main__':
|
|||||||
qt4reactor.install()
|
qt4reactor.install()
|
||||||
|
|
||||||
#create rfb protocol
|
#create rfb protocol
|
||||||
protocol = rfb.Rfb(rfb.Rfb.CLIENT)
|
factory = rfb.Factory(rfb.ProtocolMode.CLIENT)
|
||||||
w = widget.QRemoteDesktop(adaptor.RfbAdaptor(protocol))
|
w = QRemoteDesktop(RfbAdaptor(factory._protocol))
|
||||||
w.resize(1000, 700)
|
w.resize(1000, 700)
|
||||||
w.setWindowTitle('vncclient')
|
w.setWindowTitle('vncclient')
|
||||||
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)
|
||||||
reactor.run()
|
reactor.run()
|
||||||
sys.exit(app.exec_())
|
sys.exit(app.exec_())
|
||||||
Reference in New Issue
Block a user