1 /* 2 * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 #ifndef _MANIFEST_INFO_H 27 #define _MANIFEST_INFO_H 28 29 #include <sys/types.h> 30 31 /* 32 * Zip file header signatures 33 */ 34 #define SIGSIZ 4 /* size of all header signatures */ 35 36 #define PKZIP_SIGNATURE_AT(p, b2, b3) \ 37 (((p)[0] == 'P') & ((p)[1] == 'K') & ((p)[2] == b2) & ((p)[3] == b3)) 38 #define CENSIG_AT(p) PKZIP_SIGNATURE_AT(p, 1, 2) 39 #define LOCSIG_AT(p) PKZIP_SIGNATURE_AT(p, 3, 4) 40 #define ENDSIG_AT(p) PKZIP_SIGNATURE_AT(p, 5, 6) 41 #define EXTSIG_AT(p) PKZIP_SIGNATURE_AT(p, 7, 8) 42 #define ZIP64_ENDSIG_AT(p) PKZIP_SIGNATURE_AT(p, 6, 6) 43 #define ZIP64_LOCSIG_AT(p) PKZIP_SIGNATURE_AT(p, 6, 7) 44 45 /* 46 * Header sizes including signatures 47 */ 48 #define LOCHDR 30 49 #define EXTHDR 16 50 #define CENHDR 46 51 #define ENDHDR 22 52 53 #define ZIP64_ENDHDR 56 // ZIP64 end header size 54 #define ZIP64_LOCHDR 20 // ZIP64 end loc header size 55 #define ZIP64_EXTHDR 24 // EXT header size 56 #define ZIP64_EXTID 1 // Extra field Zip64 header ID 57 58 #define ZIP64_MAGICVAL 0xffffffffLL 59 #define ZIP64_MAGICCOUNT 0xffff 60 61 /* 62 * Header field access macros 63 */ 64 #define CH(b, n) (((unsigned char *)(b))[n]) 65 #define SH(b, n) (CH(b, n) | (CH(b, n+1) << 8)) 66 #define LG(b, n) ((SH(b, n) | (SH(b, n+2) << 16)) &0xffffffffUL) 67 #define LL(b, n) (((jlong)LG(b, n)) | (((jlong)LG(b, n+4)) << 32)) 68 #define GETSIG(b) LG(b, 0) 69 70 /* 71 * Macros for getting local file (LOC) header fields 72 */ 73 #define LOCVER(b) SH(b, 4) /* version needed to extract */ 74 #define LOCFLG(b) SH(b, 6) /* general purpose bit flags */ 75 #define LOCHOW(b) SH(b, 8) /* compression method */ 76 #define LOCTIM(b) LG(b, 10) /* modification time */ 77 #define LOCCRC(b) LG(b, 14) /* crc of uncompressed data */ 78 #define LOCSIZ(b) LG(b, 18) /* compressed data size */ 79 #define LOCLEN(b) LG(b, 22) /* uncompressed data size */ 80 #define LOCNAM(b) SH(b, 26) /* filename length */ 81 #define LOCEXT(b) SH(b, 28) /* extra field length */ 82 83 /* 84 * Macros for getting extra local (EXT) header fields 85 */ 86 #define EXTCRC(b) LG(b, 4) /* crc of uncompressed data */ 87 #define EXTSIZ(b) LG(b, 8) /* compressed size */ 88 #define EXTLEN(b) LG(b, 12) /* uncompressed size */ 89 90 /* 91 * Macros for getting central directory header (CEN) fields 92 */ 93 #define CENVEM(b) SH(b, 4) /* version made by */ 94 #define CENVER(b) SH(b, 6) /* version needed to extract */ 95 #define CENFLG(b) SH(b, 8) /* general purpose bit flags */ 96 #define CENHOW(b) SH(b, 10) /* compression method */ 97 #define CENTIM(b) LG(b, 12) /* modification time */ 98 #define CENCRC(b) LG(b, 16) /* crc of uncompressed data */ 99 #define CENSIZ(b) LG(b, 20) /* compressed size */ 100 #define CENLEN(b) LG(b, 24) /* uncompressed size */ 101 #define CENNAM(b) SH(b, 28) /* length of filename */ 102 #define CENEXT(b) SH(b, 30) /* length of extra field */ 103 #define CENCOM(b) SH(b, 32) /* file comment length */ 104 #define CENDSK(b) SH(b, 34) /* disk number start */ 105 #define CENATT(b) SH(b, 36) /* internal file attributes */ 106 #define CENATX(b) LG(b, 38) /* external file attributes */ 107 #define CENOFF(b) LG(b, 42) /* offset of local header */ 108 109 /* 110 * Macros for getting end of central directory header (END) fields 111 */ 112 #define ENDNMD(b) SH(b, 4) /* number of this disk */ 113 #define ENDDSK(b) SH(b, 6) /* disk number of start */ 114 #define ENDSUB(b) SH(b, 8) /* number of entries on this disk */ 115 #define ENDTOT(b) SH(b, 10) /* total number of entries */ 116 #define ENDSIZ(b) LG(b, 12) /* central directory size */ 117 #define ENDOFF(b) LG(b, 16) /* central directory offset */ 118 #define ENDCOM(b) SH(b, 20) /* size of zip file comment */ 119 120 /* 121 * Macros for getting Zip64 end of central directory header fields 122 */ 123 #define ZIP64_ENDLEN(b) LL(b, 4) /* size of zip64 end of central dir */ 124 #define ZIP64_ENDVEM(b) SH(b, 12) /* version made by */ 125 #define ZIP64_ENDVER(b) SH(b, 14) /* version needed to extract */ 126 #define ZIP64_ENDNMD(b) LG(b, 16) /* number of this disk */ 127 #define ZIP64_ENDDSK(b) LG(b, 20) /* disk number of start */ 128 #define ZIP64_ENDTOD(b) LL(b, 24) /* total number of entries on this disk */ 129 #define ZIP64_ENDTOT(b) LL(b, 32) /* total number of entries */ 130 #define ZIP64_ENDSIZ(b) LL(b, 40) /* central directory size in bytes */ 131 #define ZIP64_ENDOFF(b) LL(b, 48) /* offset of first CEN header */ 132 133 /* 134 * Macros for getting Zip64 end of central directory locator fields 135 */ 136 #define ZIP64_LOCDSK(b) LG(b, 4) /* disk number start */ 137 #define ZIP64_LOCOFF(b) LL(b, 8) /* offset of zip64 end */ 138 #define ZIP64_LOCTOT(b) LG(b, 16) /* total number of disks */ 139 140 /* 141 * A comment of maximum length of 64kb can follow the END record. This 142 * is the furthest the END record can be from the end of the file. 143 */ 144 #define END_MAXLEN (0xFFFF + ENDHDR) 145 146 /* 147 * Supported compression methods. 148 */ 149 #define STORED 0 150 #define DEFLATED 8 151 152 /* 153 * Information from the CEN entry to inflate a file. 154 */ 155 typedef struct zentry { /* Zip file entry */ 156 size_t isize; /* size of inflated data */ 157 size_t csize; /* size of compressed data (zero if uncompressed) */ 158 jlong offset; /* position of compressed data */ 159 int how; /* compression method (if any) */ 160 } zentry; 161 162 /* 163 * Information returned from the Manifest file by the ParseManifest() routine. 164 * Certainly (much) more could be returned, but this is the information 165 * currently of interest to the C based Java utilities (particularly the 166 * Java launcher). 167 */ 168 typedef struct manifest_info { /* Interesting fields from the Manifest */ 169 char *manifest_version; /* Manifest-Version string */ 170 char *main_class; /* Main-Class entry */ 171 char *jre_version; /* Appropriate J2SE release spec */ 172 char jre_restrict_search; /* Restricted JRE search */ 173 char *splashscreen_image_file_name; /* splashscreen image file */ 174 } manifest_info; 175 176 /* 177 * Attribute closure to provide to manifest_iterate. 178 */ 179 typedef void (*attribute_closure)(const char *name, const char *value, 180 void *user_data); 181 182 /* 183 * Function prototypes. 184 */ 185 int JLI_ParseManifest(char *jarfile, manifest_info *info); 186 void *JLI_JarUnpackFile(const char *jarfile, const char *filename, 187 int *size); 188 void JLI_FreeManifest(void); 189 int JLI_ManifestIterate(const char *jarfile, attribute_closure ac, 190 void *user_data); 191 192 #endif /* _MANIFEST_INFO_H */