git-svn: trunk@2432
Tomasz Kojm authored on 2006/10/26 01:04:22... | ... |
@@ -143,6 +143,52 @@ static int htmlnorm(struct optstruct *opt) |
143 | 143 |
return 0; |
144 | 144 |
} |
145 | 145 |
|
146 |
+static int utf16decode(struct optstruct *opt) |
|
147 |
+{ |
|
148 |
+ const char *fname; |
|
149 |
+ char *newname, buff[512], *decoded; |
|
150 |
+ int ret = CL_CLEAN, fd1, fd2, bytes; |
|
151 |
+ |
|
152 |
+ |
|
153 |
+ fname = opt_arg(opt, "utf16-decode"); |
|
154 |
+ if((fd1 = open(fname, O_RDONLY)) == -1) { |
|
155 |
+ mprintf("!utf16decode: Can't open file %s\n", fname); |
|
156 |
+ return -1; |
|
157 |
+ } |
|
158 |
+ |
|
159 |
+ newname = malloc(strlen(fname) + 7); |
|
160 |
+ sprintf(newname, "%s.ascii", fname); |
|
161 |
+ |
|
162 |
+ if((fd2 = open(newname, O_WRONLY|O_CREAT|O_TRUNC, S_IRWXU)) < 0) { |
|
163 |
+ mprintf("!utf16decode: Can't create file %s\n", newname); |
|
164 |
+ free(newname); |
|
165 |
+ close(fd1); |
|
166 |
+ return -1; |
|
167 |
+ } |
|
168 |
+ |
|
169 |
+ while((bytes = read(fd1, buff, sizeof(buff))) > 0) { |
|
170 |
+ decoded = cli_utf16toascii(buff, bytes); |
|
171 |
+ if(decoded) { |
|
172 |
+ if(write(fd2, decoded, strlen(decoded)) == -1) { |
|
173 |
+ mprintf("!utf16decode: Can't write to file %s\n", newname); |
|
174 |
+ free(decoded); |
|
175 |
+ unlink(newname); |
|
176 |
+ free(newname); |
|
177 |
+ close(fd1); |
|
178 |
+ close(fd2); |
|
179 |
+ return -1; |
|
180 |
+ } |
|
181 |
+ free(decoded); |
|
182 |
+ } |
|
183 |
+ } |
|
184 |
+ |
|
185 |
+ free(newname); |
|
186 |
+ close(fd1); |
|
187 |
+ close(fd2); |
|
188 |
+ |
|
189 |
+ return 0; |
|
190 |
+} |
|
191 |
+ |
|
146 | 192 |
static unsigned int countlines(const char *filename) |
147 | 193 |
{ |
148 | 194 |
FILE *fd; |
... | ... |
@@ -1612,6 +1658,7 @@ void help(void) |
1612 | 1612 |
mprintf(" --md5 [FILES] generate MD5 checksum from stdin\n"); |
1613 | 1613 |
mprintf(" or MD5 sigs for FILES\n"); |
1614 | 1614 |
mprintf(" --html-normalise=FILE create normalised parts of HTML file\n"); |
1615 |
+ mprintf(" --utf16-decode=FILE decode UTF16 encoded files\n"); |
|
1615 | 1616 |
mprintf(" --info=FILE -i FILE print database information\n"); |
1616 | 1617 |
mprintf(" --build=NAME -b NAME build a CVD file\n"); |
1617 | 1618 |
mprintf(" --server=ADDR ClamAV Signing Service address\n"); |
... | ... |
@@ -1646,6 +1693,7 @@ int main(int argc, char **argv) |
1646 | 1646 |
{"hex-dump", 0, 0, 0}, |
1647 | 1647 |
{"md5", 0, 0, 0}, |
1648 | 1648 |
{"html-normalise", 1, 0, 0}, |
1649 |
+ {"utf16-decode", 1, 0, 0}, |
|
1649 | 1650 |
{"build", 1, 0, 'b'}, |
1650 | 1651 |
{"server", 1, 0, 0}, |
1651 | 1652 |
{"unpack", 1, 0, 'u'}, |
... | ... |
@@ -1693,6 +1741,8 @@ int main(int argc, char **argv) |
1693 | 1693 |
ret = md5sig(opt); |
1694 | 1694 |
else if(opt_check(opt, "html-normalise")) |
1695 | 1695 |
ret = htmlnorm(opt); |
1696 |
+ else if(opt_check(opt, "utf16-decode")) |
|
1697 |
+ ret = utf16decode(opt); |
|
1696 | 1698 |
else if(opt_check(opt, "build")) |
1697 | 1699 |
ret = build(opt); |
1698 | 1700 |
else if(opt_check(opt, "unpack")) |