// dnlib: See LICENSE.txt for more info using System; using System.Collections.Generic; using dnlib.IO; using dnlib.W32Resources; namespace dnlib.PE { /// /// Converts s to/from s /// public interface IRvaFileOffsetConverter { /// /// Converts a to an , returns 0 if out of range /// /// The file offset to convert /// The RVA RVA ToRVA(FileOffset offset); /// /// Converts an to a , returns 0 if out of range /// /// The RVA to convert /// The file offset FileOffset ToFileOffset(RVA rva); } /// /// Interface to access a PE image /// public interface IPEImage : IRvaFileOffsetConverter, IDisposable { /// /// true if image layout is the same as the raw PE image layout, false /// if it's the same layout as a PE image loaded by the OS PE loader. /// bool IsFileImageLayout { get; } /// /// true if some of the memory where the image is located could be unavailable. /// This could happen if it's been loaded by the OS loader. /// bool MayHaveInvalidAddresses { get; } /// /// The filename or null if the data is not from a file /// string Filename { get; } /// /// Returns the DOS header /// ImageDosHeader ImageDosHeader { get; } /// /// Returns the NT headers /// ImageNTHeaders ImageNTHeaders { get; } /// /// Returns the section headers /// IList ImageSectionHeaders { get; } /// /// Returns the debug directories /// IList ImageDebugDirectories { get; } /// /// Gets/sets the Win32 resources. This is null if there are no Win32 resources. /// Win32Resources Win32Resources { get; set; } /// /// Gets the factory /// DataReaderFactory DataReaderFactory { get; } /// /// Creates a from to the end of the image /// /// Offset of data /// DataReader CreateReader(FileOffset offset); /// /// Creates a /// /// Offset of data /// Length of data /// DataReader CreateReader(FileOffset offset, uint length); /// /// Creates a from to the end of the image /// /// RVA of data /// DataReader CreateReader(RVA rva); /// /// Creates a /// /// RVA of data /// Length of data /// DataReader CreateReader(RVA rva, uint length); /// /// Creates a that can read the whole image /// /// DataReader CreateReader(); } /// /// Interface to access a PE image /// public interface IInternalPEImage : IPEImage { /// /// Call this to disable memory mapped I/O if it was used to open the file. This must only /// be called if no other code is trying to access the memory since that could lead to an /// exception. /// void UnsafeDisableMemoryMappedIO(); /// /// true if memory mapped I/O is enabled /// bool IsMemoryMappedIO { get; } } public static partial class PEExtensions { /// /// Finds a /// /// this /// Type /// Name /// Language ID /// The or null if none found public static ResourceData FindWin32ResourceData(this IPEImage self, ResourceName type, ResourceName name, ResourceName langId) => self.Win32Resources?.Find(type, name, langId); } }