internal void AddUnmanagedResourceDirectory(PEResourceDirectory directory) { Contract.Requires(directory != null); if (rsrc == null) { rsrc = new Section(FileImage.rsrcName, 0x40000040); } rsrc.IncTide(directory.Size()); unmanagedResourceRoot = directory; }
/// <summary> /// Read unmanged resource directory structure from PE-file. /// </summary> /// <param name="reader"></param> internal void PopulateResourceDirectory(PEReader reader, long baseOffset) { Contract.Requires(reader != null); PEResourceElement resElement; int junk = reader.ReadInt32(); // Must be zero. this.Date = reader.ReadUInt32(); // Time stamp. this.MajVer = reader.ReadUInt16(); this.MinVer = reader.ReadUInt16(); int numNameEntries = reader.ReadUInt16(); // Number of named entries. int numIdntEntries = reader.ReadUInt16(); // Number of ID entries. for (int i = 0; i < numNameEntries; i++) { uint nameOrId = reader.ReadUInt32(); uint elemOfst = reader.ReadUInt32(); if ((elemOfst & 0x80000000) != 0) // Element is subdirectory. { resElement = new PEResourceDirectory(); } else { resElement = new PEResourceData(); } resElement.Name = ReadName(reader, baseOffset + nameOrId & 0x7fffffff); resElement.offset = baseOffset + (long)(elemOfst & 0x7fffffff); this.AddElement(resElement); } // Read the Ident entries. for (int i = 0; i < numIdntEntries; i++) { uint nameOrId = reader.ReadUInt32(); uint elemOfst = reader.ReadUInt32(); if ((elemOfst & 0x80000000) != 0) // Element is subdirectory. { resElement = new PEResourceDirectory(); } else { resElement = new PEResourceData(); } resElement.Id = (ushort)nameOrId; resElement.offset = baseOffset + (long)(elemOfst & 0x7fffffff); this.AddElement(resElement); } // Now recurse to get subdirectories/the real data. foreach (PEResourceElement elem in this.elements) { PEResourceDirectory resDirectory; if ((resDirectory = elem as PEResourceDirectory) != null) { reader.BaseStream.Seek(resDirectory.offset, SeekOrigin.Begin); resDirectory.PopulateResourceDirectory(reader, baseOffset); } else { PEResourceData resData; if ((resData = elem as PEResourceData) != null) { reader.BaseStream.Seek(resData.offset, SeekOrigin.Begin); resData.PopulateResourceData(reader, baseOffset); } } } }