Browse code

Merge branch 'master' of git.clam.sourcefire.com:/var/lib/git/clamav-devel

Steve Morgan authored on 2013/10/10 06:19:02
Showing 10 changed files
... ...
@@ -106,6 +106,10 @@ int main(int argc, char **argv)
106 106
 	cl_debug(); /* enable debug messages */
107 107
     }
108 108
 
109
+    if (optget(opts, "gen-mdb")->enabled) {
110
+        cl_always_gen_section_hash();
111
+    }
112
+
109 113
     if(optget(opts, "version")->enabled) {
110 114
 	print_version(optget(opts, "database")->strarg);
111 115
 	optfree(opts);
... ...
@@ -41,6 +41,7 @@ CLAMAV_PUBLIC {
41 41
     cl_fmap_open_memory;
42 42
     cl_scanmap_callback;
43 43
     cl_fmap_close;
44
+    cl_always_gen_section_hash;
44 45
 };
45 46
 CLAMAV_PRIVATE {
46 47
   global:
... ...
@@ -187,6 +187,11 @@ void cl_debug(void)
187 187
     cli_debug_flag = 1;
188 188
 }
189 189
 
190
+void cl_always_gen_section_hash(void)
191
+{
192
+    cli_always_gen_section_hash = 1;
193
+}
194
+
190 195
 unsigned int cl_retflevel(void)
191 196
 {
192 197
     return CL_FLEVEL;
... ...
@@ -60,6 +60,7 @@
60 60
 #define CL_FLEVEL_SIGTOOL CL_FLEVEL
61 61
 
62 62
 extern uint8_t cli_debug_flag;
63
+extern uint8_t cli_always_gen_section_hash;
63 64
 
64 65
 /*
65 66
  * CLI_ISCONTAINED(buf1, size1, buf2, size2) checks if buf2 is contained
... ...
@@ -119,6 +119,7 @@ void cli_logg_unsetup(void)
119 119
 }
120 120
 #endif
121 121
 uint8_t cli_debug_flag = 0;
122
+uint8_t cli_always_gen_section_hash = 0;
122 123
 
123 124
 static void fputs_callback(enum cl_msg severity, const char *fullmsg, const char *msg, void *context)
124 125
 {
... ...
@@ -556,12 +556,39 @@ static int scan_pe_mdb (cli_ctx * ctx, struct cli_exe_section *exe_section)
556 556
     /* Print hash */
557 557
     if (cli_debug_flag) {
558 558
         md5 = hashset[CLI_HASH_MD5];
559
-        if (md5)
559
+        if (md5) {
560 560
             cli_dbgmsg("MDB: %u:%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\n",
561 561
                 exe_section->rsz, md5[0], md5[1], md5[2], md5[3], md5[4], md5[5], md5[6], md5[7],
562 562
                 md5[8], md5[9], md5[10], md5[11], md5[12], md5[13], md5[14], md5[15]);
563
-        else
563
+        } else if (cli_always_gen_section_hash) {
564
+            const void *hashme = fmap_need_off_once(*ctx->fmap, exe_section->raw, exe_section->rsz);
565
+            cli_md5_ctx md5ctx;
566
+            if (!(hashme)) {
567
+                cli_errmsg("scan_pe_mdb: unable to read section data\n");
568
+                ret = CL_EREAD;
569
+                goto end;
570
+            }
571
+
572
+            md5 = cli_malloc(16);
573
+            if (!(md5)) {
574
+                cli_errmsg("scan_pe_mdb: cli_malloc failed!\n");
575
+                ret = CL_EMEM;
576
+                goto end;
577
+            }
578
+
579
+            cli_md5_init(&md5ctx);
580
+            cli_md5_update(&md5ctx, hashme, exe_section->rsz);
581
+            cli_md5_final(md5, &md5ctx);
582
+
583
+            cli_dbgmsg("MDB: %u:%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x\n",
584
+                exe_section->rsz, md5[0], md5[1], md5[2], md5[3], md5[4], md5[5], md5[6], md5[7],
585
+                md5[8], md5[9], md5[10], md5[11], md5[12], md5[13], md5[14], md5[15]);
586
+
587
+            free(md5);
588
+
589
+        } else {
564 590
             cli_dbgmsg("MDB: %u:notgenerated\n", exe_section->rsz);
591
+        }
565 592
     }
566 593
 
567 594
     /* Do scans */
... ...
@@ -582,6 +609,7 @@ static int scan_pe_mdb (cli_ctx * ctx, struct cli_exe_section *exe_section)
582 582
        }
583 583
     }
584 584
 
585
+end:
585 586
     for(type = CLI_HASH_AVAIL_TYPES; type > 0;)
586 587
         free(hashset[--type]);
587 588
     return ret;
... ...
@@ -86,6 +86,7 @@ const struct clam_option __clam_options[] = {
86 86
     { NULL, "allmatch", 'z', TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMSCAN | OPT_CLAMDSCAN, "", "" },
87 87
     { NULL, "database", 'd', TYPE_STRING, NULL, -1, DATADIR, FLAG_REQUIRED | FLAG_MULTIPLE, OPT_CLAMSCAN, "", "" }, /* merge it with DatabaseDirectory (and fix conflict with --datadir */
88 88
     { NULL, "recursive", 'r', TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMSCAN, "", "" },
89
+    { NULL, "gen-mdb", 0, TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMSCAN, "Always generate MDB entries for PE sections", "" },
89 90
     { NULL, "follow-dir-symlinks", 0, TYPE_NUMBER, MATCH_NUMBER, 1, NULL, 0, OPT_CLAMSCAN, "", "" },
90 91
     { NULL, "follow-file-symlinks", 0, TYPE_NUMBER, MATCH_NUMBER, 1, NULL, 0, OPT_CLAMSCAN, "", "" },
91 92
     { NULL, "bell", 0, TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMSCAN, "", "" },
... ...
@@ -41,6 +41,7 @@ EXPORTS cl_set_clcb_msg @33
41 41
 EXPORTS cl_engine_set_clcb_hash @34
42 42
 EXPORTS cl_engine_set_clcb_pre_cache @35
43 43
 EXPORTS cl_engine_set_clcb_meta @36
44
+EXPORTS cl_always_gen_section_hash @37
44 45
 
45 46
 
46 47
 ; path variables
... ...
@@ -165,6 +165,15 @@
165 165
     <ResourceCompile Include="res\libclamav.rc" />
166 166
   </ItemGroup>
167 167
   <ItemGroup>
168
+    <ClCompile Include="..\libclamav\7z\7zCrcOpt.c" />
169
+    <ClCompile Include="..\libclamav\7z\BraIA64.c" />
170
+    <ClCompile Include="..\libclamav\7z\CpuArch.c" />
171
+    <ClCompile Include="..\libclamav\7z\Delta.c" />
172
+    <ClCompile Include="..\libclamav\7z\Sha256.c" />
173
+    <ClCompile Include="..\libclamav\7z\Xz.c" />
174
+    <ClCompile Include="..\libclamav\7z\XzCrc64.c" />
175
+    <ClCompile Include="..\libclamav\7z\XzDec.c" />
176
+    <ClCompile Include="..\libclamav\7z\XzIn.c" />
168 177
     <ClCompile Include="..\libclamav\sf_base64decode.c" />
169 178
     <ClCompile Include="..\libclamav\tomsfastmath\mul\fp_mul_comba_small_set.c" />
170 179
     <ClCompile Include="..\libclamav\tomsfastmath\mul\fp_mul_comba_9.c" />
... ...
@@ -376,6 +385,7 @@
376 376
     <ClCompile Include="..\libclamav\version.c" />
377 377
     <ClCompile Include="..\libclamav\wwunpack.c" />
378 378
     <ClCompile Include="..\libclamav\xar.c" />
379
+    <ClCompile Include="..\libclamav\xz_iface.c" />
379 380
     <ClCompile Include="..\libclamav\yc.c" />
380 381
     <ClCompile Include="..\shared\getopt.c" />
381 382
     <ClCompile Include="..\shared\misc.c" />
... ...
@@ -471,4 +481,4 @@
471 471
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
472 472
   <ImportGroup Label="ExtensionTargets">
473 473
   </ImportGroup>
474
-</Project>
474
+</Project>
475 475
\ No newline at end of file
... ...
@@ -843,5 +843,35 @@
843 843
     <ClCompile Include="3rdparty\libxml2\xmlstring.c">
844 844
       <Filter>Source Files\libxml2</Filter>
845 845
     </ClCompile>
846
+    <ClCompile Include="..\libclamav\xz_iface.c">
847
+      <Filter>Source Files</Filter>
848
+    </ClCompile>
849
+    <ClCompile Include="..\libclamav\7z\7zCrcOpt.c">
850
+      <Filter>Source Files\7z</Filter>
851
+    </ClCompile>
852
+    <ClCompile Include="..\libclamav\7z\BraIA64.c">
853
+      <Filter>Source Files\7z</Filter>
854
+    </ClCompile>
855
+    <ClCompile Include="..\libclamav\7z\CpuArch.c">
856
+      <Filter>Source Files\7z</Filter>
857
+    </ClCompile>
858
+    <ClCompile Include="..\libclamav\7z\Delta.c">
859
+      <Filter>Source Files\7z</Filter>
860
+    </ClCompile>
861
+    <ClCompile Include="..\libclamav\7z\Sha256.c">
862
+      <Filter>Source Files\7z</Filter>
863
+    </ClCompile>
864
+    <ClCompile Include="..\libclamav\7z\Xz.c">
865
+      <Filter>Source Files\7z</Filter>
866
+    </ClCompile>
867
+    <ClCompile Include="..\libclamav\7z\XzCrc64.c">
868
+      <Filter>Source Files\7z</Filter>
869
+    </ClCompile>
870
+    <ClCompile Include="..\libclamav\7z\XzDec.c">
871
+      <Filter>Source Files\7z</Filter>
872
+    </ClCompile>
873
+    <ClCompile Include="..\libclamav\7z\XzIn.c">
874
+      <Filter>Source Files\7z</Filter>
875
+    </ClCompile>
846 876
   </ItemGroup>
847
-</Project>
877
+</Project>
848 878
\ No newline at end of file