1 /*
2 * Copyright (c) 1999 Sun Microsystems, Inc. All Rights Reserved.
3 *
4 * This software is the confidential and proprietary information of Sun
5 * Microsystems, Inc. ("Confidential Information"). You shall not
6 * disclose such Confidential Information and shall use it only in
7 * accordance with the terms of the license agreement you entered into
8 * with Sun.
9 *
10 * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
11 * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
12 * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
13 * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
14 * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
15 * THIS SOFTWARE OR ITS DERIVATIVES.
16 *
17 * Use is subject to license terms.
18 */
20 /*=========================================================================
21 * SYSTEM: KVM
22 * SUBSYSTEM: JAR file reader.
23 * FILE: jar.h
24 * OVERVIEW: Public header file for the JAR file reader module.
25 * The JAR DataStream API is used by the Pre-verifier for loading
26 * JAR files.
27 * AUTHOR: Tasneem Sayeed
28 *=======================================================================*/
30 #ifndef _JAR_H_
31 #define _JAR_H_
39 /*
40 * Debug flag for JAR support
41 */
42 #define JAR_DEBUG 0
44 /*=========================================================================
45 * JAR file reader defines and macros
46 *=======================================================================*/
48 /*
49 * Supported compression types
50 */
51 #define STORED 0
52 #define DEFLATED 8
56 /*
57 * Header sizes including signatures
58 */
59 #define LOCHDRSIZ 30
60 #define CENHDRSIZ 46
61 #define ENDHDRSIZ 22
63 /*
64 * Header field access macros
65 */
66 #define CH(b, n) ((long)(((unsigned char *)(b))[n]))
67 #define SH(b, n) ((long)(CH(b, n) | (CH(b, n+1) << 8)))
68 #define LG(b, n) ((long)(SH(b, n) | (SH(b, n+2) << 16)))
76 #define freeBytes(x) if (x == NULL) {} else free(x)
79 /*
80 * Macros for getting local file header (LOC) fields
81 */
92 /*
93 * Macros for getting central directory header (CEN) fields
94 */
111 /*
112 * Macros for getting end of central directory header (END) fields
113 */
120 /*=========================================================================
121 * Macros for Huffman Codes used by the JAR file reader
122 *=======================================================================*/
124 /*
125 * This is the algorithm for decoding Huffman-encoded
126 * data.
127 *
128 * loop (until end of block code recognized)
129 * decode literal/length value from input stream
130 * if value < 256
131 * copy value (literal byte) to output stream
132 * otherwise
133 * if value = end of block (256)
134 * break from loop
135 * otherwise (value = 257..285)
136 * decode distance from input stream
137 *
138 * move backwards distance bytes in the output
139 * stream, and copy length bytes from this
140 * position to the output stream.
141 * end loop
142 */
143 #define BTYPE_NO_COMPRESSION 0x00
148 #define LITXLEN_BASE 257
151 /*=========================================================================
152 * JAR DataStream API for reading and writing to/from JAR files
153 *=======================================================================*/
159 /*=========================================================================
160 * JAR Data Stream structure
161 *=======================================================================*/
168 /* mode must be either JAR_READ or JAR_WRITE */
173 /*=========================================================================
174 * Forward declarations for JAR DataStream API
175 *=======================================================================*/
180 /*=========================================================================
181 * Forward declarations for JAR file reader
182 *=======================================================================*/
187 /*
188 typedef const unsigned char *JarCompressedType;
189 */
194 /* Any caller to inflate must ensure that it is safe to read at least
195 * this many bytes beyond compData + compLen
196 */
197 #define INFLATER_EXTRA_BYTES 4
200 /*
201 * Indicates whether JAR inflater is executed from KVM or a stand-alone
202 * program.
203 */
204 #define JAR_INFLATER_INSIDE_KVM 0