mirror of https://github.com/FreeRDP/FreeRDP
fix for -z
This commit is contained in:
parent
a1149feffe
commit
3d969de59b
|
@ -204,10 +204,10 @@ static void fastpath_recv_update_data(rdpFastPath* fastpath, STREAM* s)
|
|||
uint8 compression;
|
||||
uint8 compressionFlags;
|
||||
STREAM* update_stream;
|
||||
STREAM* comp_stream;
|
||||
rdpRdp *rdp;
|
||||
uint32 roff;
|
||||
uint32 rlen;
|
||||
uint32 i;
|
||||
|
||||
rdp = fastpath->rdp;
|
||||
|
||||
|
@ -220,18 +220,18 @@ static void fastpath_recv_update_data(rdpFastPath* fastpath, STREAM* s)
|
|||
|
||||
stream_read_uint16(s, size);
|
||||
next_pos = stream_get_pos(s) + size;
|
||||
comp_stream = s;
|
||||
|
||||
if (compressionFlags != 0)
|
||||
{
|
||||
if (decompress_rdp(rdp, s->data, size,
|
||||
compressionFlags, &roff, &rlen))
|
||||
if (decompress_rdp(rdp, s->p, size, compressionFlags, &roff, &rlen))
|
||||
{
|
||||
/* need more space to insert decompressed data */
|
||||
i = rlen - size;
|
||||
stream_extend(s, i);
|
||||
|
||||
/* copy decompressed data */
|
||||
memcpy(s->p, &rdp->mppc->history_buf[roff], rlen);
|
||||
//printf("roff %d rlen %d\n", roff, rlen);
|
||||
comp_stream = stream_new(0);
|
||||
comp_stream->data = rdp->mppc->history_buf + roff;
|
||||
comp_stream->p = comp_stream->data;
|
||||
comp_stream->size = rlen;
|
||||
size = comp_stream->size;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -244,7 +244,7 @@ static void fastpath_recv_update_data(rdpFastPath* fastpath, STREAM* s)
|
|||
if (fragmentation == FASTPATH_FRAGMENT_SINGLE)
|
||||
{
|
||||
totalSize = size;
|
||||
update_stream = s;
|
||||
update_stream = comp_stream;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -252,7 +252,7 @@ static void fastpath_recv_update_data(rdpFastPath* fastpath, STREAM* s)
|
|||
stream_set_pos(fastpath->updateData, 0);
|
||||
|
||||
stream_check_size(fastpath->updateData, size);
|
||||
stream_copy(fastpath->updateData, s, size);
|
||||
stream_copy(fastpath->updateData, comp_stream, size);
|
||||
|
||||
if (fragmentation == FASTPATH_FRAGMENT_LAST)
|
||||
{
|
||||
|
@ -266,6 +266,9 @@ static void fastpath_recv_update_data(rdpFastPath* fastpath, STREAM* s)
|
|||
fastpath_recv_update(fastpath, updateCode, totalSize, update_stream);
|
||||
|
||||
stream_set_pos(s, next_pos);
|
||||
|
||||
if (comp_stream != s)
|
||||
xfree(comp_stream);
|
||||
}
|
||||
|
||||
boolean fastpath_recv_updates(rdpFastPath* fastpath, STREAM* s)
|
||||
|
|
|
@ -24,36 +24,31 @@
|
|||
#include <unistd.h>
|
||||
#include "rdp.h"
|
||||
|
||||
int decompress_rdp(rdpRdp *rdp,
|
||||
uint8 *cbuf,
|
||||
int len,
|
||||
int ctype,
|
||||
uint32 *roff,
|
||||
uint32 *rlen)
|
||||
int decompress_rdp(rdpRdp* rdp, uint8* cbuf, int len, int ctype, uint32* roff, uint32* rlen)
|
||||
{
|
||||
int type = ctype & 0x0f;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case PACKET_COMPR_TYPE_8K:
|
||||
return decompress_rdp_4(rdp, cbuf, len, ctype, roff, rlen);
|
||||
break;
|
||||
case PACKET_COMPR_TYPE_8K:
|
||||
return decompress_rdp_4(rdp, cbuf, len, ctype, roff, rlen);
|
||||
break;
|
||||
|
||||
case PACKET_COMPR_TYPE_64K:
|
||||
return decompress_rdp_5(rdp, cbuf, len, ctype, roff, rlen);
|
||||
break;
|
||||
case PACKET_COMPR_TYPE_64K:
|
||||
return decompress_rdp_5(rdp, cbuf, len, ctype, roff, rlen);
|
||||
break;
|
||||
|
||||
case PACKET_COMPR_TYPE_RDP6:
|
||||
return decompress_rdp_6(rdp, cbuf, len, ctype, roff, rlen);
|
||||
break;
|
||||
case PACKET_COMPR_TYPE_RDP6:
|
||||
return decompress_rdp_6(rdp, cbuf, len, ctype, roff, rlen);
|
||||
break;
|
||||
|
||||
case PACKET_COMPR_TYPE_RDP61:
|
||||
return decompress_rdp_61(rdp, cbuf, len, ctype, roff, rlen);
|
||||
break;
|
||||
case PACKET_COMPR_TYPE_RDP61:
|
||||
return decompress_rdp_61(rdp, cbuf, len, ctype, roff, rlen);
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("mppc.c: invalid RDP compression code\n");
|
||||
return False;
|
||||
default:
|
||||
printf("mppc.c: invalid RDP compression code 0x%2.2x\n", type);
|
||||
return False;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -70,12 +65,7 @@ int decompress_rdp(rdpRdp *rdp,
|
|||
* @return True on success, False on failure
|
||||
*/
|
||||
|
||||
int decompress_rdp_4(rdpRdp *rdp,
|
||||
uint8 *cbuf,
|
||||
int len,
|
||||
int ctype,
|
||||
uint32 *roff,
|
||||
uint32 *rlen)
|
||||
int decompress_rdp_4(rdpRdp* rdp, uint8* cbuf, int len, int ctype, uint32* roff, uint32* rlen)
|
||||
{
|
||||
return False;
|
||||
}
|
||||
|
@ -93,20 +83,15 @@ int decompress_rdp_4(rdpRdp *rdp,
|
|||
* @return True on success, False on failure
|
||||
*/
|
||||
|
||||
int decompress_rdp_5(rdpRdp *rdp,
|
||||
uint8 *cbuf,
|
||||
int len,
|
||||
int ctype,
|
||||
uint32 *roff,
|
||||
uint32 *rlen)
|
||||
int decompress_rdp_5(rdpRdp* rdp, uint8* cbuf, int len, int ctype, uint32* roff, uint32* rlen)
|
||||
{
|
||||
uint8 *history_buf; /* uncompressed data goes here */
|
||||
uint8 *history_ptr; /* points to next free slot in bistory_buf */
|
||||
uint8* history_buf; /* uncompressed data goes here */
|
||||
uint8* history_ptr; /* points to next free slot in bistory_buf */
|
||||
uint32 d32; /* we process 4 compressed bytes at a time */
|
||||
uint16 copy_offset; /* location to copy data from */
|
||||
uint16 lom; /* length of match */
|
||||
uint8 *src_ptr; /* used while copying compressed data */
|
||||
uint8 *cptr; /* points to next byte in cbuf */
|
||||
uint8* src_ptr; /* used while copying compressed data */
|
||||
uint8* cptr; /* points to next byte in cbuf */
|
||||
uint8 cur_byte; /* last byte fetched from cbuf */
|
||||
int bits_left; /* bits left in d32 for processing */
|
||||
int cur_bits_left; /* bits left in cur_byte for processing */
|
||||
|
@ -128,7 +113,7 @@ int decompress_rdp_5(rdpRdp *rdp,
|
|||
cur_byte = 0;
|
||||
*rlen = 0;
|
||||
|
||||
mprintf("decompress_rdp_5: *** ctype=0x%x len=%d ***\n", ctype, len);
|
||||
//mprintf("decompress_rdp_5: *** ctype=0x%x len=%d ***\n", ctype, len);
|
||||
|
||||
/* get start of history buffer */
|
||||
history_buf = rdp->mppc->history_buf;
|
||||
|
@ -137,27 +122,28 @@ int decompress_rdp_5(rdpRdp *rdp,
|
|||
history_ptr = rdp->mppc->history_ptr;
|
||||
*roff = history_ptr - history_buf;
|
||||
|
||||
if (ctype & PACKET_AT_FRONT)
|
||||
if (ctype & PACKET_AT_FRONT)
|
||||
{
|
||||
/* place compressed data at start of history buffer */
|
||||
mprintf("decompress_rdp_5: got PACKET_AT_FRONT\n");
|
||||
//mprintf("decompress_rdp_5: got PACKET_AT_FRONT\n");
|
||||
history_ptr = rdp->mppc->history_buf;
|
||||
rdp->mppc->history_ptr = rdp->mppc->history_buf;
|
||||
*roff = 0;
|
||||
}
|
||||
|
||||
if (ctype & PACKET_FLUSHED)
|
||||
if (ctype & PACKET_FLUSHED)
|
||||
{
|
||||
/* re-init history buffer */
|
||||
mprintf("decompress_rdp_5: got PACKET_FLUSHED\n");
|
||||
//mprintf("decompress_rdp_5: got PACKET_FLUSHED\n");
|
||||
history_ptr = rdp->mppc->history_buf;
|
||||
memset(history_buf, 0, RDP5_HISTORY_BUF_SIZE);
|
||||
*roff = 0;
|
||||
}
|
||||
|
||||
if ((ctype & PACKET_COMPRESSED) != PACKET_COMPRESSED)
|
||||
if ((ctype & PACKET_COMPRESSED) != PACKET_COMPRESSED)
|
||||
{
|
||||
/* data in cbuf is not compressed - copy to history buf as is */
|
||||
mprintf("decompress_rdp_5: got ! PACKET_COMPRESSED\n");
|
||||
//mprintf("decompress_rdp_5: got ! PACKET_COMPRESSED\n");
|
||||
memcpy(history_ptr, cbuf, len);
|
||||
history_ptr += len;
|
||||
*rlen = history_ptr - rdp->mppc->history_ptr;
|
||||
|
@ -173,18 +159,18 @@ int decompress_rdp_5(rdpRdp *rdp,
|
|||
d32 |= i32 << tmp;
|
||||
bits_left += 8;
|
||||
tmp -= 8;
|
||||
if (tmp < 0)
|
||||
if (tmp < 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (cptr < cbuf + len)
|
||||
if (cptr < cbuf + len)
|
||||
{
|
||||
cur_byte = *cptr++;
|
||||
cur_bits_left = 8;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
cur_bits_left = 0;
|
||||
}
|
||||
|
@ -211,64 +197,64 @@ int decompress_rdp_5(rdpRdp *rdp,
|
|||
|
||||
copy_offset = 0;
|
||||
|
||||
if ((d32 & 0x80000000) == 0)
|
||||
if ((d32 & 0x80000000) == 0)
|
||||
{
|
||||
/* got a literal */
|
||||
mprintf("decompress_rdp_5: got literal\n");
|
||||
//mprintf("decompress_rdp_5: got literal\n");
|
||||
*history_ptr++ = d32 >> 24;
|
||||
d32 <<= 8;
|
||||
bits_left -= 8;
|
||||
}
|
||||
else if ((d32 & 0xc0000000) == 0x80000000)
|
||||
else if ((d32 & 0xc0000000) == 0x80000000)
|
||||
{
|
||||
/* got encoded literal */
|
||||
mprintf("decompress_rdp_5: got encoded literal\n");
|
||||
//mprintf("decompress_rdp_5: got encoded literal\n");
|
||||
d32 <<= 2;
|
||||
*history_ptr++ = (d32 >> 25) | 0x80;
|
||||
d32 <<= 7;
|
||||
bits_left -= 9;
|
||||
}
|
||||
else if ((d32 & 0xf8000000) == 0xf8000000)
|
||||
else if ((d32 & 0xf8000000) == 0xf8000000)
|
||||
{
|
||||
/* got copy offset in range 0 - 63, */
|
||||
/* with 6 bit copy offset */
|
||||
mprintf("decompress_rdp_5: "
|
||||
"got copy offset in range 0 - 63\n");
|
||||
//mprintf("decompress_rdp_5: "
|
||||
// "got copy offset in range 0 - 63\n");
|
||||
d32 <<= 5;
|
||||
copy_offset = d32 >> 26;
|
||||
d32 <<= 6;
|
||||
bits_left -= 11;
|
||||
}
|
||||
else if ((d32 & 0xf8000000) == 0xf0000000)
|
||||
else if ((d32 & 0xf8000000) == 0xf0000000)
|
||||
{
|
||||
/* got copy offset in range 64 - 319, */
|
||||
/* with 8 bit copy offset */
|
||||
mprintf("decompress_rdp_5: "
|
||||
"got copy offset in range 64 - 319\n");
|
||||
//mprintf("decompress_rdp_5: "
|
||||
// "got copy offset in range 64 - 319\n");
|
||||
d32 <<= 5;
|
||||
copy_offset = d32 >> 24;
|
||||
copy_offset += 64;
|
||||
d32 <<= 8;
|
||||
bits_left -= 13;
|
||||
}
|
||||
else if ((d32 & 0xf0000000) == 0xe0000000)
|
||||
else if ((d32 & 0xf0000000) == 0xe0000000)
|
||||
{
|
||||
/* got copy offset in range 320 - 2367, */
|
||||
/* with 11 bits copy offset */
|
||||
mprintf("decompress_rdp_5: "
|
||||
"got copy offset in range 320 - 2367\n");
|
||||
//mprintf("decompress_rdp_5: "
|
||||
// "got copy offset in range 320 - 2367\n");
|
||||
d32 <<= 4;
|
||||
copy_offset = d32 >> 21;
|
||||
copy_offset += 320;
|
||||
d32 <<= 11;
|
||||
bits_left -= 15;
|
||||
}
|
||||
else if ((d32 & 0xe0000000) == 0xc0000000)
|
||||
else if ((d32 & 0xe0000000) == 0xc0000000)
|
||||
{
|
||||
/* got copy offset in range 2368+, */
|
||||
/* with 16 bits copy offset */
|
||||
mprintf("decompress_rdp_5: "
|
||||
"got copy offset in range 2368+\n");
|
||||
//mprintf("decompress_rdp_5: "
|
||||
// "got copy offset in range 2368+\n");
|
||||
d32 <<= 3;
|
||||
copy_offset = d32 >> 16;
|
||||
copy_offset += 2368;
|
||||
|
@ -281,32 +267,33 @@ int decompress_rdp_5(rdpRdp *rdp,
|
|||
*/
|
||||
|
||||
#if 1
|
||||
|
||||
/* how may bits do we need to get? */
|
||||
tmp = 32 - bits_left;
|
||||
|
||||
while (tmp)
|
||||
{
|
||||
if (cur_bits_left < tmp)
|
||||
if (cur_bits_left < tmp)
|
||||
{
|
||||
/* we have less bits than we need */
|
||||
i32 = cur_byte >> (8 - cur_bits_left);
|
||||
d32 |= i32 << ((32 - bits_left) - cur_bits_left);
|
||||
bits_left += cur_bits_left;
|
||||
tmp -= cur_bits_left;
|
||||
if (cptr < cbuf + len)
|
||||
if (cptr < cbuf + len)
|
||||
{
|
||||
/* more compressed data available */
|
||||
cur_byte = *cptr++;
|
||||
cur_bits_left = 8;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
/* no more compressed data available */
|
||||
tmp = 0;
|
||||
cur_bits_left = 0;
|
||||
}
|
||||
}
|
||||
else if (cur_bits_left > tmp)
|
||||
else if (cur_bits_left > tmp)
|
||||
{
|
||||
/* we have more bits than we need */
|
||||
d32 |= cur_byte >> (8 - tmp);
|
||||
|
@ -315,28 +302,30 @@ int decompress_rdp_5(rdpRdp *rdp,
|
|||
bits_left = 32;
|
||||
break;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
/* we have just the right amount of bits */
|
||||
d32 |= cur_byte >> (8 - tmp);
|
||||
bits_left = 32;
|
||||
if (cptr < cbuf + len)
|
||||
if (cptr < cbuf + len)
|
||||
{
|
||||
cur_byte = *cptr++;
|
||||
cur_bits_left = 8;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
cur_bits_left = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
#else
|
||||
|
||||
#else
|
||||
|
||||
// optimization code under development
|
||||
|
||||
// LK_TODO either use only i32 or make cur_byte uint32_t
|
||||
// make cbuf + len a const variable so we dont compute it
|
||||
// make cbuf + len a const variable so we dont compute it
|
||||
// each time
|
||||
|
||||
/* if there are no more bits to get, skip this */
|
||||
|
@ -356,12 +345,12 @@ int decompress_rdp_5(rdpRdp *rdp,
|
|||
d32 |= i32 << (24 - bits_left);
|
||||
bits_left += cur_bits_left;
|
||||
tmp -= cur_bits_left;
|
||||
if (cptr < cbuf + len)
|
||||
if (cptr < cbuf + len)
|
||||
{
|
||||
cur_byte = *cptr++;
|
||||
cur_bits_left = 8;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
cur_bits_left = 0;
|
||||
goto no_more_bits1;
|
||||
|
@ -374,9 +363,10 @@ int decompress_rdp_5(rdpRdp *rdp,
|
|||
}
|
||||
}
|
||||
no_more_bits1:
|
||||
#endif
|
||||
|
||||
if (!copy_offset)
|
||||
#endif
|
||||
|
||||
if (!copy_offset)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
@ -405,122 +395,122 @@ int decompress_rdp_5(rdpRdp *rdp,
|
|||
32768..65535 1111-1111-1111-110 + 15 lower bits of LoM
|
||||
*/
|
||||
|
||||
if ((d32 & 0x80000000) == 0)
|
||||
if ((d32 & 0x80000000) == 0)
|
||||
{
|
||||
/* lom is fixed to 3 */
|
||||
mprintf("decompress_rdp_5: LoM fixed to 3\n");
|
||||
//mprintf("decompress_rdp_5: LoM fixed to 3\n");
|
||||
lom = 3;
|
||||
d32 <<= 1;
|
||||
bits_left -= 1;
|
||||
}
|
||||
else if ((d32 & 0xc0000000) == 0x80000000)
|
||||
else if ((d32 & 0xc0000000) == 0x80000000)
|
||||
{
|
||||
/* 2 lower bits of LoM */
|
||||
mprintf("decompress_rdp_5: LoM : 2 bits\n");
|
||||
//mprintf("decompress_rdp_5: LoM : 2 bits\n");
|
||||
lom = ((d32 >> 28) & 0x03) + 4;
|
||||
d32 <<= 4;
|
||||
bits_left -= 4;
|
||||
}
|
||||
else if ((d32 & 0xe0000000) == 0xc0000000)
|
||||
else if ((d32 & 0xe0000000) == 0xc0000000)
|
||||
{
|
||||
/* 3 lower bits of LoM */
|
||||
mprintf("decompress_rdp_5: LoM : 3 bits\n");
|
||||
//mprintf("decompress_rdp_5: LoM : 3 bits\n");
|
||||
lom = ((d32 >> 26) & 0x07) + 8;
|
||||
d32 <<= 6;
|
||||
bits_left -= 6;
|
||||
}
|
||||
else if ((d32 & 0xf0000000) == 0xe0000000)
|
||||
else if ((d32 & 0xf0000000) == 0xe0000000)
|
||||
{
|
||||
/* 4 lower bits of LoM */
|
||||
mprintf("decompress_rdp_5: LoM : 4 bits\n");
|
||||
//mprintf("decompress_rdp_5: LoM : 4 bits\n");
|
||||
lom = ((d32 >> 24) & 0x0f) + 16;
|
||||
d32 <<= 8;
|
||||
bits_left -= 8;
|
||||
}
|
||||
else if ((d32 & 0xf8000000) == 0xf0000000)
|
||||
else if ((d32 & 0xf8000000) == 0xf0000000)
|
||||
{
|
||||
/* 5 lower bits of LoM */
|
||||
mprintf("decompress_rdp_5: LoM : 5 bits\n");
|
||||
//mprintf("decompress_rdp_5: LoM : 5 bits\n");
|
||||
lom = ((d32 >> 22) & 0x1f) + 32;
|
||||
d32 <<= 10;
|
||||
bits_left -= 10;
|
||||
}
|
||||
else if ((d32 & 0xfc000000) == 0xf8000000)
|
||||
else if ((d32 & 0xfc000000) == 0xf8000000)
|
||||
{
|
||||
/* 6 lower bits of LoM */
|
||||
mprintf("decompress_rdp_5: LoM : 6 bits\n");
|
||||
//mprintf("decompress_rdp_5: LoM : 6 bits\n");
|
||||
lom = ((d32 >> 20) & 0x3f) + 64;
|
||||
d32 <<= 12;
|
||||
bits_left -= 12;
|
||||
}
|
||||
else if ((d32 & 0xfe000000) == 0xfc000000)
|
||||
else if ((d32 & 0xfe000000) == 0xfc000000)
|
||||
{
|
||||
/* 7 lower bits of LoM */
|
||||
mprintf("decompress_rdp_5: LoM : 7 bits\n");
|
||||
//mprintf("decompress_rdp_5: LoM : 7 bits\n");
|
||||
lom = ((d32 >> 18) & 0x7f) + 128;
|
||||
d32 <<= 14;
|
||||
bits_left -= 14;
|
||||
}
|
||||
else if ((d32 & 0xff000000) == 0xfe000000)
|
||||
else if ((d32 & 0xff000000) == 0xfe000000)
|
||||
{
|
||||
/* 8 lower bits of LoM */
|
||||
mprintf("decompress_rdp_5: LoM : 8 bits\n");
|
||||
//mprintf("decompress_rdp_5: LoM : 8 bits\n");
|
||||
lom = ((d32 >> 16) & 0xff) + 256;
|
||||
d32 <<= 16;
|
||||
bits_left -= 16;
|
||||
}
|
||||
else if ((d32 & 0xff800000) == 0xff000000)
|
||||
else if ((d32 & 0xff800000) == 0xff000000)
|
||||
{
|
||||
/* 9 lower bits of LoM */
|
||||
mprintf("decompress_rdp_5: LoM : 9 bits\n");
|
||||
//mprintf("decompress_rdp_5: LoM : 9 bits\n");
|
||||
lom = ((d32 >> 14) & 0x1ff) + 512;
|
||||
d32 <<= 18;
|
||||
bits_left -= 18;
|
||||
}
|
||||
else if ((d32 & 0xffc00000) == 0xff800000)
|
||||
else if ((d32 & 0xffc00000) == 0xff800000)
|
||||
{
|
||||
/* 10 lower bits of LoM */
|
||||
mprintf("decompress_rdp_5: LoM : 10 bits\n");
|
||||
//mprintf("decompress_rdp_5: LoM : 10 bits\n");
|
||||
lom = ((d32 >> 12) & 0x3ff) + 1024;
|
||||
d32 <<= 20;
|
||||
bits_left -= 20;
|
||||
}
|
||||
else if ((d32 & 0xffe00000) == 0xffc00000)
|
||||
else if ((d32 & 0xffe00000) == 0xffc00000)
|
||||
{
|
||||
/* 11 lower bits of LoM */
|
||||
mprintf("decompress_rdp_5: LoM : 11 bits\n");
|
||||
//mprintf("decompress_rdp_5: LoM : 11 bits\n");
|
||||
lom = ((d32 >> 10) & 0x7ff) + 2048;
|
||||
d32 <<= 22;
|
||||
bits_left -= 22;
|
||||
}
|
||||
else if ((d32 & 0xfff00000) == 0xffe00000)
|
||||
else if ((d32 & 0xfff00000) == 0xffe00000)
|
||||
{
|
||||
/* 12 lower bits of LoM */
|
||||
mprintf("decompress_rdp_5: LoM : 12 bits\n");
|
||||
//mprintf("decompress_rdp_5: LoM : 12 bits\n");
|
||||
lom = ((d32 >> 8) & 0xfff) + 4096;
|
||||
d32 <<= 24;
|
||||
bits_left -= 24;
|
||||
}
|
||||
else if ((d32 & 0xfff80000) == 0xfff00000)
|
||||
else if ((d32 & 0xfff80000) == 0xfff00000)
|
||||
{
|
||||
/* 13 lower bits of LoM */
|
||||
mprintf("decompress_rdp_5: LoM : 13 bits\n");
|
||||
//mprintf("decompress_rdp_5: LoM : 13 bits\n");
|
||||
lom = ((d32 >> 6) & 0x1fff) + 8192;
|
||||
d32 <<= 26;
|
||||
bits_left -= 26;
|
||||
}
|
||||
else if ((d32 & 0xfffc0000) == 0xfff80000)
|
||||
else if ((d32 & 0xfffc0000) == 0xfff80000)
|
||||
{
|
||||
/* 14 lower bits of LoM */
|
||||
mprintf("decompress_rdp_5: LoM : 14 bits\n");
|
||||
//mprintf("decompress_rdp_5: LoM : 14 bits\n");
|
||||
lom = ((d32 >> 4) & 0x3fff) + 16384;
|
||||
d32 <<= 28;
|
||||
bits_left -= 28;
|
||||
}
|
||||
else if ((d32 & 0xfffe0000) == 0xfffc0000)
|
||||
else if ((d32 & 0xfffe0000) == 0xfffc0000)
|
||||
{
|
||||
/* 15 lower bits of LoM */
|
||||
mprintf("decompress_rdp_5: LoM : 15 bits\n");
|
||||
//mprintf("decompress_rdp_5: LoM : 15 bits\n");
|
||||
lom = ((d32 >> 2) & 0x7fff) + 32768;
|
||||
d32 <<= 30;
|
||||
bits_left -= 30;
|
||||
|
@ -528,14 +518,36 @@ int decompress_rdp_5(rdpRdp *rdp,
|
|||
|
||||
/* now that we have copy_offset and LoM, process them */
|
||||
|
||||
mprintf("decompress_rdp_5: Length of Match = %d\n", lom);
|
||||
//mprintf("decompress_rdp_5: Length of Match = %d\n", lom);
|
||||
|
||||
src_ptr = history_ptr - copy_offset;
|
||||
while (lom > 0)
|
||||
if (src_ptr >= rdp->mppc->history_buf)
|
||||
{
|
||||
*history_ptr++ = *src_ptr++;
|
||||
lom--;
|
||||
/* data does not wrap around */
|
||||
while (lom > 0)
|
||||
{
|
||||
*history_ptr++ = *src_ptr++;
|
||||
lom--;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
src_ptr = rdp->mppc->history_buf_end - (copy_offset - (history_ptr - rdp->mppc->history_buf));
|
||||
src_ptr++;
|
||||
while (lom && (src_ptr <= rdp->mppc->history_buf_end))
|
||||
{
|
||||
*history_ptr++ = *src_ptr++;
|
||||
lom--;
|
||||
}
|
||||
|
||||
src_ptr = rdp->mppc->history_buf;
|
||||
while (lom > 0)
|
||||
{
|
||||
*history_ptr++ = *src_ptr++;
|
||||
lom--;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
** get more bits before we restart the loop
|
||||
|
@ -546,27 +558,27 @@ int decompress_rdp_5(rdpRdp *rdp,
|
|||
|
||||
while (tmp)
|
||||
{
|
||||
if (cur_bits_left < tmp)
|
||||
if (cur_bits_left < tmp)
|
||||
{
|
||||
/* we have less bits than we need */
|
||||
i32 = cur_byte >> (8 - cur_bits_left);
|
||||
d32 |= i32 << ((32 - bits_left) - cur_bits_left);
|
||||
bits_left += cur_bits_left;
|
||||
tmp -= cur_bits_left;
|
||||
if (cptr < cbuf + len)
|
||||
if (cptr < cbuf + len)
|
||||
{
|
||||
/* more compressed data available */
|
||||
cur_byte = *cptr++;
|
||||
cur_bits_left = 8;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
/* no more compressed data available */
|
||||
tmp = 0;
|
||||
cur_bits_left = 0;
|
||||
}
|
||||
}
|
||||
else if (cur_bits_left > tmp)
|
||||
else if (cur_bits_left > tmp)
|
||||
{
|
||||
/* we have more bits than we need */
|
||||
d32 |= cur_byte >> (8 - tmp);
|
||||
|
@ -575,17 +587,17 @@ int decompress_rdp_5(rdpRdp *rdp,
|
|||
bits_left = 32;
|
||||
break;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
/* we have just the right amount of bits */
|
||||
d32 |= cur_byte >> (8 - tmp);
|
||||
bits_left = 32;
|
||||
if (cptr < cbuf + len)
|
||||
if (cptr < cbuf + len)
|
||||
{
|
||||
cur_byte = *cptr++;
|
||||
cur_bits_left = 8;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
cur_bits_left = 0;
|
||||
}
|
||||
|
@ -596,8 +608,9 @@ int decompress_rdp_5(rdpRdp *rdp,
|
|||
} /* end while (cptr < cbuf + len) */
|
||||
|
||||
*rlen = history_ptr - rdp->mppc->history_ptr;
|
||||
|
||||
rdp->mppc->history_ptr = history_ptr;
|
||||
mprintf("decompress_rdp_5: roff=%d rlen=%d\n", *roff, *rlen);
|
||||
//mprintf("decompress_rdp_5: roff=%d rlen=%d\n", *roff, *rlen);
|
||||
return True;
|
||||
}
|
||||
|
||||
|
@ -614,12 +627,12 @@ int decompress_rdp_5(rdpRdp *rdp,
|
|||
* @return True on success, False on failure
|
||||
*/
|
||||
|
||||
int decompress_rdp_6(rdpRdp *rdp,
|
||||
int decompress_rdp_6(rdpRdp *rdp,
|
||||
uint8 *cbuf,
|
||||
int len,
|
||||
int ctype,
|
||||
uint32 *roff,
|
||||
uint32 *rlen)
|
||||
uint32 *rlen)
|
||||
{
|
||||
return False;
|
||||
}
|
||||
|
@ -637,32 +650,22 @@ int decompress_rdp_6(rdpRdp *rdp,
|
|||
* @return True on success, False on failure
|
||||
*/
|
||||
|
||||
int decompress_rdp_61(rdpRdp *rdp,
|
||||
uint8 *cbuf,
|
||||
int len,
|
||||
int ctype,
|
||||
uint32 *roff,
|
||||
uint32 *rlen)
|
||||
int decompress_rdp_61(rdpRdp* rdp, uint8* cbuf, int len, int ctype, uint32* roff, uint32* rlen)
|
||||
{
|
||||
return False;
|
||||
}
|
||||
|
||||
/* LK_TODO */
|
||||
#ifdef USE_RDP_4
|
||||
int decompress_rdp_4(rdpRdp *rdp,
|
||||
uint8 *cbuf,
|
||||
int len,
|
||||
int ctype,
|
||||
uint32 *roff,
|
||||
uint32 *rlen)
|
||||
int decompress_rdp_4(rdpRdp* rdp, uint8* cbuf, int len, int ctype, uint32* roff, uint32* rlen)
|
||||
{
|
||||
uint32 d32; /* we process 4 compressed bytes at a time */
|
||||
uint16 copy_offset; /* location to copy data from */
|
||||
uint16 lom; /* length of match */
|
||||
uint8 *src_ptr; /* used while copying compressed data */
|
||||
uint8 *cptr; /* points to next byte in cbuf */
|
||||
uint8 *history_buf; /* uncompressed data goes here */
|
||||
uint8 *history_ptr; /* points to next frees slot in bistory_buf */
|
||||
uint8* src_ptr; /* used while copying compressed data */
|
||||
uint8* cptr; /* points to next byte in cbuf */
|
||||
uint8* history_buf; /* uncompressed data goes here */
|
||||
uint8* history_ptr; /* points to next frees slot in bistory_buf */
|
||||
uint8 cur_byte; /* last byte fetched from cbuf */
|
||||
int bits_left; /* bits left in d32 for processing */
|
||||
int cur_bits_left; /* bits left in cur_byte for processing */
|
||||
|
@ -671,7 +674,7 @@ int decompress_rdp_4(rdpRdp *rdp,
|
|||
|
||||
if ((ctype & 0x0f) != PACKET_COMPR_TYPE_8K)
|
||||
{
|
||||
/* this is not RDP 4 compressed data */
|
||||
/* this is not RDP 4 compressed data */
|
||||
return False;
|
||||
}
|
||||
|
||||
|
@ -683,18 +686,18 @@ int decompress_rdp_4(rdpRdp *rdp,
|
|||
cur_bits_left = 0;
|
||||
d32 = 0;
|
||||
|
||||
if (ctype & PACKET_AT_FRONT)
|
||||
if (ctype & PACKET_AT_FRONT)
|
||||
{
|
||||
history_ptr = 0;
|
||||
}
|
||||
|
||||
if (ctype & PACKET_FLUSHED)
|
||||
if (ctype & PACKET_FLUSHED)
|
||||
{
|
||||
history_ptr = history_buf;
|
||||
memset(history_buf, 0, history_buf_size);
|
||||
}
|
||||
|
||||
if ((ctype & PACKET_COMPRESSED) != PACKET_COMPRESSED)
|
||||
if ((ctype & PACKET_COMPRESSED) != PACKET_COMPRESSED)
|
||||
{
|
||||
memcpy(history_ptr, cbuf, len);
|
||||
history_ptr += len;
|
||||
|
@ -716,7 +719,7 @@ int decompress_rdp_4(rdpRdp *rdp,
|
|||
value 1110xxxx = copy offset 64 - 319
|
||||
value 110xxxxx = copy offset 320 - 8191
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
at this point, we are guaranteed that d32 has 32 bits to
|
||||
be processed, unless we have reached end of cbuf
|
||||
|
@ -724,14 +727,14 @@ int decompress_rdp_4(rdpRdp *rdp,
|
|||
|
||||
copy_offset = 0;
|
||||
|
||||
if ((d32 & 0x80000000) == 0)
|
||||
if ((d32 & 0x80000000) == 0)
|
||||
{
|
||||
/* got a literal */
|
||||
*history_ptr++ = d32 >> 24;
|
||||
d32 <<= 8;
|
||||
bits_left -= 8;
|
||||
}
|
||||
else if ((d32 & 0xc0000000) == 0x80000000)
|
||||
else if ((d32 & 0xc0000000) == 0x80000000)
|
||||
{
|
||||
/* got encoded literal */
|
||||
d32 <<= 2;
|
||||
|
@ -739,7 +742,7 @@ int decompress_rdp_4(rdpRdp *rdp,
|
|||
d32 <<= 7;
|
||||
bits_left -= 9;
|
||||
}
|
||||
else if ((d32 & 0xf0000000) == 0xf0000000)
|
||||
else if ((d32 & 0xf0000000) == 0xf0000000)
|
||||
{
|
||||
/* got copy offset in range 0 - 63, */
|
||||
/* with 6 bit copy offset */
|
||||
|
@ -748,7 +751,7 @@ int decompress_rdp_4(rdpRdp *rdp,
|
|||
d32 <<= 6;
|
||||
bits_left -= 10;
|
||||
}
|
||||
else if ((d32 & 0xf0000000) == 0xe0000000)
|
||||
else if ((d32 & 0xf0000000) == 0xe0000000)
|
||||
{
|
||||
/* got copy offset in range 64 - 319, */
|
||||
/* with 8 bit copy offset */
|
||||
|
@ -758,7 +761,7 @@ int decompress_rdp_4(rdpRdp *rdp,
|
|||
d32 <<= 8;
|
||||
bits_left -= 12;
|
||||
}
|
||||
else if ((d32 & 0xe0000000) == 0xc0000000)
|
||||
else if ((d32 & 0xe0000000) == 0xc0000000)
|
||||
{
|
||||
/* got copy offset in range 320 - 8191, */
|
||||
/* with 13 bits copy offset */
|
||||
|
@ -778,27 +781,27 @@ int decompress_rdp_4(rdpRdp *rdp,
|
|||
|
||||
while (tmp)
|
||||
{
|
||||
if (cur_bits_left < tmp)
|
||||
if (cur_bits_left < tmp)
|
||||
{
|
||||
/* we have less bits than we need */
|
||||
i32 = cur_byte >> (8 - cur_bits_left);
|
||||
d32 |= i32 << ((32 - bits_left) - cur_bits_left);
|
||||
bits_left += cur_bits_left;
|
||||
tmp -= cur_bits_left;
|
||||
if (cptr < cbuf + len)
|
||||
if (cptr < cbuf + len)
|
||||
{
|
||||
/* more compressed data available */
|
||||
cur_byte = *cptr++;
|
||||
cur_bits_left = 8;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
/* no more compressed data available */
|
||||
tmp = 0;
|
||||
cur_bits_left = 0;
|
||||
}
|
||||
}
|
||||
else if (cur_bits_left > tmp)
|
||||
else if (cur_bits_left > tmp)
|
||||
{
|
||||
/* we have more bits than we need */
|
||||
d32 |= cur_byte >> (8 - tmp);
|
||||
|
@ -807,17 +810,17 @@ int decompress_rdp_4(rdpRdp *rdp,
|
|||
bits_left = 32;
|
||||
break;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
/* we have just the right amount of bits */
|
||||
d32 |= cur_byte >> (8 - tmp);
|
||||
bits_left = 32;
|
||||
if (cptr < cbuf + len)
|
||||
if (cptr < cbuf + len)
|
||||
{
|
||||
cur_byte = *cptr++;
|
||||
cur_bits_left = 8;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
cur_bits_left = 0;
|
||||
}
|
||||
|
@ -846,84 +849,84 @@ int decompress_rdp_4(rdpRdp *rdp,
|
|||
4096...8191 111111111110 + 12 lower bits of L-o-M
|
||||
*/
|
||||
|
||||
if ((d32 & 0x80000000) == 0)
|
||||
if ((d32 & 0x80000000) == 0)
|
||||
{
|
||||
/* lom is fixed to 3 */
|
||||
lom = 3;
|
||||
d32 <<= 1;
|
||||
bits_left -= 1;
|
||||
}
|
||||
else if ((d32 & 0xc0000000) == 0x80000000)
|
||||
else if ((d32 & 0xc0000000) == 0x80000000)
|
||||
{
|
||||
/* 2 lower bits of LoM */
|
||||
lom = ((d32 >> 28) & 0x03) + 4;
|
||||
d32 <<= 4;
|
||||
bits_left -= 4;
|
||||
}
|
||||
else if ((d32 & 0xe0000000) == 0xc0000000)
|
||||
else if ((d32 & 0xe0000000) == 0xc0000000)
|
||||
{
|
||||
/* 3 lower bits of LoM */
|
||||
lom = ((d32 >> 26) & 0x07) + 8;
|
||||
d32 <<= 6;
|
||||
bits_left -= 6;
|
||||
}
|
||||
else if ((d32 & 0xf0000000) == 0xe0000000)
|
||||
else if ((d32 & 0xf0000000) == 0xe0000000)
|
||||
{
|
||||
/* 4 lower bits of LoM */
|
||||
lom = ((d32 >> 24) & 0x0f) + 16;
|
||||
d32 <<= 8;
|
||||
bits_left -= 8;
|
||||
}
|
||||
else if ((d32 & 0xf8000000) == 0xf0000000)
|
||||
else if ((d32 & 0xf8000000) == 0xf0000000)
|
||||
{
|
||||
/* 5 lower bits of LoM */
|
||||
lom = ((d32 >> 22) & 0x1f) + 32;
|
||||
d32 <<= 10;
|
||||
bits_left -= 10;
|
||||
}
|
||||
else if ((d32 & 0xfc000000) == 0xf8000000)
|
||||
else if ((d32 & 0xfc000000) == 0xf8000000)
|
||||
{
|
||||
/* 6 lower bits of LoM */
|
||||
lom = ((d32 >> 20) & 0x3f) + 64;
|
||||
d32 <<= 12;
|
||||
bits_left -= 12;
|
||||
}
|
||||
else if ((d32 & 0xfe000000) == 0xfc000000)
|
||||
else if ((d32 & 0xfe000000) == 0xfc000000)
|
||||
{
|
||||
/* 7 lower bits of LoM */
|
||||
lom = ((d32 >> 18) & 0x7f) + 128;
|
||||
d32 <<= 14;
|
||||
bits_left -= 14;
|
||||
}
|
||||
else if ((d32 & 0xff000000) == 0xfe000000)
|
||||
else if ((d32 & 0xff000000) == 0xfe000000)
|
||||
{
|
||||
/* 8 lower bits of LoM */
|
||||
lom = ((d32 >> 16) & 0xff) + 256;
|
||||
d32 <<= 16;
|
||||
bits_left -= 16;
|
||||
}
|
||||
else if ((d32 & 0xff800000) == 0xff000000)
|
||||
else if ((d32 & 0xff800000) == 0xff000000)
|
||||
{
|
||||
/* 9 lower bits of LoM */
|
||||
lom = ((d32 >> 14) & 0x1ff) + 512;
|
||||
d32 <<= 18;
|
||||
bits_left -= 18;
|
||||
}
|
||||
else if ((d32 & 0xffc00000) == 0xff800000)
|
||||
else if ((d32 & 0xffc00000) == 0xff800000)
|
||||
{
|
||||
/* 10 lower bits of LoM */
|
||||
lom = ((d32 >> 12) & 0x3ff) + 1024;
|
||||
d32 <<= 20;
|
||||
bits_left -= 20;
|
||||
}
|
||||
else if ((d32 & 0xffe00000) == 0xffc00000)
|
||||
else if ((d32 & 0xffe00000) == 0xffc00000)
|
||||
{
|
||||
/* 11 lower bits of LoM */
|
||||
lom = ((d32 >> 10) & 0x7ff) + 2048;
|
||||
d32 <<= 22;
|
||||
bits_left -= 22;
|
||||
}
|
||||
else if ((d32 & 0xfff00000) == 0xffe00000)
|
||||
else if ((d32 & 0xfff00000) == 0xffe00000)
|
||||
{
|
||||
/* 12 lower bits of LoM */
|
||||
lom = ((d32 >> 8) & 0xfff) + 4096;
|
||||
|
@ -951,27 +954,27 @@ int decompress_rdp_4(rdpRdp *rdp,
|
|||
|
||||
while (tmp)
|
||||
{
|
||||
if (cur_bits_left < tmp)
|
||||
if (cur_bits_left < tmp)
|
||||
{
|
||||
/* we have less bits than we need */
|
||||
i32 = cur_byte >> (8 - cur_bits_left);
|
||||
d32 |= i32 << ((32 - bits_left) - cur_bits_left);
|
||||
bits_left += cur_bits_left;
|
||||
tmp -= cur_bits_left;
|
||||
if (cptr < cbuf + len)
|
||||
if (cptr < cbuf + len)
|
||||
{
|
||||
/* more compressed data available */
|
||||
cur_byte = *cptr++;
|
||||
cur_bits_left = 8;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
/* no more compressed data available */
|
||||
tmp = 0;
|
||||
cur_bits_left = 0;
|
||||
}
|
||||
}
|
||||
else if (cur_bits_left > tmp)
|
||||
else if (cur_bits_left > tmp)
|
||||
{
|
||||
/* we have more bits than we need */
|
||||
d32 |= cur_byte >> (8 - tmp);
|
||||
|
@ -980,17 +983,17 @@ int decompress_rdp_4(rdpRdp *rdp,
|
|||
bits_left = 32;
|
||||
break;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
/* we have just the right amount of bits */
|
||||
d32 |= cur_byte >> (8 - tmp);
|
||||
bits_left = 32;
|
||||
if (cptr < cbuf + len)
|
||||
if (cptr < cbuf + len)
|
||||
{
|
||||
cur_byte = *cptr++;
|
||||
cur_bits_left = 8;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
cur_bits_left = 0;
|
||||
}
|
||||
|
@ -1010,26 +1013,27 @@ int decompress_rdp_4(rdpRdp *rdp,
|
|||
* @return pointer to new struct, or NULL on failure
|
||||
*/
|
||||
|
||||
struct rdp_mppc *mppc_new(rdpRdp *rdp)
|
||||
struct rdp_mppc* mppc_new(rdpRdp* rdp)
|
||||
{
|
||||
struct rdp_mppc *ptr;
|
||||
struct rdp_mppc* ptr;
|
||||
|
||||
ptr = (struct rdp_mppc *) malloc(sizeof (struct rdp_mppc));
|
||||
ptr = (struct rdp_mppc *) xmalloc(sizeof (struct rdp_mppc));
|
||||
if (!ptr)
|
||||
{
|
||||
printf("mppc_new(): system out of memory\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ptr->history_buf = (uint8 *) malloc(RDP5_HISTORY_BUF_SIZE);
|
||||
ptr->history_buf = (uint8 *) xmalloc(RDP5_HISTORY_BUF_SIZE);
|
||||
if (!ptr->history_buf)
|
||||
{
|
||||
printf("mppc_new(): system out of memory\n");
|
||||
free(ptr);
|
||||
xfree(ptr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ptr->history_ptr = ptr->history_buf;
|
||||
ptr->history_buf_end = ptr->history_buf + RDP5_HISTORY_BUF_SIZE - 1;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
|
@ -1039,7 +1043,7 @@ struct rdp_mppc *mppc_new(rdpRdp *rdp)
|
|||
* @param rdp rdp struct that contains rdp_mppc struct
|
||||
*/
|
||||
|
||||
void mppc_free(rdpRdp *rdp)
|
||||
void mppc_free(rdpRdp* rdp)
|
||||
{
|
||||
if (!rdp->mppc)
|
||||
{
|
||||
|
@ -1048,10 +1052,9 @@ void mppc_free(rdpRdp *rdp)
|
|||
|
||||
if (rdp->mppc->history_buf)
|
||||
{
|
||||
free(rdp->mppc->history_buf);
|
||||
xfree(rdp->mppc->history_buf);
|
||||
rdp->mppc->history_buf = NULL;
|
||||
rdp->mppc->history_ptr = NULL;
|
||||
}
|
||||
free(rdp->mppc);
|
||||
xfree(rdp->mppc);
|
||||
}
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
struct rdp_mppc
|
||||
{
|
||||
uint8 *history_buf;
|
||||
uint8 *history_buf_end;
|
||||
uint8 *history_ptr;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue