29FILE_RCSID(
"@(#)$File: readcdf.c,v 1.80 2023/01/24 20:13:40 christos Exp $")
44#define NOTMIME(ms) (((ms)->flags & MAGIC_MIME) == 0)
46static const struct nv {
50 {
"Word",
"msword", },
51 {
"Excel",
"vnd.ms-excel", },
52 {
"Powerpoint",
"vnd.ms-powerpoint", },
53 {
"Crystal Reports",
"x-rpt", },
54 {
"Advanced Installer",
"vnd.ms-msi", },
55 {
"InstallShield",
"vnd.ms-msi", },
56 {
"Microsoft Patch Compiler",
"vnd.ms-msi", },
57 {
"NAnt",
"vnd.ms-msi", },
58 {
"Windows Installer",
"vnd.ms-msi", },
61 {
"Book",
"vnd.ms-excel", },
62 {
"Workbook",
"vnd.ms-excel", },
63 {
"WordDocument",
"msword", },
64 {
"PowerPoint",
"vnd.ms-powerpoint", },
65 {
"DigitalSignature",
"vnd.ms-msi", },
68 {
"Book",
"Microsoft Excel", },
69 {
"Workbook",
"Microsoft Excel", },
70 {
"WordDocument",
"Microsoft Word", },
71 {
"PowerPoint",
"Microsoft PowerPoint", },
72 {
"DigitalSignature",
"Microsoft Installer", },
76static const struct cv {
81 { 0x00000000000c1084ULL, 0x46000000000000c0ULL },
89 { 0x00000000000c1084ULL, 0x46000000000000c0ULL },
101 for (i = 0; cv[i].mime !=
NULL; i++) {
102 if (clsid[0] == cv[i].clsid[0] && clsid[1] == cv[i].clsid[1])
116 for (i = 0; nv[i].pattern !=
NULL; i++) {
121 found = (
strstr(vbuf_lower, pattern_lower) !=
NULL);
122 efree(pattern_lower);
142 const char *str =
NULL;
146 memset(&ts, 0,
sizeof(ts));
148 if (!
NOTMIME(ms) && root_storage)
152 for (i = 0; i <
count; i++) {
154 switch (info[i].pi_type) {
193 for (
j = 0;
s < e &&
j <
sizeof(vbuf)
197 if (isprint(
CAST(
unsigned char, *
s)))
200 if (
j ==
sizeof(vbuf))
209 }
else if (str ==
NULL && info[i].pi_id ==
219 if (tp < 1000000000000000LL) {
223 ", %s: %s",
buf, tbuf) == -1)
234 ", %s: %s",
buf, c) == -1)
264 if (
file_printf(ms,
"Microsoft Thumbs.db [") == -1)
270 for (i = 1; i < cat->
cat_num; i++)
273 i == cat->
cat_num - 1 ?
"]" :
", ") == -1) {
300 if (
file_printf(ms,
"Composite Document File V2 Document")
309 if (
file_printf(ms,
", Os: Windows, Version %d.%d",
340 return m == -1 ? -2 : m;
345format_clsid(
char *
buf,
size_t len,
const uint64_t uuid[2]) {
346 snprintf(
buf,
len,
"%.8" PRIx64
"-%.4" PRIx64
"-%.4" PRIx64
"-%.4"
347 PRIx64
"-%.12" PRIx64,
348 (uuid[0] >> 32) & (uint64_t)0x000000000ffffffffULL,
349 (uuid[0] >> 16) & (uint64_t)0x0000000000000ffffULL,
350 (uuid[0] >> 0) & (uint64_t)0x0000000000000ffffULL,
351 (uuid[1] >> 48) & (uint64_t)0x0000000000000ffffULL,
352 (uuid[1] >> 0) & (uint64_t)0x0000fffffffffffffULL);
365 dir,
"Catalog", scn)) == -1)
368 cdf_dump_catalog(h, scn);
382 const char *str =
NULL;
388 cdf_dump_summary_info(h, scn);
391 *expn =
"Can't expand summary_info";
396 for (
j = 0; str ==
NULL &&
j <
dir->dir_len;
j++) {
397 d = &
dir->dir_tab[
j];
398 for (k = 0; k <
sizeof(
name); k++)
401 NOTMIME(ms) ? name2desc : name2mime);
411 str =
"vnd.ms-office";
429 {
"Encrypted",
"encrypted",
431 "EncryptedPackage",
"EncryptedSummary",
441 {
"QuickBooks",
"quickbooks",
444 "TaxForms",
"PDFTaxForms",
"modulesInBackup",
458 {
"Microsoft Excel",
"vnd.ms-excel",
468 {
"Microsoft Word",
"msword",
477 {
"Microsoft PowerPoint",
"vnd.ms-powerpoint",
486 {
"Microsoft Outlook Message",
"vnd.ms-outlook",
488 "__properties_version1.0",
489 "__recip_version1.0_#00000000",
533 const unsigned char *
buf =
CAST(
const unsigned char *, b->
fbuf);
534 size_t nbytes = b->
flen;
541 const char *expn =
"";
557 expn =
"Can't read SAT";
565 expn =
"Can't read SSAT";
573 expn =
"Can't read directory";
578 &root_storage)) == -1) {
579 expn =
"Cannot read short stream";
583 cdf_dump_dir(&info, &h, &sat, &ssat, &sst, &
dir);
590 format_clsid(clsbuf,
sizeof(clsbuf),
598 "FileHeader", &scn) != -1) {
599#define HWP5_SIGNATURE "HWP Document File"
605 "Hancom HWP (Hangul Word Processor) file, version 5.0") == -1)
620 if (
errno != ESRCH) {
621 expn =
"Cannot read summary info";
625 &sat, &ssat, &sst, &
dir, &scn, root_storage, &expn);
630 &sst, &
dir, &scn)) == -1) {
631 if (
errno != ESRCH) {
632 expn =
"Cannot read summary info";
636 &sst, &
dir, &scn, root_storage, &expn);
642 expn =
"Cannot read section info";
660 "Composite Document File V2 Document") == -1)
667 if (
file_printf(ms,
"application/x-ole-storage") == -1)
fprintf($stream, string $format, mixed ... $values)
dir(string $directory, $context=null)
count(Countable|array $value, int $mode=COUNT_NORMAL)
strstr(string $haystack, string $needle, bool $before_needle=false)
strchr(string $haystack, string $needle, bool $before_needle=false)
int cdf_print_property_name(char *buf, size_t bufsiz, uint32_t p)
int cdf_zero_stream(cdf_stream_t *scn)
int cdf_unpack_catalog(const cdf_header_t *h, const cdf_stream_t *sst, cdf_catalog_t **cat)
char * cdf_u16tos8(char *buf, size_t len, const uint16_t *p)
int cdf_read_summary_info(const cdf_info_t *info, const cdf_header_t *h, const cdf_sat_t *sat, const cdf_sat_t *ssat, const cdf_stream_t *sst, const cdf_dir_t *dir, cdf_stream_t *scn)
int cdf_read_doc_summary_info(const cdf_info_t *info, const cdf_header_t *h, const cdf_sat_t *sat, const cdf_sat_t *ssat, const cdf_stream_t *sst, const cdf_dir_t *dir, cdf_stream_t *scn)
int cdf_find_stream(const cdf_dir_t *dir, const char *name, int type)
int cdf_read_dir(const cdf_info_t *info, const cdf_header_t *h, const cdf_sat_t *sat, cdf_dir_t *dir)
int cdf_read_short_stream(const cdf_info_t *info, const cdf_header_t *h, const cdf_sat_t *sat, const cdf_dir_t *dir, cdf_stream_t *scn, const cdf_directory_t **root)
int cdf_read_user_stream(const cdf_info_t *info, const cdf_header_t *h, const cdf_sat_t *sat, const cdf_sat_t *ssat, const cdf_stream_t *sst, const cdf_dir_t *dir, const char *name, cdf_stream_t *scn)
int cdf_read_ssat(const cdf_info_t *info, const cdf_header_t *h, const cdf_sat_t *sat, cdf_sat_t *ssat)
int cdf_unpack_summary_info(const cdf_stream_t *sst, const cdf_header_t *h, cdf_summary_info_header_t *ssi, cdf_property_info_t **info, size_t *count)
int cdf_print_elapsed_time(char *buf, size_t bufsiz, cdf_timestamp_t ts)
int cdf_read_header(const cdf_info_t *info, cdf_header_t *h)
uint16_t cdf_tole2(uint16_t sv)
int cdf_read_sat(const cdf_info_t *info, cdf_header_t *h, cdf_sat_t *sat)
#define CDF_DIR_TYPE_USER_STREAM
int cdf_timestamp_to_timespec(struct timespec *, cdf_timestamp_t)
#define CDF_DIR_TYPE_USER_STORAGE
#define CDF_PROPERTY_NAME_OF_APPLICATION
#define CDF_LENGTH32_STRING
char * cdf_ctime(const time_t *, char *)
#define CDF_SHORT_SEC_SIZE(h)
#define CDF_LENGTH32_WSTRING
memset(ptr, 0, type->size)
zend_ffi_ctype_name_buf buf
file_protected int file_printf(struct magic_set *, const char *,...) __attribute__((__format__(__printf__
file_private int cdf_file_summary_info(struct magic_set *ms, const cdf_header_t *h, const cdf_stream_t *sst, const cdf_directory_t *root_storage)
file_protected int file_trycdf(struct magic_set *ms, const struct buffer *b)
file_private int cdf_file_catalog(struct magic_set *ms, const cdf_header_t *h, const cdf_stream_t *sst)
file_private int cdf_check_summary_info(struct magic_set *ms, const cdf_info_t *info, const cdf_header_t *h, const cdf_sat_t *sat, const cdf_sat_t *ssat, const cdf_stream_t *sst, const cdf_dir_t *dir, cdf_stream_t *scn, const cdf_directory_t *root_storage, const char **expn)
file_private const char * cdf_app_to_mime(const char *vbuf, const struct nv *nv)
file_private struct sinfo sectioninfo[]
file_private int cdf_file_dir_info(struct magic_set *ms, const cdf_dir_t *dir)
file_private const char * cdf_clsid_to_mime(const uint64_t clsid[2], const struct cv *cv)
file_private int cdf_file_catalog_info(struct magic_set *ms, const cdf_info_t *info, const cdf_header_t *h, const cdf_sat_t *sat, const cdf_sat_t *ssat, const cdf_stream_t *sst, const cdf_dir_t *dir, cdf_stream_t *scn)
file_private int cdf_file_property_info(struct magic_set *ms, const cdf_property_info_t *info, size_t count, const cdf_directory_t *root_storage)
cdf_catalog_entry_t cat_e[1]
uint64_t d_storage_uuid[2]
const unsigned char * i_buf
ZEND_API char *ZEND_FASTCALL zend_str_tolower_dup(const char *source, size_t length)