Ejemplo n.º 1
0
        internal override byte[] Save(ClassWriterState writerState, AttributeScope scope)
        {
            using var attributeDataStream = new MemoryStream();

            if (BootstrapMethods.Count > ushort.MaxValue)
            {
                throw new ArgumentOutOfRangeException(nameof(BootstrapMethods.Count), $"Number of bootstrap methods is too big: {BootstrapMethods.Count} > {ushort.MaxValue}");
            }
            Binary.BigEndian.Write(attributeDataStream, (ushort)BootstrapMethods.Count);
            foreach (var method in BootstrapMethods)
            {
                Binary.BigEndian.Write(attributeDataStream,
                                       writerState.ConstantPool.Find(method.BootstrapMethodReference.ToConstantPool()));
                if (method.Arguments.Count > ushort.MaxValue)
                {
                    throw new ArgumentOutOfRangeException(nameof(method.Arguments.Count),
                                                          $"Number of arguments is too big: {method.Arguments.Count} > {ushort.MaxValue}");
                }
                Binary.BigEndian.Write(attributeDataStream, (ushort)method.Arguments.Count);
                foreach (var argument in method.Arguments)
                {
                    Binary.BigEndian.Write(attributeDataStream, writerState.ConstantPool.Find(argument switch
                    {
                        int integerValue => (Entry) new IntegerEntry(integerValue),
                        float floatValue => new FloatEntry(floatValue),
                        string stringValue => new StringEntry(new Utf8Entry(stringValue)),
                        long longValue => new LongEntry(longValue),
                        double doubleValue => new DoubleEntry(doubleValue),
                        Handle handle => handle.ToConstantPool(),
                        MethodDescriptor methodDescriptor => new MethodTypeEntry(new Utf8Entry(methodDescriptor.ToString())),
                        _ => throw new ArgumentOutOfRangeException(nameof(argument), $"Can't encode value of type {argument.GetType()}")
                    }));
        internal override byte[] Save(ClassWriterState writerState, AttributeScope scope)
        {
            using var attributeDataStream = new MemoryStream();

            if (Parameters.Count > byte.MaxValue)
            {
                throw new ArgumentOutOfRangeException(nameof(Parameters.Count), $"Number of parameters is too big: {Parameters.Count} > {byte.MaxValue}");
            }
            attributeDataStream.WriteByte((byte)Parameters.Count);
            foreach (var parameter in Parameters)
            {
                if (parameter.Annotations.Count > ushort.MaxValue)
                {
                    throw new ArgumentOutOfRangeException(nameof(parameter.Annotations.Count),
                                                          $"Number of annotations is too big: {parameter.Annotations.Count} > {ushort.MaxValue}");
                }
                Binary.BigEndian.Write(attributeDataStream, (ushort)parameter.Annotations.Count);
                foreach (var annotation in parameter.Annotations)
                {
                    annotation.Write(attributeDataStream, writerState);
                }
            }

            return(attributeDataStream.ToArray());
        }
Ejemplo n.º 3
0
        internal override byte[] Save(ClassWriterState writerState, AttributeScope scope)
        {
            using var attributeDataStream = new MemoryStream();

            Value.Write(attributeDataStream, writerState);

            return(attributeDataStream.ToArray());
        }
Ejemplo n.º 4
0
        internal override byte[] Save(ClassWriterState writerState, AttributeScope scope)
        {
            using var attributeDataStream = new MemoryStream();

            Binary.BigEndian.Write(attributeDataStream, writerState.ConstantPool.Find(new Utf8Entry(Value)));

            return(attributeDataStream.ToArray());
        }
Ejemplo n.º 5
0
        private void HandleAttributeReference(string attributeName)
        {
            AttributeScope scope = enclosingRule.GetLocalAttributeScope(attributeName);

            if (scope != null && (scope.IsPredefinedRuleScope || scope.IsPredefinedLexerRuleScope))
            {
                grammar.ReferenceRuleLabelPredefinedAttribute(enclosingRule.Name);
                //System.Console.WriteLine("referenceRuleLabelPredefinedAttribute for " + attributeName);
            }
        }
Ejemplo n.º 6
0
        private void HandleAttrScope(GrammarAST name, GrammarAST attrs, IDictionary <GrammarAST, GrammarAST> actions)
        {
            AttributeScope scope = grammar.DefineGlobalScope(name.Text, attrs.Token);

            scope.IsDynamicGlobalScope = true;
            scope.AddAttributes(attrs.Text, ';');
            foreach (var action in actions)
            {
                scope.DefineNamedAction(action.Key, action.Value);
            }
        }
Ejemplo n.º 7
0
        internal override byte[] Save(ClassWriterState writerState, AttributeScope scope)
        {
            var result = new byte[2];

            Binary.BigEndian.Set(Value switch
            {
                long longValue => writerState.ConstantPool.Find(new LongEntry(longValue)),
                float floatValue => writerState.ConstantPool.Find(new FloatEntry(floatValue)),
                double doubleValue => writerState.ConstantPool.Find(new DoubleEntry(doubleValue)),
                int integerValue => writerState.ConstantPool.Find(new IntegerEntry(integerValue)),
                string stringValue => writerState.ConstantPool.Find(new StringEntry(new Utf8Entry(stringValue))),
                _ => throw new ArgumentOutOfRangeException(nameof(Value), $"Can't encode value of type {Value.GetType()}")
            }, result);
Ejemplo n.º 8
0
        internal void Write(Stream stream, ClassWriterState writerState, AttributeScope scope)
        {
            stream.WriteByte((byte)TargetType);
            switch (TargetType)
            {
            case TargetType.GenericClassOrInterfaceDeclaration when Target.TargetTypeKind == TargetTypeKind.TypeParameter && scope == AttributeScope.Class:
            case TargetType.GenericMethodOrConstructorDeclaration when Target.TargetTypeKind == TargetTypeKind.TypeParameter && scope == AttributeScope.Method:
            case TargetType.ExtendsOrImplements when Target.TargetTypeKind == TargetTypeKind.Supertype && scope == AttributeScope.Class:
            case TargetType.TypeInBoundInGenericClassOrInterface when Target.TargetTypeKind == TargetTypeKind.TypeParameterBound && scope == AttributeScope.Class:
            case TargetType.TypeInBoundInGenericMethodOrConstructor when Target.TargetTypeKind == TargetTypeKind.TypeParameterBound && scope == AttributeScope.Method:
            case TargetType.FieldDeclaration when Target.TargetTypeKind == TargetTypeKind.Empty && scope == AttributeScope.Field:
            case TargetType.ReturnTypeOrNewObject when Target.TargetTypeKind == TargetTypeKind.Empty && scope == AttributeScope.Method:
            case TargetType.ReceiverTypeOfMethodOrConstructor when Target.TargetTypeKind == TargetTypeKind.Empty && scope == AttributeScope.Method:
            case TargetType.TypeInFormalParameterOfMethodOrConstructorOrLambda when Target.TargetTypeKind == TargetTypeKind.FormalParameter && scope == AttributeScope.Method:
            case TargetType.ThrowsClause when Target.TargetTypeKind == TargetTypeKind.Throws && scope == AttributeScope.Method:
            case TargetType.LocalVariableDeclaration when Target.TargetTypeKind == TargetTypeKind.Localvar && scope == AttributeScope.Code:
            case TargetType.ResourceVariableDeclaration when Target.TargetTypeKind == TargetTypeKind.Localvar && scope == AttributeScope.Code:
            case TargetType.ExceptionParameterDeclaration when Target.TargetTypeKind == TargetTypeKind.Catch && scope == AttributeScope.Code:
            case TargetType.InstanceOfExpression when Target.TargetTypeKind == TargetTypeKind.Offset && scope == AttributeScope.Code:
            case TargetType.NewExpression when Target.TargetTypeKind == TargetTypeKind.Offset && scope == AttributeScope.Code:
            case TargetType.MethodReferenceExpressionNew when Target.TargetTypeKind == TargetTypeKind.Offset && scope == AttributeScope.Code:
            case TargetType.MethodReferenceExpressionIdentifier when Target.TargetTypeKind == TargetTypeKind.Offset && scope == AttributeScope.Code:
            case TargetType.CastExpression when Target.TargetTypeKind == TargetTypeKind.TypeArgument && scope == AttributeScope.Code:
            case TargetType.ArgumentForGenericConstructorInvocation when Target.TargetTypeKind == TargetTypeKind.TypeArgument && scope == AttributeScope.Code:
            case TargetType.ArgumentForGenericMethodInvocation when Target.TargetTypeKind == TargetTypeKind.TypeArgument && scope == AttributeScope.Code:
            case TargetType.ArgumentForGenericMethodReferenceExpressionNew when Target.TargetTypeKind == TargetTypeKind.TypeArgument && scope == AttributeScope.Code:
            case TargetType.ArgumentForGenericMethodReferenceExpressionIdentifier when Target.TargetTypeKind == TargetTypeKind.TypeArgument && scope == AttributeScope.Code:
                Target.Write(stream, writerState);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(TargetType));
            }

            TypePath.Write(stream, writerState);

            if (ElementValuePairs.Count > ushort.MaxValue)
            {
                throw new ArgumentOutOfRangeException(nameof(ElementValuePairs.Count),
                                                      $"Too many ElementValues: {ElementValuePairs.Count} > {ushort.MaxValue}");
            }
            Binary.BigEndian.Write(stream, (ushort)ElementValuePairs.Count);
            foreach (var elementValuePair in ElementValuePairs)
            {
                Binary.BigEndian.Write(stream,
                                       writerState.ConstantPool.Find(new Utf8Entry(elementValuePair.ElementName)));
                elementValuePair.Value.Write(stream, writerState);
            }
        }
Ejemplo n.º 9
0
        internal override byte[] Save(ClassWriterState writerState, AttributeScope scope)
        {
            using var attributeDataStream = new MemoryStream();

            if (LineNumberTable.Count > ushort.MaxValue)
            {
                throw new ArgumentOutOfRangeException(nameof(LineNumberTable.Count), $"Line number table too big: {LineNumberTable.Count} > {ushort.MaxValue}");
            }
            Binary.BigEndian.Write(attributeDataStream, (ushort)LineNumberTable.Count);
            foreach (var exceptionTableEntry in LineNumberTable)
            {
                Binary.BigEndian.Write(attributeDataStream, exceptionTableEntry.StartPc);
                Binary.BigEndian.Write(attributeDataStream, exceptionTableEntry.LineNumber);
            }

            return(attributeDataStream.ToArray());
        }
Ejemplo n.º 10
0
        internal override byte[] Save(ClassWriterState writerState, AttributeScope scope)
        {
            using var attributeDataStream = new MemoryStream();

            if (ExceptionTable.Count > ushort.MaxValue)
            {
                throw new ArgumentOutOfRangeException(nameof(ExceptionTable.Count),
                                                      $"Exception table size too big: {ExceptionTable.Count} > {ushort.MaxValue}");
            }
            Binary.BigEndian.Write(attributeDataStream, (ushort)ExceptionTable.Count);
            foreach (var exceptionClassName in ExceptionTable)
            {
                Binary.BigEndian.Write(attributeDataStream,
                                       writerState.ConstantPool.Find(new ClassEntry(new Utf8Entry(exceptionClassName.Name))));
            }

            return(attributeDataStream.ToArray());
        }
Ejemplo n.º 11
0
        internal override byte[] Save(ClassWriterState writerState, AttributeScope scope)
        {
            using var attributeDataStream = new MemoryStream();

            if (Parameters.Count > byte.MaxValue)
            {
                throw new ArgumentOutOfRangeException(nameof(Parameters.Count), $"Too many parameters: {Parameters.Count} > {byte.MaxValue}");
            }
            attributeDataStream.WriteByte((byte)Parameters.Count);
            foreach (var parameter in Parameters)
            {
                Binary.BigEndian.Write(attributeDataStream,
                                       writerState.ConstantPool.Find(new Utf8Entry(parameter.Name)));
                Binary.BigEndian.Write(attributeDataStream, (ushort)parameter.Access);
            }

            return(attributeDataStream.ToArray());
        }
Ejemplo n.º 12
0
        internal override byte[] Save(ClassWriterState writerState, AttributeScope scope)
        {
            using var attributeDataStream = new MemoryStream();

            Binary.BigEndian.Write(attributeDataStream,
                                   writerState.ConstantPool.Find(new ClassEntry(new Utf8Entry(Class.Name))));

            if (MethodName == null && MethodDescriptor == null)
            {
                Binary.BigEndian.Write(attributeDataStream, (ushort)0);
            }
            else
            {
                Binary.BigEndian.Write(attributeDataStream,
                                       writerState.ConstantPool.Find(new NameAndTypeEntry(new Utf8Entry(MethodName),
                                                                                          new Utf8Entry(MethodDescriptor.ToString()))));
            }

            return(attributeDataStream.ToArray());
        }
Ejemplo n.º 13
0
        private void HandleAttributeMemberReference(string attribute, string member)
        {
            AttributeScope scope        = null;
            string         refdRuleName = null;

            if (attribute.Equals(enclosingRule.Name))
            {
                // ref to enclosing rule.
                refdRuleName = attribute;
                scope        = enclosingRule.GetLocalAttributeScope(member);
            }
            else if (enclosingRule.GetRuleLabel(attribute) != null)
            {
                // ref to rule label
                Grammar.LabelElementPair pair = enclosingRule.GetRuleLabel(attribute);
                pair.actionReferencesLabel = true;
                refdRuleName = pair.referencedRuleName;
                Rule refdRule = grammar.GetRule(refdRuleName);
                if (refdRule != null)
                {
                    scope = refdRule.GetLocalAttributeScope(member);
                }
            }
            else if (enclosingRule.GetRuleRefsInAlt(attribute, outerAltNum) != null)
            {
                // ref to rule referenced in this alt
                refdRuleName = attribute;
                Rule refdRule = grammar.GetRule(refdRuleName);
                if (refdRule != null)
                {
                    scope = refdRule.GetLocalAttributeScope(member);
                }
            }

            if (scope != null && (scope.IsPredefinedRuleScope || scope.IsPredefinedLexerRuleScope))
            {
                grammar.ReferenceRuleLabelPredefinedAttribute(refdRuleName);
                //System.Console.WriteLine("referenceRuleLabelPredefinedAttribute for " + refdRuleName);
            }
        }
Ejemplo n.º 14
0
        internal override byte[] Save(ClassWriterState writerState, AttributeScope scope)
        {
            using var attributeDataStream = new MemoryStream();

            Binary.BigEndian.Write(attributeDataStream, MaxStack);
            Binary.BigEndian.Write(attributeDataStream, MaxLocals);

            if (Code.LongLength > uint.MaxValue)
            {
                throw new ArgumentOutOfRangeException(nameof(Code.LongLength), $"Code length too big: {Code.LongLength} > {uint.MaxValue}");
            }
            Binary.BigEndian.Write(attributeDataStream, (uint)Code.LongLength);
            attributeDataStream.Write(Code);

            if (ExceptionTable.Count > ushort.MaxValue)
            {
                throw new ArgumentOutOfRangeException(nameof(ExceptionTable.Count), $"Exception table too big: {ExceptionTable.Count} > {ushort.MaxValue}");
            }
            Binary.BigEndian.Write(attributeDataStream, (ushort)ExceptionTable.Count);
            foreach (var exceptionTableEntry in ExceptionTable)
            {
                Binary.BigEndian.Write(attributeDataStream, exceptionTableEntry.StartPc);
                Binary.BigEndian.Write(attributeDataStream, exceptionTableEntry.EndPc);
                Binary.BigEndian.Write(attributeDataStream, exceptionTableEntry.HandlerPc);
                Binary.BigEndian.Write(attributeDataStream, (ushort)(exceptionTableEntry.CatchType == null ? 0 :
                                                                     writerState.ConstantPool.Find(new ClassEntry(new Utf8Entry(exceptionTableEntry.CatchType.Name)))));
            }

            if (Attributes.Count > ushort.MaxValue)
            {
                throw new ArgumentOutOfRangeException(nameof(Attributes.Count), $"Too many attributes: {Attributes.Count} > {ushort.MaxValue}");
            }
            Binary.BigEndian.Write(attributeDataStream, (ushort)Attributes.Count);
            foreach (var attriute in Attributes)
            {
                ClassFile.WriteAttribute(attributeDataStream, attriute, writerState, AttributeScope.Code);
            }

            return(attributeDataStream.ToArray());
        }
        internal override byte[] Save(ClassWriterState writerState, AttributeScope scope)
        {
            using var attributeDataStream = new MemoryStream();

            if (LocalVariableTypeTable.Count > ushort.MaxValue)
            {
                throw new ArgumentOutOfRangeException(nameof(LocalVariableTypeTable.Count), $"Local variable type table is too big: {LocalVariableTypeTable.Count} > {ushort.MaxValue}");
            }
            Binary.BigEndian.Write(attributeDataStream, (ushort)LocalVariableTypeTable.Count);
            foreach (var localVariableTypeTableEntry in LocalVariableTypeTable)
            {
                Binary.BigEndian.Write(attributeDataStream, localVariableTypeTableEntry.StartPc);
                Binary.BigEndian.Write(attributeDataStream, localVariableTypeTableEntry.Length);
                Binary.BigEndian.Write(attributeDataStream,
                                       writerState.ConstantPool.Find(new Utf8Entry(localVariableTypeTableEntry.Name)));
                Binary.BigEndian.Write(attributeDataStream,
                                       writerState.ConstantPool.Find(new Utf8Entry(localVariableTypeTableEntry.Signature)));
                Binary.BigEndian.Write(attributeDataStream, localVariableTypeTableEntry.Index);
            }

            return(attributeDataStream.ToArray());
        }
Ejemplo n.º 16
0
        internal override byte[] Save(ClassWriterState writerState, AttributeScope scope)
        {
            using var attributeDataStream = new MemoryStream();

            if (Classes.Count > ushort.MaxValue)
            {
                throw new ArgumentOutOfRangeException(nameof(Classes.Count), $"Too many inner classes: {Classes.Count} > {ushort.MaxValue}");
            }
            Binary.BigEndian.Write(attributeDataStream, (ushort)Classes.Count);
            foreach (var innerClass in Classes)
            {
                Binary.BigEndian.Write(attributeDataStream,
                                       writerState.ConstantPool.Find(new ClassEntry(new Utf8Entry(innerClass.InnerClassName.Name))));
                Binary.BigEndian.Write(attributeDataStream, innerClass.OuterClassName == null ? (ushort)0 :
                                       writerState.ConstantPool.Find(new ClassEntry(new Utf8Entry(innerClass.OuterClassName.Name))));
                Binary.BigEndian.Write(attributeDataStream, innerClass.InnerName == null ? (ushort)0 :
                                       writerState.ConstantPool.Find(new Utf8Entry(innerClass.InnerName)));
                Binary.BigEndian.Write(attributeDataStream, (ushort)innerClass.Access);
            }

            return(attributeDataStream.ToArray());
        }
Ejemplo n.º 17
0
        public InnerClassesAttribute Parse(Stream attributeDataStream, uint attributeDataLength, ClassReaderState readerState, AttributeScope scope)
        {
            var attribute = new InnerClassesAttribute();

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

            attribute.Classes.Capacity = classesCount;
            for (var i = 0; i < classesCount; i++)
            {
                var innerClass = new InnerClass
                {
                    InnerClassName = new ClassName(readerState.ConstantPool
                                                   .GetEntry <ClassEntry>(Binary.BigEndian.ReadUInt16(attributeDataStream)).Name.String)
                };
                var outerClassIndex = Binary.BigEndian.ReadUInt16(attributeDataStream);
                if (outerClassIndex != 0)
                {
                    innerClass.OuterClassName = new ClassName(readerState.ConstantPool
                                                              .GetEntry <ClassEntry>(outerClassIndex).Name.String);
                }
                var innerNameIndex = Binary.BigEndian.ReadUInt16(attributeDataStream);
                if (innerNameIndex != 0)
                {
                    innerClass.InnerName = readerState.ConstantPool
                                           .GetEntry <Utf8Entry>(innerNameIndex).String;
                }
                innerClass.Access = (ClassAccessModifiers)Binary.BigEndian.ReadUInt16(attributeDataStream);
                attribute.Classes.Add(innerClass);
            }

            return(attribute);
        }
Ejemplo n.º 18
0
        public RuntimeVisibleTypeAnnotationsAttribute Parse(Stream attributeDataStream, uint attributeDataLength, ClassReaderState readerState, AttributeScope scope)
        {
            var attribute = new RuntimeVisibleTypeAnnotationsAttribute();

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

            attribute.Annotations.Capacity = annotationsCount;
            for (var i = 0; i < annotationsCount; i++)
            {
                attribute.Annotations.Add(TypeAnnotationNode.Parse(attributeDataStream, readerState, scope));
            }

            return(attribute);
        }
Ejemplo n.º 19
0
 internal abstract byte[] Save(ClassWriterState writerState, AttributeScope scope);
Ejemplo n.º 20
0
 public AnnotationDefaultAttribute Parse(Stream attributeDataStream, uint attributeDataLength, ClassReaderState readerState, AttributeScope scope)
 {
     return(new AnnotationDefaultAttribute
     {
         Value = ElementValue.Parse(attributeDataStream, readerState)
     });
 }
Ejemplo n.º 21
0
        internal static TypeAnnotationNode Parse(Stream stream, ClassReaderState readerState, AttributeScope scope)
        {
            var typeAnnotation = new TypeAnnotationNode
            {
                TargetType = (TargetType)stream.ReadByteFully()
            };

            typeAnnotation.Target = typeAnnotation.TargetType switch
            {
                TargetType.GenericClassOrInterfaceDeclaration when scope == AttributeScope.Class => (TypeAnnotationTarget) new TypeParameterTarget(),
                TargetType.GenericMethodOrConstructorDeclaration when scope == AttributeScope.Method => new TypeParameterTarget(),
                TargetType.ExtendsOrImplements when scope == AttributeScope.Class => new SupertypeTarget(),
                TargetType.TypeInBoundInGenericClassOrInterface when scope == AttributeScope.Class => new TypeParameterBoundTarget(),
                TargetType.TypeInBoundInGenericMethodOrConstructor when scope == AttributeScope.Method => new TypeParameterBoundTarget(),
                TargetType.FieldDeclaration when scope == AttributeScope.Field => new EmptyTarget(),
                TargetType.ReturnTypeOrNewObject when scope == AttributeScope.Method => new EmptyTarget(),
                TargetType.ReceiverTypeOfMethodOrConstructor when scope == AttributeScope.Method => new EmptyTarget(),
                TargetType.TypeInFormalParameterOfMethodOrConstructorOrLambda when scope == AttributeScope.Method => new FormalParameterTarget(),
                TargetType.ThrowsClause when scope == AttributeScope.Method => new ThrowsTarget(),
                TargetType.LocalVariableDeclaration when scope == AttributeScope.Code => new LocalvarTarget(),
                TargetType.ResourceVariableDeclaration when scope == AttributeScope.Code => new LocalvarTarget(),
                TargetType.ExceptionParameterDeclaration when scope == AttributeScope.Code => new CatchTarget(),
                TargetType.InstanceOfExpression when scope == AttributeScope.Code => new OffsetTarget(),
                TargetType.NewExpression when scope == AttributeScope.Code => new OffsetTarget(),
                TargetType.MethodReferenceExpressionNew when scope == AttributeScope.Code => new OffsetTarget(),
                TargetType.MethodReferenceExpressionIdentifier when scope == AttributeScope.Code => new OffsetTarget(),
                TargetType.CastExpression when scope == AttributeScope.Code => new TypeArgumentTarget(),
                TargetType.ArgumentForGenericConstructorInvocation when scope == AttributeScope.Code => new TypeArgumentTarget(),
                TargetType.ArgumentForGenericMethodInvocation when scope == AttributeScope.Code => new TypeArgumentTarget(),
                TargetType.ArgumentForGenericMethodReferenceExpressionNew when scope == AttributeScope.Code => new TypeArgumentTarget(),
                TargetType.ArgumentForGenericMethodReferenceExpressionIdentifier when scope == AttributeScope.Code => new TypeArgumentTarget(),
                _ => throw new ArgumentOutOfRangeException(nameof(TargetType))
            };
            typeAnnotation.Target.Read(stream, readerState);
            typeAnnotation.TypePath = new TypePath();
            typeAnnotation.TypePath.Read(stream, readerState);
            var elementValuePairsCount = Binary.BigEndian.ReadUInt16(stream);

            typeAnnotation.ElementValuePairs.Capacity = elementValuePairsCount;
            for (var i = 0; i < elementValuePairsCount; i++)
            {
                typeAnnotation.ElementValuePairs.Add(new ElementValuePair
                {
                    ElementName = readerState.ConstantPool
                                  .GetEntry <Utf8Entry>(Binary.BigEndian.ReadUInt16(stream)).String,
                    Value = ElementValue.Parse(stream, readerState)
                });
            }
            return(typeAnnotation);
        }
Ejemplo n.º 22
0
 internal override byte[] Save(ClassWriterState writerState, AttributeScope scope) => new byte[0];
Ejemplo n.º 23
0
 public SyntheticAttribute Parse(Stream attributeDataStream, uint attributeDataLength, ClassReaderState readerState, AttributeScope scope) => new SyntheticAttribute();
Ejemplo n.º 24
0
 internal override byte[] Save(ClassWriterState writerState, AttributeScope scope)
 {
     return(ModifiedUtf8Helper.Encode(Value));
 }
Ejemplo n.º 25
0
 public SourceDebugExtensionAttribute Parse(Stream attributeDataStream, uint attributeDataLength, ClassReaderState readerState, AttributeScope scope)
 {
     return(new SourceDebugExtensionAttribute
     {
         Value = ModifiedUtf8Helper.Decode(attributeDataStream.ReadBytes(attributeDataLength))
     });
 }
        public RuntimeVisibleParameterAnnotationsAttribute Parse(Stream attributeDataStream, uint attributeDataLength, ClassReaderState readerState, AttributeScope scope)
        {
            var attribute = new RuntimeVisibleParameterAnnotationsAttribute();

            var parametersCount = attributeDataStream.ReadByteFully();

            attribute.Parameters.Capacity = parametersCount;
            for (var i = 0; i < parametersCount; i++)
            {
                var parameter        = new ParameterAnnotations();
                var annotationsCount = Binary.BigEndian.ReadUInt16(attributeDataStream);
                parameter.Annotations.Capacity = annotationsCount;
                for (var j = 0; j < annotationsCount; j++)
                {
                    parameter.Annotations.Add(AnnotationNode.Parse(attributeDataStream, readerState));
                }
                attribute.Parameters.Add(parameter);
            }

            return(attribute);
        }
Ejemplo n.º 27
0
        internal override byte[] Save(ClassWriterState writerState, AttributeScope scope)
        {
            using var attributeDataStream = new MemoryStream();

            if (Entries.Count > ushort.MaxValue)
            {
                throw new ArgumentOutOfRangeException(nameof(Entries.Count), $"Too many entries for StackMapTable: {Entries.Count} > {ushort.MaxValue}");
            }

            Binary.BigEndian.Write(attributeDataStream, (ushort)Entries.Count);

            foreach (var entry in Entries)
            {
                switch (entry.Type)
                {
                case FrameType.Same:
                    if (entry.OffsetDelta < 64)
                    {
                        attributeDataStream.WriteByte((byte)entry.OffsetDelta);
                    }
                    else
                    {
                        attributeDataStream.WriteByte(251);
                        Binary.BigEndian.Write(attributeDataStream, entry.OffsetDelta);
                    }
                    break;

                case FrameType.SameLocals1StackItem:
                    if (entry.OffsetDelta < 64)
                    {
                        attributeDataStream.WriteByte((byte)(entry.OffsetDelta + 64));
                    }
                    else
                    {
                        attributeDataStream.WriteByte(247);
                        Binary.BigEndian.Write(attributeDataStream, entry.OffsetDelta);
                    }

                    WriteVerificationElement(attributeDataStream, writerState, entry.Stack[0]);
                    break;

                case FrameType.Chop:
                    if (entry.ChopK == null)
                    {
                        throw new ArgumentNullException(nameof(entry.ChopK));
                    }
                    if (entry.ChopK < 1 || entry.ChopK > 3)
                    {
                        throw new ArgumentOutOfRangeException(nameof(entry.ChopK),
                                                              $"Chop K was < 1 || > 3: {entry.ChopK}");
                    }

                    attributeDataStream.WriteByte((byte)(251 - entry.ChopK));
                    Binary.BigEndian.Write(attributeDataStream, entry.OffsetDelta);
                    break;

                case FrameType.Append:
                    if (entry.Locals.Count < 1 || entry.Locals.Count > 3)
                    {
                        throw new ArgumentOutOfRangeException(nameof(entry.Locals),
                                                              $"Number of locals was < 1 || > 3: {entry.Locals}");
                    }
                    attributeDataStream.WriteByte((byte)(251 + entry.Locals.Count));
                    Binary.BigEndian.Write(attributeDataStream, entry.OffsetDelta);
                    foreach (var verificationElement in entry.Locals)
                    {
                        WriteVerificationElement(attributeDataStream, writerState, verificationElement);
                    }
                    break;

                case FrameType.Full:
                    attributeDataStream.WriteByte(255);
                    Binary.BigEndian.Write(attributeDataStream, entry.OffsetDelta);

                    if (entry.Locals.Count > ushort.MaxValue)
                    {
                        throw new ArgumentOutOfRangeException(nameof(entry.Locals.Count),
                                                              $"Too many entries in frame's locals: {entry.Locals.Count} > {ushort.MaxValue}");
                    }
                    Binary.BigEndian.Write(attributeDataStream, (ushort)entry.Locals.Count);
                    foreach (var verificationElement in entry.Locals)
                    {
                        WriteVerificationElement(attributeDataStream, writerState, verificationElement);
                    }

                    if (entry.Stack.Count > ushort.MaxValue)
                    {
                        throw new ArgumentOutOfRangeException(nameof(entry.Stack.Count),
                                                              $"Too many entries in frame's stack: {entry.Stack.Count} > {ushort.MaxValue}");
                    }
                    Binary.BigEndian.Write(attributeDataStream, (ushort)entry.Stack.Count);
                    foreach (var verificationElement in entry.Stack)
                    {
                        WriteVerificationElement(attributeDataStream, writerState, verificationElement);
                    }
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(entry.Type));
                }
            }

            return(attributeDataStream.ToArray());
        }
        public LocalVariableTypeTableAttribute Parse(Stream attributeDataStream, uint attributeDataLength, ClassReaderState readerState, AttributeScope scope)
        {
            var attribute = new LocalVariableTypeTableAttribute();

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

            attribute.LocalVariableTypeTable.Capacity = localVariableTypeTableSize;
            for (var i = 0; i < localVariableTypeTableSize; i++)
            {
                attribute.LocalVariableTypeTable.Add(new LocalVariableTypeTableAttribute.LocalVariableTypeTableEntry
                {
                    StartPc   = Binary.BigEndian.ReadUInt16(attributeDataStream),
                    Length    = Binary.BigEndian.ReadUInt16(attributeDataStream),
                    Name      = readerState.ConstantPool.GetEntry <Utf8Entry>(Binary.BigEndian.ReadUInt16(attributeDataStream)).String,
                    Signature = readerState.ConstantPool.GetEntry <Utf8Entry>(Binary.BigEndian.ReadUInt16(attributeDataStream)).String,
                    Index     = Binary.BigEndian.ReadUInt16(attributeDataStream)
                });
            }

            return(attribute);
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Get AttributeSets
        /// </summary>
        /// <param name="appId">Filter by AppId</param>
        /// <param name="scope">optional Filter by Scope</param>
        internal IQueryable<AttributeSet> GetAttributeSets(int appId, AttributeScope? scope)
        {
            var result = Context.SqlDb.AttributeSets.Where(a => a.AppID == appId && !a.ChangeLogIDDeleted.HasValue);

            if (scope != null)
            {
                var scopeString = scope.ToString();
                result = result.Where(a => a.Scope == scopeString);
            }

            return result;
        }
Ejemplo n.º 30
0
 public SignatureAttribute Parse(Stream attributeDataStream, uint attributeDataLength, ClassReaderState readerState, AttributeScope scope)
 {
     return(new SignatureAttribute
     {
         Value = readerState.ConstantPool.GetEntry <Utf8Entry>(Binary.BigEndian.ReadUInt16(attributeDataStream)).String
     });
 }
Ejemplo n.º 31
0
        public EnclosingMethodAttribute Parse(Stream attributeDataStream, uint attributeDataLength, ClassReaderState readerState, AttributeScope scope)
        {
            var attribute = new EnclosingMethodAttribute
            {
                Class = new ClassName(readerState.ConstantPool
                                      .GetEntry <ClassEntry>(Binary.BigEndian.ReadUInt16(attributeDataStream)).Name.String)
            };

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

            if (nameAndTypeEntryIndex == 0)
            {
                return(attribute);
            }

            var nameAndTypeEntry = readerState.ConstantPool.GetEntry <NameAndTypeEntry>(nameAndTypeEntryIndex);

            attribute.MethodName       = nameAndTypeEntry.Name.String;
            attribute.MethodDescriptor = MethodDescriptor.Parse(nameAndTypeEntry.Descriptor.String);

            return(attribute);
        }