summaryrefslogtreecommitdiffstats
path: root/contrib/file/src/readcdf.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/file/src/readcdf.c')
-rw-r--r--contrib/file/src/readcdf.c95
1 files changed, 72 insertions, 23 deletions
diff --git a/contrib/file/src/readcdf.c b/contrib/file/src/readcdf.c
index 7ced9ea..635a926 100644
--- a/contrib/file/src/readcdf.c
+++ b/contrib/file/src/readcdf.c
@@ -26,7 +26,7 @@
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: readcdf.c,v 1.44 2014/05/14 23:22:48 christos Exp $")
+FILE_RCSID("@(#)$File: readcdf.c,v 1.49 2014/12/04 15:56:46 christos Exp $")
#endif
#include <assert.h>
@@ -35,9 +35,6 @@ FILE_RCSID("@(#)$File: readcdf.c,v 1.44 2014/05/14 23:22:48 christos Exp $")
#include <string.h>
#include <time.h>
#include <ctype.h>
-#if defined(HAVE_LOCALE_H)
-#include <locale.h>
-#endif
#include "cdf.h"
#include "magic.h"
@@ -75,7 +72,7 @@ static const struct cv {
const char *mime;
} clsid2mime[] = {
{
- { 0x00000000000c1084LLU, 0x46000000000000c0LLU },
+ { 0x00000000000c1084ULL, 0x46000000000000c0ULL },
"x-msi",
},
{ { 0, 0 },
@@ -83,7 +80,7 @@ static const struct cv {
},
}, clsid2desc[] = {
{
- { 0x00000000000c1084LLU, 0x46000000000000c0LLU },
+ { 0x00000000000c1084ULL, 0x46000000000000c0ULL },
"MSI Installer",
},
{ { 0, 0 },
@@ -107,20 +104,23 @@ cdf_app_to_mime(const char *vbuf, const struct nv *nv)
{
size_t i;
const char *rv = NULL;
- char *old_lc_ctype;
+#ifdef USE_C_LOCALE
+ locale_t old_lc_ctype, c_lc_ctype;
- old_lc_ctype = setlocale(LC_CTYPE, NULL);
- assert(old_lc_ctype != NULL);
- old_lc_ctype = strdup(old_lc_ctype);
+ c_lc_ctype = newlocale(LC_CTYPE_MASK, "C", 0);
+ assert(c_lc_ctype != NULL);
+ old_lc_ctype = uselocale(c_lc_ctype);
assert(old_lc_ctype != NULL);
- (void)setlocale(LC_CTYPE, "C");
+#endif
for (i = 0; nv[i].pattern != NULL; i++)
if (strcasestr(vbuf, nv[i].pattern) != NULL) {
rv = nv[i].mime;
break;
}
- (void)setlocale(LC_CTYPE, old_lc_ctype);
- free(old_lc_ctype);
+#ifdef USE_C_LOCALE
+ (void)uselocale(old_lc_ctype);
+ freelocale(c_lc_ctype);
+#endif
return rv;
}
@@ -241,6 +241,37 @@ cdf_file_property_info(struct magic_set *ms, const cdf_property_info_t *info,
}
private int
+cdf_file_catalog(struct magic_set *ms, const cdf_header_t *h,
+ const cdf_stream_t *sst)
+{
+ cdf_catalog_t *cat;
+ size_t i;
+ char buf[256];
+ cdf_catalog_entry_t *ce;
+
+ if (NOTMIME(ms)) {
+ if (file_printf(ms, "Microsoft Thumbs.db [") == -1)
+ return -1;
+ if (cdf_unpack_catalog(h, sst, &cat) == -1)
+ return -1;
+ ce = cat->cat_e;
+ /* skip first entry since it has a , or paren */
+ for (i = 1; i < cat->cat_num; i++)
+ if (file_printf(ms, "%s%s",
+ cdf_u16tos8(buf, ce[i].ce_namlen, ce[i].ce_name),
+ i == cat->cat_num - 1 ? "]" : ", ") == -1) {
+ free(cat);
+ return -1;
+ }
+ free(cat);
+ } else {
+ if (file_printf(ms, "application/CDFV2") == -1)
+ return -1;
+ }
+ return 1;
+}
+
+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)
{
@@ -285,11 +316,12 @@ cdf_file_summary_info(struct magic_set *ms, const cdf_header_t *h,
if (root_storage) {
str = cdf_clsid_to_mime(root_storage->d_storage_uuid,
clsid2desc);
- if (str)
+ if (str) {
if (file_printf(ms, ", %s", str) == -1)
return -2;
}
}
+ }
m = cdf_file_property_info(ms, info, count, root_storage);
free(info);
@@ -302,11 +334,11 @@ private char *
format_clsid(char *buf, size_t len, const uint64_t uuid[2]) {
snprintf(buf, len, "%.8" PRIx64 "-%.4" PRIx64 "-%.4" PRIx64 "-%.4"
PRIx64 "-%.12" PRIx64,
- (uuid[0] >> 32) & (uint64_t)0x000000000ffffffffLLU,
- (uuid[0] >> 16) & (uint64_t)0x0000000000000ffffLLU,
- (uuid[0] >> 0) & (uint64_t)0x0000000000000ffffLLU,
- (uuid[1] >> 48) & (uint64_t)0x0000000000000ffffLLU,
- (uuid[1] >> 0) & (uint64_t)0x0000fffffffffffffLLU);
+ (uuid[0] >> 32) & (uint64_t)0x000000000ffffffffULL,
+ (uuid[0] >> 16) & (uint64_t)0x0000000000000ffffULL,
+ (uuid[0] >> 0) & (uint64_t)0x0000000000000ffffULL,
+ (uuid[1] >> 48) & (uint64_t)0x0000000000000ffffULL,
+ (uuid[1] >> 0) & (uint64_t)0x0000fffffffffffffULL);
return buf;
}
#endif
@@ -323,6 +355,7 @@ file_trycdf(struct magic_set *ms, int fd, const unsigned char *buf,
int i;
const char *expn = "";
const char *corrupt = "corrupt: ";
+ const cdf_directory_t *root_storage;
info.i_fd = fd;
info.i_buf = buf;
@@ -356,7 +389,6 @@ file_trycdf(struct magic_set *ms, int fd, const unsigned char *buf,
goto out2;
}
- const cdf_directory_t *root_storage;
if ((i = cdf_read_short_stream(&info, &h, &sat, &dir, &sst,
&root_storage)) == -1) {
expn = "Cannot read short stream";
@@ -404,8 +436,24 @@ file_trycdf(struct magic_set *ms, int fd, const unsigned char *buf,
if ((i = cdf_read_summary_info(&info, &h, &sat, &ssat, &sst, &dir,
&scn)) == -1) {
if (errno == ESRCH) {
- corrupt = expn;
- expn = "No summary info";
+ if ((i = cdf_read_catalog(&info, &h, &sat, &ssat, &sst,
+ &dir, &scn)) == -1) {
+ corrupt = expn;
+ if ((i = cdf_read_encrypted_package(&info, &h,
+ &sat, &ssat, &sst, &dir, &scn)) == -1)
+ expn = "No summary info";
+ else {
+ expn = "Encrypted";
+ i = -1;
+ }
+ goto out4;
+ }
+#ifdef CDF_DEBUG
+ cdf_dump_catalog(&h, &scn);
+#endif
+ if ((i = cdf_file_catalog(ms, &h, &scn))
+ < 0)
+ expn = "Can't expand catalog";
} else {
expn = "Cannot read summary info";
}
@@ -464,7 +512,8 @@ out0:
if (file_printf(ms, ", %s%s", corrupt, expn) == -1)
return -1;
} else {
- if (file_printf(ms, "application/CDFV2-corrupt") == -1)
+ if (file_printf(ms, "application/CDFV2-%s",
+ *corrupt ? "corrupt" : "encrypted") == -1)
return -1;
}
i = 1;
OpenPOWER on IntegriCloud