private static void WriteHintName(IBinaryStreamWriter writer, ushort hint, string name)
 {
     writer.WriteUInt16(hint);
     writer.WriteAsciiString(name);
     writer.WriteByte(0);
     writer.Align(2);
 }
Пример #2
0
        /// <summary>
        /// Writes the PE file to the provided output stream.
        /// </summary>
        /// <param name="writer">The output stream to write to.</param>
        public void Write(IBinaryStreamWriter writer)
        {
            UpdateHeaders();

            // Dos header.
            DosHeader.Write(writer);

            // NT headers
            writer.FileOffset = DosHeader.NextHeaderOffset;

            writer.WriteUInt32(ValidPESignature);
            FileHeader.Write(writer);
            OptionalHeader.Write(writer);

            // Section headers.
            writer.FileOffset = OptionalHeader.FileOffset + FileHeader.SizeOfOptionalHeader;
            foreach (var section in Sections)
            {
                section.CreateHeader().Write(writer);
            }

            // Data between section headers and sections.
            ExtraSectionData?.Write(writer);

            // Sections.

            writer.FileOffset = OptionalHeader.SizeOfHeaders;
            foreach (var section in Sections)
            {
                writer.FileOffset = section.FileOffset;
                section.Contents.Write(writer);
                writer.Align(OptionalHeader.FileAlignment);
            }
        }
Пример #3
0
        /// <inheritdoc />
        public override void Write(IBinaryStreamWriter writer)
        {
            var header = CreateHeader();

            header.Write(writer);
            writer.Align(4);
            WriteValue(writer);
        }
Пример #4
0
 /// <summary>
 /// Writes a collection of stream headers to an output stream.
 /// </summary>
 /// <param name="writer">The output stream to write to.</param>
 /// <param name="headers">The headers to write.</param>
 protected virtual void WriteStreamHeaders(IBinaryStreamWriter writer, IEnumerable <MetadataStreamHeader> headers)
 {
     foreach (var header in headers)
     {
         writer.WriteUInt32(header.Offset);
         writer.WriteUInt32(header.Size);
         writer.WriteAsciiString(header.Name);
         writer.WriteByte(0);
         writer.Align(4);
     }
 }