Browse code

add support for Zip SFX unpacking

git-svn: trunk@1670

Tomasz Kojm authored on 2005/07/26 10:33:15
Showing 4 changed files
... ...
@@ -1,3 +1,8 @@
1
+Tue Jul 26 03:31:12 CEST 2005 (tk)
2
+----------------------------------
3
+  * libclamav: add support for Zip SFX unpacking (patch by Sven Strickroth
4
+	       <sven*clamav.net>)
5
+
1 6
 Tue Jul 26 02:54:18 CEST 2005 (tk)
2 7
 ----------------------------------
3 8
   * configure.in: --disable-cr was not working properly, reported by Stephane
... ...
@@ -170,6 +170,7 @@ static const struct cli_smagic_s cli_smagic[] = {
170 170
     {"3c494652414d45", "HTML data", CL_TYPE_HTML},      /* <IFRAME */
171 171
 
172 172
     {"526172211a0700", "RAR-SFX", CL_TYPE_RARSFX},
173
+    {"504b03041400", "ZIP-SFX", CL_TYPE_ZIPSFX},
173 174
 
174 175
     {NULL,  NULL,   CL_TYPE_UNKNOWN_DATA}
175 176
 };
... ...
@@ -48,6 +48,7 @@ typedef enum {
48 48
     /* bigger numbers have higher priority (in o-t-f detection) */
49 49
     CL_TYPE_HTML, /* on the fly */
50 50
     CL_TYPE_MAIL,  /* magic + on the fly */
51
+    CL_TYPE_ZIPSFX, /* on the fly */
51 52
     CL_TYPE_RARSFX /* on the fly */
52 53
 
53 54
 } cli_file_t;
... ...
@@ -262,7 +262,7 @@ static int cli_scanrar(int desc, const char **virname, long int *scanned, const
262 262
 }
263 263
 
264 264
 #ifdef HAVE_ZLIB_H
265
-static int cli_scanzip(int desc, const char **virname, long int *scanned, const struct cl_node *root, const struct cl_limits *limits, unsigned int options, unsigned int arec, unsigned int mrec)
265
+static int cli_scanzip(int desc, const char **virname, long int *scanned, const struct cl_node *root, const struct cl_limits *limits, unsigned int options, unsigned int arec, unsigned int mrec, unsigned long int offset)
266 266
 {
267 267
 	ZZIP_DIR *zdir;
268 268
 	ZZIP_DIRENT zdirent;
... ...
@@ -280,6 +280,9 @@ static int cli_scanzip(int desc, const char **virname, long int *scanned, const
280 280
 
281 281
     cli_dbgmsg("in scanzip()\n");
282 282
 
283
+    if(offset)
284
+	lseek(desc, offset, SEEK_SET);
285
+
283 286
     if((zdir = zzip_dir_fdopen(dup(desc), &err)) == NULL) {
284 287
 	cli_dbgmsg("Zip: Not supported file format ?.\n");
285 288
 	cli_dbgmsg("Zip: zzip_dir_fdopen() return code: %d\n", err);
... ...
@@ -1443,7 +1446,7 @@ int cli_magic_scandesc(int desc, const char **virname, long int *scanned, const
1443 1443
 
1444 1444
 	case CL_TYPE_ZIP:
1445 1445
 	    if(SCAN_ARCHIVE)
1446
-		ret = cli_scanzip(desc, virname, scanned, root, limits, options, arec, mrec);
1446
+		ret = cli_scanzip(desc, virname, scanned, root, limits, options, arec, mrec, 0);
1447 1447
 	    break;
1448 1448
 
1449 1449
 	case CL_TYPE_GZ:
... ...
@@ -1584,6 +1587,13 @@ int cli_magic_scandesc(int desc, const char **virname, long int *scanned, const
1584 1584
 			if(cli_scanrar(desc, virname, scanned, root, limits, options, arec, mrec, ftoffset) == CL_VIRUS)
1585 1585
 			    return CL_VIRUS;
1586 1586
 		    break;
1587
+
1588
+		case CL_TYPE_ZIPSFX:
1589
+		    if(SCAN_ARCHIVE && type == CL_TYPE_MSEXE)
1590
+			cli_dbgmsg("ZIP-SFX found at %d\n", ftoffset);
1591
+			if(cli_scanzip(desc, virname, scanned, root, limits, options, arec, mrec, ftoffset) == CL_VIRUS)
1592
+			    return CL_VIRUS;
1593
+		    break;
1587 1594
 	    }
1588 1595
 	    nret == CL_TYPE_MAIL ? mrec-- : arec--;
1589 1596
 	}