Browse code

sync entry point calculation with cli_scanpe

git-svn: trunk@1658

Tomasz Kojm authored on 2005/07/20 05:36:38
Showing 2 changed files
... ...
@@ -1,3 +1,8 @@
1
+Tue Jul 19 22:35:02 CEST 2005 (tk)
2
+----------------------------------
3
+  * libclamav/pe.c: cli_peheader: sync entry point calculation with cli_scanpe
4
+		    (problem reported by Christoph Cordes <ccordes*clamav.net>)
5
+
1 6
 Tue Jul 19 22:07:15 CEST 2005 (tk)
2 7
 ----------------------------------
3 8
   * configure.in: fix compilation error when curl is installed in a
... ...
@@ -1369,6 +1369,7 @@ int cli_peheader(int desc, struct cli_pe_info *peinfo)
1369 1369
 {
1370 1370
 	uint16_t e_magic; /* DOS signature ("MZ") */
1371 1371
 	uint32_t e_lfanew; /* address of new exe header */
1372
+	uint32_t min, max;
1372 1373
 	struct pe_image_file_hdr file_hdr;
1373 1374
 	struct pe_image_optional_hdr optional_hdr;
1374 1375
 	struct pe_image_section_hdr *section_hdr;
... ...
@@ -1467,11 +1468,20 @@ int cli_peheader(int desc, struct cli_pe_info *peinfo)
1467 1467
 	peinfo->section[i].vsz = EC32(section_hdr[i].VirtualSize);
1468 1468
 	peinfo->section[i].raw = EC32(section_hdr[i].PointerToRawData);
1469 1469
 	peinfo->section[i].rsz = EC32(section_hdr[i].SizeOfRawData);
1470
-    }
1471 1470
 
1472
-    peinfo->ep = cli_rawaddr(EC32(optional_hdr.AddressOfEntryPoint), section_hdr, peinfo->nsections, &err);
1471
+	if(!i) {
1472
+	    min = EC32(section_hdr[i].VirtualAddress);
1473
+	    max = EC32(section_hdr[i].VirtualAddress) + EC32(section_hdr[i].SizeOfRawData);
1474
+	} else {
1475
+	    if(EC32(section_hdr[i].VirtualAddress) < min)
1476
+		min = EC32(section_hdr[i].VirtualAddress);
1477
+
1478
+	    if(EC32(section_hdr[i].VirtualAddress) + EC32(section_hdr[i].SizeOfRawData) > max)
1479
+		max = EC32(section_hdr[i].VirtualAddress) + EC32(section_hdr[i].SizeOfRawData);
1480
+	}
1481
+    }
1473 1482
 
1474
-    if(err) {
1483
+    if((peinfo->ep = EC32(optional_hdr.AddressOfEntryPoint)) >= min && !(peinfo->ep = cli_rawaddr(EC32(optional_hdr.AddressOfEntryPoint), section_hdr, peinfo->nsections, &err)) && err) {
1475 1484
 	cli_dbgmsg("Possibly broken PE file\n");
1476 1485
 	free(section_hdr);
1477 1486
 	free(peinfo->section);