1 /* $NetBSD: readcdf.c,v 1.1.1.1 2009/05/08 16:35:06 christos Exp $ */
4 * Copyright (c) 2008 Christos Zoulas
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
32 FILE_RCSID("@(#)$File: readcdf.c,v 1.18 2009/05/06 20:48:22 christos Exp $")
34 __RCSID("$NetBSD: readcdf.c,v 1.1.1.1 2009/05/08 16:35:06 christos Exp $");
47 #define NOTMIME(ms) (((ms)->flags & MAGIC_MIME) == 0)
50 cdf_file_property_info(struct magic_set
*ms
, const cdf_property_info_t
*info
,
57 const char *str
= "vnd.ms-office";
61 for (i
= 0; i
< count
; i
++) {
62 cdf_print_property_name(buf
, sizeof(buf
), info
[i
].pi_id
);
63 switch (info
[i
].pi_type
) {
65 if (NOTMIME(ms
) && file_printf(ms
, ", %s: %hd", buf
,
66 info
[i
].pi_s16
) == -1)
70 if (NOTMIME(ms
) && file_printf(ms
, ", %s: %d", buf
,
71 info
[i
].pi_s32
) == -1)
75 if (NOTMIME(ms
) && file_printf(ms
, ", %s: %u", buf
,
76 info
[i
].pi_u32
) == -1)
79 case CDF_LENGTH32_STRING
:
80 len
= info
[i
].pi_str
.s_len
;
82 s
= info
[i
].pi_str
.s_buf
;
86 for (j
= 0; j
< sizeof(vbuf
) && len
--;
90 if (isprint((unsigned char)*s
))
93 if (j
== sizeof(vbuf
))
97 if (file_printf(ms
, ", %s: %s",
101 } else if (info
[i
].pi_id
==
102 CDF_PROPERTY_NAME_OF_APPLICATION
) {
103 if (strstr(s
, "Word"))
105 else if (strstr(s
, "Excel"))
106 str
= "vnd.ms-excel";
107 else if (strstr(s
, "Powerpoint"))
108 str
= "vnd.ms-powerpoint";
115 if (tp
< 1000000000000000LL) {
117 cdf_print_elapsed_time(tbuf
,
119 if (NOTMIME(ms
) && file_printf(ms
,
120 ", %s: %s", buf
, tbuf
) == -1)
124 cdf_timestamp_to_timespec(&ts
, tp
);
125 c
= ctime(&ts
.tv_sec
);
126 if ((ec
= strchr(c
, '\n')) != NULL
)
129 if (NOTMIME(ms
) && file_printf(ms
,
130 ", %s: %s", buf
, c
) == -1)
142 if (file_printf(ms
, "application/%s", str
) == -1)
149 cdf_file_summary_info(struct magic_set
*ms
, const cdf_stream_t
*sst
)
151 cdf_summary_info_header_t si
;
152 cdf_property_info_t
*info
;
156 if (cdf_unpack_summary_info(sst
, &si
, &info
, &count
) == -1)
160 if (file_printf(ms
, "CDF V2 Document") == -1)
163 if (file_printf(ms
, ", %s Endian",
164 si
.si_byte_order
== 0xfffe ? "Little" : "Big") == -1)
168 if (file_printf(ms
, ", Os: Windows, Version %d.%d",
169 si
.si_os_version
& 0xff,
170 (uint32_t)si
.si_os_version
>> 8) == -1)
174 if (file_printf(ms
, ", Os: MacOS, Version %d.%d",
175 (uint32_t)si
.si_os_version
>> 8,
176 si
.si_os_version
& 0xff) == -1)
180 if (file_printf(ms
, ", Os %d, Version: %d.%d", si
.si_os
,
181 si
.si_os_version
& 0xff,
182 (uint32_t)si
.si_os_version
>> 8) == -1)
188 m
= cdf_file_property_info(ms
, info
, count
);
195 file_trycdf(struct magic_set
*ms
, int fd
, const unsigned char *buf
,
201 cdf_stream_t sst
, scn
;
204 const char *expn
= "";
209 if (ms
->flags
& MAGIC_APPLE
)
211 if (cdf_read_header(&info
, &h
) == -1)
217 if ((i
= cdf_read_sat(&info
, &h
, &sat
)) == -1) {
218 expn
= "Can't read SAT";
222 cdf_dump_sat("SAT", &sat
, CDF_SEC_SIZE(&h
));
225 if ((i
= cdf_read_ssat(&info
, &h
, &sat
, &ssat
)) == -1) {
226 expn
= "Can't read SSAT";
230 cdf_dump_sat("SSAT", &ssat
, CDF_SHORT_SEC_SIZE(&h
));
233 if ((i
= cdf_read_dir(&info
, &h
, &sat
, &dir
)) == -1) {
234 expn
= "Can't read directory";
238 if ((i
= cdf_read_short_stream(&info
, &h
, &sat
, &dir
, &sst
)) == -1) {
239 expn
= "Cannot read short stream";
243 cdf_dump_dir(&info
, &h
, &sat
, &ssat
, &sst
, &dir
);
246 if ((i
= cdf_read_summary_info(&info
, &h
, &sat
, &ssat
, &sst
, &dir
,
248 expn
= "Cannot read summary info";
252 cdf_dump_summary_info(&h
, &scn
);
254 if ((i
= cdf_file_summary_info(ms
, &scn
)) == -1)
255 expn
= "Can't expand summary_info";
267 if (file_printf(ms
, "CDF V2 Document") == -1)
270 if (file_printf(ms
, ", corrupt: %s", expn
) == -1)