]> granicus.if.org Git - file/commitdiff
PR/135: Use a different heuristic to recognize a word document if it missing
authorChristos Zoulas <christos@zoulas.com>
Fri, 26 Aug 2011 13:38:28 +0000 (13:38 +0000)
committerChristos Zoulas <christos@zoulas.com>
Fri, 26 Aug 2011 13:38:28 +0000 (13:38 +0000)
the application name in the properties.

src/cdf.c
src/readcdf.c

index eac4480771b77c7303649908184cf52c212d933f..345951d3f83ffe54fbdbec8e80043573533f74a9 100644 (file)
--- a/src/cdf.c
+++ b/src/cdf.c
@@ -35,7 +35,7 @@
 #include "file.h"
 
 #ifndef lint
-FILE_RCSID("@(#)$File: cdf.c,v 1.42 2011/02/10 21:35:05 christos Exp $")
+FILE_RCSID("@(#)$File: cdf.c,v 1.43 2011/03/30 19:48:13 christos Exp $")
 #endif
 
 #include <assert.h>
@@ -74,28 +74,16 @@ static union {
 
 #define NEED_SWAP      (cdf_bo.u == (uint32_t)0x01020304)
 
-#define CDF_TOLE8(x)   ((uint64_t)(NEED_SWAP ? cdf_tole8(x) : (uint64_t)(x)))
-#define CDF_TOLE4(x)   ((uint32_t)(NEED_SWAP ? cdf_tole4(x) : (uint32_t)(x)))
-#define CDF_TOLE2(x)   ((uint16_t)(NEED_SWAP ? cdf_tole2(x) : (uint16_t)(x)))
+#define CDF_TOLE8(x)   ((uint64_t)(NEED_SWAP ? _cdf_tole8(x) : (uint64_t)(x)))
+#define CDF_TOLE4(x)   ((uint32_t)(NEED_SWAP ? _cdf_tole4(x) : (uint32_t)(x)))
+#define CDF_TOLE2(x)   ((uint16_t)(NEED_SWAP ? _cdf_tole2(x) : (uint16_t)(x)))
 #define CDF_GETUINT32(x, y)    cdf_getuint32(x, y)
 
-/*
- * grab a uint32_t from a possibly unaligned address, and return it in
- * the native host order.
- */
-static uint32_t
-cdf_getuint32(const uint8_t *p, size_t offs)
-{
-       uint32_t rv;
-       (void)memcpy(&rv, p + offs * sizeof(uint32_t), sizeof(rv));
-       return CDF_TOLE4(rv);
-}
-
 /*
  * swap a short
  */
-uint16_t
-cdf_tole2(uint16_t sv)
+static uint16_t
+_cdf_tole2(uint16_t sv)
 {
        uint16_t rv;
        uint8_t *s = (uint8_t *)(void *)&sv;
@@ -108,8 +96,8 @@ cdf_tole2(uint16_t sv)
 /*
  * swap an int
  */
-uint32_t
-cdf_tole4(uint32_t sv)
+static uint32_t
+_cdf_tole4(uint32_t sv)
 {
        uint32_t rv;
        uint8_t *s = (uint8_t *)(void *)&sv;
@@ -124,8 +112,8 @@ cdf_tole4(uint32_t sv)
 /*
  * swap a quad
  */
-uint64_t
-cdf_tole8(uint64_t sv)
+static uint64_t
+_cdf_tole8(uint64_t sv)
 {
        uint64_t rv;
        uint8_t *s = (uint8_t *)(void *)&sv;
@@ -141,11 +129,41 @@ cdf_tole8(uint64_t sv)
        return rv;
 }
 
+/*
+ * grab a uint32_t from a possibly unaligned address, and return it in
+ * the native host order.
+ */
+static uint32_t
+cdf_getuint32(const uint8_t *p, size_t offs)
+{
+       uint32_t rv;
+       (void)memcpy(&rv, p + offs * sizeof(uint32_t), sizeof(rv));
+       return CDF_TOLE4(rv);
+}
+
 #define CDF_UNPACK(a)  \
     (void)memcpy(&(a), &buf[len], sizeof(a)), len += sizeof(a)
 #define CDF_UNPACKA(a) \
     (void)memcpy((a), &buf[len], sizeof(a)), len += sizeof(a)
 
+uint16_t
+cdf_tole2(uint16_t sv)
+{
+       return CDF_TOLE2(sv);
+}
+
+uint32_t
+cdf_tole4(uint32_t sv)
+{
+       return CDF_TOLE4(sv);
+}
+
+uint64_t
+cdf_tole8(uint64_t sv)
+{
+       return CDF_TOLE8(sv);
+}
+
 void
 cdf_swap_header(cdf_header_t *h)
 {
@@ -1204,7 +1222,7 @@ cdf_dump_summary_info(const cdf_header_t *h, const cdf_stream_t *sst)
        size_t count;
 
        (void)&h;
-       if (cdf_unpack_summary_info(sst, &ssi, &info, &count) == -1)
+       if (cdf_unpack_summary_info(sst, h, &ssi, &info, &count) == -1)
                return;
        (void)fprintf(stderr, "Endian: %x\n", ssi.si_byte_order);
        (void)fprintf(stderr, "Os Version %d.%d\n", ssi.si_os_version & 0xff,
index 1c7e909b38c2d9affe25b18cfeff79db3bcd9675..e3f57929f4f3f1e3b9634f3dc3fd0cb80fc3678f 100644 (file)
@@ -26,7 +26,7 @@
 #include "file.h"
 
 #ifndef lint
-FILE_RCSID("@(#)$File: readcdf.c,v 1.24 2011/02/10 17:03:16 christos Exp $")
+FILE_RCSID("@(#)$File: readcdf.c,v 1.25 2011/02/10 21:35:05 christos Exp $")
 #endif
 
 #include <stdlib.h>
@@ -48,7 +48,7 @@ cdf_file_property_info(struct magic_set *ms, const cdf_property_info_t *info,
         cdf_timestamp_t tp;
         struct timespec ts;
         char buf[64];
-        const char *str = "vnd.ms-office";
+        const char *str = NULL;
         const char *s;
         int len;
 
@@ -142,8 +142,8 @@ cdf_file_property_info(struct magic_set *ms, const cdf_property_info_t *info,
                 }
         }
         if (!NOTMIME(ms)) {
-                if (file_printf(ms, "application/%s", str) == -1)
-                        return -1;
+               if (str == NULL)
+                       return 0;
         }
         return 1;
 }
@@ -263,6 +263,24 @@ file_trycdf(struct magic_set *ms, int fd, const unsigned char *buf,
 #endif
         if ((i = cdf_file_summary_info(ms, &h, &scn)) == -1)
                 expn = "Can't expand summary_info";
+       if (i == 0) {
+               const char *str = "vnd.ms-office";
+               cdf_directory_t *d;
+               char name[__arraycount(d->d_name)];
+               size_t j, k;
+               for (j = 0; j < dir.dir_len; j++) {
+                   d = &dir.dir_tab[j];
+                   for (k = 0; k < sizeof(name); k++)
+                       name[k] = (char)cdf_tole2(d->d_name[k]);
+                   if (strstr(name, "WordDocument") == 0) {
+                       str = "msword";
+                       break;
+                   }
+               }
+                if (file_printf(ms, "application/%s", str) == -1)
+                        return -1;
+               i = 1;
+       }
         free(scn.sst_tab);
 out4:
         free(sst.sst_tab);