ReactOS  0.4.15-dev-494-g1d8c567
CMSZipCodec Class Reference

#include <mszip.h>

Inheritance diagram for CMSZipCodec:
Collaboration diagram for CMSZipCodec:

Public Member Functions

 CMSZipCodec ()
 
virtual ~CMSZipCodec ()
 
virtual ULONG Compress (void *OutputBuffer, void *InputBuffer, ULONG InputLength, PULONG OutputLength)
 
virtual ULONG Uncompress (void *OutputBuffer, void *InputBuffer, ULONG InputLength, PULONG OutputLength)
 
- Public Member Functions inherited from CCABCodec
 CCABCodec ()
 
virtual ~CCABCodec ()
 

Private Attributes

int Status
 
z_stream ZStream
 

Detailed Description

Definition at line 18 of file mszip.h.

Constructor & Destructor Documentation

◆ CMSZipCodec()

CMSZipCodec::CMSZipCodec ( )

Definition at line 36 of file mszip.cxx.

40 {
43  ZStream.opaque = (voidpf)0;
44 }
z_stream ZStream
Definition: mszip.h:37
voidpf opaque
Definition: zlib.h:100
free_func zfree
Definition: zlib.h:99
alloc_func zalloc
Definition: zlib.h:98
void MSZipFree(voidpf opaque, voidpf address)
Definition: mszip.cxx:27
Byte FAR * voidpf
Definition: zconf.h:413
voidpf MSZipAlloc(voidpf opaque, uInt items, uInt size)
Definition: mszip.cxx:21

◆ ~CMSZipCodec()

CMSZipCodec::~CMSZipCodec ( )
virtual

Definition at line 47 of file mszip.cxx.

51 {
52 }

Member Function Documentation

◆ Compress()

ULONG CMSZipCodec::Compress ( void OutputBuffer,
void InputBuffer,
ULONG  InputLength,
PULONG  OutputLength 
)
virtual

Implements CCABCodec.

Definition at line 55 of file mszip.cxx.

67 {
68  PUSHORT Magic;
69 
70  DPRINT(MAX_TRACE, ("InputLength (%u).\n", (UINT)InputLength));
71 
72  Magic = (PUSHORT)OutputBuffer;
73  *Magic = MSZIP_MAGIC;
74 
75  ZStream.next_in = (unsigned char*)InputBuffer;
76  ZStream.avail_in = InputLength;
77  ZStream.next_out = ((unsigned char *)OutputBuffer + 2);
79 
80  /* WindowBits is passed < 0 to tell that there is no zlib header */
83  Z_DEFLATED,
84  -MAX_WBITS,
85  8, /* memLevel */
87  if (Status != Z_OK)
88  {
89  DPRINT(MIN_TRACE, ("deflateInit() returned (%d).\n", Status));
90  return CS_NOMEMORY;
91  }
92 
94  if ((Status != Z_OK) && (Status != Z_STREAM_END))
95  {
96  DPRINT(MIN_TRACE, ("deflate() returned (%d) (%s).\n", Status, ZStream.msg));
97  if (Status == Z_MEM_ERROR)
98  return CS_NOMEMORY;
99  return CS_BADSTREAM;
100  }
101 
102  *OutputLength = ZStream.total_out + 2;
103 
105  if (Status != Z_OK)
106  {
107  DPRINT(MIN_TRACE, ("deflateEnd() returned (%d).\n", Status));
108  return CS_BADSTREAM;
109  }
110 
111  return CS_SUCCESS;
112 }
uInt avail_in
Definition: zlib.h:88
z_stream ZStream
Definition: mszip.h:37
#define deflateInit2(strm, level, method, windowBits, memLevel, strategy)
Definition: zlib.h:1797
#define Z_DEFAULT_STRATEGY
Definition: zlib.h:200
int ZEXPORT deflateEnd(z_streamp strm)
Definition: deflate.c:1079
CHAR InputBuffer[80]
Definition: conmgr.c:33
#define Z_STREAM_END
Definition: zlib.h:178
#define CS_BADSTREAM
Definition: cabinet.h:43
#define Z_OK
Definition: zlib.h:177
#define Z_DEFLATED
Definition: zlib.h:209
void DPRINT(...)
Definition: polytest.cpp:61
#define MSZIP_MAGIC
Definition: cabinet.c:212
_Must_inspect_result_ __drv_aliasesMem _In_ PDEVICE_OBJECT _In_opt_ PVOID _In_ ULONG _Out_opt_ PVOID OutputBuffer
Definition: iofuncs.h:713
#define CAB_BLOCKSIZE
Definition: cabinet.c:49
#define Z_DEFAULT_COMPRESSION
Definition: zlib.h:193
z_const char * msg
Definition: zlib.h:95
int ZEXPORT deflate(z_streamp strm, int flush)
Definition: deflate.c:766
Status
Definition: gdiplustypes.h:24
uLong total_out
Definition: zlib.h:93
#define CS_NOMEMORY
Definition: cabinet.h:42
#define Z_FINISH
Definition: zlib.h:172
#define MAX_TRACE
Definition: debug.h:16
unsigned int UINT
Definition: ndis.h:50
uInt avail_out
Definition: zlib.h:92
z_const Bytef * next_in
Definition: zlib.h:87
#define MIN_TRACE
Definition: debug.h:14
#define CS_SUCCESS
Definition: cabinet.h:41
Bytef * next_out
Definition: zlib.h:91
#define MAX_WBITS
Definition: zconf.h:270
unsigned short * PUSHORT
Definition: retypes.h:2
#define Z_MEM_ERROR
Definition: zlib.h:183

◆ Uncompress()

ULONG CMSZipCodec::Uncompress ( void OutputBuffer,
void InputBuffer,
ULONG  InputLength,
PULONG  OutputLength 
)
virtual

Implements CCABCodec.

Definition at line 115 of file mszip.cxx.

127 {
128  USHORT Magic;
129 
130  DPRINT(MAX_TRACE, ("InputLength (%u).\n", (UINT)InputLength));
131 
132  Magic = *((PUSHORT)InputBuffer);
133 
134  if (Magic != MSZIP_MAGIC)
135  {
136  DPRINT(MID_TRACE, ("Bad MSZIP block header magic (0x%X)\n", Magic));
137  return CS_BADSTREAM;
138  }
139 
140  ZStream.next_in = ((unsigned char*)InputBuffer + 2);
141  ZStream.avail_in = InputLength - 2;
142  ZStream.next_out = (unsigned char*)OutputBuffer;
144 
145  /* WindowBits is passed < 0 to tell that there is no zlib header.
146  * Note that in this case inflate *requires* an extra "dummy" byte
147  * after the compressed stream in order to complete decompression and
148  * return Z_STREAM_END.
149  */
151  if (Status != Z_OK)
152  {
153  DPRINT(MIN_TRACE, ("inflateInit2() returned (%d).\n", Status));
154  return CS_BADSTREAM;
155  }
156 
157  while ((ZStream.total_out < CAB_BLOCKSIZE + 12) &&
158  (ZStream.total_in < InputLength - 2))
159  {
161  if (Status == Z_STREAM_END) break;
162  if (Status != Z_OK)
163  {
164  DPRINT(MIN_TRACE, ("inflate() returned (%d) (%s).\n", Status, ZStream.msg));
165  if (Status == Z_MEM_ERROR)
166  return CS_NOMEMORY;
167  return CS_BADSTREAM;
168  }
169  }
170 
171  *OutputLength = ZStream.total_out;
172 
174  if (Status != Z_OK)
175  {
176  DPRINT(MIN_TRACE, ("inflateEnd() returned (%d).\n", Status));
177  return CS_BADSTREAM;
178  }
179  return CS_SUCCESS;
180 }
#define MID_TRACE
Definition: debug.h:15
int ZEXPORT inflateEnd(z_streamp strm)
Definition: inflate.c:1277
uInt avail_in
Definition: zlib.h:88
z_stream ZStream
Definition: mszip.h:37
CHAR InputBuffer[80]
Definition: conmgr.c:33
#define Z_STREAM_END
Definition: zlib.h:178
#define CS_BADSTREAM
Definition: cabinet.h:43
#define Z_OK
Definition: zlib.h:177
void DPRINT(...)
Definition: polytest.cpp:61
#define MSZIP_MAGIC
Definition: cabinet.c:212
_Must_inspect_result_ __drv_aliasesMem _In_ PDEVICE_OBJECT _In_opt_ PVOID _In_ ULONG _Out_opt_ PVOID OutputBuffer
Definition: iofuncs.h:713
#define CAB_BLOCKSIZE
Definition: cabinet.c:49
z_const char * msg
Definition: zlib.h:95
uLong total_in
Definition: zlib.h:89
#define inflateInit2(strm, windowBits)
Definition: zlib.h:1800
#define Z_NO_FLUSH
Definition: zlib.h:168
int ZEXPORT inflate(z_streamp strm, int flush)
Definition: inflate.c:622
Status
Definition: gdiplustypes.h:24
uLong total_out
Definition: zlib.h:93
#define CS_NOMEMORY
Definition: cabinet.h:42
#define MAX_TRACE
Definition: debug.h:16
unsigned short USHORT
Definition: pedump.c:61
unsigned int UINT
Definition: ndis.h:50
uInt avail_out
Definition: zlib.h:92
z_const Bytef * next_in
Definition: zlib.h:87
#define MIN_TRACE
Definition: debug.h:14
#define CS_SUCCESS
Definition: cabinet.h:41
Bytef * next_out
Definition: zlib.h:91
#define MAX_WBITS
Definition: zconf.h:270
unsigned short * PUSHORT
Definition: retypes.h:2
#define Z_MEM_ERROR
Definition: zlib.h:183

Member Data Documentation

◆ Status

int CMSZipCodec::Status
private

Definition at line 36 of file mszip.h.

◆ ZStream

z_stream CMSZipCodec::ZStream
private

Definition at line 37 of file mszip.h.

Referenced by CMSZipCodec(), Compress(), and Uncompress().


The documentation for this class was generated from the following files: