Browse code

add support for Mac's HQX file format

git-svn-id: file:///var/lib/svn/clamav-devel/trunk/clamav-devel@1110 77e5149b-7576-45b1-b177-96237e5ba77b

Tomasz Kojm authored on 2004/11/19 04:30:29
Showing 6 changed files
... ...
@@ -1,3 +1,7 @@
1
+Thu Nov 18 20:28:13 CET 2004 (tk)
2
+---------------------------------
3
+  * libclamav: add support for Mac's HQX file format (patch by Nigel)
4
+
1 5
 Thu Nov 18 11:03:14 CET 2004 (tk)
2 6
 ---------------------------------
3 7
   * libclamav: try to detect (and mark as Suspected.Zip) zip archives with
... ...
@@ -17,6 +17,9 @@
17 17
  *
18 18
  * Change History:
19 19
  * $Log: binhex.c,v $
20
+ * Revision 1.4  2004/11/18 19:30:29  kojm
21
+ * add support for Mac's HQX file format
22
+ *
20 23
  * Revision 1.3  2004/11/18 18:24:45  nigelhorne
21 24
  * Added binhex.h
22 25
  *
... ...
@@ -24,7 +27,7 @@
24 24
  * First draft of binhex.c
25 25
  *
26 26
  */
27
-static	char	const	rcsid[] = "$Id: binhex.c,v 1.3 2004/11/18 18:24:45 nigelhorne Exp $";
27
+static	char	const	rcsid[] = "$Id: binhex.c,v 1.4 2004/11/18 19:30:29 kojm Exp $";
28 28
 
29 29
 #include "clamav.h"
30 30
 
... ...
@@ -71,8 +74,8 @@ cli_binhex(const char *dir, int desc)
71 71
 	fileblob *fb;
72 72
 
73 73
 #ifndef HAVE_MMAP
74
-	cli_errmsg("Binhex decoding needs mmap() (for now)\n");
75
-	return CL_EMEM;
74
+	cli_warnmsg("File not decoded - binhex decoding needs mmap() (for now)\n");
75
+	return CL_CLEAN;
76 76
 #else
77 77
 	if(fstat(desc, &statb) < 0)
78 78
 		return CL_EOPEN;
... ...
@@ -99,14 +102,14 @@ cli_binhex(const char *dir, int desc)
99 99
 			--bytesleft;
100 100
 		}
101 101
 
102
-		printf("%d: ", length);
102
+		/* printf("%d: ", length); */
103 103
 
104 104
 		line = cli_malloc(length + 1);
105 105
 
106 106
 		memcpy(line, buf, length);
107 107
 		line[length] = '\0';
108 108
 
109
-		puts(line);
109
+		/* puts(line); */
110 110
 
111 111
 		if(messageAddStr(m, line) < 0)
112 112
 			break;
... ...
@@ -17,9 +17,17 @@
17 17
  *
18 18
  * Change History:
19 19
  * $Log: binhex.h,v $
20
+ * Revision 1.3  2004/11/18 19:30:29  kojm
21
+ * add support for Mac's HQX file format
22
+ *
20 23
  * Revision 1.2  2004/11/18 18:24:45  nigelhorne
21 24
  * Added binhex.h
22 25
  *
23 26
  */
24 27
 
28
+#ifndef __BINHEX_H
29
+#define __BINHEX_H
30
+
25 31
 int	cli_binhex(const char *dir, int desc);
32
+
33
+#endif
... ...
@@ -63,6 +63,8 @@ static const struct cli_magic_s cli_magic[] = {
63 63
     {0,	    "ITSF",			4,  "MS CHM",           CL_TYPE_MSCHM},
64 64
     {257,   "ustar",			5,  "POSIX tar",	CL_TYPE_TAR},
65 65
     {0,     "#@~^",			4,  "SCRENC",		CL_TYPE_SCRENC},
66
+    {0,     "(This file must be converted with BinHex 4.0)",
67
+				       45, "BinHex",		CL_TYPE_BINHEX},
66 68
 
67 69
     /* Mail */
68 70
 
... ...
@@ -39,6 +39,7 @@ typedef enum {
39 39
     CL_TYPE_MSCHM,
40 40
     CL_TYPE_SCRENC,
41 41
     CL_TYPE_GRAPHICS,
42
+    CL_TYPE_BINHEX,
42 43
 
43 44
     /* bigger numbers have higher priority (in o-t-f detection) */
44 45
     CL_TYPE_HTML, /* on the fly */
... ...
@@ -1041,6 +1041,34 @@ static int cli_scantar(int desc, const char **virname, long int *scanned, const
1041 1041
     return ret;
1042 1042
 }
1043 1043
 
1044
+static int cli_scanbinhex(int desc, const char **virname, long int *scanned, const struct cl_node *root, const struct cl_limits *limits, unsigned int options, int *arec, int *mrec)
1045
+{
1046
+	char *dir;
1047
+	int ret = CL_CLEAN;
1048
+
1049
+
1050
+    cli_dbgmsg("in cli_scanbinhex()\n");
1051
+
1052
+    /* generate temporary directory */
1053
+    dir = cli_gentemp(NULL);
1054
+
1055
+    if(mkdir(dir, 0700)) {
1056
+	cli_errmsg("Binhex: Can't create temporary directory %s\n", dir);
1057
+	return CL_ETMPDIR;
1058
+    }
1059
+
1060
+    if((ret = cli_binhex(dir, desc)))
1061
+	cli_dbgmsg("Binhex: %s\n", cl_strerror(ret));
1062
+    else
1063
+	ret = cli_scandir(dir, virname, scanned, root, limits, options, arec, mrec);
1064
+
1065
+    if(!cli_leavetemps_flag)
1066
+	cli_rmdirs(dir);
1067
+
1068
+    free(dir);
1069
+    return ret;
1070
+}
1071
+
1044 1072
 static int cli_scanmschm(int desc, const char **virname, long int *scanned, const struct cl_node *root, const struct cl_limits *limits, unsigned int options, int *arec, int *mrec)
1045 1073
 {
1046 1074
 	char *tempname;
... ...
@@ -1226,6 +1254,11 @@ int cli_magic_scandesc(int desc, const char **virname, long int *scanned, const
1226 1226
 		ret = cli_scantar(desc, virname, scanned, root, limits, options, arec, mrec);
1227 1227
 	    break;
1228 1228
 
1229
+	case CL_TYPE_BINHEX:
1230
+	    if(SCAN_ARCHIVE)
1231
+		ret = cli_scanbinhex(desc, virname, scanned, root, limits, options, arec, mrec);
1232
+	    break;
1233
+
1229 1234
 	case CL_TYPE_SCRENC:
1230 1235
 	    ret = cli_scanscrenc(desc, virname, scanned, root, limits, options, arec, mrec);
1231 1236
 	    break;