private static object ReadAnnotationElementValue(BigEndianBinaryReader rdr, ClassFile classFile) { byte tag = rdr.ReadByte(); switch(tag) { case (byte)'Z': return classFile.GetConstantPoolConstantInteger(rdr.ReadUInt16()) != 0; case (byte)'B': return (byte)classFile.GetConstantPoolConstantInteger(rdr.ReadUInt16()); case (byte)'C': return (char)classFile.GetConstantPoolConstantInteger(rdr.ReadUInt16()); case (byte)'S': return (short)classFile.GetConstantPoolConstantInteger(rdr.ReadUInt16()); case (byte)'I': return classFile.GetConstantPoolConstantInteger(rdr.ReadUInt16()); case (byte)'F': return classFile.GetConstantPoolConstantFloat(rdr.ReadUInt16()); case (byte)'J': return classFile.GetConstantPoolConstantLong(rdr.ReadUInt16()); case (byte)'D': return classFile.GetConstantPoolConstantDouble(rdr.ReadUInt16()); case (byte)'s': return classFile.GetConstantPoolUtf8String(rdr.ReadUInt16()); case (byte)'e': { ushort type_name_index = rdr.ReadUInt16(); ushort const_name_index = rdr.ReadUInt16(); return new object[] { AnnotationDefaultAttribute.TAG_ENUM, classFile.GetConstantPoolUtf8String(type_name_index), classFile.GetConstantPoolUtf8String(const_name_index) }; } case (byte)'c': return new object[] { AnnotationDefaultAttribute.TAG_CLASS, classFile.GetConstantPoolUtf8String(rdr.ReadUInt16()) }; case (byte)'@': return ReadAnnotation(rdr, classFile); case (byte)'[': { ushort num_values = rdr.ReadUInt16(); object[] array = new object[num_values + 1]; array[0] = AnnotationDefaultAttribute.TAG_ARRAY; for(int i = 0; i < num_values; i++) { array[i + 1] = ReadAnnotationElementValue(rdr, classFile); } return array; } default: throw new ClassFormatError("Invalid tag {0} in annotation element_value", tag); } }
private static object ReadAnnotationElementValue(BigEndianBinaryReader rdr, ClassFile classFile, string[] utf8_cp) { try { byte tag = rdr.ReadByte(); switch (tag) { case (byte)'Z': return classFile.GetConstantPoolConstantInteger(rdr.ReadUInt16()) != 0; case (byte)'B': return (byte)classFile.GetConstantPoolConstantInteger(rdr.ReadUInt16()); case (byte)'C': return (char)classFile.GetConstantPoolConstantInteger(rdr.ReadUInt16()); case (byte)'S': return (short)classFile.GetConstantPoolConstantInteger(rdr.ReadUInt16()); case (byte)'I': return classFile.GetConstantPoolConstantInteger(rdr.ReadUInt16()); case (byte)'F': return classFile.GetConstantPoolConstantFloat(rdr.ReadUInt16()); case (byte)'J': return classFile.GetConstantPoolConstantLong(rdr.ReadUInt16()); case (byte)'D': return classFile.GetConstantPoolConstantDouble(rdr.ReadUInt16()); case (byte)'s': return classFile.GetConstantPoolUtf8String(utf8_cp, rdr.ReadUInt16()); case (byte)'e': { ushort type_name_index = rdr.ReadUInt16(); ushort const_name_index = rdr.ReadUInt16(); return new object[] { AnnotationDefaultAttribute.TAG_ENUM, classFile.GetConstantPoolUtf8String(utf8_cp, type_name_index), classFile.GetConstantPoolUtf8String(utf8_cp, const_name_index) }; } case (byte)'c': return new object[] { AnnotationDefaultAttribute.TAG_CLASS, classFile.GetConstantPoolUtf8String(utf8_cp, rdr.ReadUInt16()) }; case (byte)'@': return ReadAnnotation(rdr, classFile, utf8_cp); case (byte)'[': { ushort num_values = rdr.ReadUInt16(); object[] array = new object[num_values + 1]; array[0] = AnnotationDefaultAttribute.TAG_ARRAY; for (int i = 0; i < num_values; i++) { array[i + 1] = ReadAnnotationElementValue(rdr, classFile, utf8_cp); } return array; } default: throw new ClassFormatError("Invalid tag {0} in annotation element_value", tag); } } catch (NullReferenceException) { } catch (InvalidCastException) { } catch (IndexOutOfRangeException) { } return new object[] { AnnotationDefaultAttribute.TAG_ERROR, "java.lang.IllegalArgumentException", "Wrong type at constant pool index" }; }
internal Field(ClassFile classFile, BigEndianBinaryReader br) : base(classFile, br) { if((IsPrivate && IsPublic) || (IsPrivate && IsProtected) || (IsPublic && IsProtected) || (IsFinal && IsVolatile) || (classFile.IsInterface && (!IsPublic || !IsStatic || !IsFinal || IsTransient))) { throw new ClassFormatError("{0} (Illegal field modifiers: 0x{1:X})", classFile.Name, access_flags); } int attributes_count = br.ReadUInt16(); for(int i = 0; i < attributes_count; i++) { switch(classFile.GetConstantPoolUtf8String(br.ReadUInt16())) { case "Deprecated": if(br.ReadUInt32() != 0) { throw new ClassFormatError("Invalid Deprecated attribute length"); } flags |= FLAG_MASK_DEPRECATED; break; case "ConstantValue": { if(br.ReadUInt32() != 2) { throw new ClassFormatError("Invalid ConstantValue attribute length"); } ushort index = br.ReadUInt16(); try { switch(Signature) { case "I": constantValue = classFile.GetConstantPoolConstantInteger(index); break; case "S": constantValue = (short)classFile.GetConstantPoolConstantInteger(index); break; case "B": constantValue = (byte)classFile.GetConstantPoolConstantInteger(index); break; case "C": constantValue = (char)classFile.GetConstantPoolConstantInteger(index); break; case "Z": constantValue = classFile.GetConstantPoolConstantInteger(index) != 0; break; case "J": constantValue = classFile.GetConstantPoolConstantLong(index); break; case "F": constantValue = classFile.GetConstantPoolConstantFloat(index); break; case "D": constantValue = classFile.GetConstantPoolConstantDouble(index); break; case "Ljava.lang.String;": constantValue = classFile.GetConstantPoolConstantString(index); break; default: throw new ClassFormatError("{0} (Invalid signature for constant)", classFile.Name); } } catch(InvalidCastException) { throw new ClassFormatError("{0} (Bad index into constant pool)", classFile.Name); } catch(IndexOutOfRangeException) { throw new ClassFormatError("{0} (Bad index into constant pool)", classFile.Name); } catch(InvalidOperationException) { throw new ClassFormatError("{0} (Bad index into constant pool)", classFile.Name); } catch(NullReferenceException) { throw new ClassFormatError("{0} (Bad index into constant pool)", classFile.Name); } break; } case "Signature": if(classFile.MajorVersion < 49) { goto default; } if(br.ReadUInt32() != 2) { throw new ClassFormatError("Signature attribute has incorrect length"); } signature = classFile.GetConstantPoolUtf8String(br.ReadUInt16()); break; case "RuntimeVisibleAnnotations": if(classFile.MajorVersion < 49) { goto default; } annotations = ReadAnnotations(br, classFile); break; case "RuntimeInvisibleAnnotations": if(classFile.MajorVersion < 49) { goto default; } foreach(object[] annot in ReadAnnotations(br, classFile)) { if(annot[1].Equals("Likvm/lang/Property;")) { DecodePropertyAnnotation(classFile, annot); } #if STATIC_COMPILER else if(annot[1].Equals("Likvm/lang/Internal;")) { this.access_flags &= ~Modifiers.AccessMask; flags |= FLAG_MASK_INTERNAL; } #endif } break; default: br.Skip(br.ReadUInt32()); break; } } }