#include <config.h>#include "tailor.h"#include "gzip.h"#include "crypt.h"Go to the source code of this file.
Defines | |
| #define | LOCSIG 0x04034b50L |
| #define | LOCFLG 6 |
| #define | CRPFLG 1 |
| #define | EXTFLG 8 |
| #define | LOCHOW 8 |
| #define | LOCTIM 10 |
| #define | LOCCRC 14 |
| #define | LOCSIZ 18 |
| #define | LOCLEN 22 |
| #define | LOCFIL 26 |
| #define | LOCEXT 28 |
| #define | LOCHDR 30 |
| #define | EXTHDR 16 |
| #define | RAND_HEAD_LEN 12 |
Functions | |
| int | check_zipfile (int in) |
| int | unzip (int in, int out) |
Variables | |
| int | decrypt |
| char * | key |
| int | pkzip = 0 |
| int | ext_header = 0 |
|
|
Definition at line 43 of file unzip.c. Referenced by check_zipfile(). |
|
|
Definition at line 44 of file unzip.c. Referenced by check_zipfile(). |
|
|
Definition at line 53 of file unzip.c. Referenced by unzip(). |
|
|
Definition at line 47 of file unzip.c. Referenced by unzip(). |
|
|
Definition at line 51 of file unzip.c. Referenced by check_zipfile(). |
|
|
Definition at line 50 of file unzip.c. Referenced by check_zipfile(). |
|
|
Definition at line 42 of file unzip.c. Referenced by check_zipfile(). |
|
|
Definition at line 52 of file unzip.c. Referenced by check_zipfile(). |
|
|
Definition at line 45 of file unzip.c. Referenced by check_zipfile(). |
|
|
Definition at line 49 of file unzip.c. Referenced by unzip(). |
|
|
Definition at line 41 of file unzip.c. Referenced by check_zipfile(), and unzip(). |
|
|
Definition at line 48 of file unzip.c. Referenced by unzip(). |
|
|
|
|
|
|
|
|
Definition at line 68 of file unzip.c. References CRPFLG, decrypt, DEFLATED, ERROR, exit_code, ext_header, EXTFLG, ifd, ifname, inptr, insize, LG, LOCEXT, LOCFIL, LOCFLG, LOCHDR, LOCHOW, LOCSIG, method, OK, pkzip, program_name, SH, and STORED. Referenced by get_method(). 00070 { 00071 uch *h = inbuf + inptr; /* first local header */ 00072 00073 ifd = in; 00074 00075 /* Check validity of local header, and skip name and extra fields */ 00076 inptr += LOCHDR + SH(h + LOCFIL) + SH(h + LOCEXT); 00077 00078 if (inptr > insize || LG(h) != LOCSIG) { 00079 fprintf(stderr, "\n%s: %s: not a valid zip file\n", 00080 program_name, ifname); 00081 exit_code = ERROR; 00082 return ERROR; 00083 } 00084 method = h[LOCHOW]; 00085 if (method != STORED && method != DEFLATED) { 00086 fprintf(stderr, 00087 "\n%s: %s: first entry not deflated or stored -- use unzip\n", 00088 program_name, ifname); 00089 exit_code = ERROR; 00090 return ERROR; 00091 } 00092 00093 /* If entry encrypted, decrypt and validate encryption header */ 00094 if ((decrypt = h[LOCFLG] & CRPFLG) != 0) { 00095 fprintf(stderr, "\n%s: %s: encrypted file -- use unzip\n", 00096 program_name, ifname); 00097 exit_code = ERROR; 00098 return ERROR; 00099 } 00100 00101 /* Save flags for unzip() */ 00102 ext_header = (h[LOCFLG] & EXTFLG) != 0; 00103 pkzip = 1; 00104 00105 /* Get ofname and time stamp from local header (to be done) */ 00106 return OK; 00107 }
|
|
||||||||||||
|
Definition at line 116 of file unzip.c. References abort_gzip(), bytes_out, decrypt, DEFLATED, ERROR, exit_code, ext_header, EXTHDR, flush_window(), get_byte, gzip_error(), ifd, ifname, inflate(), inptr, insize, LG, LOCCRC, LOCLEN, LOCSIG, LOCSIZ, method, NULL, ofd, OK, orig_len, pkzip, program_name, put_ubyte, RAND_HEAD_LEN, STORED, test, to_stdout, updcrc(), WARN, and xalloc_die(). Referenced by get_method(). 00118 { 00119 ulg orig_crc = 0; /* original crc */ 00120 ulg orig_len = 0; /* original uncompressed length */ 00121 int n; 00122 uch buf[EXTHDR]; /* extended local header */ 00123 int err = OK; 00124 00125 ifd = in; 00126 ofd = out; 00127 00128 updcrc(NULL, 0); /* initialize crc */ 00129 00130 if (pkzip && !ext_header) { /* crc and length at the end otherwise */ 00131 orig_crc = LG(inbuf + LOCCRC); 00132 orig_len = LG(inbuf + LOCLEN); 00133 } 00134 00135 /* Decompress */ 00136 if (method == DEFLATED) { 00137 00138 int res = inflate(); 00139 00140 if (res == 3) { 00141 xalloc_die (); 00142 } else if (res != 0) { 00143 gzip_error ("invalid compressed data--format violated"); 00144 } 00145 00146 } else if (pkzip && method == STORED) { 00147 00148 register ulg n = LG(inbuf + LOCLEN); 00149 00150 if (n != LG(inbuf + LOCSIZ) - (decrypt ? RAND_HEAD_LEN : 0)) { 00151 00152 fprintf(stderr, "len %ld, siz %ld\n", n, LG(inbuf + LOCSIZ)); 00153 gzip_error ("invalid compressed data--length mismatch"); 00154 } 00155 while (n--) { 00156 uch c = (uch)get_byte(); 00157 put_ubyte(c); 00158 } 00159 flush_window(); 00160 } else { 00161 gzip_error ("internal error, invalid method"); 00162 } 00163 00164 /* Get the crc and original length */ 00165 if (!pkzip) { 00166 /* crc32 (see algorithm.doc) 00167 * uncompressed input size modulo 2^32 00168 */ 00169 for (n = 0; n < 8; n++) { 00170 buf[n] = (uch)get_byte(); /* may cause an error if EOF */ 00171 } 00172 orig_crc = LG(buf); 00173 orig_len = LG(buf+4); 00174 00175 } else if (ext_header) { /* If extended header, check it */ 00176 /* signature - 4bytes: 0x50 0x4b 0x07 0x08 00177 * CRC-32 value 00178 * compressed size 4-bytes 00179 * uncompressed size 4-bytes 00180 */ 00181 for (n = 0; n < EXTHDR; n++) { 00182 buf[n] = (uch)get_byte(); /* may cause an error if EOF */ 00183 } 00184 orig_crc = LG(buf+4); 00185 orig_len = LG(buf+12); 00186 } 00187 00188 /* Validate decompression */ 00189 if (orig_crc != updcrc(outbuf, 0)) { 00190 fprintf(stderr, "\n%s: %s: invalid compressed data--crc error\n", 00191 program_name, ifname); 00192 err = ERROR; 00193 } 00194 if (orig_len != (ulg)(bytes_out & 0xffffffff)) { 00195 fprintf(stderr, "\n%s: %s: invalid compressed data--length error\n", 00196 program_name, ifname); 00197 err = ERROR; 00198 } 00199 00200 /* Check if there are more entries in a pkzip file */ 00201 if (pkzip && inptr + 4 < insize && LG(inbuf+inptr) == LOCSIG) { 00202 if (to_stdout) { 00203 WARN((stderr, 00204 "%s: %s has more than one entry--rest ignored\n", 00205 program_name, ifname)); 00206 } else { 00207 /* Don't destroy the input zip file */ 00208 fprintf(stderr, 00209 "%s: %s has more than one entry -- unchanged\n", 00210 program_name, ifname); 00211 err = ERROR; 00212 } 00213 } 00214 ext_header = pkzip = 0; /* for next file */ 00215 if (err == OK) return OK; 00216 exit_code = ERROR; 00217 if (!test) abort_gzip(); 00218 return err; 00219 }
|
|
|
Definition at line 59 of file unzip.c. Referenced by check_zipfile(), and unzip(). |
|
|
Definition at line 62 of file unzip.c. Referenced by check_zipfile(), and unzip(). |
|
|
Definition at line 60 of file unzip.c. Referenced by copy_block(). |
|
|
Definition at line 61 of file unzip.c. Referenced by check_zipfile(), and unzip(). |