| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | namespace System.Reflection.PortableExecutable |
| | | 5 | | { |
| | | 6 | | public readonly struct SectionHeader |
| | | 7 | | { |
| | | 8 | | /// <summary> |
| | | 9 | | /// The name of the section. |
| | | 10 | | /// </summary> |
| | 0 | 11 | | public string Name { get; } |
| | | 12 | | |
| | | 13 | | /// <summary> |
| | | 14 | | /// The total size of the section when loaded into memory. |
| | | 15 | | /// If this value is greater than <see cref="SizeOfRawData"/>, the section is zero-padded. |
| | | 16 | | /// This field is valid only for PE images and should be set to zero for object files. |
| | | 17 | | /// </summary> |
| | 0 | 18 | | public int VirtualSize { get; } |
| | | 19 | | |
| | | 20 | | /// <summary> |
| | | 21 | | /// For PE images, the address of the first byte of the section relative to the image base when the |
| | | 22 | | /// section is loaded into memory. For object files, this field is the address of the first byte before |
| | | 23 | | /// relocation is applied; for simplicity, compilers should set this to zero. Otherwise, |
| | | 24 | | /// it is an arbitrary value that is subtracted from offsets during relocation. |
| | | 25 | | /// </summary> |
| | 0 | 26 | | public int VirtualAddress { get; } |
| | | 27 | | |
| | | 28 | | /// <summary> |
| | | 29 | | /// The size of the section (for object files) or the size of the initialized data on disk (for image files). |
| | | 30 | | /// For PE images, this must be a multiple of <see cref="PEHeader.FileAlignment"/>. |
| | | 31 | | /// If this is less than <see cref="VirtualSize"/>, the remainder of the section is zero-filled. |
| | | 32 | | /// Because the <see cref="SizeOfRawData"/> field is rounded but the <see cref="VirtualSize"/> field is not, |
| | | 33 | | /// it is possible for <see cref="SizeOfRawData"/> to be greater than <see cref="VirtualSize"/> as well. |
| | | 34 | | /// When a section contains only uninitialized data, this field should be zero. |
| | | 35 | | /// </summary> |
| | 0 | 36 | | public int SizeOfRawData { get; } |
| | | 37 | | |
| | | 38 | | /// <summary> |
| | | 39 | | /// The file pointer to the first page of the section within the COFF file. |
| | | 40 | | /// For PE images, this must be a multiple of <see cref="PEHeader.FileAlignment"/>. |
| | | 41 | | /// For object files, the value should be aligned on a 4 byte boundary for best performance. |
| | | 42 | | /// When a section contains only uninitialized data, this field should be zero. |
| | | 43 | | /// </summary> |
| | 0 | 44 | | public int PointerToRawData { get; } |
| | | 45 | | |
| | | 46 | | /// <summary> |
| | | 47 | | /// The file pointer to the beginning of relocation entries for the section. |
| | | 48 | | /// This is set to zero for PE images or if there are no relocations. |
| | | 49 | | /// </summary> |
| | 0 | 50 | | public int PointerToRelocations { get; } |
| | | 51 | | |
| | | 52 | | /// <summary> |
| | | 53 | | /// The file pointer to the beginning of line-number entries for the section. |
| | | 54 | | /// This is set to zero if there are no COFF line numbers. |
| | | 55 | | /// This value should be zero for an image because COFF debugging information is deprecated. |
| | | 56 | | /// </summary> |
| | 0 | 57 | | public int PointerToLineNumbers { get; } |
| | | 58 | | |
| | | 59 | | /// <summary> |
| | | 60 | | /// The number of relocation entries for the section. This is set to zero for PE images. |
| | | 61 | | /// </summary> |
| | 0 | 62 | | public ushort NumberOfRelocations { get; } |
| | | 63 | | |
| | | 64 | | /// <summary> |
| | | 65 | | /// The number of line-number entries for the section. |
| | | 66 | | /// This value should be zero for an image because COFF debugging information is deprecated. |
| | | 67 | | /// </summary> |
| | 0 | 68 | | public ushort NumberOfLineNumbers { get; } |
| | | 69 | | |
| | | 70 | | /// <summary> |
| | | 71 | | /// The flags that describe the characteristics of the section. |
| | | 72 | | /// </summary> |
| | 0 | 73 | | public SectionCharacteristics SectionCharacteristics { get; } |
| | | 74 | | |
| | | 75 | | internal const int NameSize = 8; |
| | | 76 | | |
| | | 77 | | internal const int Size = |
| | | 78 | | NameSize + |
| | | 79 | | sizeof(int) + // VirtualSize |
| | | 80 | | sizeof(int) + // VirtualAddress |
| | | 81 | | sizeof(int) + // SizeOfRawData |
| | | 82 | | sizeof(int) + // PointerToRawData |
| | | 83 | | sizeof(int) + // PointerToRelocations |
| | | 84 | | sizeof(int) + // PointerToLineNumbers |
| | | 85 | | sizeof(short) + // NumberOfRelocations |
| | | 86 | | sizeof(short) + // NumberOfLineNumbers |
| | | 87 | | sizeof(int); // SectionCharacteristics |
| | | 88 | | |
| | | 89 | | internal SectionHeader(ref PEBinaryReader reader) |
| | 0 | 90 | | { |
| | 0 | 91 | | Name = reader.ReadNullPaddedUTF8(NameSize); |
| | 0 | 92 | | VirtualSize = reader.ReadInt32(); |
| | 0 | 93 | | VirtualAddress = reader.ReadInt32(); |
| | 0 | 94 | | SizeOfRawData = reader.ReadInt32(); |
| | 0 | 95 | | PointerToRawData = reader.ReadInt32(); |
| | 0 | 96 | | PointerToRelocations = reader.ReadInt32(); |
| | 0 | 97 | | PointerToLineNumbers = reader.ReadInt32(); |
| | 0 | 98 | | NumberOfRelocations = reader.ReadUInt16(); |
| | 0 | 99 | | NumberOfLineNumbers = reader.ReadUInt16(); |
| | 0 | 100 | | SectionCharacteristics = (SectionCharacteristics)reader.ReadUInt32(); |
| | 0 | 101 | | } |
| | | 102 | | } |
| | | 103 | | } |
| | | 104 | | |