mirror of
https://github.com/morgan9e/FreeRDP
synced 2026-04-15 00:44:19 +09:00
mppc: moved to libfreerdp-codec
This commit is contained in:
@@ -635,8 +635,7 @@ int add_mppc_suite(void)
|
||||
|
||||
void test_mppc(void)
|
||||
{
|
||||
rdpRdp rdp;
|
||||
struct rdp_mppc rmppc;
|
||||
struct rdp_mppc_dec* rmppc;
|
||||
uint32_t roff;
|
||||
uint32_t rlen;
|
||||
long int dur;
|
||||
@@ -644,24 +643,20 @@ void test_mppc(void)
|
||||
struct timeval start_time;
|
||||
struct timeval end_time;
|
||||
|
||||
rdp.mppc = &rmppc;
|
||||
rdp.mppc->history_buf = calloc(1, RDP6_HISTORY_BUF_SIZE);
|
||||
CU_ASSERT(rdp.mppc->history_buf != NULL)
|
||||
rdp.mppc->history_ptr = rdp.mppc->history_buf;
|
||||
|
||||
rmppc = mppc_dec_new();
|
||||
|
||||
/* save starting time */
|
||||
gettimeofday(&start_time, NULL);
|
||||
|
||||
/* uncompress data */
|
||||
CU_ASSERT(decompress_rdp_5(&rdp, compressed_rd5, sizeof(compressed_rd5),
|
||||
CU_ASSERT(decompress_rdp_5(rmppc, compressed_rd5, sizeof(compressed_rd5),
|
||||
PACKET_COMPRESSED, &roff, &rlen) == true);
|
||||
|
||||
/* get end time */
|
||||
gettimeofday(&end_time, NULL);
|
||||
|
||||
CU_ASSERT(memcmp(decompressed_rd5, rdp.mppc->history_buf, sizeof(decompressed_rd5)) == 0);
|
||||
free(rdp.mppc->history_buf);
|
||||
CU_ASSERT(memcmp(decompressed_rd5, rmppc->history_buf, sizeof(decompressed_rd5)) == 0);
|
||||
mppc_dec_free(rmppc);
|
||||
|
||||
/* print time taken */
|
||||
dur = ((end_time.tv_sec - start_time.tv_sec) * 1000000) + (end_time.tv_usec - start_time.tv_usec);
|
||||
|
||||
@@ -26,9 +26,10 @@
|
||||
#include <sys/types.h>
|
||||
#include <freerdp/freerdp.h>
|
||||
|
||||
#include "rdp.h"
|
||||
#include <freerdp/codec/mppc_dec.h>
|
||||
#include <freerdp/codec/mppc_enc.h>
|
||||
#include "test_mppc_enc.h"
|
||||
#include "mppc_enc.h"
|
||||
|
||||
|
||||
#define BUF_SIZE (1024 * 1)
|
||||
|
||||
@@ -491,10 +492,9 @@ void test_mppc_enc(void)
|
||||
char buf[BUF_SIZE];
|
||||
|
||||
/* needed by decoder */
|
||||
rdpRdp rdp;
|
||||
struct rdp_mppc rmppc;
|
||||
uint32_t roff;
|
||||
uint32_t rlen;
|
||||
struct rdp_mppc_dec* rmppc;
|
||||
uint32 roff;
|
||||
uint32 rlen;
|
||||
|
||||
/* required for timing the test */
|
||||
struct timeval start_time;
|
||||
@@ -502,10 +502,7 @@ void test_mppc_enc(void)
|
||||
long int dur;
|
||||
|
||||
/* setup decoder */
|
||||
rdp.mppc = &rmppc;
|
||||
rdp.mppc->history_buf = calloc(1, RDP6_HISTORY_BUF_SIZE);
|
||||
CU_ASSERT(rdp.mppc->history_buf != NULL);
|
||||
rdp.mppc->history_ptr = rdp.mppc->history_buf;
|
||||
rmppc = mppc_dec_new();
|
||||
|
||||
/* setup encoder for RDP 5.0 */
|
||||
CU_ASSERT((enc = mppc_enc_new(PROTO_RDP_50)) != NULL);
|
||||
@@ -532,10 +529,10 @@ void test_mppc_enc(void)
|
||||
{
|
||||
DLOG(("%d bytes compressed to %d\n", bytes_read, enc->bytes_in_opb));
|
||||
clen += enc->bytes_in_opb;
|
||||
CU_ASSERT(decompress_rdp_5(&rdp, (uint8 *) enc->outputBuffer,
|
||||
CU_ASSERT(decompress_rdp_5(rmppc, (uint8 *) enc->outputBuffer,
|
||||
enc->bytes_in_opb, enc->flags, &roff, &rlen) != false);
|
||||
CU_ASSERT(bytes_read == rlen);
|
||||
CU_ASSERT(memcmp(buf, &rdp.mppc->history_buf[roff], rlen) == 0);
|
||||
CU_ASSERT(memcmp(buf, &rmppc->history_buf[roff], rlen) == 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -566,10 +563,10 @@ void test_mppc_enc(void)
|
||||
CU_ASSERT(compress_rdp(enc, (uint8*) decompressed_rd5_data, data_len) != false);
|
||||
if (enc->flags & PACKET_COMPRESSED)
|
||||
{
|
||||
CU_ASSERT(decompress_rdp_5(&rdp, (uint8 *) enc->outputBuffer,
|
||||
CU_ASSERT(decompress_rdp_5(rmppc, (uint8 *) enc->outputBuffer,
|
||||
enc->bytes_in_opb, enc->flags, &roff, &rlen) != false);
|
||||
CU_ASSERT(data_len == rlen);
|
||||
CU_ASSERT(memcmp(decompressed_rd5_data, &rdp.mppc->history_buf[roff], rlen) == 0);
|
||||
CU_ASSERT(memcmp(decompressed_rd5_data, &rmppc->history_buf[roff], rlen) == 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -590,5 +587,5 @@ void test_mppc_enc(void)
|
||||
}
|
||||
|
||||
mppc_enc_free(enc);
|
||||
free(rdp.mppc->history_buf);
|
||||
mppc_dec_free(rmppc);
|
||||
}
|
||||
|
||||
55
include/freerdp/codec/mppc_dec.h
Normal file
55
include/freerdp/codec/mppc_dec.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* FreeRDP: A Remote Desktop Protocol Client
|
||||
* Implements Microsoft Point to Point Compression (MPPC) protocol
|
||||
*
|
||||
* Copyright 2011 Laxmikant Rashinkar <LK.Rashinkar@gmail.com>
|
||||
* Copyright Jiten Pathy
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef __MPPC_H
|
||||
#define __MPPC_H
|
||||
|
||||
#include <freerdp/types.h>
|
||||
|
||||
/* Compression Types */
|
||||
#define PACKET_COMPRESSED 0x20
|
||||
#define PACKET_AT_FRONT 0x40
|
||||
#define PACKET_FLUSHED 0x80
|
||||
#define PACKET_COMPR_TYPE_8K 0x00
|
||||
#define PACKET_COMPR_TYPE_64K 0x01
|
||||
#define PACKET_COMPR_TYPE_RDP6 0x02
|
||||
#define PACKET_COMPR_TYPE_RDP61 0x03
|
||||
#define CompressionTypeMask 0x0F
|
||||
|
||||
#define RDP6_HISTORY_BUF_SIZE 65536
|
||||
#define RDP6_OFFSET_CACHE_SIZE 8
|
||||
|
||||
struct rdp_mppc_dec
|
||||
{
|
||||
uint8* history_buf;
|
||||
uint16* offset_cache;
|
||||
uint8* history_buf_end;
|
||||
uint8* history_ptr;
|
||||
};
|
||||
|
||||
int decompress_rdp(struct rdp_mppc_dec* dec, uint8* cbuf, int len, int ctype, uint32* roff, uint32* rlen);
|
||||
int decompress_rdp_4(struct rdp_mppc_dec* dec, uint8* cbuf, int len, int ctype, uint32* roff, uint32* rlen);
|
||||
int decompress_rdp_5(struct rdp_mppc_dec* dec, uint8* cbuf, int len, int ctype, uint32* roff, uint32* rlen);
|
||||
int decompress_rdp_6(struct rdp_mppc_dec* dec, uint8* cbuf, int len, int ctype, uint32* roff, uint32* rlen);
|
||||
int decompress_rdp_61(struct rdp_mppc_dec* dec, uint8* cbuf, int len, int ctype, uint32* roff, uint32* rlen);
|
||||
struct rdp_mppc_dec* mppc_dec_new(void);
|
||||
void mppc_dec_free(struct rdp_mppc_dec* dec);
|
||||
|
||||
#endif
|
||||
@@ -22,7 +22,6 @@
|
||||
#define __MPPC_ENC_H
|
||||
|
||||
#include <freerdp/types.h>
|
||||
#include <freerdp/freerdp.h>
|
||||
|
||||
#define PROTO_RDP_40 1
|
||||
#define PROTO_RDP_50 2
|
||||
@@ -42,6 +42,8 @@ set(FREERDP_CODEC_SRCS
|
||||
nsc_encode.c
|
||||
nsc_encode.h
|
||||
nsc_types.h
|
||||
mppc_dec.c
|
||||
mppc_enc.c
|
||||
)
|
||||
|
||||
if(WITH_SSE2)
|
||||
|
||||
@@ -18,7 +18,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "rdp.h"
|
||||
#include <freerdp/codec/mppc_dec.h>
|
||||
#include <freerdp/utils/memory.h>
|
||||
|
||||
static uint8 HuffLenLEC[] = {
|
||||
0x6, 0x6, 0x6, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x7, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x9, 0x8, 0x9, 0x9, 0x9, 0x9, 0x8, 0x8, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x8, 0x9, 0x9, 0xa, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0xa, 0x9, 0xa, 0xa, 0xa, 0x9, 0x9, 0xa, 0x9, 0xa, 0x9, 0xa, 0x9, 0x9, 0x9, 0xa, 0xa, 0x9, 0xa, 0x9, 0x9, 0x8, 0x9, 0x9, 0x9, 0x9, 0xa, 0xa, 0xa, 0x9, 0x9, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0x9, 0x9, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0x9, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0x8, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0x9, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0x9, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0x9, 0x7, 0x9, 0x9, 0xa, 0x9, 0xa, 0xa, 0xa, 0x9, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0x9, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xd, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xb, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0x9, 0xa, 0xa, 0xa, 0xa, 0xa, 0x9, 0xa, 0xa, 0xa, 0xa, 0xa, 0x9, 0xa, 0xa, 0xa, 0x9, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0x9, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0x9, 0xa, 0x8, 0x9, 0x9, 0xa, 0x9, 0xa, 0xa, 0xa, 0x9, 0xa, 0xa, 0xa, 0x9, 0x9, 0x8, 0x7, 0xd, 0xd, 0x7, 0x7, 0xa, 0x7, 0x7, 0x6, 0x6, 0x6, 0x6, 0x5, 0x6, 0x6, 0x6, 0x5, 0x6, 0x5, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6, 0x8, 0x5, 0x6, 0x7, 0x7 };
|
||||
@@ -118,26 +119,26 @@ uint32 transposebits(uint32 x)
|
||||
*(_s) = *((_s) + (_i)); \
|
||||
*((_s) + (_i)) = t; } while(0)
|
||||
|
||||
int decompress_rdp(rdpRdp* rdp, uint8* cbuf, int len, int ctype, uint32* roff, uint32* rlen)
|
||||
int decompress_rdp(struct rdp_mppc_dec* dec, 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);
|
||||
return decompress_rdp_4(dec, cbuf, len, ctype, roff, rlen);
|
||||
break;
|
||||
|
||||
case PACKET_COMPR_TYPE_64K:
|
||||
return decompress_rdp_5(rdp, cbuf, len, ctype, roff, rlen);
|
||||
return decompress_rdp_5(dec, cbuf, len, ctype, roff, rlen);
|
||||
break;
|
||||
|
||||
case PACKET_COMPR_TYPE_RDP6:
|
||||
return decompress_rdp_6(rdp, cbuf, len, ctype, roff, rlen);
|
||||
return decompress_rdp_6(dec, cbuf, len, ctype, roff, rlen);
|
||||
break;
|
||||
|
||||
case PACKET_COMPR_TYPE_RDP61:
|
||||
return decompress_rdp_61(rdp, cbuf, len, ctype, roff, rlen);
|
||||
return decompress_rdp_61(dec, cbuf, len, ctype, roff, rlen);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -159,7 +160,7 @@ int decompress_rdp(rdpRdp* rdp, uint8* cbuf, int len, int ctype, uint32* roff, u
|
||||
* @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(struct rdp_mppc_dec* dec, 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 history_buf */
|
||||
@@ -176,7 +177,7 @@ int decompress_rdp_4(rdpRdp* rdp, uint8* cbuf, int len, int ctype, uint32* roff,
|
||||
|
||||
printf("decompress_rdp_4:\n");
|
||||
|
||||
if ((rdp->mppc == NULL) || (rdp->mppc->history_buf == NULL))
|
||||
if ((dec == NULL) || (dec->history_buf == NULL))
|
||||
{
|
||||
printf("decompress_rdp_4: null\n");
|
||||
return false;
|
||||
@@ -193,24 +194,24 @@ int decompress_rdp_4(rdpRdp* rdp, uint8* cbuf, int len, int ctype, uint32* roff,
|
||||
*rlen = 0;
|
||||
|
||||
/* get start of history buffer */
|
||||
history_buf = rdp->mppc->history_buf;
|
||||
history_buf = dec->history_buf;
|
||||
|
||||
/* get next free slot in history buffer */
|
||||
history_ptr = rdp->mppc->history_ptr;
|
||||
history_ptr = dec->history_ptr;
|
||||
*roff = history_ptr - history_buf;
|
||||
|
||||
if (ctype & PACKET_AT_FRONT)
|
||||
{
|
||||
/* place compressed data at start of history buffer */
|
||||
history_ptr = rdp->mppc->history_buf;
|
||||
rdp->mppc->history_ptr = rdp->mppc->history_buf;
|
||||
history_ptr = dec->history_buf;
|
||||
dec->history_ptr = dec->history_buf;
|
||||
*roff = 0;
|
||||
}
|
||||
|
||||
if (ctype & PACKET_FLUSHED)
|
||||
{
|
||||
/* re-init history buffer */
|
||||
history_ptr = rdp->mppc->history_buf;
|
||||
history_ptr = dec->history_buf;
|
||||
memset(history_buf, 0, RDP6_HISTORY_BUF_SIZE);
|
||||
*roff = 0;
|
||||
}
|
||||
@@ -220,8 +221,8 @@ int decompress_rdp_4(rdpRdp* rdp, uint8* cbuf, int len, int ctype, uint32* roff,
|
||||
/* data in cbuf is not compressed - copy to history buf as is */
|
||||
memcpy(history_ptr, cbuf, len);
|
||||
history_ptr += len;
|
||||
*rlen = history_ptr - rdp->mppc->history_ptr;
|
||||
rdp->mppc->history_ptr = history_ptr;
|
||||
*rlen = history_ptr - dec->history_ptr;
|
||||
dec->history_ptr = history_ptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -485,7 +486,7 @@ int decompress_rdp_4(rdpRdp* rdp, uint8* cbuf, int len, int ctype, uint32* roff,
|
||||
/* now that we have copy_offset and LoM, process them */
|
||||
|
||||
src_ptr = history_ptr - copy_offset;
|
||||
if (src_ptr >= rdp->mppc->history_buf)
|
||||
if (src_ptr >= dec->history_buf)
|
||||
{
|
||||
/* data does not wrap around */
|
||||
while (lom > 0)
|
||||
@@ -496,15 +497,15 @@ int decompress_rdp_4(rdpRdp* rdp, uint8* cbuf, int len, int ctype, uint32* roff,
|
||||
}
|
||||
else
|
||||
{
|
||||
src_ptr = rdp->mppc->history_buf_end - (copy_offset - (history_ptr - rdp->mppc->history_buf));
|
||||
src_ptr = dec->history_buf_end - (copy_offset - (history_ptr - dec->history_buf));
|
||||
src_ptr++;
|
||||
while (lom && (src_ptr <= rdp->mppc->history_buf_end))
|
||||
while (lom && (src_ptr <= dec->history_buf_end))
|
||||
{
|
||||
*history_ptr++ = *src_ptr++;
|
||||
lom--;
|
||||
}
|
||||
|
||||
src_ptr = rdp->mppc->history_buf;
|
||||
src_ptr = dec->history_buf;
|
||||
while (lom > 0)
|
||||
{
|
||||
*history_ptr++ = *src_ptr++;
|
||||
@@ -569,9 +570,9 @@ int decompress_rdp_4(rdpRdp* rdp, uint8* cbuf, int len, int ctype, uint32* roff,
|
||||
}
|
||||
} /* end while (bits_left >= 8) */
|
||||
|
||||
*rlen = history_ptr - rdp->mppc->history_ptr;
|
||||
*rlen = history_ptr - dec->history_ptr;
|
||||
|
||||
rdp->mppc->history_ptr = history_ptr;
|
||||
dec->history_ptr = history_ptr;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -589,7 +590,7 @@ int decompress_rdp_4(rdpRdp* rdp, uint8* cbuf, int len, int ctype, uint32* roff,
|
||||
* @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(struct rdp_mppc_dec* dec, 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 */
|
||||
@@ -604,7 +605,7 @@ int decompress_rdp_5(rdpRdp* rdp, uint8* cbuf, int len, int ctype, uint32* roff,
|
||||
int tmp;
|
||||
uint32 i32;
|
||||
|
||||
if ((rdp->mppc == NULL) || (rdp->mppc->history_buf == NULL))
|
||||
if ((dec == NULL) || (dec->history_buf == NULL))
|
||||
{
|
||||
printf("decompress_rdp_5: null\n");
|
||||
return false;
|
||||
@@ -621,24 +622,24 @@ int decompress_rdp_5(rdpRdp* rdp, uint8* cbuf, int len, int ctype, uint32* roff,
|
||||
*rlen = 0;
|
||||
|
||||
/* get start of history buffer */
|
||||
history_buf = rdp->mppc->history_buf;
|
||||
history_buf = dec->history_buf;
|
||||
|
||||
/* get next free slot in history buffer */
|
||||
history_ptr = rdp->mppc->history_ptr;
|
||||
history_ptr = dec->history_ptr;
|
||||
*roff = history_ptr - history_buf;
|
||||
|
||||
if (ctype & PACKET_AT_FRONT)
|
||||
{
|
||||
/* place compressed data at start of history buffer */
|
||||
history_ptr = rdp->mppc->history_buf;
|
||||
rdp->mppc->history_ptr = rdp->mppc->history_buf;
|
||||
history_ptr = dec->history_buf;
|
||||
dec->history_ptr = dec->history_buf;
|
||||
*roff = 0;
|
||||
}
|
||||
|
||||
if (ctype & PACKET_FLUSHED)
|
||||
{
|
||||
/* re-init history buffer */
|
||||
history_ptr = rdp->mppc->history_buf;
|
||||
history_ptr = dec->history_buf;
|
||||
memset(history_buf, 0, RDP6_HISTORY_BUF_SIZE);
|
||||
*roff = 0;
|
||||
}
|
||||
@@ -648,8 +649,8 @@ int decompress_rdp_5(rdpRdp* rdp, uint8* cbuf, int len, int ctype, uint32* roff,
|
||||
/* data in cbuf is not compressed - copy to history buf as is */
|
||||
memcpy(history_ptr, cbuf, len);
|
||||
history_ptr += len;
|
||||
*rlen = history_ptr - rdp->mppc->history_ptr;
|
||||
rdp->mppc->history_ptr = history_ptr;
|
||||
*rlen = history_ptr - dec->history_ptr;
|
||||
dec->history_ptr = history_ptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -948,7 +949,7 @@ int decompress_rdp_5(rdpRdp* rdp, uint8* cbuf, int len, int ctype, uint32* roff,
|
||||
/* now that we have copy_offset and LoM, process them */
|
||||
|
||||
src_ptr = history_ptr - copy_offset;
|
||||
if (src_ptr >= rdp->mppc->history_buf)
|
||||
if (src_ptr >= dec->history_buf)
|
||||
{
|
||||
/* data does not wrap around */
|
||||
while (lom > 0)
|
||||
@@ -959,15 +960,15 @@ int decompress_rdp_5(rdpRdp* rdp, uint8* cbuf, int len, int ctype, uint32* roff,
|
||||
}
|
||||
else
|
||||
{
|
||||
src_ptr = rdp->mppc->history_buf_end - (copy_offset - (history_ptr - rdp->mppc->history_buf));
|
||||
src_ptr = dec->history_buf_end - (copy_offset - (history_ptr - dec->history_buf));
|
||||
src_ptr++;
|
||||
while (lom && (src_ptr <= rdp->mppc->history_buf_end))
|
||||
while (lom && (src_ptr <= dec->history_buf_end))
|
||||
{
|
||||
*history_ptr++ = *src_ptr++;
|
||||
lom--;
|
||||
}
|
||||
|
||||
src_ptr = rdp->mppc->history_buf;
|
||||
src_ptr = dec->history_buf;
|
||||
while (lom > 0)
|
||||
{
|
||||
*history_ptr++ = *src_ptr++;
|
||||
@@ -1033,9 +1034,9 @@ int decompress_rdp_5(rdpRdp* rdp, uint8* cbuf, int len, int ctype, uint32* roff,
|
||||
|
||||
} /* end while (cptr < cbuf + len) */
|
||||
|
||||
*rlen = history_ptr - rdp->mppc->history_ptr;
|
||||
*rlen = history_ptr - dec->history_ptr;
|
||||
|
||||
rdp->mppc->history_ptr = history_ptr;
|
||||
dec->history_ptr = history_ptr;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1053,7 +1054,7 @@ int decompress_rdp_5(rdpRdp* rdp, uint8* cbuf, int len, int ctype, uint32* roff,
|
||||
* @return True on success, False on failure
|
||||
*/
|
||||
|
||||
int decompress_rdp_6(rdpRdp* rdp, uint8* cbuf, int len, int ctype, uint32* roff, uint32* rlen)
|
||||
int decompress_rdp_6(struct rdp_mppc_dec* dec, uint8* cbuf, int len, int ctype, uint32* roff, uint32* rlen)
|
||||
{
|
||||
uint8* history_buf; /* uncompressed data goes here */
|
||||
uint16* offset_cache; /* Copy Offset cache */
|
||||
@@ -1070,7 +1071,7 @@ int decompress_rdp_6(rdpRdp* rdp, uint8* cbuf, int len, int ctype, uint32* roff,
|
||||
int tmp, i;
|
||||
uint32 i32;
|
||||
|
||||
if ((rdp->mppc == NULL) || (rdp->mppc->history_buf == NULL))
|
||||
if ((dec == NULL) || (dec->history_buf == NULL))
|
||||
{
|
||||
printf("decompress_rdp_6: null\n");
|
||||
return false;
|
||||
@@ -1087,13 +1088,13 @@ int decompress_rdp_6(rdpRdp* rdp, uint8* cbuf, int len, int ctype, uint32* roff,
|
||||
*rlen = 0;
|
||||
|
||||
/* get start of history buffer */
|
||||
history_buf = rdp->mppc->history_buf;
|
||||
history_buf = dec->history_buf;
|
||||
|
||||
/* get start of offset_cache */
|
||||
offset_cache = rdp->mppc->offset_cache;
|
||||
offset_cache = dec->offset_cache;
|
||||
|
||||
/* get next free slot in history buffer */
|
||||
history_ptr = rdp->mppc->history_ptr;
|
||||
history_ptr = dec->history_ptr;
|
||||
*roff = history_ptr - history_buf;
|
||||
|
||||
if (ctype & PACKET_AT_FRONT)
|
||||
@@ -1101,14 +1102,14 @@ int decompress_rdp_6(rdpRdp* rdp, uint8* cbuf, int len, int ctype, uint32* roff,
|
||||
/* slid history_buf and reset history_buf to middle */
|
||||
memcpy(history_buf, (history_buf + (history_ptr - history_buf - 32768)), 32768);
|
||||
history_ptr = history_buf + 32768;
|
||||
rdp->mppc->history_ptr = history_ptr;
|
||||
dec->history_ptr = history_ptr;
|
||||
*roff = 32768;
|
||||
}
|
||||
|
||||
if (ctype & PACKET_FLUSHED)
|
||||
{
|
||||
/* re-init history buffer */
|
||||
history_ptr = rdp->mppc->history_buf;
|
||||
history_ptr = dec->history_buf;
|
||||
memset(history_buf, 0, RDP6_HISTORY_BUF_SIZE);
|
||||
memset(offset_cache, 0, RDP6_OFFSET_CACHE_SIZE);
|
||||
*roff = 0;
|
||||
@@ -1119,8 +1120,8 @@ int decompress_rdp_6(rdpRdp* rdp, uint8* cbuf, int len, int ctype, uint32* roff,
|
||||
/* data in cbuf is not compressed - copy to history buf as is */
|
||||
memcpy(history_ptr, cbuf, len);
|
||||
history_ptr += len;
|
||||
*rlen = history_ptr - rdp->mppc->history_ptr;
|
||||
rdp->mppc->history_ptr = history_ptr;
|
||||
*rlen = history_ptr - dec->history_ptr;
|
||||
dec->history_ptr = history_ptr;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1270,7 +1271,7 @@ int decompress_rdp_6(rdpRdp* rdp, uint8* cbuf, int len, int ctype, uint32* roff,
|
||||
src_ptr = history_ptr - copy_offset;
|
||||
tmp = (lom > copy_offset) ? copy_offset : lom;
|
||||
i32 = 0;
|
||||
if (src_ptr >= rdp->mppc->history_buf)
|
||||
if (src_ptr >= dec->history_buf)
|
||||
{
|
||||
while(tmp > 0)
|
||||
{
|
||||
@@ -1286,20 +1287,20 @@ int decompress_rdp_6(rdpRdp* rdp, uint8* cbuf, int len, int ctype, uint32* roff,
|
||||
}
|
||||
else
|
||||
{
|
||||
src_ptr = rdp->mppc->history_buf_end - (copy_offset - (history_ptr - rdp->mppc->history_buf));
|
||||
src_ptr = dec->history_buf_end - (copy_offset - (history_ptr - dec->history_buf));
|
||||
src_ptr++;
|
||||
while (tmp && (src_ptr <= rdp->mppc->history_buf_end))
|
||||
while (tmp && (src_ptr <= dec->history_buf_end))
|
||||
{
|
||||
*history_ptr++ = *src_ptr++;
|
||||
tmp--;
|
||||
}
|
||||
src_ptr = rdp->mppc->history_buf;
|
||||
src_ptr = dec->history_buf;
|
||||
while (tmp > 0)
|
||||
{
|
||||
*history_ptr++ = *src_ptr++;
|
||||
tmp--;
|
||||
}
|
||||
while(lom > copy_offset)
|
||||
while (lom > copy_offset)
|
||||
{
|
||||
i32 = ((i32 > copy_offset)) ? 0 : i32;
|
||||
*history_ptr++ = *(src_ptr + i32++);
|
||||
@@ -1368,9 +1369,9 @@ int decompress_rdp_6(rdpRdp* rdp, uint8* cbuf, int len, int ctype, uint32* roff,
|
||||
if(ctype & PACKET_FLUSHED)
|
||||
*rlen = history_ptr - history_buf;
|
||||
else
|
||||
*rlen = history_ptr - rdp->mppc->history_ptr;
|
||||
*rlen = history_ptr - dec->history_ptr;
|
||||
|
||||
rdp->mppc->history_ptr = history_ptr;
|
||||
dec->history_ptr = history_ptr;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1388,7 +1389,7 @@ int decompress_rdp_6(rdpRdp* rdp, uint8* cbuf, int len, int ctype, uint32* roff,
|
||||
* @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(struct rdp_mppc_dec* dec, uint8* cbuf, int len, int ctype, uint32* roff, uint32* rlen)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -1400,11 +1401,11 @@ int decompress_rdp_61(rdpRdp* rdp, uint8* cbuf, int len, int ctype, uint32* roff
|
||||
* @return pointer to new struct, or NULL on failure
|
||||
*/
|
||||
|
||||
struct rdp_mppc* mppc_new(rdpRdp* rdp)
|
||||
struct rdp_mppc_dec* mppc_dec_new(void)
|
||||
{
|
||||
struct rdp_mppc* ptr;
|
||||
struct rdp_mppc_dec* ptr;
|
||||
|
||||
ptr = (struct rdp_mppc *) xmalloc(sizeof (struct rdp_mppc));
|
||||
ptr = (struct rdp_mppc_dec*) xmalloc(sizeof(struct rdp_mppc_dec));
|
||||
if (!ptr)
|
||||
{
|
||||
printf("mppc_new(): system out of memory\n");
|
||||
@@ -1431,18 +1432,18 @@ struct rdp_mppc* mppc_new(rdpRdp* rdp)
|
||||
* @param rdp rdp struct that contains rdp_mppc struct
|
||||
*/
|
||||
|
||||
void mppc_free(rdpRdp* rdp)
|
||||
void mppc_dec_free(struct rdp_mppc_dec* dec)
|
||||
{
|
||||
if (!rdp->mppc)
|
||||
if (!dec)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (rdp->mppc->history_buf)
|
||||
if (dec->history_buf)
|
||||
{
|
||||
xfree(rdp->mppc->history_buf);
|
||||
rdp->mppc->history_buf = NULL;
|
||||
rdp->mppc->history_ptr = NULL;
|
||||
xfree(dec->history_buf);
|
||||
dec->history_buf = NULL;
|
||||
dec->history_ptr = NULL;
|
||||
}
|
||||
xfree(rdp->mppc);
|
||||
xfree(dec);
|
||||
}
|
||||
@@ -18,8 +18,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "rdp.h"
|
||||
#include "mppc_enc.h"
|
||||
#include <freerdp/codec/mppc_dec.h>
|
||||
#include <freerdp/codec/mppc_enc.h>
|
||||
#include <freerdp/utils/memory.h>
|
||||
|
||||
#define MPPC_ENC_DEBUG 0
|
||||
@@ -556,10 +556,10 @@ boolean compress_rdp_5(struct rdp_mppc_enc* enc, uint8* srcData, int len)
|
||||
uint16 data16;
|
||||
uint32 historyOffset;
|
||||
uint16 crc;
|
||||
uint ctr;
|
||||
uint saved_ctr;
|
||||
uint data_end;
|
||||
uint8 byte_val;
|
||||
uint32 ctr;
|
||||
uint32 saved_ctr;
|
||||
uint32 data_end;
|
||||
uint8 byte_val;
|
||||
|
||||
crc = 0;
|
||||
opb_index = 0;
|
||||
@@ -82,8 +82,6 @@ set(LIBFREERDP_CORE_SRCS
|
||||
listener.h
|
||||
peer.c
|
||||
peer.h
|
||||
mppc.c
|
||||
mppc_enc.c
|
||||
)
|
||||
|
||||
add_library(freerdp-core ${LIBFREERDP_CORE_SRCS})
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
#include "update.h"
|
||||
#include "surface.h"
|
||||
#include "fastpath.h"
|
||||
#include "mppc_enc.h"
|
||||
#include "rdp.h"
|
||||
|
||||
/**
|
||||
* Fast-Path packet format is defined in [MS-RDPBCGR] 2.2.9.1.2, which revises
|
||||
@@ -259,10 +259,10 @@ static boolean fastpath_recv_update_data(rdpFastPath* fastpath, STREAM* s)
|
||||
|
||||
if (compressionFlags & PACKET_COMPRESSED)
|
||||
{
|
||||
if (decompress_rdp(rdp, s->p, size, compressionFlags, &roff, &rlen))
|
||||
if (decompress_rdp(rdp->mppc_dec, s->p, size, compressionFlags, &roff, &rlen))
|
||||
{
|
||||
comp_stream = stream_new(0);
|
||||
comp_stream->data = rdp->mppc->history_buf + roff;
|
||||
comp_stream->data = rdp->mppc_dec->history_buf + roff;
|
||||
comp_stream->p = comp_stream->data;
|
||||
comp_stream->size = rlen;
|
||||
size = comp_stream->size;
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
/**
|
||||
* FreeRDP: A Remote Desktop Protocol Client
|
||||
* Implements Microsoft Point to Point Compression (MPPC) protocol
|
||||
*
|
||||
* Copyright 2011 Laxmikant Rashinkar <LK.Rashinkar@gmail.com>
|
||||
* Copyright Jiten Pathy
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef __MPPC_H
|
||||
#define __MPPC_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define RDP6_HISTORY_BUF_SIZE 65536
|
||||
#define RDP6_OFFSET_CACHE_SIZE 8
|
||||
|
||||
struct rdp_mppc
|
||||
{
|
||||
uint8 *history_buf;
|
||||
uint16 *offset_cache;
|
||||
uint8 *history_buf_end;
|
||||
uint8 *history_ptr;
|
||||
};
|
||||
|
||||
// forward declarations
|
||||
int decompress_rdp(rdpRdp *, uint8 *, int, int, uint32 *, uint32 *);
|
||||
int decompress_rdp_4(rdpRdp *, uint8 *, int, int, uint32 *, uint32 *);
|
||||
int decompress_rdp_5(rdpRdp *, uint8 *, int, int, uint32 *, uint32 *);
|
||||
int decompress_rdp_6(rdpRdp *, uint8 *, int, int, uint32 *, uint32 *);
|
||||
int decompress_rdp_61(rdpRdp *, uint8 *, int, int, uint32 *, uint32 *);
|
||||
struct rdp_mppc *mppc_new(rdpRdp *rdp);
|
||||
void mppc_free(rdpRdp *rdp);
|
||||
|
||||
#endif
|
||||
@@ -21,7 +21,6 @@
|
||||
|
||||
#include "info.h"
|
||||
#include "redirection.h"
|
||||
#include "mppc_enc.h"
|
||||
|
||||
#include <freerdp/crypto/per.h>
|
||||
|
||||
@@ -482,10 +481,10 @@ boolean rdp_recv_data_pdu(rdpRdp* rdp, STREAM* s)
|
||||
|
||||
if (compressed_type & PACKET_COMPRESSED)
|
||||
{
|
||||
if (decompress_rdp(rdp, s->p, compressed_len - 18, compressed_type, &roff, &rlen))
|
||||
if (decompress_rdp(rdp->mppc_dec, s->p, compressed_len - 18, compressed_type, &roff, &rlen))
|
||||
{
|
||||
comp_stream = stream_new(0);
|
||||
comp_stream->data = rdp->mppc->history_buf + roff;
|
||||
comp_stream->data = rdp->mppc_dec->history_buf + roff;
|
||||
comp_stream->p = comp_stream->data;
|
||||
comp_stream->size = rlen;
|
||||
}
|
||||
@@ -923,7 +922,7 @@ rdpRdp* rdp_new(freerdp* instance)
|
||||
rdp->nego = nego_new(rdp->transport);
|
||||
rdp->mcs = mcs_new(rdp->transport);
|
||||
rdp->redirection = redirection_new();
|
||||
rdp->mppc = mppc_new(rdp);
|
||||
rdp->mppc_dec = mppc_dec_new();
|
||||
rdp->mppc_enc = mppc_enc_new(PROTO_RDP_50);
|
||||
}
|
||||
|
||||
@@ -954,7 +953,7 @@ void rdp_free(rdpRdp* rdp)
|
||||
nego_free(rdp->nego);
|
||||
mcs_free(rdp->mcs);
|
||||
redirection_free(rdp->redirection);
|
||||
mppc_free(rdp);
|
||||
mppc_dec_free(rdp->mppc_dec);
|
||||
mppc_enc_free(rdp->mppc_enc);
|
||||
xfree(rdp);
|
||||
}
|
||||
|
||||
@@ -37,12 +37,13 @@
|
||||
#include "redirection.h"
|
||||
#include "capabilities.h"
|
||||
#include "channel.h"
|
||||
#include "mppc.h"
|
||||
|
||||
#include <freerdp/freerdp.h>
|
||||
#include <freerdp/settings.h>
|
||||
#include <freerdp/utils/debug.h>
|
||||
#include <freerdp/utils/stream.h>
|
||||
#include <freerdp/codec/mppc_dec.h>
|
||||
#include <freerdp/codec/mppc_enc.h>
|
||||
|
||||
/* Security Header Flags */
|
||||
#define SEC_EXCHANGE_PKT 0x0001
|
||||
@@ -104,16 +105,6 @@
|
||||
#define DATA_PDU_TYPE_STATUS_INFO 0x36
|
||||
#define DATA_PDU_TYPE_MONITOR_LAYOUT 0x37
|
||||
|
||||
/* Compression Types */
|
||||
#define PACKET_COMPRESSED 0x20
|
||||
#define PACKET_AT_FRONT 0x40
|
||||
#define PACKET_FLUSHED 0x80
|
||||
#define PACKET_COMPR_TYPE_8K 0x00
|
||||
#define PACKET_COMPR_TYPE_64K 0x01
|
||||
#define PACKET_COMPR_TYPE_RDP6 0x02
|
||||
#define PACKET_COMPR_TYPE_RDP61 0x03
|
||||
#define CompressionTypeMask 0x0F
|
||||
|
||||
/* Stream Identifiers */
|
||||
#define STREAM_UNDEFINED 0x00
|
||||
#define STREAM_LOW 0x01
|
||||
@@ -134,7 +125,7 @@ struct rdp_rdp
|
||||
struct rdp_settings* settings;
|
||||
struct rdp_transport* transport;
|
||||
struct rdp_extension* extension;
|
||||
struct rdp_mppc* mppc;
|
||||
struct rdp_mppc_dec* mppc_dec;
|
||||
struct rdp_mppc_enc* mppc_enc;
|
||||
struct crypto_rc4_struct* rc4_decrypt_key;
|
||||
int decrypt_use_count;
|
||||
|
||||
Reference in New Issue
Block a user