Пример #1
0
        public CodeAttribute Parse(Stream attributeDataStream, uint attributeDataLength, ClassReaderState readerState, AttributeScope scope)
        {
            var maxStack  = Binary.BigEndian.ReadUInt16(attributeDataStream);
            var maxLocals = Binary.BigEndian.ReadUInt16(attributeDataStream);
            var code      = new byte[Binary.BigEndian.ReadUInt32(attributeDataStream)];

            attributeDataStream.Read(code);
            var attribute = new CodeAttribute
            {
                MaxStack  = maxStack,
                MaxLocals = maxLocals,
                Code      = code
            };

            var exceptionTableSize = Binary.BigEndian.ReadUInt16(attributeDataStream);

            attribute.ExceptionTable.Capacity = exceptionTableSize;
            for (var i = 0; i < exceptionTableSize; i++)
            {
                var exceptionTableEntry = new CodeAttribute.ExceptionTableEntry
                {
                    StartPc   = Binary.BigEndian.ReadUInt16(attributeDataStream),
                    EndPc     = Binary.BigEndian.ReadUInt16(attributeDataStream),
                    HandlerPc = Binary.BigEndian.ReadUInt16(attributeDataStream)
                };
                var catchTypeIndex = Binary.BigEndian.ReadUInt16(attributeDataStream);

                if (catchTypeIndex != 0)
                {
                    exceptionTableEntry.CatchType = new ClassName(readerState.ConstantPool
                                                                  .GetEntry <ClassEntry>(catchTypeIndex)
                                                                  .Name.String);
                }

                attribute.ExceptionTable.Add(exceptionTableEntry);
            }

            var attributesCount = Binary.BigEndian.ReadUInt16(attributeDataStream);

            attribute.Attributes.Capacity = attributesCount;
            for (var i = 0; i < attributesCount; i++)
            {
                attribute.Attributes.Add(ClassFile.ParseAttribute(attributeDataStream, readerState, AttributeScope.Code));
            }

            return(attribute);
        }