public void Read(ReaderContext ctxt, BlobReader reader) { var name = reader.ReadAsciiZeroPaddedString(8); if (string.IsNullOrEmpty(name)) throw new PEException("invalid SectionHeader.Name"); if (name.Equals(".text", StringComparison.Ordinal)) Section = Section.Text; else if (name.Equals(".rsrc", StringComparison.Ordinal)) Section = Section.Rsrc; else if (name.Equals(".reloc", StringComparison.Ordinal)) Section = Section.Reloc; else throw new PEException("invalid SectionHeader.Name"); VirtualSize = reader.ReadUInt32(); VirtualAddress = reader.ReadUInt32(); SizeOfRawData = reader.ReadUInt32(); // NOTE: Virtual size may be less than raw data size if (VirtualSize > SizeOfRawData) // Need to support readers with implicit zero padding at end throw new NotImplementedException(); PointerToRawData.Read(reader); PointerToRelocations = reader.ReadUInt32(); var actualPointerToLinenumbers = reader.ReadUInt32(); if (actualPointerToLinenumbers != pointerToLinenumbers) throw new PEException("invalid SectionHeader.PointerToLinenumbers"); NumberOfRelocations = reader.ReadUInt16(); var actualNumberOfLinenumbers = reader.ReadUInt16(); if (actualNumberOfLinenumbers != numberOfLinenumbers) throw new PEException("invalid SectionHeader.NumberOfLinenumbers"); Characteristics = (ImageSectionCharacteristics)reader.ReadUInt32(); if (ctxt.Tracer != null) { ctxt.Tracer.AppendLine("SectionHeader {"); ctxt.Tracer.Indent(); ctxt.Tracer.AppendLine(String.Format("Name: {0}", Section.ToString())); ctxt.Tracer.AppendLine(String.Format("VirtualSize: {0:x8}", VirtualSize)); ctxt.Tracer.AppendLine(String.Format("VirtualAddress: {0:x8}", VirtualAddress)); ctxt.Tracer.AppendLine(String.Format("SizeOfRawData: {0:x8}", SizeOfRawData)); PointerToRawData.Append(ctxt, "PointerToRawData"); ctxt.Tracer.Outdent(); ctxt.Tracer.AppendLine("}"); } }