Skip to content

Commit

Permalink
Merge pull request #126 from agfor/badly_behaved_servers
Browse files Browse the repository at this point in the history
Make the client work with badly behaved servers
  • Loading branch information
sibson committed Jan 26, 2018
2 parents 4264ae7 + 9bd3e24 commit 5dbb3b5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
6 changes: 6 additions & 0 deletions tests/unit/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def _tryPIL(self):

def test_vncConnectionMade(self):
cli = self.client
cli._packet = [b"RFB003.003\n"]
cli._handleInitial()
cli._handleServerInit(b" " * 24)
cli.vncConnectionMade()
factory = cli.factory
Expand Down Expand Up @@ -66,6 +68,8 @@ def test_keyPress_multiple(self):

def test_captureScreen(self):
cli = self.client
cli._packet = [b"RFB003.003\n"]
cli._handleInitial()
cli._handleServerInit(b" " * 24)
cli.vncConnectionMade()
fname = 'foo.png'
Expand All @@ -86,6 +90,8 @@ def test_expectScreen(self):
self._tryPIL()

cli = self.client
cli._packet = [b"RFB003.003\n"]
cli._handleInitial()
cli._handleServerInit(b" " * 24)
cli.vncConnectionMade()
cli.screen = mock.Mock()
Expand Down
23 changes: 22 additions & 1 deletion vncdotool/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,14 @@ def mouseDrag(self, x, y, step=1):
def setImageMode(self):
""" Extracts color ordering and 24 vs. 32 bpp info out of the pixel format information
"""
if (self.truecolor and (not self.bigendian) and self.depth == 24
if self._version_server == 3.889:
self.setPixelFormat(
bpp = 16, depth = 16, bigendian = 0, truecolor = 1,
redmax = 31, greenmax = 63, bluemax = 31,
redshift = 11, greenshift = 5, blueshift = 0
)
self.image_mode = "BGR;16"
elif (self.truecolor and (not self.bigendian) and self.depth == 24
and self.redmax == 255 and self.greenmax == 255 and self.bluemax == 255):

pixel = ["X"] * self.bypp
Expand Down Expand Up @@ -444,6 +451,16 @@ def updateDesktopSize(self, width, height):
self.screen = new_screen


class VMWareClient(VNCDoToolClient):
def dataReceived(self, data):
single_pixel_update = b'\x00\x01\x00\x00\x00\x00\x00\x01\x00\x01\x00\x00\x00\x00'
if len(data) == 20 and int(data[0]) == 0 and data[2:16] == single_pixel_update:
self.framebufferUpdateRequest()
self._handler()
else:
super(VMWareClient, self).dataReceived(data)


class VNCDoToolFactory(rfb.RFBFactory):
password = None

Expand All @@ -468,6 +485,10 @@ def clientConnectionMade(self, protocol):
self.deferred.callback(protocol)


class VMWareFactory(VNCDoToolFactory):
protocol = VMWareClient


def factory_connect(factory, host, port, family):
if family == socket.AF_INET:
reactor.connectTCP(host, port, factory)
Expand Down
2 changes: 2 additions & 0 deletions vncdotool/rfb.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def __init__(self):
self._handler = self._handleInitial
self._already_expecting = 0
self._version = None
self._version_server = None

#------------------------------------------------------
# states used on connection startup
Expand Down Expand Up @@ -147,6 +148,7 @@ def _handleInitial(self):
self._packet_len = len(buffer)
self._handler = self._handleExpected
self._version = version
self._version_server = version_server
if version < 3.7:
self.expect(self._handleAuth, 4)
else:
Expand Down

0 comments on commit 5dbb3b5

Please sign in to comment.