From 99f2e8c32508ab193c1d42221c86cb7fca4be9ab Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sun, 6 Feb 2005 02:27:46 +0000 Subject: [PATCH] Decode mouse events, try to send RDP4 bitmap updates back (?). --- Makefile | 2 +- iso.c | 6 ++-- rdp5.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ rdpsrv.c | 5 +++- secure.c | 10 +++---- 5 files changed, 98 insertions(+), 11 deletions(-) create mode 100644 rdp5.c diff --git a/Makefile b/Makefile index c71c0a7..5d55b2b 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ CFLAGS=-g -Wall LIBS=-lssl all: rdpsrv protodiff -OBJS=rdpsrv.o iso.o tcp.o util.o mcs.o secure.o channels.o rdp.o licence.o +OBJS=rdpsrv.o iso.o tcp.o util.o mcs.o secure.o channels.o rdp.o licence.o rdp5.o OBJS_PROTODIFF=protodiff.o tcp.o util.o rdpsrv: $(OBJS) diff --git a/iso.c b/iso.c index b0bafa7..a098ad5 100644 --- a/iso.c +++ b/iso.c @@ -111,10 +111,8 @@ iso_recv_msg(uint8 * code) if ((version & 3) == 0) { - // FIXME :-) - // rdp5_process(s, version & 0x80); - printf("rdp5_process()\n"); - goto next_packet; + rdp5_process(s, version & 0x80); + return NULL; } in_uint8s(s, 1); /* hdrlen */ diff --git a/rdp5.c b/rdp5.c new file mode 100644 index 0000000..0ac3807 --- /dev/null +++ b/rdp5.c @@ -0,0 +1,86 @@ +/* -*- c-basic-offset: 8 -*- + rdesktop: A Remote Desktop Protocol client. + Protocol services - Multipoint Communications Service + Copyright (C) Matthew Chapman 1999-2002 + Copyright (C) Erik Forsberg 2003 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "rdesktop.h" + +extern uint8 *g_next_packet; +extern int listen_on_vnc; + +void +rdp5_process(STREAM s, BOOL encryption) +{ + uint16 length, count, x, y; + uint8 type; + uint8 *next; + + if (encryption) + { + in_uint8s(s, 8); /* signature */ + sec_decrypt(s->p, s->end - s->p); + } + +#if 1 + printf("RDP5 data:\n"); + hexdump(s->p, s->end - s->p); +#endif + + while (s->p < s->end) + { + in_uint8(s, type); + + switch (type) + { + case 32: { // mouse + listen_on_vnc = 1; + uint16 device_flags, x, y; + static int mouse1_down = 0, mouse2_down = 0; + + in_uint16_le(s, device_flags); + in_uint16_le(s, x); + in_uint16_le(s, y); + + printf("- Type: Mouse\n"); + printf("- Device flags: %x\n", device_flags); + printf("- Position: (%u,%u)\n", x, y); + + if (device_flags & MOUSE_FLAG_BUTTON1) + mouse1_down = (device_flags & MOUSE_FLAG_DOWN) ? 0x01 : 0; + if (device_flags & MOUSE_FLAG_BUTTON2) + mouse2_down = (device_flags & MOUSE_FLAG_DOWN) ? 0x02 : 0; + + printf("button mask = %x\n", mouse1_down | mouse2_down); + + /* buf[0] = 5; // message type + buf[1] = mouse1_down | mouse2_down; // button mask + buf[2] = param1 >> 8; + buf[3] = param1 & 0xff; + buf[4] = param2 >> 8; + buf[5] = param2 & 0xff; + write(vnc_sock, buf, 6); */ + + break; + } + default: + printf("Unimplemented RDP5 opcode %d (len=%u)\n", type, length); + return; + } + } +} diff --git a/rdpsrv.c b/rdpsrv.c index 9198987..c5cb187 100644 --- a/rdpsrv.c +++ b/rdpsrv.c @@ -320,10 +320,11 @@ void handle_vnc_fbupdate(int vnc_sock) } } +int listen_on_vnc = 0; + int serve_client() { int vnc_sock = vnc_init(); - int listen_on_vnc = 0; if (!mcs_recv_connect_initial()) error("MCS_CONNECT_INITIAL recv failed"); @@ -363,6 +364,8 @@ int serve_client() } } + printf("LISTEN_ON_VNC=%u\n", listen_on_vnc); + // activity on VNC socket? if (FD_ISSET(vnc_sock, &readfs) && listen_on_vnc) { unsigned char buf[256]; diff --git a/secure.c b/secure.c index 62e59a5..56c8bef 100644 --- a/secure.c +++ b/secure.c @@ -842,7 +842,7 @@ sec_recv(void) uint16 channel; STREAM s; - while ((s = mcs_recv(&channel)) != NULL) + if ((s = mcs_recv(&channel)) != NULL) { if (/*g_encryption || !g_licence_issued*/ 1) { @@ -883,7 +883,7 @@ sec_recv(void) } } - continue; + return NULL; } if (sec_flags & SEC_LOGON_INFO) @@ -901,7 +901,7 @@ sec_recv(void) sec_send(s, SEC_LICENCE_NEG); } - continue; + return NULL; } if (sec_flags & SEC_CLIENT_RANDOM) { @@ -934,7 +934,7 @@ sec_recv(void) // now we can generate the keys sec_generate_keys(inr + SEC_RANDOM_SIZE, cacert, 1); - continue; + return NULL; } } @@ -942,7 +942,7 @@ sec_recv(void) if (channel != MCS_GLOBAL_CHANNEL) { channel_process(s, channel); - continue; + return NULL; } return s; -- 2.39.2