Ejemplo n.º 1
0
 public void Write(IBigEndianWriter writer)
 {
     writer.Write(StartOffset);
     writer.Write(EndOffset);
     writer.Write(HandlerOffset);
     writer.Write(CatchType);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Writes the inner class info to an output stream.
 /// </summary>
 /// <param name="writer">The writer representing the output stream.</param>
 public void Write(IBigEndianWriter writer)
 {
     writer.Write(InnerClassInfoIndex);
     writer.Write(OuterClassInfoIndex);
     writer.Write(NameIndex);
     writer.Write((ushort)InnerClassAccessFlags);
 }
Ejemplo n.º 3
0
 public void Write(IBigEndianWriter writer)
 {
     writer.Write(StartOffset);
     writer.Write(Length);
     writer.Write(NameIndex);
     writer.Write(DescriptorIndex);
     writer.Write(LocalIndex);
 }
Ejemplo n.º 4
0
        internal BigEndianSegmentWriter(IBigEndianWriter destination, bool isU2)
        {
            _destination = destination;
            _isU2        = isU2;

            var temporary = new StreamDataDestination(new MemoryStream(), true);

            _segment = new BigEndianWriter(temporary);
        }
Ejemplo n.º 5
0
        /// <inheritdoc />
        public void WriteBody(JvmAttribute attribute, IBigEndianWriter writer)
        {
            if (attribute.Data is null)
            {
                throw new ArgumentException(nameof(attribute));
            }

            writer.Write(attribute.Data);
        }
Ejemplo n.º 6
0
        /// <inheritdoc />
        protected override void WriteBody(StackMapTableAttribute attribute, IBigEndianWriter writer)
        {
            var stackMapFrameWriter = new StackMapFrameWriter(writer);

            foreach (var frame in attribute.Entries)
            {
                stackMapFrameWriter.WriteFrame(frame);
            }
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Writes the entry to an output stream.
 /// </summary>
 /// <param name="writer">The writer to use.</param>
 public void Write(IBigEndianWriter writer)
 {
     writer.Write(MethodRefIndex);
     writer.Write((ushort)Arguments.Count);
     foreach (ushort argument in Arguments)
     {
         writer.Write(argument);
     }
 }
Ejemplo n.º 8
0
 public void Write(IBigEndianWriter writer, int baseOffset)
 {
     writer.Write(DefaultOffset - baseOffset);
     writer.Write(Table.Count);
     foreach (var entry in Table)
     {
         writer.Write(entry.Key);
         writer.Write(entry.Value - baseOffset);
     }
 }
Ejemplo n.º 9
0
 public void Write(IBigEndianWriter writer, int baseOffset)
 {
     writer.Write(DefaultOffset - baseOffset);
     writer.Write(Low);
     writer.Write(High);
     foreach (var offset in Offsets)
     {
         writer.Write(offset - baseOffset);
     }
 }
Ejemplo n.º 10
0
 private static void WriteExceptionHandlers(IBigEndianWriter writer, CodeAttribute attribute)
 {
     writer.WriteU2((ushort)attribute.ExceptionHandlers.Count);
     foreach (var exceptionHandler in attribute.ExceptionHandlers)
     {
         writer.WriteU2(exceptionHandler.TryStart);
         writer.WriteU2(exceptionHandler.TryEnd);
         writer.WriteU2(exceptionHandler.HandlerStart);
         writer.WriteU2(exceptionHandler.CatchType);
     }
 }
Ejemplo n.º 11
0
        private static void WriteUtf8Constant(Utf8Constant constant, IBigEndianWriter writer)
        {
            var    encoder = JavaUtf8.Instance;
            string value   = constant.Value;

            byte[] array = Pool.Rent(encoder.GetMaxByteCount(value.Length));
            int    chars = encoder.GetBytes(value, 0, value.Length, array, 0);

            writer.WriteU2((ushort)chars);
            writer.Write(array.AsSpan().Slice(0, chars));
            Pool.Return(array, true);
        }
Ejemplo n.º 12
0
        /// <inheritdoc />
        protected override void WriteBody(CodeAttribute attribute, IBigEndianWriter writer)
        {
            writer.WriteU2(attribute.MaxStack);
            writer.WriteU2(attribute.MaxLocals);

            WriteBytecode(writer, attribute);
            WriteExceptionHandlers(writer, attribute);

            writer.WriteU2((ushort)attribute.Attributes.Count);
            foreach (var nestedAttribute in attribute.Attributes)
            {
                Director.WriteAttribute(nestedAttribute, writer);
            }
        }
Ejemplo n.º 13
0
 /// <inheritdoc />
 public void WriteName(JvmAttribute attribute, IBigEndianWriter writer) => writer.WriteU2(attribute.NameIndex);
Ejemplo n.º 14
0
 private void WriteBytecode(IBigEndianWriter writer, CodeAttribute attribute)
 {
     using var segment = writer.WithU4Length();
     _assembler.Assemble(attribute.Instructions, segment);
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Writes the Java class file to a specified binary writer.
 /// </summary>
 /// <param name="writer">The writer to use.</param>
 public void Write(IBigEndianWriter writer)
 {
     Write(new WritingContext(writer));
 }
Ejemplo n.º 16
0
 internal StackMapFrameWriter(IBigEndianWriter writer)
 {
     _writer = writer;
     _verificationInfoWriter = new(writer);
 }
Ejemplo n.º 17
0
 /// <inheritdoc cref="WriteBody(T, IBigEndianWriter)" />
 protected abstract void WriteBody(T attribute, IBigEndianWriter writer);
Ejemplo n.º 18
0
 internal VerificationInfoWriter(IBigEndianWriter writer)
 {
     _writer = writer;
 }
Ejemplo n.º 19
0
        /// <summary>
        /// Writes the <paramref name="constant"/> to the given output <paramref name="writer"/>.
        /// </summary>
        /// <param name="constant">The <see cref="Constant"/> to serialize.</param>
        /// <param name="writer">The <see cref="BigEndianWriter"/> to write data to.</param>
        public static void BuildConstant(Constant constant, IBigEndianWriter writer)
        {
            writer.WriteU1((byte)constant.Tag);
            switch (constant)
            {
            case ClassConstant classConstant:
                writer.WriteU2(classConstant.NameIndex);
                break;

            case FieldrefConstant fieldrefConstant:
                writer.WriteU2(fieldrefConstant.ClassIndex);
                writer.WriteU2(fieldrefConstant.NameAndTypeIndex);
                break;

            case MethodrefConstant methodrefConstant:
                writer.WriteU2(methodrefConstant.ClassIndex);
                writer.WriteU2(methodrefConstant.NameAndTypeIndex);
                break;

            case InterfaceMethodrefConstant interfaceMethodrefConstant:
                writer.WriteU2(interfaceMethodrefConstant.ClassIndex);
                writer.WriteU2(interfaceMethodrefConstant.NameAndTypeIndex);
                break;

            case StringConstant stringConstant:
                writer.WriteU2(stringConstant.StringIndex);
                break;

            case IntegerConstant integerConstant:
                writer.WriteI4(integerConstant.Value);
                break;

            case FloatConstant floatConstant:
                writer.WriteR4(floatConstant.Value);
                break;

            case LongConstant longConstant:
                writer.WriteI8(longConstant.Value);
                break;

            case DoubleConstant doubleConstant:
                writer.WriteR8(doubleConstant.Value);
                break;

            case NameAndTypeConstant nameAndTypeConstant:
                writer.WriteU2(nameAndTypeConstant.NameIndex);
                writer.WriteU2(nameAndTypeConstant.DescriptorIndex);
                break;

            case Utf8Constant utf8Constant:
                WriteUtf8Constant(utf8Constant, writer);
                break;

            case MethodHandleConstant methodHandleConstant:
                writer.WriteU1((byte)methodHandleConstant.ReferenceKind);
                writer.WriteU2(methodHandleConstant.ReferenceIndex);
                break;

            case MethodTypeConstant methodTypeConstant:
                writer.WriteU2(methodTypeConstant.DescriptorIndex);
                break;

            case InvokeDynamicConstant invokeDynamicConstant:
                writer.WriteU2(invokeDynamicConstant.BootstrapMethodAttributeIndex);
                writer.WriteU2(invokeDynamicConstant.NameAndTypeIndex);
                break;

            default:
                throw new NotSupportedException($"Unsupported constant type: {constant.GetType().FullName}");
            }
        }
Ejemplo n.º 20
0
 /// <inheritdoc />
 public void WriteBody(JvmAttribute attribute, IBigEndianWriter writer) => WriteBody((T)attribute, (IBigEndianSegmentWriter)writer);
Ejemplo n.º 21
0
 public ByteCodeAssembler(IBigEndianWriter writer)
 {
     _writer = writer ?? throw new ArgumentNullException(nameof(writer));
 }
Ejemplo n.º 22
0
 /// <summary>
 /// Writes the <see cref="ClassFileHeader"/> to the <paramref name="writer"/>.
 /// </summary>
 /// <param name="writer">The <see cref="IBigEndianWriter"/> to write the <see cref="ClassFileHeader"/> to.</param>
 public void Write(IBigEndianWriter writer)
 {
     writer.WriteU4(Magic);
     writer.WriteU2(Minor);
     writer.WriteU2(Major);
 }
Ejemplo n.º 23
0
 public WritingContext(IBigEndianWriter writer)
 {
     Writer = writer ?? throw new ArgumentNullException(nameof(writer));
 }
Ejemplo n.º 24
0
 /// <summary>
 /// Writes the <see cref="MetadataBody"/> to the <paramref name="writer"/>.
 /// </summary>
 /// <param name="writer">The <see cref="IBigEndianWriter"/> to write the <see cref="MetadataBody"/> to.</param>
 /// <param name="director">The <see cref="IJvmAttributeDirector"/> to write <see cref="JvmAttribute"/>s with.</param>
 public void Write(IBigEndianWriter writer, IJvmAttributeDirector director) =>
 new MetadataBodyWriter(this, writer, director).WriteMetadataBody();
Ejemplo n.º 25
0
 /// <summary>
 /// Writes the <see cref="ClassFileBody"/> to the <paramref name="writer"/>.
 /// </summary>
 /// <param name="writer">The <see cref="IBigEndianWriter"/> to write the <see cref="ClassFileBody"/> to.</param>
 public void Write(IBigEndianWriter writer)
 {
     writer.WriteU2((ushort)AccessFlags);
     writer.WriteU2(ThisClass);
     writer.WriteU2(SuperClass);
 }
Ejemplo n.º 26
0
 internal ConstantPoolWriter(ConstantPool pool, IBigEndianWriter writer)
 {
     _pool   = pool;
     _writer = writer;
 }
Ejemplo n.º 27
0
 /// <summary>
 /// Writes the <see cref="MetadataBody"/> of a <see cref="ClassFile"/> to the <paramref name="writer"/>.
 /// </summary>
 /// <param name="classFile">The <see cref="ClassFile"/> to write the header of.</param>
 /// <param name="writer">The <see cref="IBigEndianWriter"/> to write the <see cref="ConstantPool"/> to.</param>
 public static void IntoWriter(ClassFile classFile, IBigEndianWriter writer) =>
 new MetadataBody(classFile).Write(writer, new JvmAttributeDirector(classFile.Constants));