Browse code

Added Windows support

git-svn: trunk@2225

Nigel Horne authored on 2006/08/31 22:50:25
Showing 2 changed files
... ...
@@ -1,3 +1,7 @@
1
+Thu Aug 31 14:49:42 BST 2006 (njh)
2
+----------------------------------
3
+  * libclamav/pe.c:	Added Windows support (with permission from ACAB)
4
+
1 5
 Thu Aug 31 00:37:10 CEST 2006 (tk)
2 6
 ----------------------------------
3 7
   * freshclam: minor code cleanup
... ...
@@ -50,6 +50,10 @@
50 50
 #include "str.h"
51 51
 #include "execs.h"
52 52
 
53
+#ifndef	O_BINARY
54
+#define	O_BINARY	0
55
+#endif
56
+
53 57
 #define IMAGE_DOS_SIGNATURE	    0x5a4d	    /* MZ */
54 58
 #define IMAGE_DOS_SIGNATURE_OLD	    0x4d5a          /* ZM */
55 59
 #define IMAGE_NT_SIGNATURE	    0x00004550
... ...
@@ -135,7 +139,7 @@ static int cli_ddump(int desc, int offset, int size, const char *file)
135 135
 	return -1;
136 136
     }
137 137
 
138
-    if((ndesc = open(file, O_WRONLY|O_CREAT|O_TRUNC, S_IRWXU)) < 0) {
138
+    if((ndesc = open(file, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, S_IRWXU)) < 0) {
139 139
 	cli_dbgmsg("Can't create file %s\n", file);
140 140
 	lseek(desc, pos, SEEK_SET);
141 141
 	return -1;
... ...
@@ -848,7 +852,7 @@ int cli_scanpe(int desc, cli_ctx *ctx)
848 848
 	    return CL_EMEM;
849 849
 	  }
850 850
 	  
851
-	  if((ndesc = open(tempfile, O_RDWR|O_CREAT|O_TRUNC, S_IRWXU)) < 0) {
851
+	  if((ndesc = open(tempfile, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, S_IRWXU)) < 0) {
852 852
 	    cli_dbgmsg("sue: Can't create file %s\n", tempfile);
853 853
 	    free(tempfile);
854 854
 	    free(sue);
... ...
@@ -1020,7 +1024,7 @@ int cli_scanpe(int desc, cli_ctx *ctx)
1020 1020
 		    return CL_EMEM;
1021 1021
 		}
1022 1022
 
1023
-		if((ndesc = open(tempfile, O_RDWR|O_CREAT|O_TRUNC, S_IRWXU)) < 0) {
1023
+		if((ndesc = open(tempfile, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, S_IRWXU)) < 0) {
1024 1024
 		    cli_dbgmsg("FSG: Can't create file %s\n", tempfile);
1025 1025
 		    free(tempfile);
1026 1026
 		    free(section_hdr);
... ...
@@ -1225,7 +1229,7 @@ int cli_scanpe(int desc, cli_ctx *ctx)
1225 1225
 		    return CL_EMEM;
1226 1226
 		}
1227 1227
 
1228
-		if((ndesc = open(tempfile, O_RDWR|O_CREAT|O_TRUNC, S_IRWXU)) < 0) {
1228
+		if((ndesc = open(tempfile, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, S_IRWXU)) < 0) {
1229 1229
 		    cli_dbgmsg("FSG: Can't create file %s\n", tempfile);
1230 1230
 		    free(tempfile);
1231 1231
 		    free(section_hdr);
... ...
@@ -1435,7 +1439,7 @@ int cli_scanpe(int desc, cli_ctx *ctx)
1435 1435
 		    return CL_EMEM;
1436 1436
 		}
1437 1437
 
1438
-		if((ndesc = open(tempfile, O_RDWR|O_CREAT|O_TRUNC, S_IRWXU)) < 0) {
1438
+		if((ndesc = open(tempfile, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, S_IRWXU)) < 0) {
1439 1439
 		    cli_dbgmsg("FSG: Can't create file %s\n", tempfile);
1440 1440
 		    free(tempfile);
1441 1441
 		    free(section_hdr);
... ...
@@ -1655,7 +1659,7 @@ int cli_scanpe(int desc, cli_ctx *ctx)
1655 1655
 		return CL_EMEM;
1656 1656
 	    }
1657 1657
 
1658
-	    if((ndesc = open(tempfile, O_RDWR|O_CREAT|O_TRUNC, S_IRWXU)) < 0) {
1658
+	    if((ndesc = open(tempfile, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, S_IRWXU)) < 0) {
1659 1659
 		cli_dbgmsg("UPX/FSG: Can't create file %s\n", tempfile);
1660 1660
 		free(tempfile);
1661 1661
 		free(dest);
... ...
@@ -1755,7 +1759,7 @@ int cli_scanpe(int desc, cli_ctx *ctx)
1755 1755
 	      return CL_EMEM;
1756 1756
 	    }
1757 1757
 
1758
-	    if((ndesc = open(tempfile, O_RDWR|O_CREAT|O_TRUNC, S_IRWXU)) < 0) {
1758
+	    if((ndesc = open(tempfile, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, S_IRWXU)) < 0) {
1759 1759
 		cli_dbgmsg("Petite: Can't create file %s\n", tempfile);
1760 1760
 		free(tempfile);
1761 1761
 		free(section_hdr);
... ...
@@ -1837,7 +1841,7 @@ int cli_scanpe(int desc, cli_ctx *ctx)
1837 1837
 	  return CL_EMEM;
1838 1838
 	}
1839 1839
 
1840
-	if((ndesc = open(tempfile, O_RDWR|O_CREAT|O_TRUNC, S_IRWXU)) < 0) {
1840
+	if((ndesc = open(tempfile, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, S_IRWXU)) < 0) {
1841 1841
 	    cli_dbgmsg("PESpin: Can't create file %s\n", tempfile);
1842 1842
 	    free(tempfile);
1843 1843
 	    free(spinned);
... ...
@@ -1906,7 +1910,7 @@ int cli_scanpe(int desc, cli_ctx *ctx)
1906 1906
 	    return CL_EMEM;
1907 1907
 	  }
1908 1908
 
1909
-	  if((ndesc = open(tempfile, O_RDWR|O_CREAT|O_TRUNC, S_IRWXU)) < 0) {
1909
+	  if((ndesc = open(tempfile, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, S_IRWXU)) < 0) {
1910 1910
 	    cli_dbgmsg("yC: Can't create file %s\n", tempfile);
1911 1911
 	    free(tempfile);
1912 1912
 	    free(spinned);
... ...
@@ -2031,7 +2035,7 @@ int cli_scanpe(int desc, cli_ctx *ctx)
2031 2031
 	  return CL_EMEM;
2032 2032
 	}
2033 2033
 
2034
-	if((ndesc = open(tempfile, O_RDWR|O_CREAT|O_TRUNC, S_IRWXU)) < 0) {
2034
+	if((ndesc = open(tempfile, O_RDWR|O_CREAT|O_TRUNC|O_BINARY, S_IRWXU)) < 0) {
2035 2035
 	  cli_dbgmsg("WWPack: Can't create file %s\n", tempfile);
2036 2036
 	  free(tempfile);
2037 2037
 	  free(dest);