--- sourceforge.net/trunk/rdesktop/orders.c 2002/07/30 07:18:48 82 +++ sourceforge.net/trunk/rdesktop/orders.c 2003/03/28 09:13:48 356 @@ -1,7 +1,7 @@ -/* +/* -*- c-basic-offset: 8 -*- rdesktop: A Remote Desktop Protocol client. RDP order processing - Copyright (C) Matthew Chapman 1999-2001 + Copyright (C) Matthew Chapman 1999-2002 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 @@ -23,6 +23,7 @@ extern uint8 *next_packet; static RDP_ORDER_STATE order_state; +extern BOOL use_rdp5; /* Read field indicating which parameters are present */ static void @@ -56,12 +57,12 @@ static void rdp_in_coord(STREAM s, uint16 * coord, BOOL delta) { - uint8 change; + sint8 change; if (delta) { in_uint8(s, change); - *coord += (signed char) change; + *coord += change; } else { @@ -71,10 +72,15 @@ /* Read a colour entry */ static void -rdp_in_colour(STREAM s, uint8 * colour) +rdp_in_colour(STREAM s, uint32 * colour) { - in_uint8(s, *colour); - s->p += 2; + uint32 i; + in_uint8(s, i); + *colour = i; + in_uint8(s, i); + *colour |= i << 8; + in_uint8(s, i); + *colour |= i << 16; } /* Parse bounds information */ @@ -279,6 +285,7 @@ static void process_rect(STREAM s, RECT_ORDER * os, uint32 present, BOOL delta) { + uint32 i; if (present & 0x01) rdp_in_coord(s, &os->x, delta); @@ -292,7 +299,22 @@ rdp_in_coord(s, &os->cy, delta); if (present & 0x10) - in_uint8(s, os->colour); + { + in_uint8(s, i); + os->colour = (os->colour & 0xffffff00) | i; + } + + if (present & 0x20) + { + in_uint8(s, i); + os->colour = (os->colour & 0xffff00ff) | (i << 8); + } + + if (present & 0x40) + { + in_uint8(s, i); + os->colour = (os->colour & 0xff00ffff) | (i << 16); + } DEBUG(("RECT(x=%d,y=%d,cx=%d,cy=%d,fg=0x%x)\n", os->x, os->y, os->cx, os->cy, os->colour)); @@ -475,7 +497,7 @@ rdp_in_coord(s, &os->y, delta); if (present & 0x04) - in_uint8(s, os->flags); + in_uint8(s, os->opcode); if (present & 0x10) rdp_in_colour(s, &os->fgcolour); @@ -488,13 +510,9 @@ in_uint8(s, os->datasize); in_uint8a(s, os->data, os->datasize); } - if (os->flags & 1) - opcode = ROP2_COPY; - else - opcode = ROP2_NXOR; - DEBUG(("POLYLINE(x=%d,y=%d,fl=0x%x,fg=0x%x,n=%d,sz=%d)\n", - os->x, os->y, os->flags, os->fgcolour, os->lines, os->datasize)); + DEBUG(("POLYLINE(x=%d,y=%d,op=0x%x,fg=0x%x,n=%d,sz=%d)\n", + os->x, os->y, os->opcode, os->fgcolour, os->lines, os->datasize)); DEBUG(("Data: ")); @@ -503,6 +521,13 @@ DEBUG(("\n")); + if (os->opcode < 0x01 || os->opcode > 0x10) + { + error("bad ROP2 0x%x\n", os->opcode); + return; + } + + opcode = os->opcode - 1; x = os->x; y = os->y; pen.style = pen.width = 0; @@ -581,6 +606,10 @@ if (present & 0x002000) in_uint16_le(s, os->boxbottom); + if (present & 0x004000) /* fix for connecting to a server that */ + in_uint8s(s, 10); /* was disconnected with mstsc.exe */ + /* 0x008000, 0x020000, and 0x040000 are present too ??? */ + if (present & 0x080000) in_uint16_le(s, os->x); @@ -617,7 +646,7 @@ { HBITMAP bitmap; uint16 cache_idx, bufsize; - uint8 cache_id, width, height, bpp; + uint8 cache_id, width, height, bpp, Bpp; uint8 *data, *inverted; int y; @@ -626,15 +655,17 @@ in_uint8(s, width); in_uint8(s, height); in_uint8(s, bpp); + Bpp = (bpp + 7) / 8; in_uint16_le(s, bufsize); in_uint16_le(s, cache_idx); in_uint8p(s, data, bufsize); DEBUG(("RAW_BMPCACHE(cx=%d,cy=%d,id=%d,idx=%d)\n", width, height, cache_id, cache_idx)); - inverted = xmalloc(width * height); + inverted = xmalloc(width * height * Bpp); for (y = 0; y < height; y++) { - memcpy(&inverted[(height - y - 1) * width], &data[y * width], width); + memcpy(&inverted[(height - y - 1) * (width * Bpp)], &data[y * (width * Bpp)], + width * Bpp); } bitmap = ui_create_bitmap(width, height, inverted); @@ -648,30 +679,52 @@ { HBITMAP bitmap; uint16 cache_idx, size; - uint8 cache_id, width, height, bpp; + uint8 cache_id, width, height, bpp, Bpp; uint8 *data, *bmpdata; + uint16 bufsize, pad2, row_size, final_size; + uint8 pad1; + + pad2 = row_size = final_size = -1; /* Shut the compiler up */ in_uint8(s, cache_id); - in_uint8s(s, 1); /* pad */ + in_uint8(s, pad1); /* pad */ in_uint8(s, width); in_uint8(s, height); in_uint8(s, bpp); - in_uint8s(s, 2); /* bufsize */ + Bpp = (bpp + 7) / 8; + in_uint16_le(s, bufsize); /* bufsize */ in_uint16_le(s, cache_idx); - in_uint8s(s, 2); /* pad */ - in_uint16_le(s, size); - in_uint8s(s, 4); /* row_size, final_size */ + + if (!use_rdp5) { + + /* Begin compressedBitmapData */ + in_uint16_le(s, pad2); /* pad */ + in_uint16_le(s, size); + // in_uint8s(s, 4); /* row_size, final_size */ + in_uint16_le(s, row_size); + in_uint16_le(s, final_size); + + } else { + size = bufsize; + } in_uint8p(s, data, size); - DEBUG(("BMPCACHE(cx=%d,cy=%d,id=%d,idx=%d)\n", width, height, cache_id, cache_idx)); + DEBUG(("BMPCACHE(cx=%d,cy=%d,id=%d,idx=%d,bpp=%d,size=%d,pad1=%d,bufsize=%d,pad2=%d,rs=%d,fs=%d)\n", + width, height, + cache_id, cache_idx, + bpp, size, pad1, bufsize, pad2, row_size, final_size)); - bmpdata = xmalloc(width * height); + bmpdata = xmalloc(width * height * Bpp); - if (bitmap_decompress(bmpdata, width, height, data, size)) + if (bitmap_decompress(bmpdata, width, height, data, size, Bpp)) { bitmap = ui_create_bitmap(width, height, bmpdata); cache_put_bitmap(cache_id, cache_idx, bitmap); } + else + { + DEBUG(("Failed to decompress bitmap data\n")); + } xfree(bmpdata); } @@ -780,19 +833,14 @@ /* Process an order PDU */ void -process_orders(STREAM s) +process_orders(STREAM s, uint16 num_orders) { RDP_ORDER_STATE *os = &order_state; uint32 present; - uint16 num_orders; uint8 order_flags; int size, processed = 0; BOOL delta; - in_uint8s(s, 2); /* pad */ - in_uint16_le(s, num_orders); - in_uint8s(s, 2); /* pad */ - while (processed < num_orders) { in_uint8(s, order_flags); @@ -907,7 +955,7 @@ /* Reset order state */ void -reset_order_state() +reset_order_state(void) { memset(&order_state, 0, sizeof(order_state)); order_state.order_type = RDP_ORDER_PATBLT;