Added XML documentation.

This commit is contained in:
2017-10-16 15:49:07 +01:00
parent e1ce4f4ec9
commit ebcf787e4f
10 changed files with 226 additions and 27 deletions

View File

@@ -29,6 +29,9 @@ namespace libexeinfo
{ {
public partial class MZ public partial class MZ
{ {
/// <summary>
/// MZ executable signature, "MZ"
/// </summary>
public const ushort Signature = 0x5A4D; public const ushort Signature = 0x5A4D;
} }
} }

View File

@@ -24,12 +24,17 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
using System;
using System.Text; using System.Text;
namespace libexeinfo namespace libexeinfo
{ {
public partial class MZ public partial class MZ
{ {
/// <summary>
/// Gets a string with human readable information for a given MZ header
/// </summary>
/// <returns>Human readable information for given MZ header.</returns>
/// <param name="header">MZ executable header.</param>
public static string GetInfo(MZHeader header) public static string GetInfo(MZHeader header)
{ {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
@@ -53,6 +58,10 @@ namespace libexeinfo
return sb.ToString(); return sb.ToString();
} }
/// <summary>
/// Gets a string with human readable information for the MZ executable represented by this instance
/// </summary>
/// <returns>Human readable information for this instance.</returns>
public string GetInfo() public string GetInfo()
{ {
return GetInfo(Header); return GetInfo(Header);

View File

@@ -29,12 +29,28 @@ using System.Runtime.InteropServices;
namespace libexeinfo namespace libexeinfo
{ {
/// <summary>
/// Represents a DOS relocatable executable
/// </summary>
public partial class MZ public partial class MZ
{ {
/// <summary>
/// The <see cref="FileStream"/> that contains the executable represented by this instance
/// </summary>
public readonly FileStream BaseStream; public readonly FileStream BaseStream;
/// <summary>
/// Header for this executable
/// </summary>
public readonly MZHeader Header; public readonly MZHeader Header;
/// <summary>
/// If true this instance correctly represents a DOS relocatable executable
/// </summary>
public readonly bool IsMZ; public readonly bool IsMZ;
/// <summary>
/// Initializes a new instance of the <see cref="T:libexeinfo.MZ"/> class.
/// </summary>
/// <param name="path">Executable path.</param>
public MZ(string path) public MZ(string path)
{ {
byte[] buffer = new byte[Marshal.SizeOf(typeof(MZHeader))]; byte[] buffer = new byte[Marshal.SizeOf(typeof(MZHeader))];
@@ -49,6 +65,10 @@ namespace libexeinfo
IsMZ = Header.signature == Signature; IsMZ = Header.signature == Signature;
} }
/// <summary>
/// Initializes a new instance of the <see cref="T:libexeinfo.MZ"/> class.
/// </summary>
/// <param name="stream">Stream containing the executable.</param>
public MZ(FileStream stream) public MZ(FileStream stream)
{ {
byte[] buffer = new byte[Marshal.SizeOf(typeof(MZHeader))]; byte[] buffer = new byte[Marshal.SizeOf(typeof(MZHeader))];
@@ -63,17 +83,22 @@ namespace libexeinfo
IsMZ = Header.signature == Signature; IsMZ = Header.signature == Signature;
} }
public bool Identify() /// <summary>
{ /// Identifies if the specified executable is a DOS relocatable executable
return IsMZ; /// </summary>
} /// <returns><c>true</c> if the specified executable is a DOS relocatable executable, <c>false</c> otherwise.</returns>
/// <param name="path">Executable path.</param>
public static bool Identify(string path) public static bool Identify(string path)
{ {
FileStream exeFs = File.Open(path, FileMode.Open, FileAccess.Read); FileStream exeFs = File.Open(path, FileMode.Open, FileAccess.Read);
return Identify(exeFs); return Identify(exeFs);
} }
/// <summary>
/// Identifies if the specified executable is a DOS relocatable executable
/// </summary>
/// <returns><c>true</c> if the specified executable is a DOS relocatable executable, <c>false</c> otherwise.</returns>
/// <param name="stream">Stream containing the executable.</param>
public static bool Identify(FileStream stream) public static bool Identify(FileStream stream)
{ {
byte[] buffer = new byte[Marshal.SizeOf(typeof(MZHeader))]; byte[] buffer = new byte[Marshal.SizeOf(typeof(MZHeader))];

View File

@@ -30,6 +30,9 @@ namespace libexeinfo
{ {
public partial class MZ public partial class MZ
{ {
/// <summary>
/// Header of a DOS relocatable executable
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 1)] [StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct MZHeader public struct MZHeader
{ {
@@ -56,6 +59,9 @@ namespace libexeinfo
public uint new_offset; public uint new_offset;
} }
/// <summary>
/// Entry in the relocation table
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 1)] [StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct RelocationTableEntry public struct RelocationTableEntry
{ {

View File

@@ -30,11 +30,25 @@ namespace libexeinfo
{ {
public partial class NE public partial class NE
{ {
/// <summary>
/// New Executable signature, "NE"
/// </summary>
public const ushort Signature = 0x454E; public const ushort Signature = 0x454E;
/// <summary>
/// Signature for a <see cref="FixedFileInfo"/>
/// </summary>
public static readonly string FixedFileInfoSig = "VS_VERSION_INFO"; public static readonly string FixedFileInfoSig = "VS_VERSION_INFO";
/// <summary>
/// Signature for list of name=value strings inside a version resource
/// </summary>
public static readonly string StringFileInfo = "StringFileInfo"; public static readonly string StringFileInfo = "StringFileInfo";
public static string IdToName(ushort id) /// <summary>
/// Gets the name of a resource type according to its identifier
/// </summary>
/// <returns>The resource type name.</returns>
/// <param name="id">Resource type identifier.</param>
public static string ResourceIdToName(ushort id)
{ {
switch (id & 0x7FFF) switch (id & 0x7FFF)
{ {

View File

@@ -29,6 +29,9 @@ namespace libexeinfo
{ {
public partial class NE public partial class NE
{ {
/// <summary>
/// Program flags.
/// </summary>
[Flags] [Flags]
public enum ProgramFlags : byte public enum ProgramFlags : byte
{ {
@@ -43,6 +46,9 @@ namespace libexeinfo
i87 = 1 << 7 i87 = 1 << 7
} }
/// <summary>
/// Target operating system.
/// </summary>
public enum TargetOS : byte public enum TargetOS : byte
{ {
Unknown = 0, Unknown = 0,
@@ -53,6 +59,9 @@ namespace libexeinfo
Borland = 5 Borland = 5
} }
/// <summary>
/// Application flags.
/// </summary>
[Flags] [Flags]
public enum ApplicationFlags : byte public enum ApplicationFlags : byte
{ {
@@ -63,6 +72,9 @@ namespace libexeinfo
DLL = 1 << 7 DLL = 1 << 7
} }
/// <summary>
/// OS/2 flags.
/// </summary>
[Flags] [Flags]
public enum OS2Flags : byte public enum OS2Flags : byte
{ {
@@ -72,6 +84,9 @@ namespace libexeinfo
GangloadArea = 1 << 3, GangloadArea = 1 << 3,
} }
/// <summary>
/// Resource flags.
/// </summary>
[Flags] [Flags]
public enum ResourceFlags : ushort public enum ResourceFlags : ushort
{ {
@@ -80,6 +95,9 @@ namespace libexeinfo
Preload = 0x40 Preload = 0x40
} }
/// <summary>
/// Resource types.
/// </summary>
public enum ResourceTypes : ushort public enum ResourceTypes : ushort
{ {
RT_ACCELERATOR = 9, RT_ACCELERATOR = 9,
@@ -111,6 +129,9 @@ namespace libexeinfo
RT_NEW = 0x2000, RT_NEW = 0x2000,
} }
/// <summary>
/// Version file flags.
/// </summary>
[Flags] [Flags]
public enum VersionFileFlags : uint public enum VersionFileFlags : uint
{ {
@@ -122,6 +143,9 @@ namespace libexeinfo
VS_FF_SPECIALBUILD = 0x00000020, VS_FF_SPECIALBUILD = 0x00000020,
} }
/// <summary>
/// Version file operating system.
/// </summary>
public enum VersionFileOS : uint public enum VersionFileOS : uint
{ {
VOS_DOS = 0x00010000, VOS_DOS = 0x00010000,
@@ -154,6 +178,9 @@ namespace libexeinfo
VOS_OS232_PM32 = 0x00030003, VOS_OS232_PM32 = 0x00030003,
} }
/// <summary>
/// Version file type.
/// </summary>
public enum VersionFileType : uint public enum VersionFileType : uint
{ {
VFT_APP = 0x00000001, VFT_APP = 0x00000001,
@@ -165,6 +192,9 @@ namespace libexeinfo
VFT_VXD = 0x00000005, VFT_VXD = 0x00000005,
} }
/// <summary>
/// Version file subtype.
/// </summary>
public enum VersionFileSubtype : uint public enum VersionFileSubtype : uint
{ {
VFT2_UNKNOWN = 0x00000000, VFT2_UNKNOWN = 0x00000000,

View File

@@ -223,7 +223,7 @@ namespace libexeinfo
table.types[t].name = Encoding.ASCII.GetString(str); table.types[t].name = Encoding.ASCII.GetString(str);
} }
else else
table.types[t].name = IdToName(table.types[t].id); table.types[t].name = ResourceIdToName(table.types[t].id);
for (int r = 0; r < table.types[t].resources.Length; r++) for (int r = 0; r < table.types[t].resources.Length; r++)
{ {

View File

@@ -29,15 +29,31 @@ using System.Runtime.InteropServices;
namespace libexeinfo namespace libexeinfo
{ {
/// <summary>
/// Represents a Microsoft New Executable
/// </summary>
public partial class NE public partial class NE
{ {
/// <summary>
/// The <see cref="FileStream"/> that contains the executable represented by this instance
/// </summary>
public readonly FileStream BaseStream; public readonly FileStream BaseStream;
/// <summary>
/// Header for this executable
/// </summary>
public readonly NEHeader Header; public readonly NEHeader Header;
/// <summary>
/// If true this instance correctly represents a Microsoft New Executable
/// </summary>
public readonly bool IsNE; public readonly bool IsNE;
public readonly MZ BaseExecutable; public readonly MZ BaseExecutable;
public readonly ResourceTable Resources; public readonly ResourceTable Resources;
public readonly Version[] Versions; public readonly Version[] Versions;
/// <summary>
/// Initializes a new instance of the <see cref="T:libexeinfo.NE"/> class.
/// </summary>
/// <param name="path">Executable path.</param>
public NE(string path) public NE(string path)
{ {
IsNE = false; IsNE = false;
@@ -61,6 +77,10 @@ namespace libexeinfo
} }
} }
/// <summary>
/// Initializes a new instance of the <see cref="T:libexeinfo.NE"/> class.
/// </summary>
/// <param name="stream">Stream containing the executable.</param>
public NE(FileStream stream) public NE(FileStream stream)
{ {
IsNE = false; IsNE = false;
@@ -84,11 +104,11 @@ namespace libexeinfo
} }
} }
public bool Identify() /// <summary>
{ /// Identifies if the specified executable is a Microsoft New Executable
return IsNE; /// </summary>
} /// <returns><c>true</c> if the specified executable is a Microsoft New Executable, <c>false</c> otherwise.</returns>
/// <param name="path">Executable path.</param>
public static bool Identify(string path) public static bool Identify(string path)
{ {
FileStream BaseStream = File.Open(path, FileMode.Open, FileAccess.Read); FileStream BaseStream = File.Open(path, FileMode.Open, FileAccess.Read);
@@ -111,6 +131,11 @@ namespace libexeinfo
return false; return false;
} }
/// <summary>
/// Identifies if the specified executable is a Microsoft New Executable
/// </summary>
/// <returns><c>true</c> if the specified executable is a Microsoft New Executable, <c>false</c> otherwise.</returns>
/// <param name="stream">Stream containing the executable.</param>
public static bool Identify(FileStream stream) public static bool Identify(FileStream stream)
{ {
FileStream BaseStream = stream; FileStream BaseStream = stream;

View File

@@ -31,6 +31,9 @@ namespace libexeinfo
{ {
public partial class NE public partial class NE
{ {
/// <summary>
/// Header for a Microsoft New Executable
/// </summary>
[StructLayout(LayoutKind.Sequential/*, Pack = 2*/)] [StructLayout(LayoutKind.Sequential/*, Pack = 2*/)]
public struct NEHeader public struct NEHeader
{ {
@@ -68,12 +71,18 @@ namespace libexeinfo
public byte os_major; public byte os_major;
} }
/// <summary>
/// Resource table
/// </summary>
public struct ResourceTable public struct ResourceTable
{ {
public ushort alignment_shift; public ushort alignment_shift;
public ResourceType[] types; public ResourceType[] types;
} }
/// <summary>
/// Resource type
/// </summary>
public struct ResourceType public struct ResourceType
{ {
public ushort id; public ushort id;
@@ -85,6 +94,9 @@ namespace libexeinfo
public string name; public string name;
} }
/// <summary>
/// Resource
/// </summary>
public struct Resource public struct Resource
{ {
public ushort dataOffset; public ushort dataOffset;
@@ -98,6 +110,9 @@ namespace libexeinfo
public byte[] data; public byte[] data;
} }
/// <summary>
/// Node in a version resource
/// </summary>
class VersionNode class VersionNode
{ {
public ushort cbNode; public ushort cbNode;
@@ -107,6 +122,9 @@ namespace libexeinfo
public VersionNode[] children; public VersionNode[] children;
} }
/// <summary>
/// Fixed file version info
/// </summary>
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
public class FixedFileInfo public class FixedFileInfo
{ {

View File

@@ -34,6 +34,10 @@ namespace libexeinfo
{ {
public partial class NE public partial class NE
{ {
/// <summary>
/// Gets all the version resources from this instance
/// </summary>
/// <returns>The decoded version resources.</returns>
public List<Version> GetVersions() public List<Version> GetVersions()
{ {
List<Version> versions = new List<Version>(); List<Version> versions = new List<Version>();
@@ -53,8 +57,15 @@ namespace libexeinfo
return versions; return versions;
} }
/// <summary>
/// Represents a version ("RT_VERSION") resource
/// </summary>
public class Version public class Version
{ {
/// <summary>
/// This contains a list of all name=value strings pairs sorted by language
/// </summary>
/// <value>List of all name=value strings pairs sorted by language.</value>
public Dictionary<string, Dictionary<string, string>> StringsByLanguage { get; } public Dictionary<string, Dictionary<string, string>> StringsByLanguage { get; }
string fileVersion; string fileVersion;
@@ -66,6 +77,10 @@ namespace libexeinfo
DateTime fileDate; DateTime fileDate;
string name; string name;
/// <summary>
/// File version.
/// </summary>
/// <value>The file version.</value>
public string FileVersion public string FileVersion
{ {
get get
@@ -74,6 +89,10 @@ namespace libexeinfo
} }
} }
/// <summary>
/// Product version.
/// </summary>
/// <value>The product version.</value>
public string ProductVersion public string ProductVersion
{ {
get get
@@ -82,6 +101,10 @@ namespace libexeinfo
} }
} }
/// <summary>
/// File flags.
/// </summary>
/// <value>The file flags.</value>
public VersionFileFlags FileFlags public VersionFileFlags FileFlags
{ {
get get
@@ -90,6 +113,10 @@ namespace libexeinfo
} }
} }
/// <summary>
/// File operating system.
/// </summary>
/// <value>The file operating system.</value>
public VersionFileOS FileOS public VersionFileOS FileOS
{ {
get get
@@ -98,6 +125,10 @@ namespace libexeinfo
} }
} }
/// <summary>
/// File type.
/// </summary>
/// <value>The type of the file.</value>
public VersionFileType FileType public VersionFileType FileType
{ {
get get
@@ -106,6 +137,10 @@ namespace libexeinfo
} }
} }
/// <summary>
/// File subtype.
/// </summary>
/// <value>The file subtype.</value>
public VersionFileSubtype FileSubtype public VersionFileSubtype FileSubtype
{ {
get get
@@ -114,6 +149,10 @@ namespace libexeinfo
} }
} }
/// <summary>
/// File date.
/// </summary>
/// <value>The file date.</value>
public DateTime FileDate public DateTime FileDate
{ {
get get
@@ -122,11 +161,20 @@ namespace libexeinfo
} }
} }
/// <summary>
/// Resource name
/// </summary>
/// <value>The resource name.</value>
public string Name public string Name
{ {
get { return name; } get { return name; }
} }
/// <summary>
/// Initializes a new instance of the <see cref="T:libexeinfo.NE.Version"/> class.
/// </summary>
/// <param name="data">Resource data.</param>
/// <param name="resourceName">Resource name.</param>
public Version(byte[] data, string resourceName = null) public Version(byte[] data, string resourceName = null)
{ {
if (data == null || data.Length < 5) if (data == null || data.Length < 5)
@@ -235,6 +283,11 @@ namespace libexeinfo
} }
} }
/// <summary>
/// Converts a <see cref="VersionFileType"/> to string
/// </summary>
/// <returns>The string.</returns>
/// <param name="type"><see cref="VersionFileType"/></param>
public static string TypeToString(VersionFileType type) public static string TypeToString(VersionFileType type)
{ {
switch (type) switch (type)
@@ -258,6 +311,11 @@ namespace libexeinfo
} }
} }
/// <summary>
/// Converts a <see cref="VersionFileSubtype"/> to string, considering file type to be a driver
/// </summary>
/// <returns>The string.</returns>
/// <param name="subtype"><see cref="VersionFileSubtype"/></param>
public static string DriverToString(VersionFileSubtype subtype) public static string DriverToString(VersionFileSubtype subtype)
{ {
switch (subtype) switch (subtype)
@@ -291,6 +349,11 @@ namespace libexeinfo
} }
} }
/// <summary>
/// Converts a <see cref="VersionFileSubtype"/> to string, considering file type to be a font
/// </summary>
/// <returns>The string.</returns>
/// <param name="subtype"><see cref="VersionFileSubtype"/></param>
public static string FontToString(VersionFileSubtype subtype) public static string FontToString(VersionFileSubtype subtype)
{ {
switch (subtype) switch (subtype)
@@ -307,6 +370,12 @@ namespace libexeinfo
return string.Format("Unknown type code {0}", (uint)subtype); return string.Format("Unknown type code {0}", (uint)subtype);
} }
} }
/// <summary>
/// Converts a <see cref="VersionFileOS"/> to string
/// </summary>
/// <returns>The string.</returns>
/// <param name="os"><see cref="VersionFileOS"/></param>
public static string OsToString(VersionFileOS os) public static string OsToString(VersionFileOS os)
{ {
switch (os) switch (os)