Update file version resource handling

This commit is contained in:
Matt Nadareski
2022-04-01 10:16:31 -07:00
parent edc4cc1706
commit 4b66cd8cd2
14 changed files with 114 additions and 113 deletions

View File

@@ -51,13 +51,8 @@ namespace BurnOutSharp.PackerType
private string GetVersion(PortableExecutable pex)
{
// Check the file version first
string version = Utilities.GetFileVersion(pex);
if (!string.IsNullOrEmpty(version))
return version;
// Then check the manifest version
version = Utilities.GetManifestVersion(pex);
// Check the internal versions
string version = Utilities.GetInternalVersion(pex);
if (!string.IsNullOrEmpty(version))
return version;

View File

@@ -20,7 +20,7 @@ namespace BurnOutSharp.PackerType
&& (name.Equals("Intel(R) Installation Framework", StringComparison.OrdinalIgnoreCase)
|| name.Equals("Intel Installation Framework", StringComparison.OrdinalIgnoreCase)))
{
return $"Intel Installation Framework {Utilities.GetFileVersion(pex)}";
return $"Intel Installation Framework {Utilities.GetInternalVersion(pex)}";
}
name = Utilities.GetProductName(pex);
@@ -28,7 +28,7 @@ namespace BurnOutSharp.PackerType
&& (name.Equals("Intel(R) Installation Framework", StringComparison.OrdinalIgnoreCase)
|| name.Equals("Intel Installation Framework", StringComparison.OrdinalIgnoreCase)))
{
return $"Intel Installation Framework {Utilities.GetFileVersion(pex)}";
return $"Intel Installation Framework {Utilities.GetInternalVersion(pex)}";
}
return null;

View File

@@ -87,11 +87,8 @@ namespace BurnOutSharp.PackerType
private string GetVersion(PortableExecutable pex)
{
string version = Utilities.GetFileVersion(pex);
if (!string.IsNullOrWhiteSpace(version))
return $"v{version}";
version = Utilities.GetManifestVersion(pex);
// Check the internal versions
string version = Utilities.GetInternalVersion(pex);
if (!string.IsNullOrWhiteSpace(version))
return $"v{version}";

View File

@@ -61,18 +61,13 @@ namespace BurnOutSharp.PackerType
private string GetVersion(PortableExecutable pex)
{
// Check the product version first
// Check the product version explicitly
string version = Utilities.GetProductVersion(pex);
if (!string.IsNullOrEmpty(version))
return version;
// Then check the file version
version = Utilities.GetFileVersion(pex);
if (!string.IsNullOrEmpty(version))
return version;
// Then check the manifest version
version = Utilities.GetManifestVersion(pex);
// Check the internal versions
version = Utilities.GetInternalVersion(pex);
if (!string.IsNullOrEmpty(version))
return version;

View File

@@ -24,19 +24,19 @@ namespace BurnOutSharp.ProtectionType
string name = Utilities.GetFileDescription(pex);
if (!string.IsNullOrWhiteSpace(name) && name.Contains("EReg MFC Application"))
return $"EA CdKey Registration Module {Utilities.GetFileVersion(pex)}";
return $"EA CdKey Registration Module {Utilities.GetInternalVersion(pex)}";
else if (!string.IsNullOrWhiteSpace(name) && name.Contains("Registration code installer program"))
return $"EA CdKey Registration Module {Utilities.GetFileVersion(pex)}";
return $"EA CdKey Registration Module {Utilities.GetInternalVersion(pex)}";
else if (!string.IsNullOrWhiteSpace(name) && name.Equals("EA DRM Helper", StringComparison.OrdinalIgnoreCase))
return $"EA DRM Protection {Utilities.GetFileVersion(pex)}";
return $"EA DRM Protection {Utilities.GetInternalVersion(pex)}";
name = Utilities.GetInternalName(pex);
if (!string.IsNullOrWhiteSpace(name) && name.Equals("CDCode", StringComparison.Ordinal))
return $"EA CdKey Registration Module {Utilities.GetFileVersion(pex)}";
return $"EA CdKey Registration Module {Utilities.GetInternalVersion(pex)}";
var resource = Utilities.FindResourceInSection(pex.ResourceSection, dataContains: "A\0b\0o\0u\0t\0 \0C\0D\0K\0e\0y");
if (resource != null)
return $"EA CdKey Registration Module {Utilities.GetFileVersion(pex)}";
return $"EA CdKey Registration Module {Utilities.GetInternalVersion(pex)}";
// Get the .data section, if it exists
if (pex.DataSectionRaw != null)
@@ -48,7 +48,7 @@ namespace BurnOutSharp.ProtectionType
{
0x45, 0x52, 0x65, 0x67, 0x20, 0x43, 0x6F, 0x6E,
0x66, 0x69, 0x67, 0x20, 0x46, 0x6F, 0x72, 0x6D
}, Utilities.GetFileVersion, "EA CdKey Registration Module"),
}, Utilities.GetInternalVersion, "EA CdKey Registration Module"),
};
string match = MatchUtil.GetFirstMatch(file, pex.DataSectionRaw, matchers, includeDebug);

View File

@@ -19,9 +19,9 @@ namespace BurnOutSharp.ProtectionType
string name = Utilities.GetFileDescription(pex);
if (!string.IsNullOrWhiteSpace(name) && name.StartsWith("Games for Windows - LIVE Zero Day Piracy Protection", StringComparison.OrdinalIgnoreCase))
return $"Games for Windows LIVE - Zero Day Piracy Protection Module {Utilities.GetFileVersion(pex)}";
return $"Games for Windows LIVE - Zero Day Piracy Protection Module {Utilities.GetInternalVersion(pex)}";
else if (!string.IsNullOrWhiteSpace(name) && name.StartsWith("Games for Windows", StringComparison.OrdinalIgnoreCase))
return $"Games for Windows LIVE {Utilities.GetFileVersion(pex)}";
return $"Games for Windows LIVE {Utilities.GetInternalVersion(pex)}";
// Get the .rdata section, if it exists
if (pex.ResourceDataSectionRaw != null)

View File

@@ -20,15 +20,15 @@ namespace BurnOutSharp.ProtectionType
string name = Utilities.GetFileDescription(pex);
if (!string.IsNullOrWhiteSpace(name) && name.Contains("ImpulseReactor Dynamic Link Library"))
return $"Impulse Reactor Core Module {Utilities.GetFileVersion(pex)}";
return $"Impulse Reactor Core Module {Utilities.GetInternalVersion(pex)}";
name = Utilities.GetProductName(pex);
if (!string.IsNullOrWhiteSpace(name) && name.Contains("ImpulseReactor Dynamic Link Library"))
return $"Impulse Reactor Core Module {Utilities.GetFileVersion(pex)}";
return $"Impulse Reactor Core Module {Utilities.GetInternalVersion(pex)}";
name = Utilities.GetOriginalFileName(pex);
if (!string.IsNullOrWhiteSpace(name) && name.Contains("ReactorActivate.exe"))
return $"Stardock Product Activation {Utilities.GetFileVersion(pex)}";
return $"Stardock Product Activation {Utilities.GetInternalVersion(pex)}";
// Get the .rdata section, if it exists
if (pex.ResourceDataSectionRaw != null)
@@ -56,7 +56,7 @@ namespace BurnOutSharp.ProtectionType
bool containsCheck2 = pex.ResourceDataSectionRaw.FirstPosition(check2, out int position2);
if (containsCheck && containsCheck2)
return $"Impulse Reactor Core Module {Utilities.GetFileVersion(pex)}" + (includeDebug ? $" (Index {position}, {position2})" : string.Empty);
return $"Impulse Reactor Core Module {Utilities.GetInternalVersion(pex)}" + (includeDebug ? $" (Index {position}, {position2})" : string.Empty);
else if (containsCheck && !containsCheck2)
return $"Impulse Reactor" + (includeDebug ? $" (Index {position})" : string.Empty);
}
@@ -69,8 +69,8 @@ namespace BurnOutSharp.ProtectionType
{
var matchers = new List<PathMatchSet>
{
new PathMatchSet(new PathMatch("ImpulseReactor.dll", useEndsWith: true), Utilities.GetFileVersion, "Impulse Reactor Core Module"),
new PathMatchSet(new PathMatch("ReactorActivate.exe", useEndsWith: true), Utilities.GetFileVersion, "Stardock Product Activation"),
new PathMatchSet(new PathMatch("ImpulseReactor.dll", useEndsWith: true), Utilities.GetInternalVersion, "Impulse Reactor Core Module"),
new PathMatchSet(new PathMatch("ReactorActivate.exe", useEndsWith: true), Utilities.GetInternalVersion, "Stardock Product Activation"),
};
return MatchUtil.GetAllMatches(files, matchers, any: true);
@@ -81,8 +81,8 @@ namespace BurnOutSharp.ProtectionType
{
var matchers = new List<PathMatchSet>
{
new PathMatchSet(new PathMatch("ImpulseReactor.dll", useEndsWith: true), Utilities.GetFileVersion, "Impulse Reactor Core Module"),
new PathMatchSet(new PathMatch("ReactorActivate.exe", useEndsWith: true), Utilities.GetFileVersion, "Stardock Product Activation"),
new PathMatchSet(new PathMatch("ImpulseReactor.dll", useEndsWith: true), Utilities.GetInternalVersion, "Impulse Reactor Core Module"),
new PathMatchSet(new PathMatch("ReactorActivate.exe", useEndsWith: true), Utilities.GetInternalVersion, "Stardock Product Activation"),
};
return MatchUtil.GetFirstMatch(path, matchers, any: true);

View File

@@ -17,7 +17,7 @@ namespace BurnOutSharp.ProtectionType
// TODO: Is this too broad in general?
string name = Utilities.GetInternalName(pex);
if (!string.IsNullOrWhiteSpace(name) && name.StartsWith("EReg", StringComparison.OrdinalIgnoreCase))
return $"Executable-Based Online Registration {Utilities.GetFileVersion(pex)}";
return $"Executable-Based Online Registration {Utilities.GetInternalVersion(pex)}";
return null;
}

View File

@@ -22,7 +22,7 @@ namespace BurnOutSharp.ProtectionType
string name = Utilities.GetFileDescription(pex);
if (!string.IsNullOrWhiteSpace(name) && name.Contains("SecuROM PA"))
return $"SecuROM PA v{Utilities.GetFileVersion(pex)}";
return $"SecuROM PA v{Utilities.GetInternalVersion(pex)}";
// Get the matrosch section, if it exists
bool matroschSection = pex.ContainsSection("matrosch", exact: true);
@@ -101,7 +101,7 @@ namespace BurnOutSharp.ProtectionType
{
0x64, 0x72, 0x6D, 0x5F, 0x70, 0x61, 0x67, 0x75,
0x69, 0x5F, 0x64, 0x6F, 0x69, 0x74
}, Utilities.GetFileVersion, "SecuROM Product Activation"),
}, Utilities.GetInternalVersion, "SecuROM Product Activation"),
// TODO: Re-enable this one if the above undermatches somehow
// // S + (char)0x00 + e + (char)0x00 + c + (char)0x00 + u + (char)0x00 + R + (char)0x00 + O + (char)0x00 + M + (char)0x00 + + (char)0x00 + P + (char)0x00 + A + (char)0x00
@@ -110,7 +110,7 @@ namespace BurnOutSharp.ProtectionType
// 0x53, 0x00, 0x65, 0x00, 0x63, 0x00, 0x75, 0x00,
// 0x52, 0x00, 0x4F, 0x00, 0x4D, 0x00, 0x20, 0x00,
// 0x50, 0x00, 0x41, 0x00
// }, Utilities.GetFileVersion, "SecuROM Product Activation"),
// }, Utilities.GetInternalVersion, "SecuROM Product Activation"),
};
string match = MatchUtil.GetFirstMatch(file, pex.ResourceDataSectionRaw, matchers, includeDebug);

View File

@@ -22,19 +22,19 @@ namespace BurnOutSharp.ProtectionType
string name = Utilities.GetFileDescription(pex);
if (!string.IsNullOrWhiteSpace(name) && name.StartsWith("DVM Library", StringComparison.OrdinalIgnoreCase))
return $"SolidShield {Utilities.GetFileVersion(pex)}";
return $"SolidShield {Utilities.GetInternalVersion(pex)}";
else if (!string.IsNullOrWhiteSpace(name) && name.StartsWith("Solidshield Activation Library", StringComparison.OrdinalIgnoreCase))
return $"SolidShield Core.dll {Utilities.GetFileVersion(pex)}";
return $"SolidShield Core.dll {Utilities.GetInternalVersion(pex)}";
else if (!string.IsNullOrWhiteSpace(name) && name.StartsWith("Activation Manager", StringComparison.OrdinalIgnoreCase))
return $"SolidShield Activation Manager Module {GetFileVersion(pex)}";
return $"SolidShield Activation Manager Module {GetInternalVersion(pex)}";
name = Utilities.GetProductName(pex);
if (!string.IsNullOrWhiteSpace(name) && name.StartsWith("Solidshield Activation Library", StringComparison.OrdinalIgnoreCase))
return $"SolidShield Core.dll {Utilities.GetFileVersion(pex)}";
return $"SolidShield Core.dll {Utilities.GetInternalVersion(pex)}";
else if (!string.IsNullOrWhiteSpace(name) && name.StartsWith("Solidshield Library", StringComparison.OrdinalIgnoreCase))
return $"SolidShield Core.dll {Utilities.GetFileVersion(pex)}";
return $"SolidShield Core.dll {Utilities.GetInternalVersion(pex)}";
else if (!string.IsNullOrWhiteSpace(name) && name.StartsWith("Activation Manager", StringComparison.OrdinalIgnoreCase))
return $"SolidShield Activation Manager Module {GetFileVersion(pex)}";
return $"SolidShield Activation Manager Module {GetInternalVersion(pex)}";
// Get the .init section, if it exists
var initSectionRaw = pex.ReadRawSection(".init", first: true);
@@ -188,11 +188,11 @@ namespace BurnOutSharp.ProtectionType
return null;
}
private static string GetFileVersion(PortableExecutable pex)
private static string GetInternalVersion(PortableExecutable pex)
{
string companyName = Utilities.GetCompanyName(pex)?.ToLowerInvariant();
if (!string.IsNullOrWhiteSpace(companyName) && (companyName.Contains("solidshield") || companyName.Contains("tages")))
return Utilities.GetFileVersion(pex);
return Utilities.GetInternalVersion(pex);
return null;
}

View File

@@ -20,13 +20,13 @@ namespace BurnOutSharp.ProtectionType
string name = Utilities.GetLegalCopyright(pex);
if (!string.IsNullOrWhiteSpace(name) && name.Contains("Protection Technology")) // Protection Technology (StarForce)?
return $"StarForce {Utilities.GetFileVersion(pex)}";
return $"StarForce {Utilities.GetInternalVersion(pex)}";
name = Utilities.GetInternalName(pex);
if (!string.IsNullOrWhiteSpace(name) && name.Equals("CORE.EXE", StringComparison.Ordinal))
return $"StarForce {Utilities.GetFileVersion(pex)}";
return $"StarForce {Utilities.GetInternalVersion(pex)}";
else if (!string.IsNullOrWhiteSpace(name) && name.Equals("protect.exe", StringComparison.Ordinal))
return $"StarForce {Utilities.GetFileVersion(pex)}";
return $"StarForce {Utilities.GetInternalVersion(pex)}";
// TODO: Find what fvinfo field actually maps to this
name = Utilities.GetFileDescription(pex);
@@ -139,7 +139,7 @@ namespace BurnOutSharp.ProtectionType
// }, GetVersion, "StarForce"),
// public static string GetVersion(string file, byte[] fileContent, List<int> positions)
// {
// return $"{Utilities.GetFileVersion(fileContent)} ({fileContent.Skip(positions[1] + 22).TakeWhile(c => c != 0x00)})";
// return $"{Utilities.GetInternalVersion(fileContent)} ({fileContent.Skip(positions[1] + 22).TakeWhile(c => c != 0x00)})";
// }
}
}

View File

@@ -22,7 +22,7 @@ namespace BurnOutSharp.ProtectionType
else if (!string.IsNullOrEmpty(name) && name.Contains("Steam Client API"))
return "Steam";
else if (!string.IsNullOrEmpty(name) && name.Contains("Steam Client Engine"))
return $"Steam Client Engine {Utilities.GetFileVersion(pex)}";
return $"Steam Client Engine {Utilities.GetInternalVersion(pex)}";
else if (!string.IsNullOrEmpty(name) && name.Contains("Steam Client Service"))
return "Steam";

View File

@@ -180,13 +180,8 @@ namespace BurnOutSharp.ProtectionType
private string GetVersion(PortableExecutable pex)
{
// Check the file version first
string version = Utilities.GetFileVersion(pex);
if (!string.IsNullOrEmpty(version))
return version;
// Then check the manifest version
version = Utilities.GetManifestVersion(pex);
// Check the internal versions
string version = Utilities.GetInternalVersion(pex);
if (!string.IsNullOrEmpty(version))
return version;

View File

@@ -181,41 +181,49 @@ namespace BurnOutSharp.Tools
#endregion
#region Executable Information
#region Processed Executable Information
/// <summary>
/// Get the company name as reported by the filesystem
/// </summary>
/// <param name="pex">PortableExecutable representing the file contents</param>
/// <returns>Company name string, null on error</returns>
public static string GetCompanyName(PortableExecutable pex) => GetResourceString(pex, "CompanyName");
/// <summary>
/// Get the file description as reported by the filesystem
/// </summary>
/// <param name="pex">PortableExecutable representing the file contents</param>
/// <returns>Description string, null on error</returns>
public static string GetFileDescription(PortableExecutable pex) => GetResourceString(pex, "FileDescription");
/// <summary>
/// Get the file version as reported by the filesystem
/// Get the internal version as reported by the resources
/// </summary>
/// <param name="fileContent">Byte array representing the file contents</param>
/// <returns>Version string, null on error</returns>
public static string GetFileVersion(byte[] fileContent)
public static string GetInternalVersion(byte[] fileContent)
{
if (fileContent == null || !fileContent.Any())
return null;
return GetFileVersion(new PortableExecutable(fileContent, 0));
return GetInternalVersion(new PortableExecutable(fileContent, 0));
}
/// <summary>
/// Get the file version as reported by the filesystem
/// Get the internal version as reported by the resources
/// </summary>
/// <param name="pex">PortableExecutable representing the file contents</param>
/// <returns>Version string, null on error</returns>
public static string GetInternalVersion(PortableExecutable pex)
{
string version = GetFileVersion(pex);
if (!string.IsNullOrWhiteSpace(version))
return version;
version = GetProductVersion(pex);
if (!string.IsNullOrWhiteSpace(version))
return version;
version = GetManifestVersion(pex);
if (!string.IsNullOrWhiteSpace(version))
return version;
return null;
}
/// <summary>
/// Get the internal version as reported by the filesystem
/// </summary>
/// <param name="file">File to check for version</param>
/// <returns>Version string, null on error</returns>
public static string GetFileVersion(string file)
public static string GetInternalVersion(string file)
{
var fvinfo = GetFileVersionInfo(file);
if (fvinfo?.FileVersion == null)
@@ -225,51 +233,41 @@ namespace BurnOutSharp.Tools
else
return fvinfo.ProductVersion.Replace(", ", ".");
}
#endregion
#region Executable Information
/// <summary>
/// Get the file version as reported by the filesystem
/// Get the company name as reported by the resources
/// </summary>
/// <param name="pex">PortableExecutable representing the file contents</param>
/// <returns>Version string, null on error</returns>
public static string GetFileVersion(PortableExecutable pex)
{
string version = GetResourceString(pex, "FileVersion");
if (!string.IsNullOrWhiteSpace(version))
return version.Replace(", ", ".");
version = GetProductVersion(pex);
if (!string.IsNullOrWhiteSpace(version))
return version;
return null;
}
/// <returns>Company name string, null on error</returns>
public static string GetCompanyName(PortableExecutable pex) => GetResourceString(pex, "CompanyName");
/// <summary>
/// Wrapper for GetFileVersion for use in content matching
/// Get the file description as reported by the resources
/// </summary>
/// <param name="file">File to check for version</param>
/// <param name="fileContent">Byte array representing the file contents</param>
/// <param name="positions">Last matched positions in the contents</param>
/// <returns>Version string, null on error</returns>
public static string GetFileVersion(string file, byte[] fileContent, List<int> positions) => GetFileVersion(fileContent);
/// <param name="pex">PortableExecutable representing the file contents</param>
/// <returns>Description string, null on error</returns>
public static string GetFileDescription(PortableExecutable pex) => GetResourceString(pex, "FileDescription");
/// <summary>
/// Wrapper for GetFileVersion for use in path matching
/// Get the file version as reported by the resources
/// </summary>
/// <param name="firstMatchedString">File to check for version</param>
/// <param name="files">Full list of input paths</param>
/// <returns>Version string, null on error</returns>
public static string GetFileVersion(string firstMatchedString, IEnumerable<string> files) => GetFileVersion(firstMatchedString);
/// <param name="pex">PortableExecutable representing the file contents</param>
/// <returns>File version string, null on error</returns>
public static string GetFileVersion(PortableExecutable pex) => GetResourceString(pex, "FileVersion")?.Replace(", ", ".");
/// <summary>
/// Get the internal name as reported by the filesystem
/// Get the internal name as reported by the resources
/// </summary>
/// <param name="pex">PortableExecutable representing the file contents</param>
/// <returns>Internal name string, null on error</returns>
public static string GetInternalName(PortableExecutable pex) => GetResourceString(pex, "InternalName");
/// <summary>
/// Get the legal copyright as reported by the filesystem
/// Get the legal copyright as reported by the resources
/// </summary>
/// <param name="pex">PortableExecutable representing the file contents</param>
/// <returns>Legal copyright string, null on error</returns>
@@ -353,21 +351,21 @@ namespace BurnOutSharp.Tools
}
/// <summary>
/// Get the original filename as reported by the filesystem
/// Get the original filename as reported by the resources
/// </summary>
/// <param name="pex">PortableExecutable representing the file contents</param>
/// <returns>Original filename string, null on error</returns>
public static string GetOriginalFileName(PortableExecutable pex) => GetResourceString(pex, "OriginalFileName");
/// <summary>
/// Get the product name as reported by the filesystem
/// Get the product name as reported by the resources
/// </summary>
/// <param name="pex">PortableExecutable representing the file contents</param>
/// <returns>Product name string, null on error</returns>
public static string GetProductName(PortableExecutable pex) => GetResourceString(pex, "ProductName");
/// <summary>
/// Get the product name as reported by the filesystem
/// Get the product name as reported by the resources
/// </summary>
/// <param name="pex">PortableExecutable representing the file contents</param>
/// <returns>Product version string, null on error</returns>
@@ -552,5 +550,26 @@ namespace BurnOutSharp.Tools
}
#endregion
#region Wrappers for Matchers
/// <summary>
/// Wrapper for GetInternalVersion for use in content matching
/// </summary>
/// <param name="file">File to check for version</param>
/// <param name="fileContent">Byte array representing the file contents</param>
/// <param name="positions">Last matched positions in the contents</param>
/// <returns>Version string, null on error</returns>
public static string GetInternalVersion(string file, byte[] fileContent, List<int> positions) => GetInternalVersion(fileContent);
/// <summary>
/// Wrapper for GetInternalVersion for use in path matching
/// </summary>
/// <param name="firstMatchedString">File to check for version</param>
/// <param name="files">Full list of input paths</param>
/// <returns>Version string, null on error</returns>
public static string GetInternalVersion(string firstMatchedString, IEnumerable<string> files) => GetInternalVersion(firstMatchedString);
#endregion
}
}