public FieldInfo(ref ReadOnlySpan <byte> data, CPInfo[] constants) { AccessFlags = data.ReadTwo(); NameIndex = data.ReadTwo(); DescriptorIndex = data.ReadTwo(); AttributesCount = data.ReadTwo(); AttributeInfo = new AttributeInfo[AttributesCount]; for (int i = 0; i < AttributesCount; i++) { ushort nameIndexNonSwapped = MemoryMarshal.Cast <byte, ushort>(data)[0]; ushort nameIndex = nameIndexNonSwapped.SwapEndian(); string name = ((CUtf8Info)constants[nameIndex]).String; switch (name) { case "ConstantValue": AttributeInfo[i] = new ConstantValueAttribute(ref data, constants); break; case "Synthetic": AttributeInfo[i] = new SyntheticAttribute(ref data, constants); break; case "Signature": AttributeInfo[i] = new SignatureAttribute(ref data, constants); break; case "Deprecated": AttributeInfo[i] = new DeprecatedAttribute(ref data, constants); Deprecated = true; break; case "RuntimeVisibleAnnotations": AttributeInfo[i] = new RuntimeVisibleAnnotationsAttribute(ref data, constants); break; case "RuntimeInvisibleAnnotations": throw new NotImplementedException(); default: AttributeInfo[i] = new AttributeInfo(ref data, constants); break; } } Name = ((CUtf8Info)constants[NameIndex]).String; Descriptor = ((CUtf8Info)constants[DescriptorIndex]).String; }
/// <summary> /// Read a list of attributes /// </summary> private void ReadAttributes(ConstantPool cp, IModifiableAttributeProvider provider) { var count = stream.ReadU2(); for (var i = 0; i < count; i++) { var nameIndex = stream.ReadU2(); var name = cp.GetEntry <ConstantPoolUtf8>(nameIndex).Value; var length = stream.ReadU4(); Attribute attr; int tmp; switch (name) { case CodeAttribute.AttributeName: attr = ReadCodeAttribute((MethodDefinition)provider, cp); break; case ConstantValueAttribute.AttributeName: tmp = stream.ReadU2(); attr = new ConstantValueAttribute(((IConstantPoolValue)cp[tmp]).Value); break; case ExceptionsAttribute.AttributeName: attr = ReadExceptionsAttribute(cp); break; case InnerClassesAttribute.AttributeName: attr = ReadInnerClassesAttribute(cp); break; case SyntheticAttribute.AttributeName: attr = new SyntheticAttribute(); break; case SourceFileAttribute.AttributeName: tmp = stream.ReadU2(); attr = new SourceFileAttribute(cp.GetEntry <ConstantPoolUtf8>(tmp).Value); break; case LineNumberTableAttribute.AttributeName: attr = ReadLineNumberTableAttribute(); break; case LocalVariableTableAttribute.AttributeName: attr = ReadLocalVariableTableAttribute(cp); break; case DeprecatedAttribute.AttributeName: attr = new DeprecatedAttribute(); break; case OverrideAttribute.AttributeName: attr = new OverrideAttribute(); break; case SignatureAttribute.AttributeName: tmp = stream.ReadU2(); attr = new SignatureAttribute(cp.GetEntry <ConstantPoolUtf8>(tmp).Value); break; case RuntimeVisibleAnnotationsAttribute.AttributeName: attr = new RuntimeVisibleAnnotationsAttribute(ReadAnnotationsAttribute(cp)); break; case RuntimeInvisibleAnnotationsAttribute.AttributeName: attr = new RuntimeInvisibleAnnotationsAttribute(ReadAnnotationsAttribute(cp)); break; case RuntimeVisibleParameterAnnotationsAttribute.AttributeName: attr = new RuntimeVisibleParameterAnnotationsAttribute(ReadAnnotationsAttribute(cp)); break; case RuntimeInvisibleParameterAnnotationsAttribute.AttributeName: attr = new RuntimeInvisibleParameterAnnotationsAttribute(ReadAnnotationsAttribute(cp)); break; case AnnotationDefaultAttribute.AttributeName: attr = new AnnotationDefaultAttribute(ReadElementValue(cp)); break; default: stream.Skip(length); attr = new UnknownAttribute(name); break; } provider.Add(attr); } provider.AttributesLoaded(); }
public MethodInfo(ref ReadOnlySpan <byte> data, ClassFile classFile) { AccessFlags = data.ReadTwo(); NameIndex = data.ReadTwo(); Name = ((CUtf8Info)classFile.Constants[NameIndex]).String; DescriptorIndex = data.ReadTwo(); Descriptor = ((CUtf8Info)classFile.Constants[DescriptorIndex]).String; AttributesCount = data.ReadTwo(); Attributes = new AttributeInfo[AttributesCount]; for (int i = 0; i < AttributesCount; i++) { ushort nameIndexNonSwapped = MemoryMarshal.Cast <byte, ushort>(data)[0]; ushort nameIndex = nameIndexNonSwapped.SwapEndian(); string name = ((CUtf8Info)classFile.Constants[nameIndex]).String; switch (name) { case "Code": CodeAttribute code = new CodeAttribute(ref data, classFile.Constants); Attributes[i] = code; MaxStack = code.MaxStack; MaxLocals = code.MaxLocals; CodeAttribute = code; break; case "Exceptions": ExceptionsAttribute exceptionsAttribute = new ExceptionsAttribute(ref data, classFile.Constants); Attributes[i] = exceptionsAttribute; ExceptionsAttribute = exceptionsAttribute; break; case "Deprecated": Attributes[i] = new DeprecatedAttribute(ref data, classFile.Constants); Deprecated = true; break; case "RuntimeVisibleAnnotations": Attributes[i] = new RuntimeVisibleAnnotationsAttribute(ref data, classFile.Constants); break; case "Synthetic": Attributes[i] = new SyntheticAttribute(ref data, classFile.Constants); break; case "Signature": Attributes[i] = new SignatureAttribute(ref data, classFile.Constants); break; case "RuntimeInvisibleAnnotations": case "RuntimeVisibleParameterAnnotations": case "RuntimeInvisibleParameterAnnotations": case "AnnotationDefault": throw new NotImplementedException(); default: Attributes[i] = new AttributeInfo(ref data, classFile.Constants); break; } } ClassFile = classFile; }