-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a7ca5d6
commit 02d9a92
Showing
18 changed files
with
2,315 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
namespace AssemblyInfo | ||
{ | ||
public class AssemblyData | ||
{ | ||
public string Name { get; set; } | ||
public string ProductName { get; set; } | ||
public string FileDescription { get; set; } | ||
public string Description { get; set; } | ||
public string Company { get; set; } | ||
public string Version { get; set; } | ||
public string FileVersion { get; set; } | ||
public string ProductVersion { get; set; } | ||
public bool IsStronglyNamed { get; set; } | ||
public string PublicKeyToken { get; set; } | ||
public string Framework { get; set; } | ||
public string FrameworkVersion { get; set; } | ||
public string Copyright { get; set; } | ||
public string Build { get; set; } | ||
public string DebuggableModes { get; set; } | ||
public bool IsDebug { get; set; } | ||
public bool IsPatched { get; set; } | ||
public bool IsPreRelease { get; set; } | ||
public string Language { get; set; } | ||
public string OriginalFilename { get; set; } | ||
public string FileSize { get; set; } | ||
public long FileLength { get; set; } | ||
public string Sha { get; set; } | ||
public string Md5 { get; set; } | ||
public bool IsClsCompliant { get; set; } | ||
public string InformationalVersion { get; set; } | ||
public string Metadata { get; set; } | ||
|
||
public override string ToString() => Name; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace AssemblyInfo | ||
{ | ||
public static class AssemblyDataFormatter | ||
{ | ||
public static string GetAssemblyDataOutput(FormatterOutput formatterOutput, AssemblyData data) | ||
{ | ||
var d = ","; | ||
var sb = new StringBuilder(); | ||
var properties = typeof(AssemblyData).GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance).OrderBy(x => x.Name); | ||
switch (formatterOutput) | ||
{ | ||
case FormatterOutput.Parsable: | ||
sb.AppendLine(string.Join(d, properties.Select(x => x.Name))); | ||
sb.AppendLine(string.Join(d, properties.Select(x => x.GetValue(data)))); | ||
break; | ||
case FormatterOutput.Pretty: | ||
foreach (var property in properties) | ||
sb.AppendLine($"{property.Name}: {property.GetValue(data)}"); | ||
break; | ||
} | ||
return sb.ToString(); | ||
} | ||
|
||
public enum FormatterOutput | ||
{ | ||
Pretty, | ||
Parsable | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
using AssemblyInfo.Extensions; | ||
using System; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Runtime.Versioning; | ||
using System.Security.Cryptography; | ||
|
||
namespace AssemblyInfo | ||
{ | ||
public class AssemblyInspector | ||
{ | ||
/// <summary> | ||
/// Max 1GB hash inspection length | ||
/// </summary> | ||
private const int MaxHashInspectionLength = 1 * 1024 * 1024 * 1024; | ||
|
||
public AssemblyData Inspect(string filename) | ||
{ | ||
if (File.Exists(filename)) | ||
return InspectAssembly(filename); | ||
throw new FileNotFoundException(filename); | ||
} | ||
|
||
private AssemblyData InspectAssembly(string filename) | ||
{ | ||
var assembly = Assembly.LoadFrom(filename); | ||
var assemblyName = assembly.GetName(); | ||
var version = assemblyName.Version; | ||
var fileVersion = FileVersionInfo.GetVersionInfo(assembly.Location); | ||
var targetFramework = assembly.CustomAttributes.FirstOrDefault(x => x.AttributeType == typeof(TargetFrameworkAttribute)); | ||
var assemblyConfiguration = assembly.CustomAttributes.FirstOrDefault(x => x.AttributeType == typeof(AssemblyConfigurationAttribute)); | ||
var clsCompliant = assembly.CustomAttributes.FirstOrDefault(x => x.AttributeType == typeof(CLSCompliantAttribute)); | ||
var assemblyInformationalVersion = assembly.CustomAttributes.FirstOrDefault(x => x.AttributeType == typeof(AssemblyInformationalVersionAttribute)); | ||
var assemblyMetadatas = assembly.CustomAttributes.Where(x => x.AttributeType == typeof(AssemblyMetadataAttribute)).ToList(); | ||
var debuggable = assembly.CustomAttributes.FirstOrDefault(x => x.AttributeType == typeof(DebuggableAttribute)); | ||
var debuggableAttributeArguments = debuggable.ConstructorArguments.FirstOrDefault(); | ||
var fileInfo = new FileInfo(filename); | ||
|
||
var frameworkString = targetFramework?.ConstructorArguments?.FirstOrDefault().Value.ToString(); | ||
var targetFrameworkName = frameworkString | ||
?.Split(new string[] { "," }, System.StringSplitOptions.None) | ||
.FirstOrDefault(); | ||
var targetFrameworkVersion = frameworkString | ||
?.Split(new string[] { "," }, System.StringSplitOptions.None) | ||
// remove version label | ||
?.Skip(1).FirstOrDefault()?.Split(new string[] { "="}, System.StringSplitOptions.None) | ||
// remove v prepend | ||
?.Skip(1).FirstOrDefault()?.Replace("v", ""); | ||
var metadata = assemblyMetadatas?.SelectMany(x => x.ConstructorArguments.Select(y => y.Value.ToString())); | ||
var metadataKeys = metadata?.Where((x, i) => i % 2 == 0).ToList(); | ||
var metadataValues = metadata?.Skip(1).Where((x, i) => i % 2 == 0).ToList(); | ||
var data = new AssemblyData | ||
{ | ||
Name = assembly.FullName, | ||
ProductName = fileVersion.ProductName, | ||
FileDescription = fileVersion.FileDescription, | ||
Description = fileVersion.Comments, | ||
Company = fileVersion.CompanyName, | ||
Version = version.ToString(), | ||
FileVersion = fileVersion.FileVersion, | ||
ProductVersion = fileVersion.ProductVersion, | ||
IsClsCompliant = (bool?)clsCompliant?.ConstructorArguments?.FirstOrDefault().Value ?? false, | ||
InformationalVersion = assemblyInformationalVersion?.ConstructorArguments?.FirstOrDefault().Value.ToString(), | ||
Metadata = string.Join(",", metadataKeys.Select((x, i) => $"{x}={metadataValues[i].ToString()}")), | ||
IsStronglyNamed = assemblyName.GetPublicKeyToken().Length > 0, | ||
PublicKeyToken = string.Join("", assemblyName.GetPublicKeyToken().Select(b => b.ToString("x2"))), | ||
Framework = targetFrameworkName, | ||
FrameworkVersion = targetFrameworkVersion, | ||
Copyright = fileVersion.LegalCopyright, | ||
Build = assemblyConfiguration?.ConstructorArguments?.FirstOrDefault().Value.ToString(), | ||
IsDebug = fileVersion.IsDebug, | ||
DebuggableModes = debuggableAttributeArguments != null ? ((DebuggableAttribute.DebuggingModes)debuggableAttributeArguments.Value).ToString() : string.Empty, | ||
IsPatched = fileVersion.IsPatched, | ||
IsPreRelease = fileVersion.IsPreRelease, | ||
Language = fileVersion.Language, | ||
OriginalFilename = fileVersion.OriginalFilename, | ||
FileSize = Util.BytesToString(fileInfo.Length), | ||
FileLength = fileInfo.Length | ||
}; | ||
|
||
if (data.FileLength < MaxHashInspectionLength) | ||
ComputeHash(data, filename); | ||
return data; | ||
} | ||
|
||
private void ComputeHash(AssemblyData data, string filename) | ||
{ | ||
var bytes = File.ReadAllBytes(filename); | ||
using (var sha = SHA256.Create()) | ||
{ | ||
var shaHash = sha.ComputeHash(bytes); | ||
data.Sha = AssemblyInfo.Extensions.ByteConverter.ToHex(shaHash); | ||
} | ||
using (var md5 = MD5.Create()) | ||
{ | ||
var md5Hash = md5.ComputeHash(bytes); | ||
data.Md5 = AssemblyInfo.Extensions.ByteConverter.ToHex(md5Hash); | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.