2
|
1 |
/*
|
|
2 |
* Copyright 2002-2005 Sun Microsystems, Inc. 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. Sun designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
23 |
* have any questions.
|
|
24 |
*/
|
|
25 |
|
|
26 |
// -*- C++ -*-
|
|
27 |
// Small program for unpacking specially compressed Java packages.
|
|
28 |
// John R. Rose
|
|
29 |
|
|
30 |
#include <sys/types.h>
|
|
31 |
|
|
32 |
#include <stdio.h>
|
|
33 |
#include <string.h>
|
|
34 |
#include <stdlib.h>
|
|
35 |
#include <stdarg.h>
|
|
36 |
|
|
37 |
#include "defines.h"
|
|
38 |
#include "bytes.h"
|
|
39 |
#include "utils.h"
|
|
40 |
#include "coding.h"
|
|
41 |
#include "bands.h"
|
|
42 |
|
|
43 |
#include "constants.h"
|
|
44 |
#include "unpack.h"
|
|
45 |
|
|
46 |
inline void band::abort(const char* msg) { u->abort(msg); }
|
|
47 |
inline bool band::aborting() { return u->aborting(); }
|
|
48 |
|
|
49 |
void band::readData(int expectedLength) {
|
|
50 |
CHECK;
|
|
51 |
assert(expectedLength >= 0);
|
|
52 |
assert(vs[0].cmk == cmk_ERROR);
|
|
53 |
if (expectedLength != 0) {
|
|
54 |
assert(length == 0);
|
|
55 |
length = expectedLength;
|
|
56 |
}
|
|
57 |
if (length == 0) {
|
|
58 |
assert((rplimit = cm.vs0.rp = u->rp) != null);
|
|
59 |
return;
|
|
60 |
}
|
|
61 |
assert(length > 0);
|
|
62 |
|
|
63 |
bool is_BYTE1 = (defc->spec == BYTE1_spec);
|
|
64 |
|
|
65 |
if (is_BYTE1) {
|
|
66 |
// No possibility of coding change. Sizing is exact.
|
|
67 |
u->ensure_input(length);
|
|
68 |
} else {
|
|
69 |
// Make a conservatively generous estimate of band size in bytes.
|
|
70 |
// Assume B == 5 everywhere.
|
|
71 |
// Assume awkward pop with all {U} values (2*5 per value)
|
|
72 |
jlong generous = (jlong) length * (B_MAX*3+1) + C_SLOP;
|
|
73 |
u->ensure_input(generous);
|
|
74 |
}
|
|
75 |
|
|
76 |
// Read one value to see what it might be.
|
|
77 |
int XB = _meta_default;
|
|
78 |
int cp1 = 0, cp2 = 0;
|
|
79 |
if (!is_BYTE1) {
|
|
80 |
// must be a variable-length coding
|
|
81 |
assert(defc->B() > 1 && defc->L() > 0);
|
|
82 |
// must have already read from previous band:
|
|
83 |
assert(bn >= BAND_LIMIT || bn <= 0
|
|
84 |
|| bn == e_cp_Utf8_big_chars
|
|
85 |
|| endsWith(name, "_lo") // preceded by _hi conditional band
|
|
86 |
|| bn == e_file_options // preceded by conditional band
|
|
87 |
|| u->rp == u->all_bands[bn-1].maxRP()
|
|
88 |
|| u->all_bands[bn-1].defc == null);
|
|
89 |
|
|
90 |
value_stream xvs;
|
|
91 |
coding* valc = defc;
|
|
92 |
if (valc->D() != 0) {
|
|
93 |
valc = coding::findBySpec(defc->B(), defc->H(), defc->S());
|
|
94 |
assert(!valc->isMalloc);
|
|
95 |
}
|
|
96 |
xvs.init(u->rp, u->rplimit, valc);
|
|
97 |
int X = xvs.getInt();
|
|
98 |
if (valc->S() != 0) {
|
|
99 |
assert(valc->min <= -256);
|
|
100 |
XB = -1-X;
|
|
101 |
} else {
|
|
102 |
int L = valc->L();
|
|
103 |
assert(valc->max >= L+255);
|
|
104 |
XB = X-L;
|
|
105 |
}
|
|
106 |
if (0 <= XB && XB < 256) {
|
|
107 |
// Skip over the escape value.
|
|
108 |
u->rp = xvs.rp;
|
|
109 |
cp1 = 1;
|
|
110 |
} else {
|
|
111 |
// No, it's still default.
|
|
112 |
XB = _meta_default;
|
|
113 |
}
|
|
114 |
}
|
|
115 |
|
|
116 |
if (XB <= _meta_canon_max) {
|
|
117 |
byte XB_byte = (byte) XB;
|
|
118 |
byte* XB_ptr = &XB_byte;
|
|
119 |
cm.init(u->rp, u->rplimit, XB_ptr, 0, defc, length, null);
|
|
120 |
} else {
|
|
121 |
NOT_PRODUCT(byte* meta_rp0 = u->meta_rp);
|
|
122 |
assert(u->meta_rp != null);
|
|
123 |
// Scribble the initial byte onto the band.
|
|
124 |
byte* save_meta_rp = --u->meta_rp;
|
|
125 |
byte save_meta_xb = (*save_meta_rp);
|
|
126 |
(*save_meta_rp) = (byte) XB;
|
|
127 |
cm.init(u->rp, u->rplimit, u->meta_rp, 0, defc, length, null);
|
|
128 |
(*save_meta_rp) = save_meta_xb; // put it back, just to be tidy
|
|
129 |
NOT_PRODUCT(cp2 = (u->meta_rp - meta_rp0));
|
|
130 |
}
|
|
131 |
rplimit = u->rp;
|
|
132 |
|
|
133 |
rewind();
|
|
134 |
|
|
135 |
#ifndef PRODUCT
|
|
136 |
printcr(3,"readFrom %s at %p [%d values, %d bytes, cp=%d/%d]",
|
|
137 |
(name?name:"(band)"), minRP(), length, size(), cp1, cp2);
|
|
138 |
if (u->verbose_bands || u->verbose >= 4) dump();
|
|
139 |
|
|
140 |
if (ix != null && u->verbose != 0 && length > 0) {
|
|
141 |
// Check referential integrity early, for easier debugging.
|
|
142 |
band saved = (*this); // save state
|
|
143 |
for (int i = 0; i < length; i++) {
|
|
144 |
int n = vs[0].getInt() - nullOK;
|
|
145 |
entry *ref = ix->get(n);
|
|
146 |
assert(ref != null || n == -1);
|
|
147 |
}
|
|
148 |
(*this) = saved;
|
|
149 |
}
|
|
150 |
#endif
|
|
151 |
}
|
|
152 |
|
|
153 |
#ifndef PRODUCT
|
|
154 |
void band::dump() {
|
|
155 |
band saved = (*this); // save state
|
|
156 |
const char* b_name = name;
|
|
157 |
char b_name_buf[100];
|
|
158 |
if (b_name == null) {
|
|
159 |
char* bp = &b_name_buf[0];
|
|
160 |
b_name = bp;
|
|
161 |
sprintf(bp, "#%d/%d", bn, le_kind); bp += strlen(bp);
|
|
162 |
if (le_bci != 0) { sprintf(bp, "/bci%d", le_bci); bp += strlen(bp); }
|
|
163 |
if (le_back != 0) { sprintf(bp, "/back%d", le_back); bp += strlen(bp); }
|
|
164 |
if (le_len != 0) { sprintf(bp, "/len%d", le_len); bp += strlen(bp); }
|
|
165 |
}
|
|
166 |
fprintf(u->errstrm, "band %s[%d]%s", b_name, length, (length==0?"\n":" {"));
|
|
167 |
if (length > 0) {
|
|
168 |
for (int i = 0; i < length; i++) {
|
|
169 |
const char* eol = (length > 10 && i % 10 == 0) ? "\n" : " ";
|
|
170 |
fprintf(u->errstrm, "%s%d", eol, vs[0].getInt());
|
|
171 |
}
|
|
172 |
fprintf(u->errstrm, " }\n");
|
|
173 |
}
|
|
174 |
(*this) = saved;
|
|
175 |
}
|
|
176 |
#endif
|
|
177 |
|
|
178 |
void band::setIndex(cpindex* ix_) {
|
|
179 |
assert(ix_ == null || ixTag == ix_->ixTag);
|
|
180 |
ix = ix_;
|
|
181 |
}
|
|
182 |
void band::setIndexByTag(byte tag) {
|
|
183 |
setIndex(u->cp.getIndex(tag));
|
|
184 |
}
|
|
185 |
|
|
186 |
entry* band::getRefCommon(cpindex* ix_, bool nullOKwithCaller) {
|
|
187 |
CHECK_0;
|
|
188 |
assert(ix_->ixTag == ixTag
|
|
189 |
|| (ixTag == CONSTANT_Literal
|
|
190 |
&& ix_->ixTag >= CONSTANT_Integer
|
|
191 |
&& ix_->ixTag <= CONSTANT_String));
|
|
192 |
int n = vs[0].getInt() - nullOK;
|
|
193 |
// Note: band-local nullOK means null encodes as 0.
|
|
194 |
// But nullOKwithCaller means caller is willing to tolerate a null.
|
|
195 |
entry *ref = ix_->get(n);
|
|
196 |
if (ref == null && !(nullOKwithCaller && n == -1))
|
|
197 |
abort(n == -1 ? "null ref" : "bad ref");
|
|
198 |
return ref;
|
|
199 |
}
|
|
200 |
|
|
201 |
jlong band::getLong(band& lo_band, bool have_hi) {
|
|
202 |
band& hi_band = (*this);
|
|
203 |
assert(lo_band.bn == hi_band.bn + 1);
|
|
204 |
uint lo = lo_band.getInt();
|
|
205 |
if (!have_hi) {
|
|
206 |
assert(hi_band.length == 0);
|
|
207 |
return makeLong(0, lo);
|
|
208 |
}
|
|
209 |
uint hi = hi_band.getInt();
|
|
210 |
return makeLong(hi, lo);
|
|
211 |
}
|
|
212 |
|
|
213 |
int band::getIntTotal() {
|
|
214 |
CHECK_0;
|
|
215 |
if (length == 0) return 0;
|
|
216 |
if (total_memo > 0) return total_memo-1;
|
|
217 |
int total = getInt();
|
|
218 |
for (int k = length-1; k > 0; k--) {
|
|
219 |
total += vs[0].getInt();
|
|
220 |
}
|
|
221 |
rewind();
|
|
222 |
total_memo = total+1;
|
|
223 |
return total;
|
|
224 |
}
|
|
225 |
|
|
226 |
int band::getIntCount(int tag) {
|
|
227 |
CHECK_0;
|
|
228 |
if (length == 0) return 0;
|
|
229 |
if (tag >= HIST0_MIN && tag <= HIST0_MAX) {
|
|
230 |
if (hist0 == null) {
|
|
231 |
// Lazily calculate an approximate histogram.
|
|
232 |
hist0 = U_NEW(int, (HIST0_MAX - HIST0_MIN)+1);
|
|
233 |
CHECK_0;
|
|
234 |
for (int k = length; k > 0; k--) {
|
|
235 |
int x = vs[0].getInt();
|
|
236 |
if (x >= HIST0_MIN && x <= HIST0_MAX)
|
|
237 |
hist0[x - HIST0_MIN] += 1;
|
|
238 |
}
|
|
239 |
rewind();
|
|
240 |
}
|
|
241 |
return hist0[tag - HIST0_MIN];
|
|
242 |
}
|
|
243 |
int total = 0;
|
|
244 |
for (int k = length; k > 0; k--) {
|
|
245 |
total += (vs[0].getInt() == tag) ? 1 : 0;
|
|
246 |
}
|
|
247 |
rewind();
|
|
248 |
return total;
|
|
249 |
}
|
|
250 |
|
|
251 |
#define INDEX_INIT(tag, nullOK, subindex) \
|
|
252 |
((tag) + (subindex)*SUBINDEX_BIT + (nullOK)*256)
|
|
253 |
|
|
254 |
#define INDEX(tag) INDEX_INIT(tag, 0, 0)
|
|
255 |
#define NULL_OR_INDEX(tag) INDEX_INIT(tag, 1, 0)
|
|
256 |
#define SUB_INDEX(tag) INDEX_INIT(tag, 0, 1)
|
|
257 |
#define NO_INDEX 0
|
|
258 |
|
|
259 |
struct band_init {
|
|
260 |
#ifndef PRODUCT
|
|
261 |
int bn;
|
|
262 |
const char* name;
|
|
263 |
#endif
|
|
264 |
int defc;
|
|
265 |
int index;
|
|
266 |
};
|
|
267 |
|
|
268 |
#ifdef PRODUCT
|
|
269 |
#define BAND_INIT(name, cspec, ix) \
|
|
270 |
{ cspec, ix }
|
|
271 |
#else
|
|
272 |
#define BAND_INIT(name, cspec, ix) \
|
|
273 |
{ e_##name, #name, /*debug only*/ \
|
|
274 |
cspec, ix }
|
|
275 |
#endif
|
|
276 |
|
|
277 |
const band_init all_band_inits[] = {
|
|
278 |
//BAND_INIT(archive_magic, BYTE1_spec, 0),
|
|
279 |
//BAND_INIT(archive_header, UNSIGNED5_spec, 0),
|
|
280 |
//BAND_INIT(band_headers, BYTE1_spec, 0),
|
|
281 |
BAND_INIT(cp_Utf8_prefix, DELTA5_spec, 0),
|
|
282 |
BAND_INIT(cp_Utf8_suffix, UNSIGNED5_spec, 0),
|
|
283 |
BAND_INIT(cp_Utf8_chars, CHAR3_spec, 0),
|
|
284 |
BAND_INIT(cp_Utf8_big_suffix, DELTA5_spec, 0),
|
|
285 |
BAND_INIT(cp_Utf8_big_chars, DELTA5_spec, 0),
|
|
286 |
BAND_INIT(cp_Int, UDELTA5_spec, 0),
|
|
287 |
BAND_INIT(cp_Float, UDELTA5_spec, 0),
|
|
288 |
BAND_INIT(cp_Long_hi, UDELTA5_spec, 0),
|
|
289 |
BAND_INIT(cp_Long_lo, DELTA5_spec, 0),
|
|
290 |
BAND_INIT(cp_Double_hi, UDELTA5_spec, 0),
|
|
291 |
BAND_INIT(cp_Double_lo, DELTA5_spec, 0),
|
|
292 |
BAND_INIT(cp_String, UDELTA5_spec, INDEX(CONSTANT_Utf8)),
|
|
293 |
BAND_INIT(cp_Class, UDELTA5_spec, INDEX(CONSTANT_Utf8)),
|
|
294 |
BAND_INIT(cp_Signature_form, DELTA5_spec, INDEX(CONSTANT_Utf8)),
|
|
295 |
BAND_INIT(cp_Signature_classes, UDELTA5_spec, INDEX(CONSTANT_Class)),
|
|
296 |
BAND_INIT(cp_Descr_name, DELTA5_spec, INDEX(CONSTANT_Utf8)),
|
|
297 |
BAND_INIT(cp_Descr_type, UDELTA5_spec, INDEX(CONSTANT_Signature)),
|
|
298 |
BAND_INIT(cp_Field_class, DELTA5_spec, INDEX(CONSTANT_Class)),
|
|
299 |
BAND_INIT(cp_Field_desc, UDELTA5_spec, INDEX(CONSTANT_NameandType)),
|
|
300 |
BAND_INIT(cp_Method_class, DELTA5_spec, INDEX(CONSTANT_Class)),
|
|
301 |
BAND_INIT(cp_Method_desc, UDELTA5_spec, INDEX(CONSTANT_NameandType)),
|
|
302 |
BAND_INIT(cp_Imethod_class, DELTA5_spec, INDEX(CONSTANT_Class)),
|
|
303 |
BAND_INIT(cp_Imethod_desc, UDELTA5_spec, INDEX(CONSTANT_NameandType)),
|
|
304 |
BAND_INIT(attr_definition_headers, BYTE1_spec, 0),
|
|
305 |
BAND_INIT(attr_definition_name, UNSIGNED5_spec, INDEX(CONSTANT_Utf8)),
|
|
306 |
BAND_INIT(attr_definition_layout, UNSIGNED5_spec, INDEX(CONSTANT_Utf8)),
|
|
307 |
BAND_INIT(ic_this_class, UDELTA5_spec, INDEX(CONSTANT_Class)),
|
|
308 |
BAND_INIT(ic_flags, UNSIGNED5_spec, 0),
|
|
309 |
BAND_INIT(ic_outer_class, DELTA5_spec, NULL_OR_INDEX(CONSTANT_Class)),
|
|
310 |
BAND_INIT(ic_name, DELTA5_spec, NULL_OR_INDEX(CONSTANT_Utf8)),
|
|
311 |
BAND_INIT(class_this, DELTA5_spec, INDEX(CONSTANT_Class)),
|
|
312 |
BAND_INIT(class_super, DELTA5_spec, INDEX(CONSTANT_Class)),
|
|
313 |
BAND_INIT(class_interface_count, DELTA5_spec, 0),
|
|
314 |
BAND_INIT(class_interface, DELTA5_spec, INDEX(CONSTANT_Class)),
|
|
315 |
BAND_INIT(class_field_count, DELTA5_spec, 0),
|
|
316 |
BAND_INIT(class_method_count, DELTA5_spec, 0),
|
|
317 |
BAND_INIT(field_descr, DELTA5_spec, INDEX(CONSTANT_NameandType)),
|
|
318 |
BAND_INIT(field_flags_hi, UNSIGNED5_spec, 0),
|
|
319 |
BAND_INIT(field_flags_lo, UNSIGNED5_spec, 0),
|
|
320 |
BAND_INIT(field_attr_count, UNSIGNED5_spec, 0),
|
|
321 |
BAND_INIT(field_attr_indexes, UNSIGNED5_spec, 0),
|
|
322 |
BAND_INIT(field_attr_calls, UNSIGNED5_spec, 0),
|
|
323 |
BAND_INIT(field_ConstantValue_KQ, UNSIGNED5_spec, INDEX(CONSTANT_Literal)),
|
|
324 |
BAND_INIT(field_Signature_RS, UNSIGNED5_spec, INDEX(CONSTANT_Signature)),
|
|
325 |
BAND_INIT(field_metadata_bands, -1, -1),
|
|
326 |
BAND_INIT(field_attr_bands, -1, -1),
|
|
327 |
BAND_INIT(method_descr, MDELTA5_spec, INDEX(CONSTANT_NameandType)),
|
|
328 |
BAND_INIT(method_flags_hi, UNSIGNED5_spec, 0),
|
|
329 |
BAND_INIT(method_flags_lo, UNSIGNED5_spec, 0),
|
|
330 |
BAND_INIT(method_attr_count, UNSIGNED5_spec, 0),
|
|
331 |
BAND_INIT(method_attr_indexes, UNSIGNED5_spec, 0),
|
|
332 |
BAND_INIT(method_attr_calls, UNSIGNED5_spec, 0),
|
|
333 |
BAND_INIT(method_Exceptions_N, UNSIGNED5_spec, 0),
|
|
334 |
BAND_INIT(method_Exceptions_RC, UNSIGNED5_spec, INDEX(CONSTANT_Class)),
|
|
335 |
BAND_INIT(method_Signature_RS, UNSIGNED5_spec, INDEX(CONSTANT_Signature)),
|
|
336 |
BAND_INIT(method_metadata_bands, -1, -1),
|
|
337 |
BAND_INIT(method_attr_bands, -1, -1),
|
|
338 |
BAND_INIT(class_flags_hi, UNSIGNED5_spec, 0),
|
|
339 |
BAND_INIT(class_flags_lo, UNSIGNED5_spec, 0),
|
|
340 |
BAND_INIT(class_attr_count, UNSIGNED5_spec, 0),
|
|
341 |
BAND_INIT(class_attr_indexes, UNSIGNED5_spec, 0),
|
|
342 |
BAND_INIT(class_attr_calls, UNSIGNED5_spec, 0),
|
|
343 |
BAND_INIT(class_SourceFile_RUN, UNSIGNED5_spec, NULL_OR_INDEX(CONSTANT_Utf8)),
|
|
344 |
BAND_INIT(class_EnclosingMethod_RC, UNSIGNED5_spec, INDEX(CONSTANT_Class)),
|
|
345 |
BAND_INIT(class_EnclosingMethod_RDN, UNSIGNED5_spec, NULL_OR_INDEX(CONSTANT_NameandType)),
|
|
346 |
BAND_INIT(class_Signature_RS, UNSIGNED5_spec, INDEX(CONSTANT_Signature)),
|
|
347 |
BAND_INIT(class_metadata_bands, -1, -1),
|
|
348 |
BAND_INIT(class_InnerClasses_N, UNSIGNED5_spec, 0),
|
|
349 |
BAND_INIT(class_InnerClasses_RC, UNSIGNED5_spec, INDEX(CONSTANT_Class)),
|
|
350 |
BAND_INIT(class_InnerClasses_F, UNSIGNED5_spec, 0),
|
|
351 |
BAND_INIT(class_InnerClasses_outer_RCN, UNSIGNED5_spec, NULL_OR_INDEX(CONSTANT_Class)),
|
|
352 |
BAND_INIT(class_InnerClasses_name_RUN, UNSIGNED5_spec, NULL_OR_INDEX(CONSTANT_Utf8)),
|
|
353 |
BAND_INIT(class_ClassFile_version_minor_H, UNSIGNED5_spec, 0),
|
|
354 |
BAND_INIT(class_ClassFile_version_major_H, UNSIGNED5_spec, 0),
|
|
355 |
BAND_INIT(class_attr_bands, -1, -1),
|
|
356 |
BAND_INIT(code_headers, BYTE1_spec, 0),
|
|
357 |
BAND_INIT(code_max_stack, UNSIGNED5_spec, 0),
|
|
358 |
BAND_INIT(code_max_na_locals, UNSIGNED5_spec, 0),
|
|
359 |
BAND_INIT(code_handler_count, UNSIGNED5_spec, 0),
|
|
360 |
BAND_INIT(code_handler_start_P, BCI5_spec, 0),
|
|
361 |
BAND_INIT(code_handler_end_PO, BRANCH5_spec, 0),
|
|
362 |
BAND_INIT(code_handler_catch_PO, BRANCH5_spec, 0),
|
|
363 |
BAND_INIT(code_handler_class_RCN, UNSIGNED5_spec, NULL_OR_INDEX(CONSTANT_Class)),
|
|
364 |
BAND_INIT(code_flags_hi, UNSIGNED5_spec, 0),
|
|
365 |
BAND_INIT(code_flags_lo, UNSIGNED5_spec, 0),
|
|
366 |
BAND_INIT(code_attr_count, UNSIGNED5_spec, 0),
|
|
367 |
BAND_INIT(code_attr_indexes, UNSIGNED5_spec, 0),
|
|
368 |
BAND_INIT(code_attr_calls, UNSIGNED5_spec, 0),
|
|
369 |
BAND_INIT(code_StackMapTable_N, UNSIGNED5_spec, 0),
|
|
370 |
BAND_INIT(code_StackMapTable_frame_T, BYTE1_spec, 0),
|
|
371 |
BAND_INIT(code_StackMapTable_local_N, UNSIGNED5_spec, 0),
|
|
372 |
BAND_INIT(code_StackMapTable_stack_N, UNSIGNED5_spec, 0),
|
|
373 |
BAND_INIT(code_StackMapTable_offset, UNSIGNED5_spec, 0),
|
|
374 |
BAND_INIT(code_StackMapTable_T, BYTE1_spec, 0),
|
|
375 |
BAND_INIT(code_StackMapTable_RC, UNSIGNED5_spec, INDEX(CONSTANT_Class)),
|
|
376 |
BAND_INIT(code_StackMapTable_P, BCI5_spec, 0),
|
|
377 |
BAND_INIT(code_LineNumberTable_N, UNSIGNED5_spec, 0),
|
|
378 |
BAND_INIT(code_LineNumberTable_bci_P, BCI5_spec, 0),
|
|
379 |
BAND_INIT(code_LineNumberTable_line, UNSIGNED5_spec, 0),
|
|
380 |
BAND_INIT(code_LocalVariableTable_N, UNSIGNED5_spec, 0),
|
|
381 |
BAND_INIT(code_LocalVariableTable_bci_P, BCI5_spec, 0),
|
|
382 |
BAND_INIT(code_LocalVariableTable_span_O, BRANCH5_spec, 0),
|
|
383 |
BAND_INIT(code_LocalVariableTable_name_RU, UNSIGNED5_spec, INDEX(CONSTANT_Utf8)),
|
|
384 |
BAND_INIT(code_LocalVariableTable_type_RS, UNSIGNED5_spec, INDEX(CONSTANT_Signature)),
|
|
385 |
BAND_INIT(code_LocalVariableTable_slot, UNSIGNED5_spec, 0),
|
|
386 |
BAND_INIT(code_LocalVariableTypeTable_N, UNSIGNED5_spec, 0),
|
|
387 |
BAND_INIT(code_LocalVariableTypeTable_bci_P, BCI5_spec, 0),
|
|
388 |
BAND_INIT(code_LocalVariableTypeTable_span_O, BRANCH5_spec, 0),
|
|
389 |
BAND_INIT(code_LocalVariableTypeTable_name_RU, UNSIGNED5_spec, INDEX(CONSTANT_Utf8)),
|
|
390 |
BAND_INIT(code_LocalVariableTypeTable_type_RS, UNSIGNED5_spec, INDEX(CONSTANT_Signature)),
|
|
391 |
BAND_INIT(code_LocalVariableTypeTable_slot, UNSIGNED5_spec, 0),
|
|
392 |
BAND_INIT(code_attr_bands, -1, -1),
|
|
393 |
BAND_INIT(bc_codes, BYTE1_spec, 0),
|
|
394 |
BAND_INIT(bc_case_count, UNSIGNED5_spec, 0),
|
|
395 |
BAND_INIT(bc_case_value, DELTA5_spec, 0),
|
|
396 |
BAND_INIT(bc_byte, BYTE1_spec, 0),
|
|
397 |
BAND_INIT(bc_short, DELTA5_spec, 0),
|
|
398 |
BAND_INIT(bc_local, UNSIGNED5_spec, 0),
|
|
399 |
BAND_INIT(bc_label, BRANCH5_spec, 0),
|
|
400 |
BAND_INIT(bc_intref, DELTA5_spec, INDEX(CONSTANT_Integer)),
|
|
401 |
BAND_INIT(bc_floatref, DELTA5_spec, INDEX(CONSTANT_Float)),
|
|
402 |
BAND_INIT(bc_longref, DELTA5_spec, INDEX(CONSTANT_Long)),
|
|
403 |
BAND_INIT(bc_doubleref, DELTA5_spec, INDEX(CONSTANT_Double)),
|
|
404 |
BAND_INIT(bc_stringref, DELTA5_spec, INDEX(CONSTANT_String)),
|
|
405 |
BAND_INIT(bc_classref, UNSIGNED5_spec, NULL_OR_INDEX(CONSTANT_Class)),
|
|
406 |
BAND_INIT(bc_fieldref, DELTA5_spec, INDEX(CONSTANT_Fieldref)),
|
|
407 |
BAND_INIT(bc_methodref, UNSIGNED5_spec, INDEX(CONSTANT_Methodref)),
|
|
408 |
BAND_INIT(bc_imethodref, DELTA5_spec, INDEX(CONSTANT_InterfaceMethodref)),
|
|
409 |
BAND_INIT(bc_thisfield, UNSIGNED5_spec, SUB_INDEX(CONSTANT_Fieldref)),
|
|
410 |
BAND_INIT(bc_superfield, UNSIGNED5_spec, SUB_INDEX(CONSTANT_Fieldref)),
|
|
411 |
BAND_INIT(bc_thismethod, UNSIGNED5_spec, SUB_INDEX(CONSTANT_Methodref)),
|
|
412 |
BAND_INIT(bc_supermethod, UNSIGNED5_spec, SUB_INDEX(CONSTANT_Methodref)),
|
|
413 |
BAND_INIT(bc_initref, UNSIGNED5_spec, SUB_INDEX(CONSTANT_Methodref)),
|
|
414 |
BAND_INIT(bc_escref, UNSIGNED5_spec, INDEX(CONSTANT_All)),
|
|
415 |
BAND_INIT(bc_escrefsize, UNSIGNED5_spec, 0),
|
|
416 |
BAND_INIT(bc_escsize, UNSIGNED5_spec, 0),
|
|
417 |
BAND_INIT(bc_escbyte, BYTE1_spec, 0),
|
|
418 |
BAND_INIT(file_name, UNSIGNED5_spec, INDEX(CONSTANT_Utf8)),
|
|
419 |
BAND_INIT(file_size_hi, UNSIGNED5_spec, 0),
|
|
420 |
BAND_INIT(file_size_lo, UNSIGNED5_spec, 0),
|
|
421 |
BAND_INIT(file_modtime, DELTA5_spec, 0),
|
|
422 |
BAND_INIT(file_options, UNSIGNED5_spec, 0),
|
|
423 |
//BAND_INIT(file_bits, BYTE1_spec, 0),
|
|
424 |
{0}
|
|
425 |
};
|
|
426 |
#define NUM_BAND_INITS \
|
|
427 |
(sizeof(all_band_inits)/sizeof(all_band_inits[0]))
|
|
428 |
|
|
429 |
band* band::makeBands(unpacker* u) {
|
|
430 |
band* all_bands = U_NEW(band, BAND_LIMIT);
|
|
431 |
for (int i = 0; i < BAND_LIMIT; i++) {
|
|
432 |
assert((byte*)&all_band_inits[i+1]
|
|
433 |
< (byte*)all_band_inits+sizeof(all_band_inits));
|
|
434 |
const band_init& bi = all_band_inits[i];
|
|
435 |
band& b = all_bands[i];
|
|
436 |
coding* defc = coding::findBySpec(bi.defc);
|
|
437 |
assert((defc == null) == (bi.defc == -1)); // no garbage, please
|
|
438 |
assert(defc == null || !defc->isMalloc);
|
|
439 |
assert(bi.bn == i); // band array consistent w/ band enum
|
|
440 |
b.init(u, i, defc);
|
|
441 |
if (bi.index > 0) {
|
|
442 |
b.nullOK = ((bi.index >> 8) & 1);
|
|
443 |
b.ixTag = (bi.index & 0xFF);
|
|
444 |
}
|
|
445 |
#ifndef PRODUCT
|
|
446 |
b.name = bi.name;
|
|
447 |
#endif
|
|
448 |
}
|
|
449 |
return all_bands;
|
|
450 |
}
|
|
451 |
|
|
452 |
void band::initIndexes(unpacker* u) {
|
|
453 |
band* all_bands = u->all_bands;
|
|
454 |
for (int i = 0; i < BAND_LIMIT; i++) {
|
|
455 |
band* scan = &all_bands[i];
|
|
456 |
uint tag = scan->ixTag; // Cf. #define INDEX(tag) above
|
|
457 |
if (tag != 0 && tag != CONSTANT_Literal && (tag & SUBINDEX_BIT) == 0) {
|
|
458 |
scan->setIndex(u->cp.getIndex(tag));
|
|
459 |
}
|
|
460 |
}
|
|
461 |
}
|