Mercurial > libpst
comparison src/lzfu.c @ 79:56fa05fd5271
Patch from Robert Simpson for encryption type 2.
Fix the order of testing item types to avoid claiming there are multiple message stores.
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Fri, 13 Jun 2008 20:47:01 -0700 |
parents | 535075b4d261 |
children | 582e927756d3 |
comparison
equal
deleted
inserted
replaced
78:535075b4d261 | 79:56fa05fd5271 |
---|---|
38 uint32_t dwMagic; | 38 uint32_t dwMagic; |
39 uint32_t dwCRC; | 39 uint32_t dwCRC; |
40 } lzfuheader; | 40 } lzfuheader; |
41 | 41 |
42 | 42 |
43 char* lzfu_decompress (char* rtfcomp, uint32_t compsize, size_t *size) { | 43 char* lzfu_decompress(char* rtfcomp, uint32_t compsize, size_t *size) { |
44 // the dictionary buffer | 44 unsigned char dict[4096]; // the dictionary buffer |
45 unsigned char dict[4096]; | 45 unsigned int dict_length = 0; // the dictionary pointer |
46 // the dictionary pointer | 46 lzfuheader lzfuhdr; // the header of the lzfu block |
47 unsigned int dict_length=0; | 47 unsigned char flags; // 8 bits of flags (1=2byte block pointer into the dict, 0=1 byte literal) |
48 // the header of the lzfu block | 48 unsigned char flag_mask; // look at one flag bit each time thru the loop |
49 lzfuheader lzfuhdr; | |
50 // container for the data blocks | |
51 unsigned char flags; | |
52 // temp value for determining the bits in the flag | |
53 unsigned char flag_mask; | |
54 uint32_t i; | 49 uint32_t i; |
55 char *out_buf; | 50 char *out_buf; |
56 uint32_t out_ptr = 0; | 51 uint32_t out_ptr = 0; |
57 uint32_t out_size; | 52 uint32_t out_size; |
58 uint32_t in_ptr; | 53 uint32_t in_ptr; |
59 uint32_t in_size; | 54 uint32_t in_size; |
60 | 55 |
61 memcpy(dict, LZFU_INITDICT, LZFU_INITLENGTH); | 56 memcpy(dict, LZFU_INITDICT, LZFU_INITLENGTH); |
57 memset(dict + LZFU_INITLENGTH, 0, sizeof(dict) - LZFU_INITLENGTH); | |
62 dict_length = LZFU_INITLENGTH; | 58 dict_length = LZFU_INITLENGTH; |
59 | |
63 memcpy(&lzfuhdr, rtfcomp, sizeof(lzfuhdr)); | 60 memcpy(&lzfuhdr, rtfcomp, sizeof(lzfuhdr)); |
64 LE32_CPU(lzfuhdr.cbSize); | 61 LE32_CPU(lzfuhdr.cbSize); |
65 LE32_CPU(lzfuhdr.cbRawSize); | 62 LE32_CPU(lzfuhdr.cbRawSize); |
66 LE32_CPU(lzfuhdr.dwMagic); | 63 LE32_CPU(lzfuhdr.dwMagic); |
67 LE32_CPU(lzfuhdr.dwCRC); | 64 LE32_CPU(lzfuhdr.dwCRC); |
97 length = (blkhdr&0x000F)+2; | 94 length = (blkhdr&0x000F)+2; |
98 // add the value we are about to print to the dictionary | 95 // add the value we are about to print to the dictionary |
99 for (i=0; i < length; i++) { | 96 for (i=0; i < length; i++) { |
100 unsigned char c1; | 97 unsigned char c1; |
101 c1 = dict[(offset+i)%4096]; | 98 c1 = dict[(offset+i)%4096]; |
102 dict[dict_length]=c1; | 99 dict[dict_length] = c1; |
103 dict_length = (dict_length+1) % 4096; | 100 dict_length = (dict_length+1) % 4096; |
104 if (out_ptr < out_size) out_buf[out_ptr++] = (char)c1; | 101 if (out_ptr < out_size) out_buf[out_ptr++] = (char)c1; |
105 // required for dictionary wrap around | 102 // required for dictionary wrap around |
106 // otherwise 0 byte values are referenced incorrectly | 103 // otherwise 0 byte values are referenced incorrectly |
107 dict[dict_length] = 0; | 104 dict[dict_length] = 0; |