1 /*
2 * Copyright (c) 2001, 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
631 #endif
632 return;
633 }
634
635 // Read the magic number.
636 magic = 0;
637 for (int i1 = 0; i1 < (int)sizeof(magic); i1++) {
638 magic <<= 8;
639 magic += (*rp++ & 0xFF);
640 }
641
642 // Read the first 3 values from the header.
643 value_stream hdr;
644 int hdrVals = 0;
645 int hdrValsSkipped = 0; // for assert
646 hdr.init(rp, rplimit, UNSIGNED5_spec);
647 minver = hdr.getInt();
648 majver = hdr.getInt();
649 hdrVals += 2;
650
651 int majmin[3][2] = {
652 {JAVA5_PACKAGE_MAJOR_VERSION, JAVA5_PACKAGE_MINOR_VERSION},
653 {JAVA6_PACKAGE_MAJOR_VERSION, JAVA6_PACKAGE_MINOR_VERSION},
654 {JAVA7_PACKAGE_MAJOR_VERSION, JAVA7_PACKAGE_MINOR_VERSION}
655 };
656 int majminfound = false;
657 for (int i = 0 ; i < 3 ; i++) {
658 if (majver == majmin[i][0] && minver == majmin[i][1]) {
659 majminfound = true;
660 break;
661 }
662 }
663 if (majminfound == null) {
664 char message[200];
665 sprintf(message, "@" ERROR_FORMAT ": magic/ver = "
666 "%08X/%d.%d should be %08X/%d.%d OR %08X/%d.%d OR %08X/%d.%d\n",
667 magic, majver, minver,
668 JAVA_PACKAGE_MAGIC, JAVA5_PACKAGE_MAJOR_VERSION, JAVA5_PACKAGE_MINOR_VERSION,
669 JAVA_PACKAGE_MAGIC, JAVA6_PACKAGE_MAJOR_VERSION, JAVA6_PACKAGE_MINOR_VERSION,
670 JAVA_PACKAGE_MAGIC, JAVA7_PACKAGE_MAJOR_VERSION, JAVA7_PACKAGE_MINOR_VERSION);
671 abort(message);
672 }
673 CHECK;
674
675 archive_options = hdr.getInt();
676 hdrVals += 1;
677 assert(hdrVals == AH_LENGTH_0); // first three fields only
678 bool haveSizeHi = testBit(archive_options, AO_HAVE_FILE_SIZE_HI);
679 bool haveModTime = testBit(archive_options, AO_HAVE_FILE_MODTIME);
680 bool haveFileOpt = testBit(archive_options, AO_HAVE_FILE_OPTIONS);
681
682 bool haveSpecial = testBit(archive_options, AO_HAVE_SPECIAL_FORMATS);
683 bool haveFiles = testBit(archive_options, AO_HAVE_FILE_HEADERS);
684 bool haveNumbers = testBit(archive_options, AO_HAVE_CP_NUMBERS);
685 bool haveCPExtra = testBit(archive_options, AO_HAVE_CP_EXTRAS);
686
687 if (majver < JAVA7_PACKAGE_MAJOR_VERSION) {
688 if (haveCPExtra) {
689 abort("Format bits for Java 7 must be zero in previous releases");
690 return;
2464
2465 code_count = ad.predefCount(METHOD_ATTR_Code);
2466 // Code attrs are handled very specially below...
2467
2468 count = ad.predefCount(METHOD_ATTR_Exceptions);
2469 method_Exceptions_N.readData(count);
2470 count = method_Exceptions_N.getIntTotal();
2471 method_Exceptions_RC.readData(count);
2472 CHECK;
2473
2474 count = ad.predefCount(X_ATTR_Signature);
2475 method_Signature_RS.readData(count);
2476 CHECK;
2477
2478 ad.readBandData(X_ATTR_RuntimeVisibleAnnotations);
2479 ad.readBandData(X_ATTR_RuntimeInvisibleAnnotations);
2480 ad.readBandData(METHOD_ATTR_RuntimeVisibleParameterAnnotations);
2481 ad.readBandData(METHOD_ATTR_RuntimeInvisibleParameterAnnotations);
2482 ad.readBandData(METHOD_ATTR_AnnotationDefault);
2483 CHECK;
2484 break;
2485
2486 case ATTR_CONTEXT_CODE:
2487 // (keep this code aligned with its brother in unpacker::write_attrs)
2488 count = ad.predefCount(CODE_ATTR_StackMapTable);
2489 // disable this feature in old archives!
2490 if (count != 0 && majver < JAVA6_PACKAGE_MAJOR_VERSION) {
2491 abort("undefined StackMapTable attribute (old archive format)");
2492 return;
2493 }
2494 code_StackMapTable_N.readData(count);
2495 CHECK;
2496 count = code_StackMapTable_N.getIntTotal();
2497 code_StackMapTable_frame_T.readData(count);
2498 CHECK;
2499 // the rest of it depends in a complicated way on frame tags
2500 {
2501 int fat_frame_count = 0;
2502 int offset_count = 0;
2503 int type_count = 0;
4399 putref(class_EnclosingMethod_RDN.getRefN());
4400 break;
4401
4402 case ADH_BYTE(ATTR_CONTEXT_FIELD, FIELD_ATTR_ConstantValue):
4403 aname = cp.sym[cpool::s_ConstantValue];
4404 putref(field_ConstantValue_KQ.getRefUsing(cp.getKQIndex()));
4405 break;
4406
4407 case ADH_BYTE(ATTR_CONTEXT_METHOD, METHOD_ATTR_Code):
4408 aname = cp.sym[cpool::s_Code];
4409 write_code();
4410 break;
4411
4412 case ADH_BYTE(ATTR_CONTEXT_METHOD, METHOD_ATTR_Exceptions):
4413 aname = cp.sym[cpool::s_Exceptions];
4414 putu2(count = method_Exceptions_N.getInt());
4415 for (j = 0; j < count; j++) {
4416 putref(method_Exceptions_RC.getRefN());
4417 }
4418 break;
4419
4420 case ADH_BYTE(ATTR_CONTEXT_CODE, CODE_ATTR_StackMapTable):
4421 aname = cp.sym[cpool::s_StackMapTable];
4422 // (keep this code aligned with its brother in unpacker::read_attrs)
4423 putu2(count = code_StackMapTable_N.getInt());
4424 for (j = 0; j < count; j++) {
4425 int tag = code_StackMapTable_frame_T.getByte();
4426 putu1(tag);
4427 if (tag <= 127) {
4428 // (64-127) [(2)]
4429 if (tag >= 64) put_stackmap_type();
4430 } else if (tag <= 251) {
4431 // (247) [(1)(2)]
4432 // (248-251) [(1)]
4433 if (tag >= 247) putu2(code_StackMapTable_offset.getInt());
4434 if (tag == 247) put_stackmap_type();
4435 } else if (tag <= 254) {
4436 // (252) [(1)(2)]
4437 // (253) [(1)(2)(2)]
4438 // (254) [(1)(2)(2)(2)]
|
1 /*
2 * Copyright (c) 2001, 2013, 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
631 #endif
632 return;
633 }
634
635 // Read the magic number.
636 magic = 0;
637 for (int i1 = 0; i1 < (int)sizeof(magic); i1++) {
638 magic <<= 8;
639 magic += (*rp++ & 0xFF);
640 }
641
642 // Read the first 3 values from the header.
643 value_stream hdr;
644 int hdrVals = 0;
645 int hdrValsSkipped = 0; // for assert
646 hdr.init(rp, rplimit, UNSIGNED5_spec);
647 minver = hdr.getInt();
648 majver = hdr.getInt();
649 hdrVals += 2;
650
651 int majmin[4][2] = {
652 {JAVA5_PACKAGE_MAJOR_VERSION, JAVA5_PACKAGE_MINOR_VERSION},
653 {JAVA6_PACKAGE_MAJOR_VERSION, JAVA6_PACKAGE_MINOR_VERSION},
654 {JAVA7_PACKAGE_MAJOR_VERSION, JAVA7_PACKAGE_MINOR_VERSION},
655 {JAVA8_PACKAGE_MAJOR_VERSION, JAVA8_PACKAGE_MINOR_VERSION}
656 };
657 int majminfound = false;
658 for (int i = 0 ; i < 4 ; i++) {
659 if (majver == majmin[i][0] && minver == majmin[i][1]) {
660 majminfound = true;
661 break;
662 }
663 }
664 if (majminfound == null) {
665 char message[200];
666 sprintf(message, "@" ERROR_FORMAT ": magic/ver = "
667 "%08X/%d.%d should be %08X/%d.%d OR %08X/%d.%d OR %08X/%d.%d OR %08X/%d.%d\n",
668 magic, majver, minver,
669 JAVA_PACKAGE_MAGIC, JAVA5_PACKAGE_MAJOR_VERSION, JAVA5_PACKAGE_MINOR_VERSION,
670 JAVA_PACKAGE_MAGIC, JAVA6_PACKAGE_MAJOR_VERSION, JAVA6_PACKAGE_MINOR_VERSION,
671 JAVA_PACKAGE_MAGIC, JAVA7_PACKAGE_MAJOR_VERSION, JAVA7_PACKAGE_MINOR_VERSION,
672 JAVA_PACKAGE_MAGIC, JAVA8_PACKAGE_MAJOR_VERSION, JAVA8_PACKAGE_MINOR_VERSION);
673 abort(message);
674 }
675 CHECK;
676
677 archive_options = hdr.getInt();
678 hdrVals += 1;
679 assert(hdrVals == AH_LENGTH_0); // first three fields only
680 bool haveSizeHi = testBit(archive_options, AO_HAVE_FILE_SIZE_HI);
681 bool haveModTime = testBit(archive_options, AO_HAVE_FILE_MODTIME);
682 bool haveFileOpt = testBit(archive_options, AO_HAVE_FILE_OPTIONS);
683
684 bool haveSpecial = testBit(archive_options, AO_HAVE_SPECIAL_FORMATS);
685 bool haveFiles = testBit(archive_options, AO_HAVE_FILE_HEADERS);
686 bool haveNumbers = testBit(archive_options, AO_HAVE_CP_NUMBERS);
687 bool haveCPExtra = testBit(archive_options, AO_HAVE_CP_EXTRAS);
688
689 if (majver < JAVA7_PACKAGE_MAJOR_VERSION) {
690 if (haveCPExtra) {
691 abort("Format bits for Java 7 must be zero in previous releases");
692 return;
2466
2467 code_count = ad.predefCount(METHOD_ATTR_Code);
2468 // Code attrs are handled very specially below...
2469
2470 count = ad.predefCount(METHOD_ATTR_Exceptions);
2471 method_Exceptions_N.readData(count);
2472 count = method_Exceptions_N.getIntTotal();
2473 method_Exceptions_RC.readData(count);
2474 CHECK;
2475
2476 count = ad.predefCount(X_ATTR_Signature);
2477 method_Signature_RS.readData(count);
2478 CHECK;
2479
2480 ad.readBandData(X_ATTR_RuntimeVisibleAnnotations);
2481 ad.readBandData(X_ATTR_RuntimeInvisibleAnnotations);
2482 ad.readBandData(METHOD_ATTR_RuntimeVisibleParameterAnnotations);
2483 ad.readBandData(METHOD_ATTR_RuntimeInvisibleParameterAnnotations);
2484 ad.readBandData(METHOD_ATTR_AnnotationDefault);
2485 CHECK;
2486
2487 count = ad.predefCount(METHOD_ATTR_MethodParameters);
2488 method_MethodParameters_NB.readData(count);
2489 count = method_MethodParameters_NB.getIntTotal();
2490 method_MethodParameters_name_RUN.readData(count);
2491 method_MethodParameters_flag_I.readData(count);
2492 CHECK;
2493 break;
2494
2495 case ATTR_CONTEXT_CODE:
2496 // (keep this code aligned with its brother in unpacker::write_attrs)
2497 count = ad.predefCount(CODE_ATTR_StackMapTable);
2498 // disable this feature in old archives!
2499 if (count != 0 && majver < JAVA6_PACKAGE_MAJOR_VERSION) {
2500 abort("undefined StackMapTable attribute (old archive format)");
2501 return;
2502 }
2503 code_StackMapTable_N.readData(count);
2504 CHECK;
2505 count = code_StackMapTable_N.getIntTotal();
2506 code_StackMapTable_frame_T.readData(count);
2507 CHECK;
2508 // the rest of it depends in a complicated way on frame tags
2509 {
2510 int fat_frame_count = 0;
2511 int offset_count = 0;
2512 int type_count = 0;
4408 putref(class_EnclosingMethod_RDN.getRefN());
4409 break;
4410
4411 case ADH_BYTE(ATTR_CONTEXT_FIELD, FIELD_ATTR_ConstantValue):
4412 aname = cp.sym[cpool::s_ConstantValue];
4413 putref(field_ConstantValue_KQ.getRefUsing(cp.getKQIndex()));
4414 break;
4415
4416 case ADH_BYTE(ATTR_CONTEXT_METHOD, METHOD_ATTR_Code):
4417 aname = cp.sym[cpool::s_Code];
4418 write_code();
4419 break;
4420
4421 case ADH_BYTE(ATTR_CONTEXT_METHOD, METHOD_ATTR_Exceptions):
4422 aname = cp.sym[cpool::s_Exceptions];
4423 putu2(count = method_Exceptions_N.getInt());
4424 for (j = 0; j < count; j++) {
4425 putref(method_Exceptions_RC.getRefN());
4426 }
4427 break;
4428
4429 case ADH_BYTE(ATTR_CONTEXT_METHOD, METHOD_ATTR_MethodParameters):
4430 aname = cp.sym[cpool::s_MethodParameters];
4431 putu1(count = method_MethodParameters_NB.getByte());
4432 for (j = 0; j < count; j++) {
4433 putref(method_MethodParameters_name_RUN.getRefN());
4434 putu4(method_MethodParameters_flag_I.getInt());
4435 }
4436 break;
4437
4438 case ADH_BYTE(ATTR_CONTEXT_CODE, CODE_ATTR_StackMapTable):
4439 aname = cp.sym[cpool::s_StackMapTable];
4440 // (keep this code aligned with its brother in unpacker::read_attrs)
4441 putu2(count = code_StackMapTable_N.getInt());
4442 for (j = 0; j < count; j++) {
4443 int tag = code_StackMapTable_frame_T.getByte();
4444 putu1(tag);
4445 if (tag <= 127) {
4446 // (64-127) [(2)]
4447 if (tag >= 64) put_stackmap_type();
4448 } else if (tag <= 251) {
4449 // (247) [(1)(2)]
4450 // (248-251) [(1)]
4451 if (tag >= 247) putu2(code_StackMapTable_offset.getInt());
4452 if (tag == 247) put_stackmap_type();
4453 } else if (tag <= 254) {
4454 // (252) [(1)(2)]
4455 // (253) [(1)(2)(2)]
4456 // (254) [(1)(2)(2)(2)]
|