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
{
/// <summary>
/// MZ executable signature, "MZ"
/// </summary>
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
// THE SOFTWARE.
using System;
using System.Text;
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)
{
StringBuilder sb = new StringBuilder();
@@ -53,7 +58,11 @@ namespace libexeinfo
return sb.ToString();
}
public string GetInfo()
/// <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()
{
return GetInfo(Header);
}

View File

@@ -29,12 +29,28 @@ using System.Runtime.InteropServices;
namespace libexeinfo
{
/// <summary>
/// Represents a DOS relocatable executable
/// </summary>
public partial class MZ
{
/// <summary>
/// The <see cref="FileStream"/> that contains the executable represented by this instance
/// </summary>
public readonly FileStream BaseStream;
/// <summary>
/// Header for this executable
/// </summary>
public readonly MZHeader Header;
/// <summary>
/// If true this instance correctly represents a DOS relocatable executable
/// </summary>
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)
{
byte[] buffer = new byte[Marshal.SizeOf(typeof(MZHeader))];
@@ -49,6 +65,10 @@ namespace libexeinfo
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)
{
byte[] buffer = new byte[Marshal.SizeOf(typeof(MZHeader))];
@@ -63,18 +83,23 @@ namespace libexeinfo
IsMZ = Header.signature == Signature;
}
public bool Identify()
{
return IsMZ;
}
/// <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="path">Executable path.</param>
public static bool Identify(string path)
{
FileStream exeFs = File.Open(path, FileMode.Open, FileAccess.Read);
return Identify(exeFs);
}
public static bool Identify(FileStream stream)
/// <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)
{
byte[] buffer = new byte[Marshal.SizeOf(typeof(MZHeader))];

View File

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

View File

@@ -30,11 +30,25 @@ namespace libexeinfo
{
public partial class NE
{
/// <summary>
/// New Executable signature, "NE"
/// </summary>
public const ushort Signature = 0x454E;
public static readonly string FixedFileInfoSig = "VS_VERSION_INFO";
public static readonly string StringFileInfo = "StringFileInfo";
/// <summary>
/// Signature for a <see cref="FixedFileInfo"/>
/// </summary>
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 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)
{

View File

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

View File

@@ -223,7 +223,7 @@ namespace libexeinfo
table.types[t].name = Encoding.ASCII.GetString(str);
}
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++)
{

View File

@@ -29,15 +29,31 @@ using System.Runtime.InteropServices;
namespace libexeinfo
{
public partial class NE
/// <summary>
/// Represents a Microsoft New Executable
/// </summary>
public partial class NE
{
/// <summary>
/// The <see cref="FileStream"/> that contains the executable represented by this instance
/// </summary>
public readonly FileStream BaseStream;
/// <summary>
/// Header for this executable
/// </summary>
public readonly NEHeader Header;
/// <summary>
/// If true this instance correctly represents a Microsoft New Executable
/// </summary>
public readonly bool IsNE;
public readonly MZ BaseExecutable;
public readonly ResourceTable Resources;
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)
{
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)
{
IsNE = false;
@@ -84,12 +104,12 @@ namespace libexeinfo
}
}
public bool Identify()
{
return IsNE;
}
public static bool Identify(string path)
/// <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="path">Executable path.</param>
public static bool Identify(string path)
{
FileStream BaseStream = File.Open(path, FileMode.Open, FileAccess.Read);
MZ BaseExecutable = new MZ(BaseStream);
@@ -110,8 +130,13 @@ namespace libexeinfo
return false;
}
public static bool Identify(FileStream stream)
/// <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)
{
FileStream BaseStream = stream;
MZ BaseExecutable = new MZ(BaseStream);

View File

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

View File

@@ -34,6 +34,10 @@ namespace libexeinfo
{
public partial class NE
{
/// <summary>
/// Gets all the version resources from this instance
/// </summary>
/// <returns>The decoded version resources.</returns>
public List<Version> GetVersions()
{
List<Version> versions = new List<Version>();
@@ -53,9 +57,16 @@ namespace libexeinfo
return versions;
}
/// <summary>
/// Represents a version ("RT_VERSION") resource
/// </summary>
public class Version
{
public Dictionary<string, Dictionary<string, string>> StringsByLanguage { get; }
/// <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; }
string fileVersion;
string productVersion;
@@ -66,6 +77,10 @@ namespace libexeinfo
DateTime fileDate;
string name;
/// <summary>
/// File version.
/// </summary>
/// <value>The file version.</value>
public string FileVersion
{
get
@@ -74,6 +89,10 @@ namespace libexeinfo
}
}
/// <summary>
/// Product version.
/// </summary>
/// <value>The product version.</value>
public string ProductVersion
{
get
@@ -82,6 +101,10 @@ namespace libexeinfo
}
}
/// <summary>
/// File flags.
/// </summary>
/// <value>The file flags.</value>
public VersionFileFlags FileFlags
{
get
@@ -90,6 +113,10 @@ namespace libexeinfo
}
}
/// <summary>
/// File operating system.
/// </summary>
/// <value>The file operating system.</value>
public VersionFileOS FileOS
{
get
@@ -98,6 +125,10 @@ namespace libexeinfo
}
}
/// <summary>
/// File type.
/// </summary>
/// <value>The type of the file.</value>
public VersionFileType FileType
{
get
@@ -106,6 +137,10 @@ namespace libexeinfo
}
}
/// <summary>
/// File subtype.
/// </summary>
/// <value>The file subtype.</value>
public VersionFileSubtype FileSubtype
{
get
@@ -114,6 +149,10 @@ namespace libexeinfo
}
}
/// <summary>
/// File date.
/// </summary>
/// <value>The file date.</value>
public DateTime FileDate
{
get
@@ -122,11 +161,20 @@ namespace libexeinfo
}
}
/// <summary>
/// Resource name
/// </summary>
/// <value>The resource name.</value>
public string 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)
{
if (data == null || data.Length < 5)
@@ -235,7 +283,12 @@ namespace libexeinfo
}
}
public static string TypeToString(VersionFileType type)
/// <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)
{
switch (type)
{
@@ -258,7 +311,12 @@ namespace libexeinfo
}
}
public static string DriverToString(VersionFileSubtype subtype)
/// <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)
{
switch (subtype)
{
@@ -291,7 +349,12 @@ namespace libexeinfo
}
}
public static string FontToString(VersionFileSubtype subtype)
/// <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)
{
switch (subtype)
{
@@ -307,7 +370,13 @@ namespace libexeinfo
return string.Format("Unknown type code {0}", (uint)subtype);
}
}
public static string OsToString(VersionFileOS os)
/// <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)
{
switch (os)
{