// dnlib: See LICENSE.txt for more info using System; using System.Diagnostics; using System.Text; using dnlib.IO; namespace dnlib.PE { /// /// Represents the IMAGE_SECTION_HEADER PE section /// [DebuggerDisplay("RVA:{virtualAddress} VS:{virtualSize} FO:{pointerToRawData} FS:{sizeOfRawData} {displayName}")] public sealed class ImageSectionHeader : FileSection { readonly string displayName; readonly byte[] name; readonly uint virtualSize; readonly RVA virtualAddress; readonly uint sizeOfRawData; readonly uint pointerToRawData; readonly uint pointerToRelocations; readonly uint pointerToLinenumbers; readonly ushort numberOfRelocations; readonly ushort numberOfLinenumbers; readonly uint characteristics; /// /// Returns the human readable section name, ignoring everything after /// the first nul byte /// public string DisplayName => displayName; /// /// Returns the IMAGE_SECTION_HEADER.Name field /// public byte[] Name => name; /// /// Returns the IMAGE_SECTION_HEADER.VirtualSize field /// public uint VirtualSize => virtualSize; /// /// Returns the IMAGE_SECTION_HEADER.VirtualAddress field /// public RVA VirtualAddress => virtualAddress; /// /// Returns the IMAGE_SECTION_HEADER.SizeOfRawData field /// public uint SizeOfRawData => sizeOfRawData; /// /// Returns the IMAGE_SECTION_HEADER.PointerToRawData field /// public uint PointerToRawData => pointerToRawData; /// /// Returns the IMAGE_SECTION_HEADER.PointerToRelocations field /// public uint PointerToRelocations => pointerToRelocations; /// /// Returns the IMAGE_SECTION_HEADER.PointerToLinenumbers field /// public uint PointerToLinenumbers => pointerToLinenumbers; /// /// Returns the IMAGE_SECTION_HEADER.NumberOfRelocations field /// public ushort NumberOfRelocations => numberOfRelocations; /// /// Returns the IMAGE_SECTION_HEADER.NumberOfLinenumbers field /// public ushort NumberOfLinenumbers => numberOfLinenumbers; /// /// Returns the IMAGE_SECTION_HEADER.Characteristics field /// public uint Characteristics => characteristics; /// /// Constructor /// /// PE file reader pointing to the start of this section /// Verify section /// Thrown if verification fails public ImageSectionHeader(ref DataReader reader, bool verify) { SetStartOffset(ref reader); name = reader.ReadBytes(8); virtualSize = reader.ReadUInt32(); virtualAddress = (RVA)reader.ReadUInt32(); sizeOfRawData = reader.ReadUInt32(); pointerToRawData = reader.ReadUInt32(); pointerToRelocations = reader.ReadUInt32(); pointerToLinenumbers = reader.ReadUInt32(); numberOfRelocations = reader.ReadUInt16(); numberOfLinenumbers = reader.ReadUInt16(); characteristics = reader.ReadUInt32(); SetEndoffset(ref reader); displayName = ToString(name); } static string ToString(byte[] name) { var sb = new StringBuilder(name.Length); foreach (var b in name) { if (b == 0) break; sb.Append((char)b); } return sb.ToString(); } } }