git-svn: trunk@2408
Trog authored on 2006/10/18 17:53:51... | ... |
@@ -1,3 +1,14 @@ |
1 |
+Wed Oct 18 09:48:46 BST 2006 (trog) |
|
2 |
+----------------------------------- |
|
3 |
+ * libclamav/unrar/unrar.c,unrar.h,unrar20.c,unrarfilter.c,unrarppm.c,unrarvm.c: |
|
4 |
+ - Add O_BINARY support |
|
5 |
+ - Clean up includes |
|
6 |
+ - Extract per-file comments |
|
7 |
+ |
|
8 |
+Tue Oct 17 14:11:32 BST 2006 (trog) |
|
9 |
+----------------------------------- |
|
10 |
+ * libclamav/unrar/unrar.c, unrar.h: extract main archive comment for scan |
|
11 |
+ |
|
1 | 12 |
Mon Oct 16 10:53:09 CEST 2006 (tk) |
2 | 13 |
---------------------------------- |
3 | 14 |
* 0.90RC1.1 |
... | ... |
@@ -46,6 +46,10 @@ |
46 | 46 |
#include "others.h" |
47 | 47 |
#include "cltypes.h" |
48 | 48 |
|
49 |
+#ifndef O_BINARY |
|
50 |
+#define O_BINARY 0 |
|
51 |
+#endif |
|
52 |
+ |
|
49 | 53 |
#define int64to32(x) ((unsigned int)(x)) |
50 | 54 |
#define rar_endian_convert_16(v) le16_to_host(v) |
51 | 55 |
#define rar_endian_convert_32(v) le32_to_host(v) |
... | ... |
@@ -320,6 +324,7 @@ static file_header_t *read_block(int fd, header_type hdr_type) |
320 | 320 |
return NULL; |
321 | 321 |
} |
322 | 322 |
rar_dbgmsg(" head_size=%u\n", file_header->head_size); |
323 |
+ file_header->start_offset = offset; |
|
323 | 324 |
file_header->next_offset = offset + file_header->head_size; |
324 | 325 |
if (file_header->flags & LONG_BLOCK) { |
325 | 326 |
file_header->next_offset += file_header->pack_size; |
... | ... |
@@ -359,12 +364,7 @@ static file_header_t *read_block(int fd, header_type hdr_type) |
359 | 359 |
} |
360 | 360 |
file_header->filename[file_header->name_size] = '\0'; |
361 | 361 |
cli_dbgmsg("Filename: %s\n", file_header->filename); |
362 |
- /* Move to the end of the header */ |
|
363 |
- if (lseek(fd, offset+file_header->head_size, SEEK_SET) != offset+file_header->head_size) { |
|
364 |
- cli_dbgmsg("Seek failed: %ld\n", offset+file_header->head_size); |
|
365 |
- return NULL; |
|
366 |
- } |
|
367 |
- |
|
362 |
+ |
|
368 | 363 |
return file_header; |
369 | 364 |
} |
370 | 365 |
|
... | ... |
@@ -1446,7 +1446,7 @@ rar_metadata_t *cli_unrar(int fd, const char *dirname, const struct cl_limits *l |
1446 | 1446 |
cli_dbgmsg("UnPack Version: 0x%.2x\n", comment_header->unpack_ver); |
1447 | 1447 |
cli_dbgmsg("Pack Method: 0x%.2x\n", comment_header->method); |
1448 | 1448 |
snprintf(filename, 1024, "%s/main.cmt", dirname); |
1449 |
- ofd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0600); |
|
1449 |
+ ofd = open(filename, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0600); |
|
1450 | 1450 |
if (ofd < 0) { |
1451 | 1451 |
free(comment_header); |
1452 | 1452 |
cli_dbgmsg("ERROR: Failed to open output file\n"); |
... | ... |
@@ -1513,13 +1513,49 @@ rar_metadata_t *cli_unrar(int fd, const char *dirname, const struct cl_limits *l |
1513 | 1513 |
break; |
1514 | 1514 |
} |
1515 | 1515 |
} |
1516 |
+ if (file_header->flags & LHD_COMMENT) { |
|
1517 |
+ comment_header_t *comment_header; |
|
1518 |
+ |
|
1519 |
+ cli_dbgmsg("File comment present\n"); |
|
1520 |
+ comment_header = read_header(fd, COMM_HEAD); |
|
1521 |
+ if (comment_header) { |
|
1522 |
+ cli_dbgmsg("Comment type: 0x%.2x\n", comment_header->head_type); |
|
1523 |
+ cli_dbgmsg("Head size: 0x%.4x\n", comment_header->head_size); |
|
1524 |
+ cli_dbgmsg("UnPack Size: 0x%.4x\n", comment_header->unpack_size); |
|
1525 |
+ cli_dbgmsg("UnPack Version: 0x%.2x\n", comment_header->unpack_ver); |
|
1526 |
+ cli_dbgmsg("Pack Method: 0x%.2x\n", comment_header->method); |
|
1516 | 1527 |
|
1528 |
+ if ((comment_header->unpack_ver < 15) || (comment_header->unpack_ver > 29) || |
|
1529 |
+ (comment_header->method > 0x30)) { |
|
1530 |
+ cli_dbgmsg("Can't process file comment - skipping\n"); |
|
1531 |
+ } else { |
|
1532 |
+ snprintf(filename, 1024, "%s/%lu.cmt", dirname, file_count); |
|
1533 |
+ ofd = open(filename, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0600); |
|
1534 |
+ if (ofd < 0) { |
|
1535 |
+ free(comment_header); |
|
1536 |
+ cli_dbgmsg("ERROR: Failed to open output file\n"); |
|
1537 |
+ } else { |
|
1538 |
+ cli_dbgmsg("Copying file comment (not packed)\n"); |
|
1539 |
+ copy_file_data(fd, ofd, comment_header->unpack_size); |
|
1540 |
+ close(ofd); |
|
1541 |
+ } |
|
1542 |
+ } |
|
1543 |
+ free(comment_header); |
|
1544 |
+ } |
|
1545 |
+ } |
|
1546 |
+ if (lseek(fd, file_header->start_offset+file_header->head_size, SEEK_SET) != |
|
1547 |
+ file_header->start_offset+file_header->head_size) { |
|
1548 |
+ cli_dbgmsg("Seek failed: %ld\n", offset+file_header->head_size); |
|
1549 |
+ free(file_header->filename); |
|
1550 |
+ free(file_header); |
|
1551 |
+ break; |
|
1552 |
+ } |
|
1517 | 1553 |
if (file_header->flags & LHD_PASSWORD) { |
1518 | 1554 |
cli_dbgmsg("PASSWORDed file: %s\n", file_header->filename); |
1519 | 1555 |
metadata_tail->encrypted = TRUE; |
1520 | 1556 |
} else /*if (file_header->unpack_size)*/ { |
1521 | 1557 |
snprintf(filename, 1024, "%s/%lu.ura", dirname, file_count); |
1522 |
- ofd = open(filename, O_WRONLY|O_CREAT|O_TRUNC, 0600); |
|
1558 |
+ ofd = open(filename, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0600); |
|
1523 | 1559 |
if (ofd < 0) { |
1524 | 1560 |
free(file_header->filename); |
1525 | 1561 |
free(file_header); |
... | ... |
@@ -29,7 +29,6 @@ |
29 | 29 |
#include <unistd.h> |
30 | 30 |
#endif |
31 | 31 |
|
32 |
-/* #define RAR_DEBUG */ |
|
33 | 32 |
/* #define RAR_HIGH_DEBUG */ |
34 | 33 |
|
35 | 34 |
struct unpack_data_tag; |
... | ... |
@@ -144,6 +143,7 @@ typedef struct file_header_tag |
144 | 144 |
uint16_t name_size __attribute__ ((packed)); |
145 | 145 |
uint32_t file_attr __attribute__ ((packed)); |
146 | 146 |
unsigned char *filename __attribute__ ((packed)); |
147 |
+ off_t start_offset __attribute__ ((packed)); |
|
147 | 148 |
off_t next_offset __attribute__ ((packed)); |
148 | 149 |
} file_header_t; |
149 | 150 |
|
... | ... |
@@ -21,15 +21,11 @@ |
21 | 21 |
* MA 02110-1301, USA. |
22 | 22 |
*/ |
23 | 23 |
|
24 |
+#include <string.h> |
|
25 |
+ |
|
24 | 26 |
#include "unrar.h" |
25 | 27 |
#include "unrar20.h" |
26 | 28 |
|
27 |
-#ifdef RAR_DEBUG |
|
28 |
-#define cli_dbgmsg printf |
|
29 |
-#else |
|
30 |
-static void cli_dbgmsg(){}; |
|
31 |
-#endif |
|
32 |
- |
|
33 | 29 |
#ifdef RAR_HIGH_DEBUG |
34 | 30 |
#define rar_dbgmsg printf |
35 | 31 |
#else |
... | ... |
@@ -47,7 +43,7 @@ void unpack_init_data20(int solid, unpack_data_t *unpack_data) |
47 | 47 |
} |
48 | 48 |
} |
49 | 49 |
|
50 |
-static void copy_string20(unpack_data_t *unpack_data, int length, unsigned int distance) |
|
50 |
+static void copy_string20(unpack_data_t *unpack_data, unsigned int length, unsigned int distance) |
|
51 | 51 |
{ |
52 | 52 |
unsigned int dest_ptr; |
53 | 53 |
|
... | ... |
@@ -309,7 +305,7 @@ int rar_unpack20(int fd, int solid, unpack_data_t *unpack_data) |
309 | 309 |
if (unpack_data->in_addr > unpack_data->read_top-30) { |
310 | 310 |
if (!unp_read_buf(fd, unpack_data)) { |
311 | 311 |
cli_dbgmsg("unp_read_buf 2 failed\n"); |
312 |
- return FALSE; |
|
312 |
+ break; |
|
313 | 313 |
} |
314 | 314 |
} |
315 | 315 |
if (((unpack_data->wr_ptr - unpack_data->unp_ptr) & MAXWINMASK) < 270 && |
... | ... |
@@ -30,12 +30,7 @@ |
30 | 30 |
#include "unrar.h" |
31 | 31 |
#include "unrarvm.h" |
32 | 32 |
#include "unrarcmd.h" |
33 |
- |
|
34 |
-#ifdef RAR_DEBUG |
|
35 |
-#define cli_dbgmsg printf |
|
36 |
-#else |
|
37 |
-static void cli_dbgmsg(){}; |
|
38 |
-#endif |
|
33 |
+#include "others.h" |
|
39 | 34 |
|
40 | 35 |
#ifdef RAR_HIGH_DEBUG |
41 | 36 |
#define rar_dbgmsg printf |