Browse code

add dconfs for XDP, MBR, GPT, APM, OOXML, MSXML, and HWP formats

Kevin Lin authored on 2016/01/30 06:17:40
Showing 3 changed files
... ...
@@ -103,6 +103,9 @@ static struct dconf_module modules[] = {
103 103
     { "ARCHIVE",    "HFSPLUS",      ARCH_CONF_HFSPLUS,      1 },
104 104
     { "ARCHIVE",    "XZ",       ARCH_CONF_XZ,       1 },
105 105
     { "ARCHIVE",    "PASSWD",   ARCH_CONF_PASSWD,   1 },
106
+    { "ARCHIVE",    "MBR",      ARCH_CONF_MBR,      1 },
107
+    { "ARCHIVE",    "GPT",      ARCH_CONF_GPT,      1 },
108
+    { "ARCHIVE",    "APM",      ARCH_CONF_APM,      1 },
106 109
 
107 110
     { "DOCUMENT",   "HTML",     DOC_CONF_HTML,      1 },
108 111
     { "DOCUMENT",   "RTF",      DOC_CONF_RTF,       1 },
... ...
@@ -111,6 +114,9 @@ static struct dconf_module modules[] = {
111 111
     { "DOCUMENT",   "HTMLSKIPRAW",  DOC_CONF_HTML_SKIPRAW,  1 },
112 112
     { "DOCUMENT",   "JSNORM",       DOC_CONF_JSNORM,        1 },
113 113
     { "DOCUMENT",   "SWF",      DOC_CONF_SWF,       1 },
114
+    { "DOCUMENT",   "OOXML",    DOC_CONF_OOXML,     1 },
115
+    { "DOCUMENT",   "MSPML",    DOC_CONF_MSXML,     1 },
116
+    { "DOCUMENT",   "HWP",      DOC_CONF_HWP,       1 },
114 117
 
115 118
     { "MAIL",       "MBOX",     MAIL_CONF_MBOX,     1 },
116 119
     { "MAIL",       "TNEF",     MAIL_CONF_TNEF,     1 },
... ...
@@ -91,6 +91,9 @@ struct cli_dconf {
91 91
 #define ARCH_CONF_HFSPLUS   0x100000
92 92
 #define ARCH_CONF_XZ        0x200000
93 93
 #define ARCH_CONF_PASSWD    0x400000
94
+#define ARCH_CONF_MBR       0x800000
95
+#define ARCH_CONF_GPT       0x1000000
96
+#define ARCH_CONF_APM       0x2000000
94 97
 
95 98
 /* Document flags */
96 99
 #define DOC_CONF_HTML		0x1
... ...
@@ -100,6 +103,9 @@ struct cli_dconf {
100 100
 #define DOC_CONF_HTML_SKIPRAW	0x10
101 101
 #define DOC_CONF_JSNORM         0x20
102 102
 #define DOC_CONF_SWF		0x40
103
+#define DOC_CONF_MSXML		0x80
104
+#define DOC_CONF_OOXML		0x100
105
+#define DOC_CONF_HWP		0x200
103 106
 
104 107
 /* Mail flags */
105 108
 #define MAIL_CONF_MBOX	    0x1
... ...
@@ -2267,16 +2267,28 @@ static int cli_scanraw(cli_ctx *ctx, cli_file_t type, uint8_t typercg, cli_file_
2267 2267
         while(fpt) {
2268 2268
             if(fpt->offset) switch(fpt->type) {
2269 2269
                 case CL_TYPE_XDP:
2270
-                    ret = cli_scanxdp(ctx);
2270
+                    if(SCAN_PDF && (DCONF_DOC & DOC_CONF_PDF)) {
2271
+                        cli_dbgmsg("XDP signature found at %u\n", (unsigned int) fpt->offset);
2272
+                        ret = cli_scanxdp(ctx);
2273
+                    }
2271 2274
                     break;
2272 2275
                 case CL_TYPE_XML_WORD:
2273
-                    ret = cli_scanmsxml(ctx);
2276
+                    if(DCONF_DOC & DOC_CONF_MSXML) {
2277
+                        cli_dbgmsg("XML-WORD signature found at %u\n", (unsigned int) fpt->offset);
2278
+                        ret = cli_scanmsxml(ctx);
2279
+                    }
2274 2280
                     break;
2275 2281
                 case CL_TYPE_XML_XL:
2276
-                    ret = cli_scanmsxml(ctx);
2282
+                    if(DCONF_DOC & DOC_CONF_MSXML) {
2283
+                        cli_dbgmsg("XML-XL signature found at %u\n", (unsigned int) fpt->offset);
2284
+                        ret = cli_scanmsxml(ctx);
2285
+                    }
2277 2286
                     break;
2278 2287
                 case CL_TYPE_XML_HWP:
2279
-                    ret = cli_scanhwpml(ctx);
2288
+                    if(DCONF_DOC & DOC_CONF_HWP) {
2289
+                        cli_dbgmsg("XML-HWP signature found at %u\n", (unsigned int) fpt->offset);
2290
+                        ret = cli_scanhwpml(ctx);
2291
+                    }
2280 2292
                     break;
2281 2293
                 case CL_TYPE_RARSFX:
2282 2294
                     if(type != CL_TYPE_RAR && have_rar && SCAN_ARCHIVE && (DCONF_ARCH & ARCH_CONF_RAR)) {
... ...
@@ -2387,24 +2399,24 @@ static int cli_scanraw(cli_ctx *ctx, cli_file_t type, uint8_t typercg, cli_file_
2387 2387
                 case CL_TYPE_DMG:
2388 2388
                     if(SCAN_ARCHIVE && (DCONF_ARCH & ARCH_CONF_DMG)) {
2389 2389
                         ctx->container_type = CL_TYPE_DMG;
2390
-                        nret = cli_scandmg(ctx);
2391 2390
                         cli_dbgmsg("DMG signature found at %u\n", (unsigned int) fpt->offset);
2391
+                        nret = cli_scandmg(ctx);
2392 2392
                     }
2393 2393
                     break;
2394 2394
 
2395 2395
                 case CL_TYPE_MBR:
2396
-                    {
2396
+                    if(SCAN_ARCHIVE) {
2397 2397
                         int iret = cli_mbr_check2(ctx, 0);
2398
-                        if (iret == CL_TYPE_GPT) {
2398
+                        if ((iret == CL_TYPE_GPT) && (DCONF_ARCH & ARCH_CONF_GPT)) {
2399 2399
                             cli_dbgmsg("Recognized GUID Partition Table file\n");
2400 2400
                             ctx->container_type = CL_TYPE_GPT;
2401
-                            nret = cli_scangpt(ctx, 0);
2402 2401
                             cli_dbgmsg("GPT signature found at %u\n", (unsigned int) fpt->offset);
2402
+                            nret = cli_scangpt(ctx, 0);
2403 2403
                         }
2404
-                        else if (iret == CL_CLEAN) {
2404
+                        else if ((iret == CL_CLEAN) && (DCONF_ARCH & ARCH_CONF_MBR)) {
2405 2405
                             ctx->container_type = CL_TYPE_MBR;
2406
-                            nret = cli_scanmbr(ctx, 0);
2407 2406
                             cli_dbgmsg("MBR signature found at %u\n", (unsigned int) fpt->offset);
2407
+                            nret = cli_scanmbr(ctx, 0);
2408 2408
                         }
2409 2409
                     }
2410 2410
                     break;
... ...
@@ -2845,29 +2857,35 @@ static int magic_scandesc(cli_ctx *ctx, cli_file_t type)
2845 2845
 	case CL_TYPE_IGNORED:
2846 2846
 	    break;
2847 2847
 
2848
-    case CL_TYPE_HWP3:
2849
-        ret = cli_scanhwp3(ctx);
2850
-        break;
2848
+	case CL_TYPE_HWP3:
2849
+	    if(DCONF_DOC & DOC_CONF_HWP)
2850
+		ret = cli_scanhwp3(ctx);
2851
+	    break;
2851 2852
 
2852
-    case CL_TYPE_HWPOLE2:
2853
-        ret = cli_scanhwpole2(ctx);
2854
-        break;
2853
+	case CL_TYPE_HWPOLE2:
2854
+	    if(SCAN_OLE2 && (DCONF_ARCH & ARCH_CONF_OLE2))
2855
+		ret = cli_scanhwpole2(ctx);
2856
+	    break;
2855 2857
 
2856
-    case CL_TYPE_XML_WORD:
2857
-        ret = cli_scanmsxml(ctx);
2858
-        break;
2858
+	case CL_TYPE_XML_WORD:
2859
+	    if(DCONF_DOC & DOC_CONF_MSXML)
2860
+		ret = cli_scanmsxml(ctx);
2861
+	    break;
2859 2862
 
2860
-    case CL_TYPE_XML_XL:
2861
-        ret = cli_scanmsxml(ctx);
2862
-        break;
2863
+	case CL_TYPE_XML_XL:
2864
+	    if(DCONF_DOC & DOC_CONF_MSXML)
2865
+		ret = cli_scanmsxml(ctx);
2866
+	    break;
2863 2867
 
2864
-    case CL_TYPE_XML_HWP:
2865
-        ret = cli_scanhwpml(ctx);
2866
-        break;
2868
+	case CL_TYPE_XML_HWP:
2869
+	    if(DCONF_DOC & DOC_CONF_HWP)
2870
+		ret = cli_scanhwpml(ctx);
2871
+	    break;
2867 2872
 
2868
-    case CL_TYPE_XDP:
2869
-        ret = cli_scanxdp(ctx);
2870
-        break;
2873
+	case CL_TYPE_XDP:
2874
+	    if(SCAN_PDF && (DCONF_DOC & DOC_CONF_PDF))
2875
+		ret = cli_scanxdp(ctx);
2876
+	    break;
2871 2877
 
2872 2878
 	case CL_TYPE_RAR:
2873 2879
 	    ctx->container_type = CL_TYPE_RAR;
... ...
@@ -2896,17 +2914,22 @@ static int magic_scandesc(cli_ctx *ctx, cli_file_t type)
2896 2896
 	case CL_TYPE_OOXML_XL:
2897 2897
 	case CL_TYPE_OOXML_HWP:
2898 2898
 #if HAVE_JSON
2899
-	    if ((ctx->options & CL_SCAN_FILE_PROPERTIES) && (ctx->wrkproperty != NULL)) {
2900
-		ret = cli_process_ooxml(ctx, type);
2899
+	    if(DCONF_DOC & DOC_CONF_OOXML) {
2900
+		if ((ctx->options & CL_SCAN_FILE_PROPERTIES) && (ctx->wrkproperty != NULL)) {
2901
+		    ret = cli_process_ooxml(ctx, type);
2901 2902
 
2902
-		if (ret == CL_EMEM || ret == CL_ENULLARG) {
2903
-		    /* critical error */
2904
-		    break;
2905
-		}
2906
-		else if (ret != CL_SUCCESS) {
2907
-		    /* allow for the CL_TYPE_ZIP scan to occur; cli_process_ooxml other possible returns: */
2908
-		    /* CL_ETIMEOUT, CL_EMAXSIZE, CL_EMAXFILES, CL_EPARSE, CL_EFORMAT, CL_BREAK, CL_ESTAT  */
2909
-		    ret = CL_SUCCESS;
2903
+		    if (ret == CL_EMEM || ret == CL_ENULLARG) {
2904
+			/* critical error */
2905
+			break;
2906
+		    } else if (ret != CL_SUCCESS) {
2907
+			/*
2908
+			 * non-critical return => allow for the CL_TYPE_ZIP scan to occur
2909
+			 * cli_process_ooxml other possible returns:
2910
+			 *   CL_ETIMEOUT, CL_EMAXSIZE, CL_EMAXFILES, CL_EPARSE,
2911
+			 *   CL_EFORMAT, CL_BREAK, CL_ESTAT
2912
+			 */
2913
+			ret = CL_SUCCESS;
2914
+		    }
2910 2915
 		}
2911 2916
 	    }
2912 2917
 #endif
... ...
@@ -2932,11 +2955,13 @@ static int magic_scandesc(cli_ctx *ctx, cli_file_t type)
2932 2932
 	    break;
2933 2933
 
2934 2934
 	case CL_TYPE_GPT:
2935
-	    ret = cli_scangpt(ctx, 0);
2935
+	    if(SCAN_ARCHIVE && (DCONF_ARCH & ARCH_CONF_GPT))
2936
+		ret = cli_scangpt(ctx, 0);
2936 2937
 	    break;
2937 2938
 
2938 2939
 	case CL_TYPE_APM:
2939
-	    ret = cli_scanapm(ctx);
2940
+	    if(SCAN_ARCHIVE && (DCONF_ARCH & ARCH_CONF_APM))
2941
+		ret = cli_scanapm(ctx);
2940 2942
 	    break;
2941 2943
 
2942 2944
 	case CL_TYPE_ARJ: