a180a41bba1d50822df23fff0099e90b86638b89vboxsync/* -*- c-basic-offset: 8 -*-
a180a41bba1d50822df23fff0099e90b86638b89vboxsync rdesktop: A Remote Desktop Protocol client.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync Protocol services - RDP5 short form PDU processing
a180a41bba1d50822df23fff0099e90b86638b89vboxsync Copyright (C) Matthew Chapman <matthewc.unsw.edu.au> 1999-2008
a180a41bba1d50822df23fff0099e90b86638b89vboxsync Copyright 2003-2008 Erik Forsberg <forsberg@cendio.se> for Cendio AB
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync This program is free software: you can redistribute it and/or modify
a180a41bba1d50822df23fff0099e90b86638b89vboxsync it under the terms of the GNU General Public License as published by
a180a41bba1d50822df23fff0099e90b86638b89vboxsync the Free Software Foundation, either version 3 of the License, or
a180a41bba1d50822df23fff0099e90b86638b89vboxsync (at your option) any later version.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync This program is distributed in the hope that it will be useful,
a180a41bba1d50822df23fff0099e90b86638b89vboxsync but WITHOUT ANY WARRANTY; without even the implied warranty of
a180a41bba1d50822df23fff0099e90b86638b89vboxsync MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a180a41bba1d50822df23fff0099e90b86638b89vboxsync GNU General Public License for more details.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync You should have received a copy of the GNU General Public License
a180a41bba1d50822df23fff0099e90b86638b89vboxsync along with this program. If not, see <http://www.gnu.org/licenses/>.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync*/
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
6e9aa255e3376b2da5824c09c4c62bc233463bfevboxsync/*
6e9aa255e3376b2da5824c09c4c62bc233463bfevboxsync * Oracle GPL Disclaimer: For the avoidance of doubt, except that if any license choice
6e9aa255e3376b2da5824c09c4c62bc233463bfevboxsync * other than GPL or LGPL is available it will apply instead, Oracle elects to use only
6e9aa255e3376b2da5824c09c4c62bc233463bfevboxsync * the General Public License version 2 (GPLv2) at this time for any software where
6e9aa255e3376b2da5824c09c4c62bc233463bfevboxsync * a choice of GPL license versions is made available with the language indicating
6e9aa255e3376b2da5824c09c4c62bc233463bfevboxsync * that GPLv2 or any later version may be used, or where a choice of which version
6e9aa255e3376b2da5824c09c4c62bc233463bfevboxsync * of the GPL is applied is otherwise unspecified.
6e9aa255e3376b2da5824c09c4c62bc233463bfevboxsync */
6e9aa255e3376b2da5824c09c4c62bc233463bfevboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync#include "rdesktop.h"
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncextern uint8 *g_next_packet;
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncextern RDPCOMP g_mppc_dict;
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncvoid
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncrdp5_process(STREAM s)
a180a41bba1d50822df23fff0099e90b86638b89vboxsync{
a180a41bba1d50822df23fff0099e90b86638b89vboxsync uint16 length, count, x, y;
a180a41bba1d50822df23fff0099e90b86638b89vboxsync uint8 type, ctype;
a180a41bba1d50822df23fff0099e90b86638b89vboxsync uint8 *next;
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync uint32 roff, rlen;
a180a41bba1d50822df23fff0099e90b86638b89vboxsync struct stream *ns = &(g_mppc_dict.ns);
a180a41bba1d50822df23fff0099e90b86638b89vboxsync struct stream *ts;
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync#if 0
a180a41bba1d50822df23fff0099e90b86638b89vboxsync printf("RDP5 data:\n");
a180a41bba1d50822df23fff0099e90b86638b89vboxsync hexdump(s->p, s->end - s->p);
a180a41bba1d50822df23fff0099e90b86638b89vboxsync#endif
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync ui_begin_update();
a180a41bba1d50822df23fff0099e90b86638b89vboxsync while (s->p < s->end)
a180a41bba1d50822df23fff0099e90b86638b89vboxsync {
a180a41bba1d50822df23fff0099e90b86638b89vboxsync in_uint8(s, type);
a180a41bba1d50822df23fff0099e90b86638b89vboxsync if (type & RDP5_COMPRESSED)
a180a41bba1d50822df23fff0099e90b86638b89vboxsync {
a180a41bba1d50822df23fff0099e90b86638b89vboxsync in_uint8(s, ctype);
a180a41bba1d50822df23fff0099e90b86638b89vboxsync in_uint16_le(s, length);
a180a41bba1d50822df23fff0099e90b86638b89vboxsync type ^= RDP5_COMPRESSED;
a180a41bba1d50822df23fff0099e90b86638b89vboxsync }
a180a41bba1d50822df23fff0099e90b86638b89vboxsync else
a180a41bba1d50822df23fff0099e90b86638b89vboxsync {
a180a41bba1d50822df23fff0099e90b86638b89vboxsync ctype = 0;
a180a41bba1d50822df23fff0099e90b86638b89vboxsync in_uint16_le(s, length);
a180a41bba1d50822df23fff0099e90b86638b89vboxsync }
a180a41bba1d50822df23fff0099e90b86638b89vboxsync g_next_packet = next = s->p + length;
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync if (ctype & RDP_MPPC_COMPRESSED)
a180a41bba1d50822df23fff0099e90b86638b89vboxsync {
a180a41bba1d50822df23fff0099e90b86638b89vboxsync if (mppc_expand(s->p, length, ctype, &roff, &rlen) == -1)
a180a41bba1d50822df23fff0099e90b86638b89vboxsync error("error while decompressing packet\n");
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync /* allocate memory and copy the uncompressed data into the temporary stream */
a180a41bba1d50822df23fff0099e90b86638b89vboxsync ns->data = (uint8 *) xrealloc(ns->data, rlen);
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync memcpy((ns->data), (unsigned char *) (g_mppc_dict.hist + roff), rlen);
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync ns->size = rlen;
a180a41bba1d50822df23fff0099e90b86638b89vboxsync ns->end = (ns->data + ns->size);
a180a41bba1d50822df23fff0099e90b86638b89vboxsync ns->p = ns->data;
a180a41bba1d50822df23fff0099e90b86638b89vboxsync ns->rdp_hdr = ns->p;
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync ts = ns;
a180a41bba1d50822df23fff0099e90b86638b89vboxsync }
a180a41bba1d50822df23fff0099e90b86638b89vboxsync else
a180a41bba1d50822df23fff0099e90b86638b89vboxsync ts = s;
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync switch (type)
a180a41bba1d50822df23fff0099e90b86638b89vboxsync {
a180a41bba1d50822df23fff0099e90b86638b89vboxsync case 0: /* update orders */
a180a41bba1d50822df23fff0099e90b86638b89vboxsync in_uint16_le(ts, count);
a180a41bba1d50822df23fff0099e90b86638b89vboxsync process_orders(ts, count);
a180a41bba1d50822df23fff0099e90b86638b89vboxsync break;
a180a41bba1d50822df23fff0099e90b86638b89vboxsync case 1: /* update bitmap */
a180a41bba1d50822df23fff0099e90b86638b89vboxsync in_uint8s(ts, 2); /* part length */
a180a41bba1d50822df23fff0099e90b86638b89vboxsync process_bitmap_updates(ts);
a180a41bba1d50822df23fff0099e90b86638b89vboxsync break;
a180a41bba1d50822df23fff0099e90b86638b89vboxsync case 2: /* update palette */
a180a41bba1d50822df23fff0099e90b86638b89vboxsync in_uint8s(ts, 2); /* uint16 = 2 */
a180a41bba1d50822df23fff0099e90b86638b89vboxsync process_palette(ts);
a180a41bba1d50822df23fff0099e90b86638b89vboxsync break;
a180a41bba1d50822df23fff0099e90b86638b89vboxsync case 3: /* update synchronize */
a180a41bba1d50822df23fff0099e90b86638b89vboxsync break;
a180a41bba1d50822df23fff0099e90b86638b89vboxsync case 5: /* null pointer */
a180a41bba1d50822df23fff0099e90b86638b89vboxsync ui_set_null_cursor();
a180a41bba1d50822df23fff0099e90b86638b89vboxsync break;
a180a41bba1d50822df23fff0099e90b86638b89vboxsync case 6: /* default pointer */
a180a41bba1d50822df23fff0099e90b86638b89vboxsync break;
a180a41bba1d50822df23fff0099e90b86638b89vboxsync case 8: /* pointer position */
a180a41bba1d50822df23fff0099e90b86638b89vboxsync in_uint16_le(ts, x);
a180a41bba1d50822df23fff0099e90b86638b89vboxsync in_uint16_le(ts, y);
a180a41bba1d50822df23fff0099e90b86638b89vboxsync if (s_check(ts))
a180a41bba1d50822df23fff0099e90b86638b89vboxsync ui_move_pointer(x, y);
a180a41bba1d50822df23fff0099e90b86638b89vboxsync break;
a180a41bba1d50822df23fff0099e90b86638b89vboxsync case 9: /* color pointer */
a180a41bba1d50822df23fff0099e90b86638b89vboxsync process_colour_pointer_pdu(ts);
a180a41bba1d50822df23fff0099e90b86638b89vboxsync break;
a180a41bba1d50822df23fff0099e90b86638b89vboxsync case 10: /* cached pointer */
a180a41bba1d50822df23fff0099e90b86638b89vboxsync process_cached_pointer_pdu(ts);
a180a41bba1d50822df23fff0099e90b86638b89vboxsync break;
a180a41bba1d50822df23fff0099e90b86638b89vboxsync case 11:
a180a41bba1d50822df23fff0099e90b86638b89vboxsync process_new_pointer_pdu(ts);
a180a41bba1d50822df23fff0099e90b86638b89vboxsync break;
a180a41bba1d50822df23fff0099e90b86638b89vboxsync default:
a180a41bba1d50822df23fff0099e90b86638b89vboxsync unimpl("RDP5 opcode %d\n", type);
a180a41bba1d50822df23fff0099e90b86638b89vboxsync }
a180a41bba1d50822df23fff0099e90b86638b89vboxsync
a180a41bba1d50822df23fff0099e90b86638b89vboxsync s->p = next;
a180a41bba1d50822df23fff0099e90b86638b89vboxsync }
a180a41bba1d50822df23fff0099e90b86638b89vboxsync ui_end_update();
a180a41bba1d50822df23fff0099e90b86638b89vboxsync}