Move common RT_VERSION structures to both PE and NE to Windows class.

This commit is contained in:
2018-03-09 16:36:39 +00:00
parent 658a82ac10
commit a2ed853dc1
15 changed files with 371 additions and 544 deletions

View File

@@ -30,6 +30,8 @@ using System.Globalization;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using libexeinfo; using libexeinfo;
using libexeinfo.Windows;
using Version = libexeinfo.Windows.Version;
namespace exeinfo namespace exeinfo
{ {
@@ -64,16 +66,15 @@ namespace exeinfo
Console.WriteLine("\tVersion resource {0}:", vers.Name); Console.WriteLine("\tVersion resource {0}:", vers.Name);
Console.WriteLine("\t\tFile version: {0}", vers.FileVersion); Console.WriteLine("\t\tFile version: {0}", vers.FileVersion);
Console.WriteLine("\t\tProduct version: {0}", vers.ProductVersion); Console.WriteLine("\t\tProduct version: {0}", vers.ProductVersion);
Console.WriteLine("\t\tFile type: {0}", NE.Version.TypeToString(vers.FileType)); Console.WriteLine("\t\tFile type: {0}", Version.TypeToString(vers.FileType));
if(vers.FileType == NE.VersionFileType.VFT_DRV) if(vers.FileType == VersionFileType.VFT_DRV)
Console.WriteLine("\t\tFile subtype: {0} driver", Console.WriteLine("\t\tFile subtype: {0} driver", Version.DriverToString(vers.FileSubtype));
NE.Version.DriverToString(vers.FileSubtype)); else if(vers.FileType == VersionFileType.VFT_DRV)
else if(vers.FileType == NE.VersionFileType.VFT_DRV) Console.WriteLine("\t\tFile subtype: {0} font", Version.FontToString(vers.FileSubtype));
Console.WriteLine("\t\tFile subtype: {0} font", NE.Version.FontToString(vers.FileSubtype));
else if(vers.FileSubtype > 0) else if(vers.FileSubtype > 0)
Console.WriteLine("\t\tFile subtype: {0}", (uint)vers.FileSubtype); Console.WriteLine("\t\tFile subtype: {0}", (uint)vers.FileSubtype);
Console.WriteLine("\t\tFile flags: {0}", vers.FileFlags); Console.WriteLine("\t\tFile flags: {0}", vers.FileFlags);
Console.WriteLine("\t\tFile OS: {0}", NE.Version.OsToString(vers.FileOS)); Console.WriteLine("\t\tFile OS: {0}", Version.OsToString(vers.FileOs));
foreach(KeyValuePair<string, Dictionary<string, string>> strByLang in vers.StringsByLanguage) foreach(KeyValuePair<string, Dictionary<string, string>> strByLang in vers.StringsByLanguage)
{ {
@@ -126,15 +127,15 @@ namespace exeinfo
Console.WriteLine("\tVxD version resource {0}:", vers.Name); Console.WriteLine("\tVxD version resource {0}:", vers.Name);
Console.WriteLine("\t\tFile version: {0}", vers.FileVersion); Console.WriteLine("\t\tFile version: {0}", vers.FileVersion);
Console.WriteLine("\t\tProduct version: {0}", vers.ProductVersion); Console.WriteLine("\t\tProduct version: {0}", vers.ProductVersion);
Console.WriteLine("\t\tFile type: {0}", NE.Version.TypeToString(vers.FileType)); Console.WriteLine("\t\tFile type: {0}", Version.TypeToString(vers.FileType));
if(vers.FileType == NE.VersionFileType.VFT_DRV) if(vers.FileType == VersionFileType.VFT_DRV)
Console.WriteLine("\t\tFile subtype: {0} driver", NE.Version.DriverToString(vers.FileSubtype)); Console.WriteLine("\t\tFile subtype: {0} driver", Version.DriverToString(vers.FileSubtype));
else if(vers.FileType == NE.VersionFileType.VFT_DRV) else if(vers.FileType == VersionFileType.VFT_DRV)
Console.WriteLine("\t\tFile subtype: {0} font", Console.WriteLine("\t\tFile subtype: {0} font",
NE.Version.FontToString(vers.FileSubtype)); Version.FontToString(vers.FileSubtype));
else if(vers.FileSubtype > 0) Console.WriteLine("\t\tFile subtype: {0}", (uint)vers.FileSubtype); else if(vers.FileSubtype > 0) Console.WriteLine("\t\tFile subtype: {0}", (uint)vers.FileSubtype);
Console.WriteLine("\t\tFile flags: {0}", vers.FileFlags); Console.WriteLine("\t\tFile flags: {0}", vers.FileFlags);
Console.WriteLine("\t\tFile OS: {0}", NE.Version.OsToString(vers.FileOS)); Console.WriteLine("\t\tFile OS: {0}", Version.OsToString(vers.FileOs));
foreach(KeyValuePair<string, Dictionary<string, string>> strByLang in vers.StringsByLanguage) foreach(KeyValuePair<string, Dictionary<string, string>> strByLang in vers.StringsByLanguage)
{ {
@@ -186,16 +187,15 @@ namespace exeinfo
Console.WriteLine("\tVersion resource {0}:", vers.Name); Console.WriteLine("\tVersion resource {0}:", vers.Name);
Console.WriteLine("\t\tFile version: {0}", vers.FileVersion); Console.WriteLine("\t\tFile version: {0}", vers.FileVersion);
Console.WriteLine("\t\tProduct version: {0}", vers.ProductVersion); Console.WriteLine("\t\tProduct version: {0}", vers.ProductVersion);
Console.WriteLine("\t\tFile type: {0}", PE.Version.TypeToString(vers.FileType)); Console.WriteLine("\t\tFile type: {0}", Version.TypeToString(vers.FileType));
if(vers.FileType == PE.VersionFileType.VFT_DRV) if(vers.FileType == VersionFileType.VFT_DRV)
Console.WriteLine("\t\tFile subtype: {0} driver", Console.WriteLine("\t\tFile subtype: {0} driver", Version.DriverToString(vers.FileSubtype));
PE.Version.DriverToString(vers.FileSubtype)); else if(vers.FileType == VersionFileType.VFT_DRV)
else if(vers.FileType == PE.VersionFileType.VFT_DRV) Console.WriteLine("\t\tFile subtype: {0} font", Version.FontToString(vers.FileSubtype));
Console.WriteLine("\t\tFile subtype: {0} font", PE.Version.FontToString(vers.FileSubtype));
else if(vers.FileSubtype > 0) else if(vers.FileSubtype > 0)
Console.WriteLine("\t\tFile subtype: {0}", (uint)vers.FileSubtype); Console.WriteLine("\t\tFile subtype: {0}", (uint)vers.FileSubtype);
Console.WriteLine("\t\tFile flags: {0}", vers.FileFlags); Console.WriteLine("\t\tFile flags: {0}", vers.FileFlags);
Console.WriteLine("\t\tFile OS: {0}", PE.Version.OsToString(vers.FileOS)); Console.WriteLine("\t\tFile OS: {0}", Version.OsToString(vers.FileOs));
foreach(KeyValuePair<string, Dictionary<string, string>> strByLang in vers.StringsByLanguage) foreach(KeyValuePair<string, Dictionary<string, string>> strByLang in vers.StringsByLanguage)
{ {
@@ -231,7 +231,6 @@ namespace exeinfo
} }
} }
if(peExe.Strings != null && peExe.Strings.Any()) if(peExe.Strings != null && peExe.Strings.Any())
{ {
Console.WriteLine("\tStrings:"); Console.WriteLine("\tStrings:");

View File

@@ -31,6 +31,8 @@ using System.Globalization;
using System.Text; using System.Text;
using Eto.Forms; using Eto.Forms;
using Eto.Serialization.Xaml; using Eto.Serialization.Xaml;
using libexeinfo.Windows;
using Version = libexeinfo.Windows.Version;
namespace exeinfogui.Win16 namespace exeinfogui.Win16
{ {
@@ -95,17 +97,16 @@ namespace exeinfogui.Win16
{ {
txtFileDate.Text = version.FileDate != new DateTime(1601, 1, 1) ? $"{version.FileDate}" : "Not set"; txtFileDate.Text = version.FileDate != new DateTime(1601, 1, 1) ? $"{version.FileDate}" : "Not set";
txtFileFlags.Text = version.FileFlags == 0 ? "Normal" : $"{version.FileFlags}"; txtFileFlags.Text = version.FileFlags == 0 ? "Normal" : $"{version.FileFlags}";
txtFileOs.Text = libexeinfo.NE.Version.OsToString(version.FileOS); txtFileOs.Text = Version.OsToString(version.FileOs);
if(version.FileType == libexeinfo.NE.VersionFileType.VFT_DRV) if(version.FileType == VersionFileType.VFT_DRV)
txtFileSubtype.Text = $"{libexeinfo.NE.Version.DriverToString(version.FileSubtype)} driver"; txtFileSubtype.Text = $"{Version.DriverToString(version.FileSubtype)} driver";
else if(version.FileType == libexeinfo.NE.VersionFileType.VFT_DRV) else if(version.FileType == VersionFileType.VFT_DRV)
txtFileSubtype.Text = txtFileSubtype.Text = $"{Version.FontToString(version.FileSubtype)} font";
$"{libexeinfo.NE.Version.FontToString(version.FileSubtype)} font";
else if(version.FileSubtype > 0) txtFileSubtype.Text = $"{(uint)version.FileSubtype}"; else if(version.FileSubtype > 0) txtFileSubtype.Text = $"{(uint)version.FileSubtype}";
else txtFileSubtype.Text = "None"; else txtFileSubtype.Text = "None";
txtFileType.Text = libexeinfo.NE.Version.TypeToString(version.FileType); txtFileType.Text = Version.TypeToString(version.FileType);
txtFileVersion.Text = $"{version.FileVersion}"; txtFileVersion.Text = $"{version.FileVersion}";
txtProductVersion.Text = $"{version.ProductVersion}"; txtProductVersion.Text = $"{version.ProductVersion}";

View File

@@ -32,14 +32,6 @@ namespace libexeinfo
/// New Executable signature, "NE" /// New Executable signature, "NE"
/// </summary> /// </summary>
const ushort SIGNATURE = 0x454E; const ushort SIGNATURE = 0x454E;
/// <summary>
/// Signature for a <see cref="FixedFileInfo" />
/// </summary>
const string FIXED_FILE_INFO_SIG = "VS_VERSION_INFO";
/// <summary>
/// Signature for list of name=value strings inside a version resource
/// </summary>
const string STRING_FILE_INFO = "StringFileInfo";
const ushort SEGMENT_TYPE_MASK = 0x07; const ushort SEGMENT_TYPE_MASK = 0x07;
const ushort SEGMENT_FLAGS_MASK = 0x3F8; const ushort SEGMENT_FLAGS_MASK = 0x3F8;

View File

@@ -136,92 +136,5 @@ namespace libexeinfo
Win32 = 4, Win32 = 4,
Borland = 5 Borland = 5
} }
/// <summary>
/// Version file flags.
/// </summary>
[Flags]
public enum VersionFileFlags : uint
{
VS_FF_DEBUG = 0x00000001,
VS_FF_INFOINFERRED = 0x00000010,
VS_FF_PATCHED = 0x00000004,
VS_FF_PRERELEASE = 0x00000002,
VS_FF_PRIVATEBUILD = 0x00000008,
VS_FF_SPECIALBUILD = 0x00000020
}
/// <summary>
/// Version file operating system.
/// </summary>
public enum VersionFileOS : uint
{
VOS_DOS = 0x00010000,
VOS_NT = 0x00040000,
VOS_WINDOWS16 = 0x00000001,
VOS_WINDOWS32 = 0x00000004,
VOS_OS216 = 0x00020000,
VOS_OS232 = 0x00030000,
VOS_PM16 = 0x00000002,
VOS_PM32 = 0x00000003,
VOS_UNKNOWN = 0x00000000,
// Combinations, some have no sense
VOS_DOS_NT = 0x00050000,
VOS_DOS_WINDOWS16 = 0x00010001,
VOS_DOS_WINDOWS32 = 0x00010004,
VOS_DOS_PM16 = 0x00010002,
VOS_DOS_PM32 = 0x00010003,
VOS_NT_WINDOWS16 = 0x00040001,
VOS_NT_WINDOWS32 = 0x00040004,
VOS_NT_PM16 = 0x00040002,
VOS_NT_PM32 = 0x00040003,
VOS_OS216_WINDOWS16 = 0x00020001,
VOS_OS216_WINDOWS32 = 0x00020004,
VOS_OS216_PM16 = 0x00020002,
VOS_OS216_PM32 = 0x00020003,
VOS_OS232_WINDOWS16 = 0x00030001,
VOS_OS232_WINDOWS32 = 0x00030004,
VOS_OS232_PM16 = 0x00030002,
VOS_OS232_PM32 = 0x00030003
}
/// <summary>
/// Version file subtype.
/// </summary>
public enum VersionFileSubtype : uint
{
VFT2_UNKNOWN = 0x00000000,
// Drivers
VFT2_DRV_COMM = 0x0000000A,
VFT2_DRV_DISPLAY = 0x00000004,
VFT2_DRV_INSTALLABLE = 0x00000008,
VFT2_DRV_KEYBOARD = 0x00000002,
VFT2_DRV_LANGUAGE = 0x00000003,
VFT2_DRV_MOUSE = 0x00000005,
VFT2_DRV_NETWORK = 0x00000006,
VFT2_DRV_PRINTER = 0x00000001,
VFT2_DRV_SOUND = 0x00000009,
VFT2_DRV_SYSTEM = 0x00000007,
VFT2_DRV_VERSIONED_PRINTER = 0x0000000C,
// Fonts
VFT2_FONT_RASTER = 0x00000001,
VFT2_FONT_TRUETYPE = 0x00000003,
VFT2_FONT_VECTOR = 0x00000002
}
/// <summary>
/// Version file type.
/// </summary>
public enum VersionFileType : uint
{
VFT_APP = 0x00000001,
VFT_DLL = 0x00000002,
VFT_DRV = 0x00000003,
VFT_FONT = 0x00000004,
VFT_STATIC_LIB = 0x00000007,
VFT_UNKNOWN = 0x00000000,
VFT_VXD = 0x00000005
}
} }
} }

View File

@@ -122,27 +122,6 @@ namespace libexeinfo
public string szName; public string szName;
} }
/// <summary>
/// Fixed file version info
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct FixedFileInfo
{
public uint dwSignature;
public uint dwStrucVersion;
public uint dwFileVersionMS;
public uint dwFileVersionLS;
public uint dwProductVersionMS;
public uint dwProductVersionLS;
public uint dwFileFlagsMask;
public uint dwFileFlags;
public uint dwFileOS;
public uint dwFileType;
public uint dwFileSubtype;
public uint dwFileDateMS;
public uint dwFileDateLS;
}
public struct ResidentName public struct ResidentName
{ {
/// <summary> /// <summary>

View File

@@ -40,7 +40,7 @@ namespace libexeinfo
/// Gets all the version resources from this instance /// Gets all the version resources from this instance
/// </summary> /// </summary>
/// <returns>The decoded version resources.</returns> /// <returns>The decoded version resources.</returns>
public List<Version> GetVersions() List<Version> GetVersions()
{ {
return (from type in Resources.types return (from type in Resources.types
where (type.id & 0x7FFF) == (int)ResourceTypes.RT_VERSION where (type.id & 0x7FFF) == (int)ResourceTypes.RT_VERSION
@@ -80,43 +80,43 @@ namespace libexeinfo
/// File version. /// File version.
/// </summary> /// </summary>
/// <value>The file version.</value> /// <value>The file version.</value>
public string FileVersion { get; set; } public string FileVersion { get; private set; }
/// <summary> /// <summary>
/// Product version. /// Product version.
/// </summary> /// </summary>
/// <value>The product version.</value> /// <value>The product version.</value>
public string ProductVersion { get; set; } public string ProductVersion { get; private set; }
/// <summary> /// <summary>
/// File flags. /// File flags.
/// </summary> /// </summary>
/// <value>The file flags.</value> /// <value>The file flags.</value>
public VersionFileFlags FileFlags { get; set; } public VersionFileFlags FileFlags { get; private set; }
/// <summary> /// <summary>
/// File operating system. /// File operating system.
/// </summary> /// </summary>
/// <value>The file operating system.</value> /// <value>The file operating system.</value>
public VersionFileOS FileOS { get; set; } public VersionFileOS FileOs { get; private set; }
/// <summary> /// <summary>
/// File type. /// File type.
/// </summary> /// </summary>
/// <value>The type of the file.</value> /// <value>The type of the file.</value>
public VersionFileType FileType { get; set; } public VersionFileType FileType { get; private set; }
/// <summary> /// <summary>
/// File subtype. /// File subtype.
/// </summary> /// </summary>
/// <value>The file subtype.</value> /// <value>The file subtype.</value>
public VersionFileSubtype FileSubtype { get; set; } public VersionFileSubtype FileSubtype { get; private set; }
/// <summary> /// <summary>
/// File date. /// File date.
/// </summary> /// </summary>
/// <value>The file date.</value> /// <value>The file date.</value>
public DateTime FileDate { get; set; } public DateTime FileDate { get; private set; }
/// <summary> /// <summary>
/// Resource name /// Resource name
@@ -167,7 +167,7 @@ namespace libexeinfo
void DecodeNode(VersionNode node, string parent, string grandparent) void DecodeNode(VersionNode node, string parent, string grandparent)
{ {
if(node.szName == FIXED_FILE_INFO_SIG) if(node.szName == Consts.FixedFileInfoSig)
{ {
IntPtr infoPtr = Marshal.AllocHGlobal(node.cbData); IntPtr infoPtr = Marshal.AllocHGlobal(node.cbData);
Marshal.Copy(node.rgbData, 0, infoPtr, node.cbData); Marshal.Copy(node.rgbData, 0, infoPtr, node.cbData);
@@ -179,19 +179,19 @@ namespace libexeinfo
ProductVersion = ProductVersion =
$"{(info.dwProductVersionMS & 0xFFFF0000) >> 16}.{info.dwProductVersionMS & 0xFFFF:D2}.{(info.dwProductVersionLS & 0xFFFF0000) >> 16}.{info.dwProductVersionLS & 0xFFFF}"; $"{(info.dwProductVersionMS & 0xFFFF0000) >> 16}.{info.dwProductVersionMS & 0xFFFF:D2}.{(info.dwProductVersionLS & 0xFFFF0000) >> 16}.{info.dwProductVersionLS & 0xFFFF}";
FileFlags = (VersionFileFlags)(info.dwFileFlags & info.dwFileFlagsMask); FileFlags = (VersionFileFlags)(info.dwFileFlags & info.dwFileFlagsMask);
FileOS = (VersionFileOS)info.dwFileOS; FileOs = (VersionFileOS)info.dwFileOS;
FileType = (VersionFileType)info.dwFileType; FileType = (VersionFileType)info.dwFileType;
FileSubtype = (VersionFileSubtype)info.dwFileSubtype; FileSubtype = (VersionFileSubtype)info.dwFileSubtype;
FileDate = DateTime.FromFileTime(info.dwFileDateMS * 0x100000000 + info.dwFileDateLS); FileDate = DateTime.FromFileTime(info.dwFileDateMS * 0x100000000 + info.dwFileDateLS);
} }
if(parent == STRING_FILE_INFO) if(parent == Consts.StringFileInfo)
{ {
Dictionary<string, string> strings = new Dictionary<string, string>(); Dictionary<string, string> strings = new Dictionary<string, string>();
StringsByLanguage.Add(node.szName, strings); StringsByLanguage.Add(node.szName, strings);
} }
if(grandparent == STRING_FILE_INFO) if(grandparent == Consts.StringFileInfo)
if(StringsByLanguage.TryGetValue(parent, out Dictionary<string, string> strings)) if(StringsByLanguage.TryGetValue(parent, out Dictionary<string, string> strings))
{ {
Encoding encoding; Encoding encoding;
@@ -206,121 +206,6 @@ namespace libexeinfo
foreach(VersionNode n in node.children) DecodeNode(n, node.szName, parent); foreach(VersionNode n in node.children) DecodeNode(n, node.szName, parent);
} }
/// <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)
{
case VersionFileType.VFT_APP: return "Application";
case VersionFileType.VFT_DLL: return "Dynamic-link library";
case VersionFileType.VFT_DRV: return "Device driver";
case VersionFileType.VFT_FONT: return "Font";
case VersionFileType.VFT_STATIC_LIB: return "Static-link library";
case VersionFileType.VFT_UNKNOWN: return "Unknown";
case VersionFileType.VFT_VXD: return "Virtual device";
default: return $"Unknown type code {(uint)type}";
}
}
/// <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)
{
case VersionFileSubtype.VFT2_DRV_COMM: return "Communications";
case VersionFileSubtype.VFT2_DRV_DISPLAY: return "Display";
case VersionFileSubtype.VFT2_DRV_INSTALLABLE: return "Installable";
case VersionFileSubtype.VFT2_DRV_KEYBOARD: return "Keyboard";
case VersionFileSubtype.VFT2_DRV_LANGUAGE: return "Language";
case VersionFileSubtype.VFT2_DRV_MOUSE: return "Mouse";
case VersionFileSubtype.VFT2_DRV_NETWORK: return "Network";
case VersionFileSubtype.VFT2_DRV_PRINTER: return "Printer";
case VersionFileSubtype.VFT2_DRV_SOUND: return "Sound";
case VersionFileSubtype.VFT2_DRV_SYSTEM: return "System";
case VersionFileSubtype.VFT2_DRV_VERSIONED_PRINTER: return "Versioned";
case VersionFileSubtype.VFT2_UNKNOWN: return "Unknown";
default: return $"Unknown type code {(uint)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)
{
case VersionFileSubtype.VFT2_FONT_RASTER: return "Raster";
case VersionFileSubtype.VFT2_FONT_TRUETYPE: return "TrueType";
case VersionFileSubtype.VFT2_FONT_VECTOR: return "Vector";
case VersionFileSubtype.VFT2_UNKNOWN: return "Unknown";
default: return $"Unknown type code {(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)
{
switch(os)
{
case VersionFileOS.VOS_DOS: return "DOS";
case VersionFileOS.VOS_NT: return "Windows NT";
case VersionFileOS.VOS_WINDOWS16: return "16-bit Windows";
case VersionFileOS.VOS_WINDOWS32: return "32-bit Windows";
case VersionFileOS.VOS_OS216: return "16-bit OS/2";
case VersionFileOS.VOS_OS232: return "32-bit OS/2";
case VersionFileOS.VOS_PM16: return "16-bit Presentation Manager";
case VersionFileOS.VOS_PM32: return "32-bit Presentation Manager";
case VersionFileOS.VOS_UNKNOWN: return "Unknown";
case VersionFileOS.VOS_DOS_NT: return "DOS running under Windows NT";
case VersionFileOS.VOS_DOS_WINDOWS16: return "16-bit Windows running under DOS";
case VersionFileOS.VOS_DOS_WINDOWS32: return "32-bit Windows running under DOS";
case VersionFileOS.VOS_DOS_PM16: return "16-bit Presentation Manager running under DOS";
case VersionFileOS.VOS_DOS_PM32: return "32-bit Presentation Manager running under DOS";
case VersionFileOS.VOS_NT_WINDOWS16: return "16-bit Windows running under Windows NT";
case VersionFileOS.VOS_NT_WINDOWS32: return "32-bit Windows running under Windows NT";
case VersionFileOS.VOS_NT_PM16:
return "16-bit Presentation Manager running under Windows NT";
case VersionFileOS.VOS_NT_PM32:
return "32-bit Presentation Manager running under Windows NT";
case VersionFileOS.VOS_OS216_WINDOWS16: return "16-bit Windows running under 16-bit OS/2";
case VersionFileOS.VOS_OS216_WINDOWS32: return "32-bit Windows running under 16-bit OS/2";
case VersionFileOS.VOS_OS216_PM16:
return "16-bit Presentation Manager running under 16-bit OS/2";
case VersionFileOS.VOS_OS216_PM32:
return "32-bit Presentation Manager running under 16-bit OS/2";
case VersionFileOS.VOS_OS232_WINDOWS16: return "16-bit Windows running under 32-bit OS/2";
case VersionFileOS.VOS_OS232_WINDOWS32: return "32-bit Windows running under 32-bit OS/2";
case VersionFileOS.VOS_OS232_PM16:
return "16-bit Presentation Manager running under 32-bit OS/2";
case VersionFileOS.VOS_OS232_PM32:
return "32-bit Presentation Manager running under 32-bit OS/2";
default: return $"Unknown OS code {(uint)os}";
}
}
} }
} }
} }

View File

@@ -34,13 +34,5 @@ namespace libexeinfo
const ushort SIGNATURE = 0x00004550; const ushort SIGNATURE = 0x00004550;
const ushort PE32 = COFF.ZMAGIC; const ushort PE32 = COFF.ZMAGIC;
internal const ushort PE32Plus = 0x20b; internal const ushort PE32Plus = 0x20b;
/// <summary>
/// Signature for a <see cref="FixedFileInfo" />
/// </summary>
const string FIXED_FILE_INFO_SIG = "VS_VERSION_INFO";
/// <summary>
/// Signature for list of name=value strings inside a version resource
/// </summary>
const string STRING_FILE_INFO = "StringFileInfo";
} }
} }

View File

@@ -25,13 +25,14 @@
// THE SOFTWARE. // THE SOFTWARE.
using System; using System;
// ReSharper disable InconsistentNaming // ReSharper disable InconsistentNaming
namespace libexeinfo namespace libexeinfo
{ {
public partial class PE public partial class PE
{ {
public enum DebugTypes : uint enum DebugTypes : uint
{ {
/// <summary> /// <summary>
/// Unknown value, ignored by all tools. /// Unknown value, ignored by all tools.
@@ -65,7 +66,7 @@ namespace libexeinfo
/// The following values are defined for the DllCharacteristics field of the optional header. /// The following values are defined for the DllCharacteristics field of the optional header.
/// </summary> /// </summary>
[Flags] [Flags]
public enum DllCharacteristics : ushort enum DllCharacteristics : ushort
{ {
/// <summary> /// <summary>
/// Image can handle a high entropy 64-bit virtual address space. /// Image can handle a high entropy 64-bit virtual address space.
@@ -117,7 +118,7 @@ namespace libexeinfo
/// The following values defined for the Subsystem field of the optional header determine which Windows subsystem (if /// The following values defined for the Subsystem field of the optional header determine which Windows subsystem (if
/// any) is required to run the image. /// any) is required to run the image.
/// </summary> /// </summary>
public enum Subsystems : ushort enum Subsystems : ushort
{ {
/// <summary> /// <summary>
/// An unknown subsystem /// An unknown subsystem
@@ -176,92 +177,5 @@ namespace libexeinfo
/// </summary> /// </summary>
IMAGE_SUBSYSTEM_WINDOWS_BOOT_APPLICATION = 16 IMAGE_SUBSYSTEM_WINDOWS_BOOT_APPLICATION = 16
} }
/// <summary>
/// Version file flags.
/// </summary>
[Flags]
public enum VersionFileFlags : uint
{
VS_FF_DEBUG = 0x00000001,
VS_FF_INFOINFERRED = 0x00000010,
VS_FF_PATCHED = 0x00000004,
VS_FF_PRERELEASE = 0x00000002,
VS_FF_PRIVATEBUILD = 0x00000008,
VS_FF_SPECIALBUILD = 0x00000020
}
/// <summary>
/// Version file operating system.
/// </summary>
public enum VersionFileOS : uint
{
VOS_DOS = 0x00010000,
VOS_NT = 0x00040000,
VOS_WINDOWS16 = 0x00000001,
VOS_WINDOWS32 = 0x00000004,
VOS_OS216 = 0x00020000,
VOS_OS232 = 0x00030000,
VOS_PM16 = 0x00000002,
VOS_PM32 = 0x00000003,
VOS_UNKNOWN = 0x00000000,
// Combinations, some have no sense
VOS_DOS_NT = 0x00050000,
VOS_DOS_WINDOWS16 = 0x00010001,
VOS_DOS_WINDOWS32 = 0x00010004,
VOS_DOS_PM16 = 0x00010002,
VOS_DOS_PM32 = 0x00010003,
VOS_NT_WINDOWS16 = 0x00040001,
VOS_NT_WINDOWS32 = 0x00040004,
VOS_NT_PM16 = 0x00040002,
VOS_NT_PM32 = 0x00040003,
VOS_OS216_WINDOWS16 = 0x00020001,
VOS_OS216_WINDOWS32 = 0x00020004,
VOS_OS216_PM16 = 0x00020002,
VOS_OS216_PM32 = 0x00020003,
VOS_OS232_WINDOWS16 = 0x00030001,
VOS_OS232_WINDOWS32 = 0x00030004,
VOS_OS232_PM16 = 0x00030002,
VOS_OS232_PM32 = 0x00030003
}
/// <summary>
/// Version file subtype.
/// </summary>
public enum VersionFileSubtype : uint
{
VFT2_UNKNOWN = 0x00000000,
// Drivers
VFT2_DRV_COMM = 0x0000000A,
VFT2_DRV_DISPLAY = 0x00000004,
VFT2_DRV_INSTALLABLE = 0x00000008,
VFT2_DRV_KEYBOARD = 0x00000002,
VFT2_DRV_LANGUAGE = 0x00000003,
VFT2_DRV_MOUSE = 0x00000005,
VFT2_DRV_NETWORK = 0x00000006,
VFT2_DRV_PRINTER = 0x00000001,
VFT2_DRV_SOUND = 0x00000009,
VFT2_DRV_SYSTEM = 0x00000007,
VFT2_DRV_VERSIONED_PRINTER = 0x0000000C,
// Fonts
VFT2_FONT_RASTER = 0x00000001,
VFT2_FONT_TRUETYPE = 0x00000003,
VFT2_FONT_VECTOR = 0x00000002
}
/// <summary>
/// Version file type.
/// </summary>
public enum VersionFileType : uint
{
VFT_APP = 0x00000001,
VFT_DLL = 0x00000002,
VFT_DRV = 0x00000003,
VFT_FONT = 0x00000004,
VFT_STATIC_LIB = 0x00000007,
VFT_UNKNOWN = 0x00000000,
VFT_VXD = 0x00000005
}
} }
} }

View File

@@ -24,7 +24,6 @@
// 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.Runtime.InteropServices; using System.Runtime.InteropServices;
using static libexeinfo.COFF; using static libexeinfo.COFF;
@@ -453,11 +452,11 @@ namespace libexeinfo
public class ResourceNode public class ResourceNode
{ {
public uint id;
public string name;
public ResourceNode[] children; public ResourceNode[] children;
public byte[] data; public byte[] data;
public uint id;
public int level; public int level;
public string name;
} }
/// <summary> /// <summary>
@@ -465,33 +464,12 @@ namespace libexeinfo
/// </summary> /// </summary>
class VersionNode class VersionNode
{ {
public ushort wValueLength;
public ushort wLength;
public ushort wType;
public VersionNode[] children; public VersionNode[] children;
public byte[] rgbData; public byte[] rgbData;
public string szName; public string szName;
} public ushort wLength;
public ushort wType;
/// <summary> public ushort wValueLength;
/// Fixed file version info
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct FixedFileInfo
{
public uint dwSignature;
public uint dwStrucVersion;
public uint dwFileVersionMS;
public uint dwFileVersionLS;
public uint dwProductVersionMS;
public uint dwProductVersionLS;
public uint dwFileFlagsMask;
public uint dwFileFlags;
public uint dwFileOS;
public uint dwFileType;
public uint dwFileSubtype;
public uint dwFileDateMS;
public uint dwFileDateLS;
} }
} }
} }

View File

@@ -40,7 +40,7 @@ namespace libexeinfo
/// Gets all the version resources from this instance /// Gets all the version resources from this instance
/// </summary> /// </summary>
/// <returns>The decoded version resources.</returns> /// <returns>The decoded version resources.</returns>
public List<Version> GetVersions() List<Version> GetVersions()
{ {
return (from node in WindowsResourcesRoot.children return (from node in WindowsResourcesRoot.children
where node.id == (uint)ResourceTypes.RT_VERSION where node.id == (uint)ResourceTypes.RT_VERSION
@@ -67,7 +67,7 @@ namespace libexeinfo
StringsByLanguage = new Dictionary<string, Dictionary<string, string>>(); StringsByLanguage = new Dictionary<string, Dictionary<string, string>>();
VersionNode root = GetNode(data, 0, out int rootLength); VersionNode root = GetNode(data, 0, out int _);
DecodeNode(root, null, null); DecodeNode(root, null, null);
} }
@@ -81,37 +81,37 @@ namespace libexeinfo
/// File version. /// File version.
/// </summary> /// </summary>
/// <value>The file version.</value> /// <value>The file version.</value>
public string FileVersion { get; set; } public string FileVersion { get; private set; }
/// <summary> /// <summary>
/// Product version. /// Product version.
/// </summary> /// </summary>
/// <value>The product version.</value> /// <value>The product version.</value>
public string ProductVersion { get; set; } public string ProductVersion { get; private set; }
/// <summary> /// <summary>
/// File flags. /// File flags.
/// </summary> /// </summary>
/// <value>The file flags.</value> /// <value>The file flags.</value>
public VersionFileFlags FileFlags { get; set; } public VersionFileFlags FileFlags { get; private set; }
/// <summary> /// <summary>
/// File operating system. /// File operating system.
/// </summary> /// </summary>
/// <value>The file operating system.</value> /// <value>The file operating system.</value>
public VersionFileOS FileOS { get; set; } public VersionFileOS FileOs { get; private set; }
/// <summary> /// <summary>
/// File type. /// File type.
/// </summary> /// </summary>
/// <value>The type of the file.</value> /// <value>The type of the file.</value>
public VersionFileType FileType { get; set; } public VersionFileType FileType { get; private set; }
/// <summary> /// <summary>
/// File subtype. /// File subtype.
/// </summary> /// </summary>
/// <value>The file subtype.</value> /// <value>The file subtype.</value>
public VersionFileSubtype FileSubtype { get; set; } public VersionFileSubtype FileSubtype { get; private set; }
/// <summary> /// <summary>
/// File date. /// File date.
@@ -140,8 +140,7 @@ namespace libexeinfo
MemoryStream nameMs = new MemoryStream(); MemoryStream nameMs = new MemoryStream();
while(true) while(true)
{ {
if(data[startPosition + nodeLength] == 0 && data[startPosition + nodeLength + 1] == 0) if(data[startPosition + nodeLength] == 0 && data[startPosition + nodeLength + 1] == 0) break;
break;
nameMs.WriteByte(data[startPosition + nodeLength]); nameMs.WriteByte(data[startPosition + nodeLength]);
nameMs.WriteByte(data[startPosition + nodeLength + 1]); nameMs.WriteByte(data[startPosition + nodeLength + 1]);
@@ -177,7 +176,7 @@ namespace libexeinfo
void DecodeNode(VersionNode node, string parent, string grandparent) void DecodeNode(VersionNode node, string parent, string grandparent)
{ {
if(node.szName == FIXED_FILE_INFO_SIG) if(node.szName == Consts.FixedFileInfoSig)
{ {
IntPtr infoPtr = Marshal.AllocHGlobal(node.wValueLength); IntPtr infoPtr = Marshal.AllocHGlobal(node.wValueLength);
Marshal.Copy(node.rgbData, 0, infoPtr, node.wValueLength); Marshal.Copy(node.rgbData, 0, infoPtr, node.wValueLength);
@@ -189,143 +188,26 @@ namespace libexeinfo
ProductVersion = ProductVersion =
$"{(info.dwProductVersionMS & 0xFFFF0000) >> 16}.{info.dwProductVersionMS & 0xFFFF:D2}.{(info.dwProductVersionLS & 0xFFFF0000) >> 16}.{info.dwProductVersionLS & 0xFFFF}"; $"{(info.dwProductVersionMS & 0xFFFF0000) >> 16}.{info.dwProductVersionMS & 0xFFFF:D2}.{(info.dwProductVersionLS & 0xFFFF0000) >> 16}.{info.dwProductVersionLS & 0xFFFF}";
FileFlags = (VersionFileFlags)(info.dwFileFlags & info.dwFileFlagsMask); FileFlags = (VersionFileFlags)(info.dwFileFlags & info.dwFileFlagsMask);
FileOS = (VersionFileOS)info.dwFileOS; FileOs = (VersionFileOS)info.dwFileOS;
FileType = (VersionFileType)info.dwFileType; FileType = (VersionFileType)info.dwFileType;
FileSubtype = (VersionFileSubtype)info.dwFileSubtype; FileSubtype = (VersionFileSubtype)info.dwFileSubtype;
FileDate = DateTime.FromFileTime(info.dwFileDateMS * 0x100000000 + info.dwFileDateLS); FileDate = DateTime.FromFileTime(info.dwFileDateMS * 0x100000000 + info.dwFileDateLS);
} }
if(parent == STRING_FILE_INFO) if(parent == Consts.StringFileInfo)
{ {
Dictionary<string, string> strings = new Dictionary<string, string>(); Dictionary<string, string> strings = new Dictionary<string, string>();
StringsByLanguage.Add(node.szName, strings); StringsByLanguage.Add(node.szName, strings);
} }
if(grandparent == STRING_FILE_INFO) if(grandparent == Consts.StringFileInfo)
if(StringsByLanguage.TryGetValue(parent, out Dictionary<string, string> strings)) if(StringsByLanguage.TryGetValue(parent, out Dictionary<string, string> strings))
{
strings.Add(node.szName, Encoding.Unicode.GetString(node.rgbData)); strings.Add(node.szName, Encoding.Unicode.GetString(node.rgbData));
}
if(node.children == null) return; if(node.children == null) return;
foreach(VersionNode n in node.children) DecodeNode(n, node.szName, parent); foreach(VersionNode n in node.children) DecodeNode(n, node.szName, parent);
} }
/// <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)
{
case VersionFileType.VFT_APP: return "Application";
case VersionFileType.VFT_DLL: return "Dynamic-link library";
case VersionFileType.VFT_DRV: return "Device driver";
case VersionFileType.VFT_FONT: return "Font";
case VersionFileType.VFT_STATIC_LIB: return "Static-link library";
case VersionFileType.VFT_UNKNOWN: return "Unknown";
case VersionFileType.VFT_VXD: return "Virtual device";
default: return $"Unknown type code {(uint)type}";
}
}
/// <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)
{
case VersionFileSubtype.VFT2_DRV_COMM: return "Communications";
case VersionFileSubtype.VFT2_DRV_DISPLAY: return "Display";
case VersionFileSubtype.VFT2_DRV_INSTALLABLE: return "Installable";
case VersionFileSubtype.VFT2_DRV_KEYBOARD: return "Keyboard";
case VersionFileSubtype.VFT2_DRV_LANGUAGE: return "Language";
case VersionFileSubtype.VFT2_DRV_MOUSE: return "Mouse";
case VersionFileSubtype.VFT2_DRV_NETWORK: return "Network";
case VersionFileSubtype.VFT2_DRV_PRINTER: return "Printer";
case VersionFileSubtype.VFT2_DRV_SOUND: return "Sound";
case VersionFileSubtype.VFT2_DRV_SYSTEM: return "System";
case VersionFileSubtype.VFT2_DRV_VERSIONED_PRINTER: return "Versioned";
case VersionFileSubtype.VFT2_UNKNOWN: return "Unknown";
default: return $"Unknown type code {(uint)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)
{
case VersionFileSubtype.VFT2_FONT_RASTER: return "Raster";
case VersionFileSubtype.VFT2_FONT_TRUETYPE: return "TrueType";
case VersionFileSubtype.VFT2_FONT_VECTOR: return "Vector";
case VersionFileSubtype.VFT2_UNKNOWN: return "Unknown";
default: return $"Unknown type code {(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)
{
switch(os)
{
case VersionFileOS.VOS_DOS: return "DOS";
case VersionFileOS.VOS_NT: return "Windows NT";
case VersionFileOS.VOS_WINDOWS16: return "16-bit Windows";
case VersionFileOS.VOS_WINDOWS32: return "32-bit Windows";
case VersionFileOS.VOS_OS216: return "16-bit OS/2";
case VersionFileOS.VOS_OS232: return "32-bit OS/2";
case VersionFileOS.VOS_PM16: return "16-bit Presentation Manager";
case VersionFileOS.VOS_PM32: return "32-bit Presentation Manager";
case VersionFileOS.VOS_UNKNOWN: return "Unknown";
case VersionFileOS.VOS_DOS_NT: return "DOS running under Windows NT";
case VersionFileOS.VOS_DOS_WINDOWS16: return "16-bit Windows running under DOS";
case VersionFileOS.VOS_DOS_WINDOWS32: return "32-bit Windows running under DOS";
case VersionFileOS.VOS_DOS_PM16: return "16-bit Presentation Manager running under DOS";
case VersionFileOS.VOS_DOS_PM32: return "32-bit Presentation Manager running under DOS";
case VersionFileOS.VOS_NT_WINDOWS16: return "16-bit Windows running under Windows NT";
case VersionFileOS.VOS_NT_WINDOWS32: return "32-bit Windows running under Windows NT";
case VersionFileOS.VOS_NT_PM16:
return "16-bit Presentation Manager running under Windows NT";
case VersionFileOS.VOS_NT_PM32:
return "32-bit Presentation Manager running under Windows NT";
case VersionFileOS.VOS_OS216_WINDOWS16: return "16-bit Windows running under 16-bit OS/2";
case VersionFileOS.VOS_OS216_WINDOWS32: return "32-bit Windows running under 16-bit OS/2";
case VersionFileOS.VOS_OS216_PM16:
return "16-bit Presentation Manager running under 16-bit OS/2";
case VersionFileOS.VOS_OS216_PM32:
return "32-bit Presentation Manager running under 16-bit OS/2";
case VersionFileOS.VOS_OS232_WINDOWS16: return "16-bit Windows running under 32-bit OS/2";
case VersionFileOS.VOS_OS232_WINDOWS32: return "32-bit Windows running under 32-bit OS/2";
case VersionFileOS.VOS_OS232_PM16:
return "16-bit Presentation Manager running under 32-bit OS/2";
case VersionFileOS.VOS_OS232_PM32:
return "32-bit Presentation Manager running under 32-bit OS/2";
default: return $"Unknown OS code {(uint)os}";
}
}
} }
} }
} }

View File

@@ -0,0 +1,40 @@
//
// Consts.cs
//
// Author:
// Natalia Portillo <claunia@claunia.com>
//
// Copyright (c) 2017-2018 Copyright © Claunia.com
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
namespace libexeinfo.Windows
{
public static class Consts
{
/// <summary>
/// Signature for a <see cref="FixedFileInfo" />
/// </summary>
public const string FixedFileInfoSig = "VS_VERSION_INFO";
/// <summary>
/// Signature for list of name=value strings inside a version resource
/// </summary>
public const string StringFileInfo = "StringFileInfo";
}
}

View File

@@ -24,6 +24,8 @@
// 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;
namespace libexeinfo.Windows namespace libexeinfo.Windows
{ {
/// <summary> /// <summary>
@@ -73,4 +75,91 @@ namespace libexeinfo.Windows
CmykRle8 = 12, CmykRle8 = 12,
CmykRle4 = 13 CmykRle4 = 13
} }
/// <summary>
/// Version file flags.
/// </summary>
[Flags]
public enum VersionFileFlags : uint
{
VS_FF_DEBUG = 0x00000001,
VS_FF_INFOINFERRED = 0x00000010,
VS_FF_PATCHED = 0x00000004,
VS_FF_PRERELEASE = 0x00000002,
VS_FF_PRIVATEBUILD = 0x00000008,
VS_FF_SPECIALBUILD = 0x00000020
}
/// <summary>
/// Version file operating system.
/// </summary>
public enum VersionFileOS : uint
{
VOS_DOS = 0x00010000,
VOS_NT = 0x00040000,
VOS_WINDOWS16 = 0x00000001,
VOS_WINDOWS32 = 0x00000004,
VOS_OS216 = 0x00020000,
VOS_OS232 = 0x00030000,
VOS_PM16 = 0x00000002,
VOS_PM32 = 0x00000003,
VOS_UNKNOWN = 0x00000000,
// Combinations, some have no sense
VOS_DOS_NT = 0x00050000,
VOS_DOS_WINDOWS16 = 0x00010001,
VOS_DOS_WINDOWS32 = 0x00010004,
VOS_DOS_PM16 = 0x00010002,
VOS_DOS_PM32 = 0x00010003,
VOS_NT_WINDOWS16 = 0x00040001,
VOS_NT_WINDOWS32 = 0x00040004,
VOS_NT_PM16 = 0x00040002,
VOS_NT_PM32 = 0x00040003,
VOS_OS216_WINDOWS16 = 0x00020001,
VOS_OS216_WINDOWS32 = 0x00020004,
VOS_OS216_PM16 = 0x00020002,
VOS_OS216_PM32 = 0x00020003,
VOS_OS232_WINDOWS16 = 0x00030001,
VOS_OS232_WINDOWS32 = 0x00030004,
VOS_OS232_PM16 = 0x00030002,
VOS_OS232_PM32 = 0x00030003
}
/// <summary>
/// Version file subtype.
/// </summary>
public enum VersionFileSubtype : uint
{
VFT2_UNKNOWN = 0x00000000,
// Drivers
VFT2_DRV_COMM = 0x0000000A,
VFT2_DRV_DISPLAY = 0x00000004,
VFT2_DRV_INSTALLABLE = 0x00000008,
VFT2_DRV_KEYBOARD = 0x00000002,
VFT2_DRV_LANGUAGE = 0x00000003,
VFT2_DRV_MOUSE = 0x00000005,
VFT2_DRV_NETWORK = 0x00000006,
VFT2_DRV_PRINTER = 0x00000001,
VFT2_DRV_SOUND = 0x00000009,
VFT2_DRV_SYSTEM = 0x00000007,
VFT2_DRV_VERSIONED_PRINTER = 0x0000000C,
// Fonts
VFT2_FONT_RASTER = 0x00000001,
VFT2_FONT_TRUETYPE = 0x00000003,
VFT2_FONT_VECTOR = 0x00000002
}
/// <summary>
/// Version file type.
/// </summary>
public enum VersionFileType : uint
{
VFT_APP = 0x00000001,
VFT_DLL = 0x00000002,
VFT_DRV = 0x00000003,
VFT_FONT = 0x00000004,
VFT_STATIC_LIB = 0x00000007,
VFT_UNKNOWN = 0x00000000,
VFT_VXD = 0x00000005
}
} }

View File

@@ -60,4 +60,25 @@ namespace libexeinfo.Windows
public int[] Pixels; public int[] Pixels;
public uint Width; public uint Width;
} }
/// <summary>
/// Fixed file version info
/// </summary>
[StructLayout(LayoutKind.Sequential)]
public struct FixedFileInfo
{
public uint dwSignature;
public uint dwStrucVersion;
public uint dwFileVersionMS;
public uint dwFileVersionLS;
public uint dwProductVersionMS;
public uint dwProductVersionLS;
public uint dwFileFlagsMask;
public uint dwFileFlags;
public uint dwFileOS;
public uint dwFileType;
public uint dwFileSubtype;
public uint dwFileDateMS;
public uint dwFileDateLS;
}
} }

View File

@@ -0,0 +1,140 @@
//
// Version.cs
//
// Author:
// Natalia Portillo <claunia@claunia.com>
//
// Copyright (c) 2017-2018 Copyright © Claunia.com
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
namespace libexeinfo.Windows
{
public static class Version
{
/// <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)
{
case VersionFileType.VFT_APP: return "Application";
case VersionFileType.VFT_DLL: return "Dynamic-link library";
case VersionFileType.VFT_DRV: return "Device driver";
case VersionFileType.VFT_FONT: return "Font";
case VersionFileType.VFT_STATIC_LIB: return "Static-link library";
case VersionFileType.VFT_UNKNOWN: return "Unknown";
case VersionFileType.VFT_VXD: return "Virtual device";
default: return $"Unknown type code {(uint)type}";
}
}
/// <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)
{
case VersionFileSubtype.VFT2_DRV_COMM: return "Communications";
case VersionFileSubtype.VFT2_DRV_DISPLAY: return "Display";
case VersionFileSubtype.VFT2_DRV_INSTALLABLE: return "Installable";
case VersionFileSubtype.VFT2_DRV_KEYBOARD: return "Keyboard";
case VersionFileSubtype.VFT2_DRV_LANGUAGE: return "Language";
case VersionFileSubtype.VFT2_DRV_MOUSE: return "Mouse";
case VersionFileSubtype.VFT2_DRV_NETWORK: return "Network";
case VersionFileSubtype.VFT2_DRV_PRINTER: return "Printer";
case VersionFileSubtype.VFT2_DRV_SOUND: return "Sound";
case VersionFileSubtype.VFT2_DRV_SYSTEM: return "System";
case VersionFileSubtype.VFT2_DRV_VERSIONED_PRINTER: return "Versioned";
case VersionFileSubtype.VFT2_UNKNOWN: return "Unknown";
default: return $"Unknown type code {(uint)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)
{
case VersionFileSubtype.VFT2_FONT_RASTER: return "Raster";
case VersionFileSubtype.VFT2_FONT_TRUETYPE: return "TrueType";
case VersionFileSubtype.VFT2_FONT_VECTOR: return "Vector";
case VersionFileSubtype.VFT2_UNKNOWN: return "Unknown";
default: return $"Unknown type code {(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)
{
switch(os)
{
case VersionFileOS.VOS_DOS: return "DOS";
case VersionFileOS.VOS_NT: return "Windows NT";
case VersionFileOS.VOS_WINDOWS16: return "16-bit Windows";
case VersionFileOS.VOS_WINDOWS32: return "32-bit Windows";
case VersionFileOS.VOS_OS216: return "16-bit OS/2";
case VersionFileOS.VOS_OS232: return "32-bit OS/2";
case VersionFileOS.VOS_PM16: return "16-bit Presentation Manager";
case VersionFileOS.VOS_PM32: return "32-bit Presentation Manager";
case VersionFileOS.VOS_UNKNOWN: return "Unknown";
case VersionFileOS.VOS_DOS_NT: return "DOS running under Windows NT";
case VersionFileOS.VOS_DOS_WINDOWS16: return "16-bit Windows running under DOS";
case VersionFileOS.VOS_DOS_WINDOWS32: return "32-bit Windows running under DOS";
case VersionFileOS.VOS_DOS_PM16: return "16-bit Presentation Manager running under DOS";
case VersionFileOS.VOS_DOS_PM32: return "32-bit Presentation Manager running under DOS";
case VersionFileOS.VOS_NT_WINDOWS16: return "16-bit Windows running under Windows NT";
case VersionFileOS.VOS_NT_WINDOWS32: return "32-bit Windows running under Windows NT";
case VersionFileOS.VOS_NT_PM16: return "16-bit Presentation Manager running under Windows NT";
case VersionFileOS.VOS_NT_PM32: return "32-bit Presentation Manager running under Windows NT";
case VersionFileOS.VOS_OS216_WINDOWS16: return "16-bit Windows running under 16-bit OS/2";
case VersionFileOS.VOS_OS216_WINDOWS32: return "32-bit Windows running under 16-bit OS/2";
case VersionFileOS.VOS_OS216_PM16: return "16-bit Presentation Manager running under 16-bit OS/2";
case VersionFileOS.VOS_OS216_PM32: return "32-bit Presentation Manager running under 16-bit OS/2";
case VersionFileOS.VOS_OS232_WINDOWS16: return "16-bit Windows running under 32-bit OS/2";
case VersionFileOS.VOS_OS232_WINDOWS32: return "32-bit Windows running under 32-bit OS/2";
case VersionFileOS.VOS_OS232_PM16: return "16-bit Presentation Manager running under 32-bit OS/2";
case VersionFileOS.VOS_OS232_PM32: return "32-bit Presentation Manager running under 32-bit OS/2";
default: return $"Unknown OS code {(uint)os}";
}
}
}
}

View File

@@ -105,9 +105,11 @@
<Compile Include="Swapping.cs" /> <Compile Include="Swapping.cs" />
<Compile Include="PE\Subsystems.cs" /> <Compile Include="PE\Subsystems.cs" />
<Compile Include="Windows\Bitmap.cs" /> <Compile Include="Windows\Bitmap.cs" />
<Compile Include="Windows\Consts.cs" />
<Compile Include="Windows\Enums.cs" /> <Compile Include="Windows\Enums.cs" />
<Compile Include="Windows\Resources.cs" /> <Compile Include="Windows\Resources.cs" />
<Compile Include="Windows\Structs.cs" /> <Compile Include="Windows\Structs.cs" />
<Compile Include="Windows\Version.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="packages.config" /> <None Include="packages.config" />