Deleted Added
full compact
cdf.h (192348) cdf.h (226048)
1/*-
2 * Copyright (c) 2008 Christos Zoulas
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 10 unchanged lines hidden (view full) ---

19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 * POSSIBILITY OF SUCH DAMAGE.
25 */
26/*
1/*-
2 * Copyright (c) 2008 Christos Zoulas
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 10 unchanged lines hidden (view full) ---

19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 * POSSIBILITY OF SUCH DAMAGE.
25 */
26/*
27 * Info from: http://sc.openoffice.org/compdocfileformat.pdf
27 * Parse Composite Document Files, the format used in Microsoft Office
28 * document files before they switched to zipped XML.
29 * Info from: http://sc.openoffice.org/compdocfileformat.pdf
30 *
31 * N.B. This is the "Composite Document File" format, and not the
32 * "Compound Document Format", nor the "Channel Definition Format".
28 */
29
30#ifndef _H_CDF_
31#define _H_CDF_
32
33 */
34
35#ifndef _H_CDF_
36#define _H_CDF_
37
38#ifdef WIN32
39#include <winsock2.h>
40#define timespec timeval
41#define tv_nsec tv_usec
42#endif
43#ifdef __DJGPP__
44#define timespec timeval
45#define tv_nsec tv_usec
46#endif
47
33typedef int32_t cdf_secid_t;
34
35#define CDF_LOOP_LIMIT 10000
36
37#define CDF_SECID_NULL 0
38#define CDF_SECID_FREE -1
39#define CDF_SECID_END_OF_CHAIN -2
40#define CDF_SECID_SECTOR_ALLOCATION_TABLE -3
41#define CDF_SECID_MASTER_SECTOR_ALLOCATION_TABLE -4
42
43typedef struct {
48typedef int32_t cdf_secid_t;
49
50#define CDF_LOOP_LIMIT 10000
51
52#define CDF_SECID_NULL 0
53#define CDF_SECID_FREE -1
54#define CDF_SECID_END_OF_CHAIN -2
55#define CDF_SECID_SECTOR_ALLOCATION_TABLE -3
56#define CDF_SECID_MASTER_SECTOR_ALLOCATION_TABLE -4
57
58typedef struct {
44 uint64_t h_magic;
59 uint64_t h_magic;
45#define CDF_MAGIC 0xE11AB1A1E011CFD0LL
60#define CDF_MAGIC 0xE11AB1A1E011CFD0LL
46 uint64_t h_uuid[2];
47 uint16_t h_revision;
48 uint16_t h_version;
49 uint16_t h_byte_order;
50 uint16_t h_sec_size_p2;
51 uint16_t h_short_sec_size_p2;
52 uint8_t h_unused0[10];
53 uint32_t h_num_sectors_in_sat;
54 uint32_t h_secid_first_directory;
55 uint8_t h_unused1[4];
56 uint32_t h_min_size_standard_stream;
57 cdf_secid_t h_secid_first_sector_in_short_sat;
58 uint32_t h_num_sectors_in_short_sat;
59 cdf_secid_t h_secid_first_sector_in_master_sat;
60 uint32_t h_num_sectors_in_master_sat;
61 cdf_secid_t h_master_sat[436/4];
61 uint64_t h_uuid[2];
62 uint16_t h_revision;
63 uint16_t h_version;
64 uint16_t h_byte_order;
65 uint16_t h_sec_size_p2;
66 uint16_t h_short_sec_size_p2;
67 uint8_t h_unused0[10];
68 uint32_t h_num_sectors_in_sat;
69 uint32_t h_secid_first_directory;
70 uint8_t h_unused1[4];
71 uint32_t h_min_size_standard_stream;
72 cdf_secid_t h_secid_first_sector_in_short_sat;
73 uint32_t h_num_sectors_in_short_sat;
74 cdf_secid_t h_secid_first_sector_in_master_sat;
75 uint32_t h_num_sectors_in_master_sat;
76 cdf_secid_t h_master_sat[436/4];
62} cdf_header_t;
63
64#define CDF_SEC_SIZE(h) (1 << (h)->h_sec_size_p2)
65#define CDF_SEC_POS(h, secid) (CDF_SEC_SIZE(h) + (secid) * CDF_SEC_SIZE(h))
66#define CDF_SHORT_SEC_SIZE(h) (1 << (h)->h_short_sec_size_p2)
67#define CDF_SHORT_SEC_POS(h, secid) ((secid) * CDF_SHORT_SEC_SIZE(h))
68
69typedef int32_t cdf_dirid_t;
70#define CDF_DIRID_NULL -1
71
72typedef int64_t cdf_timestamp_t;
73#define CDF_BASE_YEAR 1601
74#define CDF_TIME_PREC 10000000
75
76typedef struct {
77} cdf_header_t;
78
79#define CDF_SEC_SIZE(h) (1 << (h)->h_sec_size_p2)
80#define CDF_SEC_POS(h, secid) (CDF_SEC_SIZE(h) + (secid) * CDF_SEC_SIZE(h))
81#define CDF_SHORT_SEC_SIZE(h) (1 << (h)->h_short_sec_size_p2)
82#define CDF_SHORT_SEC_POS(h, secid) ((secid) * CDF_SHORT_SEC_SIZE(h))
83
84typedef int32_t cdf_dirid_t;
85#define CDF_DIRID_NULL -1
86
87typedef int64_t cdf_timestamp_t;
88#define CDF_BASE_YEAR 1601
89#define CDF_TIME_PREC 10000000
90
91typedef struct {
77 uint16_t d_name[32];
78 uint16_t d_namelen;
79 uint8_t d_type;
92 uint16_t d_name[32];
93 uint16_t d_namelen;
94 uint8_t d_type;
80#define CDF_DIR_TYPE_EMPTY 0
81#define CDF_DIR_TYPE_USER_STORAGE 1
82#define CDF_DIR_TYPE_USER_STREAM 2
83#define CDF_DIR_TYPE_LOCKBYTES 3
84#define CDF_DIR_TYPE_PROPERTY 4
85#define CDF_DIR_TYPE_ROOT_STORAGE 5
95#define CDF_DIR_TYPE_EMPTY 0
96#define CDF_DIR_TYPE_USER_STORAGE 1
97#define CDF_DIR_TYPE_USER_STREAM 2
98#define CDF_DIR_TYPE_LOCKBYTES 3
99#define CDF_DIR_TYPE_PROPERTY 4
100#define CDF_DIR_TYPE_ROOT_STORAGE 5
86 uint8_t d_color;
101 uint8_t d_color;
87#define CDF_DIR_COLOR_READ 0
88#define CDF_DIR_COLOR_BLACK 1
102#define CDF_DIR_COLOR_READ 0
103#define CDF_DIR_COLOR_BLACK 1
89 cdf_dirid_t d_left_child;
90 cdf_dirid_t d_right_child;
91 cdf_dirid_t d_storage;
92 uint64_t d_storage_uuid[2];
93 uint32_t d_flags;
94 cdf_timestamp_t d_created;
95 cdf_timestamp_t d_modified;
96 cdf_secid_t d_stream_first_sector;
97 uint32_t d_size;
98 uint32_t d_unused0;
104 cdf_dirid_t d_left_child;
105 cdf_dirid_t d_right_child;
106 cdf_dirid_t d_storage;
107 uint64_t d_storage_uuid[2];
108 uint32_t d_flags;
109 cdf_timestamp_t d_created;
110 cdf_timestamp_t d_modified;
111 cdf_secid_t d_stream_first_sector;
112 uint32_t d_size;
113 uint32_t d_unused0;
99} cdf_directory_t;
100
101#define CDF_DIRECTORY_SIZE 128
102
103typedef struct {
114} cdf_directory_t;
115
116#define CDF_DIRECTORY_SIZE 128
117
118typedef struct {
104 cdf_secid_t *sat_tab;
105 size_t sat_len;
119 cdf_secid_t *sat_tab;
120 size_t sat_len;
106} cdf_sat_t;
107
108typedef struct {
121} cdf_sat_t;
122
123typedef struct {
109 cdf_directory_t *dir_tab;
110 size_t dir_len;
124 cdf_directory_t *dir_tab;
125 size_t dir_len;
111} cdf_dir_t;
112
113typedef struct {
126} cdf_dir_t;
127
128typedef struct {
114 void *sst_tab;
115 size_t sst_len;
116 size_t sst_dirlen;
129 void *sst_tab;
130 size_t sst_len;
131 size_t sst_dirlen;
117} cdf_stream_t;
118
119typedef struct {
132} cdf_stream_t;
133
134typedef struct {
120 uint32_t cl_dword;
121 uint16_t cl_word[2];
122 uint8_t cl_two[2];
123 uint8_t cl_six[6];
135 uint32_t cl_dword;
136 uint16_t cl_word[2];
137 uint8_t cl_two[2];
138 uint8_t cl_six[6];
124} cdf_classid_t;
125
126typedef struct {
139} cdf_classid_t;
140
141typedef struct {
127 uint16_t si_byte_order;
128 uint16_t si_zero;
129 uint16_t si_os_version;
130 uint16_t si_os;
131 cdf_classid_t si_class;
132 uint32_t si_count;
142 uint16_t si_byte_order;
143 uint16_t si_zero;
144 uint16_t si_os_version;
145 uint16_t si_os;
146 cdf_classid_t si_class;
147 uint32_t si_count;
133} cdf_summary_info_header_t;
134
135#define CDF_SECTION_DECLARATION_OFFSET 0x1c
136
137typedef struct {
148} cdf_summary_info_header_t;
149
150#define CDF_SECTION_DECLARATION_OFFSET 0x1c
151
152typedef struct {
138 cdf_classid_t sd_class;
139 uint32_t sd_offset;
153 cdf_classid_t sd_class;
154 uint32_t sd_offset;
140} cdf_section_declaration_t;
141
142typedef struct {
155} cdf_section_declaration_t;
156
157typedef struct {
143 uint32_t sh_len;
144 uint32_t sh_properties;
158 uint32_t sh_len;
159 uint32_t sh_properties;
145} cdf_section_header_t;
146
147typedef struct {
160} cdf_section_header_t;
161
162typedef struct {
148 uint32_t pi_id;
149 uint32_t pi_type;
150 union {
151 uint16_t _pi_u16;
152 int16_t _pi_s16;
153 uint32_t _pi_u32;
154 int32_t _pi_s32;
155 uint64_t _pi_u64;
156 int64_t _pi_s64;
157 cdf_timestamp_t _pi_tp;
158 struct {
159 uint32_t s_len;
160 const char *s_buf;
161 } _pi_str;
162 } pi_val;
163 uint32_t pi_id;
164 uint32_t pi_type;
165 union {
166 uint16_t _pi_u16;
167 int16_t _pi_s16;
168 uint32_t _pi_u32;
169 int32_t _pi_s32;
170 uint64_t _pi_u64;
171 int64_t _pi_s64;
172 cdf_timestamp_t _pi_tp;
173 struct {
174 uint32_t s_len;
175 const char *s_buf;
176 } _pi_str;
177 } pi_val;
163#define pi_u64 pi_val._pi_u64
164#define pi_s64 pi_val._pi_s64
165#define pi_u32 pi_val._pi_u32
166#define pi_s32 pi_val._pi_s32
167#define pi_u16 pi_val._pi_u16
168#define pi_s16 pi_val._pi_s16
169#define pi_tp pi_val._pi_tp
170#define pi_str pi_val._pi_str

--- 50 unchanged lines hidden (view full) ---

221#define CDF_ILLEGALMASKED 0x00000fff
222#define CDF_TYPEMASK 0x00000fff
223
224#define CDF_PROPERTY_CODE_PAGE 0x00000001
225#define CDF_PROPERTY_TITLE 0x00000002
226#define CDF_PROPERTY_SUBJECT 0x00000003
227#define CDF_PROPERTY_AUTHOR 0x00000004
228#define CDF_PROPERTY_KEYWORDS 0x00000005
178#define pi_u64 pi_val._pi_u64
179#define pi_s64 pi_val._pi_s64
180#define pi_u32 pi_val._pi_u32
181#define pi_s32 pi_val._pi_s32
182#define pi_u16 pi_val._pi_u16
183#define pi_s16 pi_val._pi_s16
184#define pi_tp pi_val._pi_tp
185#define pi_str pi_val._pi_str

--- 50 unchanged lines hidden (view full) ---

236#define CDF_ILLEGALMASKED 0x00000fff
237#define CDF_TYPEMASK 0x00000fff
238
239#define CDF_PROPERTY_CODE_PAGE 0x00000001
240#define CDF_PROPERTY_TITLE 0x00000002
241#define CDF_PROPERTY_SUBJECT 0x00000003
242#define CDF_PROPERTY_AUTHOR 0x00000004
243#define CDF_PROPERTY_KEYWORDS 0x00000005
229#define CDF_PROPERTY_COMMENTS 0x00000006
244#define CDF_PROPERTY_COMMENTS 0x00000006
230#define CDF_PROPERTY_TEMPLATE 0x00000007
231#define CDF_PROPERTY_LAST_SAVED_BY 0x00000008
232#define CDF_PROPERTY_REVISION_NUMBER 0x00000009
233#define CDF_PROPERTY_TOTAL_EDITING_TIME 0x0000000a
234#define CDF_PROPERTY_LAST_PRINTED 0X0000000b
235#define CDF_PROPERTY_CREATE_TIME 0x0000000c
236#define CDF_PROPERTY_LAST_SAVED_TIME 0x0000000d
237#define CDF_PROPERTY_NUMBER_OF_PAGES 0x0000000e
238#define CDF_PROPERTY_NUMBER_OF_WORDS 0x0000000f
239#define CDF_PROPERTY_NUMBER_OF_CHARACTERS 0x00000010
240#define CDF_PROPERTY_THUMBNAIL 0x00000011
241#define CDF_PROPERTY_NAME_OF_APPLICATION 0x00000012
242#define CDF_PROPERTY_SECURITY 0x00000013
243#define CDF_PROPERTY_LOCALE_ID 0x80000000
244
245typedef struct {
245#define CDF_PROPERTY_TEMPLATE 0x00000007
246#define CDF_PROPERTY_LAST_SAVED_BY 0x00000008
247#define CDF_PROPERTY_REVISION_NUMBER 0x00000009
248#define CDF_PROPERTY_TOTAL_EDITING_TIME 0x0000000a
249#define CDF_PROPERTY_LAST_PRINTED 0X0000000b
250#define CDF_PROPERTY_CREATE_TIME 0x0000000c
251#define CDF_PROPERTY_LAST_SAVED_TIME 0x0000000d
252#define CDF_PROPERTY_NUMBER_OF_PAGES 0x0000000e
253#define CDF_PROPERTY_NUMBER_OF_WORDS 0x0000000f
254#define CDF_PROPERTY_NUMBER_OF_CHARACTERS 0x00000010
255#define CDF_PROPERTY_THUMBNAIL 0x00000011
256#define CDF_PROPERTY_NAME_OF_APPLICATION 0x00000012
257#define CDF_PROPERTY_SECURITY 0x00000013
258#define CDF_PROPERTY_LOCALE_ID 0x80000000
259
260typedef struct {
246 int i_fd;
247 const unsigned char *i_buf;
248 size_t i_len;
261 int i_fd;
262 const unsigned char *i_buf;
263 size_t i_len;
249} cdf_info_t;
250
251struct timespec;
252int cdf_timestamp_to_timespec(struct timespec *, cdf_timestamp_t);
253int cdf_timespec_to_timestamp(cdf_timestamp_t *, const struct timespec *);
254int cdf_read_header(const cdf_info_t *, cdf_header_t *);
255void cdf_swap_header(cdf_header_t *);
256void cdf_unpack_header(cdf_header_t *, char *);

--- 14 unchanged lines hidden (view full) ---

271 const cdf_sat_t *, const cdf_sat_t *, const cdf_stream_t *, cdf_secid_t,
272 size_t, cdf_stream_t *);
273int cdf_read_dir(const cdf_info_t *, const cdf_header_t *, const cdf_sat_t *,
274 cdf_dir_t *);
275int cdf_read_ssat(const cdf_info_t *, const cdf_header_t *, const cdf_sat_t *,
276 cdf_sat_t *);
277int cdf_read_short_stream(const cdf_info_t *, const cdf_header_t *,
278 const cdf_sat_t *, const cdf_dir_t *, cdf_stream_t *);
264} cdf_info_t;
265
266struct timespec;
267int cdf_timestamp_to_timespec(struct timespec *, cdf_timestamp_t);
268int cdf_timespec_to_timestamp(cdf_timestamp_t *, const struct timespec *);
269int cdf_read_header(const cdf_info_t *, cdf_header_t *);
270void cdf_swap_header(cdf_header_t *);
271void cdf_unpack_header(cdf_header_t *, char *);

--- 14 unchanged lines hidden (view full) ---

286 const cdf_sat_t *, const cdf_sat_t *, const cdf_stream_t *, cdf_secid_t,
287 size_t, cdf_stream_t *);
288int cdf_read_dir(const cdf_info_t *, const cdf_header_t *, const cdf_sat_t *,
289 cdf_dir_t *);
290int cdf_read_ssat(const cdf_info_t *, const cdf_header_t *, const cdf_sat_t *,
291 cdf_sat_t *);
292int cdf_read_short_stream(const cdf_info_t *, const cdf_header_t *,
293 const cdf_sat_t *, const cdf_dir_t *, cdf_stream_t *);
279int cdf_read_property_info(const cdf_stream_t *, uint32_t,
294int cdf_read_property_info(const cdf_stream_t *, const cdf_header_t *, uint32_t,
280 cdf_property_info_t **, size_t *, size_t *);
281int cdf_read_summary_info(const cdf_info_t *, const cdf_header_t *,
282 const cdf_sat_t *, const cdf_sat_t *, const cdf_stream_t *,
283 const cdf_dir_t *, cdf_stream_t *);
295 cdf_property_info_t **, size_t *, size_t *);
296int cdf_read_summary_info(const cdf_info_t *, const cdf_header_t *,
297 const cdf_sat_t *, const cdf_sat_t *, const cdf_stream_t *,
298 const cdf_dir_t *, cdf_stream_t *);
284int cdf_unpack_summary_info(const cdf_stream_t *, cdf_summary_info_header_t *,
285 cdf_property_info_t **, size_t *);
299int cdf_unpack_summary_info(const cdf_stream_t *, const cdf_header_t *,
300 cdf_summary_info_header_t *, cdf_property_info_t **, size_t *);
286int cdf_print_classid(char *, size_t, const cdf_classid_t *);
287int cdf_print_property_name(char *, size_t, uint32_t);
288int cdf_print_elapsed_time(char *, size_t, cdf_timestamp_t);
289uint16_t cdf_tole2(uint16_t);
290uint32_t cdf_tole4(uint32_t);
291uint64_t cdf_tole8(uint64_t);
301int cdf_print_classid(char *, size_t, const cdf_classid_t *);
302int cdf_print_property_name(char *, size_t, uint32_t);
303int cdf_print_elapsed_time(char *, size_t, cdf_timestamp_t);
304uint16_t cdf_tole2(uint16_t);
305uint32_t cdf_tole4(uint32_t);
306uint64_t cdf_tole8(uint64_t);
307char *cdf_ctime(const time_t *);
292
293#ifdef CDF_DEBUG
294void cdf_dump_header(const cdf_header_t *);
295void cdf_dump_sat(const char *, const cdf_sat_t *, size_t);
296void cdf_dump(void *, size_t);
297void cdf_dump_stream(const cdf_header_t *, const cdf_stream_t *);
298void cdf_dump_dir(const cdf_info_t *, const cdf_header_t *, const cdf_sat_t *,
299 const cdf_sat_t *, const cdf_stream_t *, const cdf_dir_t *);
300void cdf_dump_property_info(const cdf_property_info_t *, size_t);
301void cdf_dump_summary_info(const cdf_header_t *, const cdf_stream_t *);
302#endif
303
304
305#endif /* _H_CDF_ */
308
309#ifdef CDF_DEBUG
310void cdf_dump_header(const cdf_header_t *);
311void cdf_dump_sat(const char *, const cdf_sat_t *, size_t);
312void cdf_dump(void *, size_t);
313void cdf_dump_stream(const cdf_header_t *, const cdf_stream_t *);
314void cdf_dump_dir(const cdf_info_t *, const cdf_header_t *, const cdf_sat_t *,
315 const cdf_sat_t *, const cdf_stream_t *, const cdf_dir_t *);
316void cdf_dump_property_info(const cdf_property_info_t *, size_t);
317void cdf_dump_summary_info(const cdf_header_t *, const cdf_stream_t *);
318#endif
319
320
321#endif /* _H_CDF_ */