int bulk_decompress(rdpBulk* bulk, BYTE* pSrcData, UINT32 SrcSize, BYTE** ppDstData, UINT32* pDstSize, UINT32 flags) { UINT32 type; int status = -1; rdpMetrics* metrics; UINT32 CompressedBytes; UINT32 UncompressedBytes; double CompressionRatio; metrics = bulk->context->metrics; bulk_compression_max_size(bulk); type = flags & BULK_COMPRESSION_TYPE_MASK; if (flags & BULK_COMPRESSION_FLAGS_MASK) { switch (type) { case PACKET_COMPR_TYPE_8K: mppc_set_compression_level(bulk->mppcRecv, 0); status = mppc_decompress(bulk->mppcRecv, pSrcData, SrcSize, ppDstData, pDstSize, flags); break; case PACKET_COMPR_TYPE_64K: mppc_set_compression_level(bulk->mppcRecv, 1); status = mppc_decompress(bulk->mppcRecv, pSrcData, SrcSize, ppDstData, pDstSize, flags); break; case PACKET_COMPR_TYPE_RDP6: status = ncrush_decompress(bulk->ncrushRecv, pSrcData, SrcSize, ppDstData, pDstSize, flags); break; case PACKET_COMPR_TYPE_RDP61: status = xcrush_decompress(bulk->xcrushRecv, pSrcData, SrcSize, ppDstData, pDstSize, flags); break; case PACKET_COMPR_TYPE_RDP8: status = -1; break; } } else { *ppDstData = pSrcData; *pDstSize = SrcSize; status = 0; } if (status >= 0) { CompressedBytes = SrcSize; UncompressedBytes = *pDstSize; CompressionRatio = metrics_write_bytes(metrics, UncompressedBytes, CompressedBytes); #ifdef WITH_BULK_DEBUG { DEBUG_MSG("Decompress Type: %d Flags: %s (0x%04X) Compression Ratio: %f (%d / %d), Total: %f (%u / %u)\n", type, bulk_get_compression_flags_string(flags), flags, CompressionRatio, CompressedBytes, UncompressedBytes, metrics->TotalCompressionRatio, (UINT32) metrics->TotalCompressedBytes, (UINT32) metrics->TotalUncompressedBytes); } #endif } else { DEBUG_WARN("Decompression failure!\n"); } return status; }
int bulk_decompress(rdpBulk* bulk, BYTE* pSrcData, UINT32 SrcSize, BYTE** ppDstData, UINT32* pDstSize, UINT32 flags) { UINT32 type; int status = -1; UINT32 CompressedBytes; UINT32 UncompressedBytes; bulk_compression_max_size(bulk); type = flags & BULK_COMPRESSION_TYPE_MASK; if (flags & BULK_COMPRESSION_FLAGS_MASK) { switch (type) { case PACKET_COMPR_TYPE_8K: mppc_set_compression_level(bulk->mppcRecv, 0); status = mppc_decompress(bulk->mppcRecv, pSrcData, SrcSize, ppDstData, pDstSize, flags); break; case PACKET_COMPR_TYPE_64K: mppc_set_compression_level(bulk->mppcRecv, 1); status = mppc_decompress(bulk->mppcRecv, pSrcData, SrcSize, ppDstData, pDstSize, flags); break; case PACKET_COMPR_TYPE_RDP6: status = ncrush_decompress(bulk->ncrushRecv, pSrcData, SrcSize, ppDstData, pDstSize, flags); break; case PACKET_COMPR_TYPE_RDP61: status = xcrush_decompress(bulk->xcrushRecv, pSrcData, SrcSize, ppDstData, pDstSize, flags); break; case PACKET_COMPR_TYPE_RDP8: status = -1; break; } } else { *ppDstData = pSrcData; *pDstSize = SrcSize; status = 0; } if (status >= 0) { CompressedBytes = SrcSize; UncompressedBytes = *pDstSize; bulk->TotalUncompressedBytes += UncompressedBytes; bulk->TotalCompressedBytes += CompressedBytes; #ifdef WITH_BULK_DEBUG { double CompressionRatio; double TotalCompressionRatio; CompressionRatio = ((double) CompressedBytes) / ((double) UncompressedBytes); TotalCompressionRatio = ((double) bulk->TotalCompressedBytes) / ((double) bulk->TotalUncompressedBytes); printf("Decompress Type: %d Flags: %s (0x%04X) Compression Ratio: %f (%d / %d), Total: %f (%d / %d)\n", type, bulk_get_compression_flags_string(flags), flags, CompressionRatio, CompressedBytes, UncompressedBytes, TotalCompressionRatio, bulk->TotalCompressedBytes, bulk->TotalUncompressedBytes); } #endif } else { fprintf(stderr, "Decompression failure!\n"); } return status; }