2 * Copyright (c) 2002 Sergey Chaban <serge@wildwestsoftware.com>
\r
8 using System.Runtime.InteropServices;
\r
10 namespace Mono.PEToolkit {
\r
12 public class Section {
\r
14 // IMAGE_SECTION_HEADER
\r
15 [StructLayoutAttribute(LayoutKind.Sequential)]
\r
16 public struct Header {
\r
17 internal uint phAddr_virtSize;
\r
18 internal RVA virtAddr;
\r
19 internal uint rawSize;
\r
20 internal RVA rawDataPtr;
\r
21 internal RVA relocPtr;
\r
22 internal RVA lineNumPtr;
\r
23 internal short relocNum;
\r
24 internal short linenumNum;
\r
25 internal SectionCharacteristics flags;
\r
28 private string name;
\r
29 internal Header hdr;
\r
31 public readonly static Section Invalid;
\r
35 Invalid = new Section();
\r
43 public string Name {
\r
53 public uint PhysicalAddress {
\r
55 return hdr.phAddr_virtSize;
\r
58 hdr.phAddr_virtSize = value;
\r
62 public uint VirtualSize {
\r
64 return hdr.phAddr_virtSize;
\r
67 hdr.phAddr_virtSize = value;
\r
71 public RVA VirtualAddress {
\r
73 return hdr.virtAddr;
\r
76 hdr.virtAddr = value;
\r
80 public uint SizeOfRawData {
\r
85 hdr.rawSize = value;
\r
89 public RVA PointerToRawData {
\r
91 return hdr.rawDataPtr;
\r
94 hdr.rawDataPtr = value;
\r
98 public RVA PointerToRelocations {
\r
100 return hdr.relocPtr;
\r
103 hdr.relocPtr = value;
\r
107 public RVA PointerToLinenumbers {
\r
109 return hdr.lineNumPtr;
\r
112 hdr.lineNumPtr = value;
\r
116 public short NumberOfRelocations {
\r
118 return hdr.relocNum;
\r
121 hdr.relocNum = value;
\r
125 public short NumberOfLinenumbers {
\r
127 return hdr.linenumNum;
\r
130 hdr.linenumNum = value;
\r
134 public SectionCharacteristics Characteristics {
\r
147 unsafe public void Read(BinaryReader reader)
\r
149 sbyte* pName = stackalloc sbyte [8];
\r
152 for (int i = 8; --i >=0;) {
\r
153 sbyte c = reader.ReadSByte();
\r
158 int len = (int) (p - pName);
\r
160 name = new string(pName, 0, len, Encoding.ASCII);
\r
162 name = String.Empty;
\r
165 reader.BaseStream.Position += 8 - len - 1;
\r
167 fixed (void* pHdr = &this.hdr) {
\r
168 PEUtils.ReadStruct(reader, pHdr, sizeof (Header), typeof (Header));
\r