/// <summary>Class used to gather executable and dynamic link library information.</summary>
public sealed class Executables
{
/// <summary>Gets the Assembly Build Version.</summary>
public static string AssemblyBuildVersion
{
get { return Assembly.GetEntryAssembly().GetName().Version.Build.ToString(); }
}
/// <summary>Gets the Assembly Copyright information.</summary>
public static string AssemblyCopyright
{
get
{
object[] attributes = Assembly.GetEntryAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
return (attributes != null && attributes.Length > 0) && ((AssemblyCopyrightAttribute)attributes[0] != null) ? ((AssemblyCopyrightAttribute)attributes[0]).Copyright : string.Empty;
}
}
/// <summary>Gets the Assembly Guid.</summary>
public static string AssemblyGuid
{
get
{
object[] attributes = Assembly.GetEntryAssembly().GetCustomAttributes(typeof(GuidAttribute), false);
return attributes != null && attributes.Length > 0 ? ((GuidAttribute)attributes[0]).Value : string.Empty;
}
}
/// <summary>Gets the Assembly Major Version.</summary>
public static string AssemblyMajorVersion
{
get { return Assembly.GetEntryAssembly().GetName().Version.Major.ToString(); }
}
/// <summary>Gets the Assembly Minor Version.</summary>
public static string AssemblyMinorVersion
{
get { return Assembly.GetEntryAssembly().GetName().Version.Minor.ToString(); }
}
/// <summary>Gets the Assembly Revision Version.</summary>
public static string AssemblyRevisionVersion
{
get { return Assembly.GetEntryAssembly().GetName().Version.Revision.ToString(); }
}
/// <summary>Gets the Assembly Title.</summary>
public static string AssemblyTitle
{
get
{
object[] attributes = Assembly.GetEntryAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
return (attributes != null && attributes.Length > 0) && (((AssemblyTitleAttribute)attributes[0]).Title != "") ? ((AssemblyTitleAttribute)attributes[0]).Title : Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().CodeBase);
}
}
/// <summary>Gets the Assembly Version.</summary>
public static string AssemblyVersion
{
get
{
object[] attributes = Assembly.GetEntryAssembly().GetCustomAttributes(typeof(AssemblyVersionAttribute), false);
return attributes != null && attributes.Length > 0 ? ((AssemblyVersionAttribute)attributes[0]).Version : string.Empty;
}
}
}
.NET Reactor automatically detects the attribute and excludes the corresponding types and members from obfuscation.Example code posted from MSDN:
using System;
using System.Reflection;
// Mark this public assembly for obfuscation.
[assembly:ObfuscateAssemblyAttribute(false)]
// This class is marked for obfuscation, because the assembly
// is marked.
public class Type1
{
// Exclude this method from obfuscation. The default value
// of the Exclude property is true, so it is not necessary
// to specify Exclude=True, although spelling it out makes
// your intent clearer.
[ObfuscationAttribute(Exclude=true)]
public void MethodA() {}
// This member is marked for obfuscation because the class
// is marked.
public void MethodB() {}
}
// Exclude this type from obfuscation, but do not apply that
// exclusion to members. The default value of the Exclude
// property is true, so it is not necessary to specify
// Exclude=true, although spelling it out makes your intent
// clearer.
[ObfuscationAttribute(Exclude=true, ApplyToMembers=false)]
public class Type2
{
// The exclusion of the type is not applied to its members,
// however in order to mark the member with the "default"
// feature it is necessary to specify Exclude=false,
// because the default value of Exclude is true. The tool
// should not strip this attribute after obfuscation.
[ObfuscationAttribute(Exclude=false, Feature="default",
StripAfterObfuscation=false)]
public void MethodA() {}
// This member is marked for obfuscation, because the
// exclusion of the type is not applied to its members.
public void MethodB() {}
}
// This class only exists to provide an entry point for the
// assembly and to display the attribute values.
internal class Test
{
public static void Main()
{
// Display the ObfuscateAssemblyAttribute properties
// for the assembly.
Assembly assem = typeof(Test).Assembly;
object[] assemAttrs = assem.GetCustomAttributes(
typeof(ObfuscateAssemblyAttribute), false);
foreach( Attribute a in assemAttrs )
{
ShowObfuscateAssembly((ObfuscateAssemblyAttribute) a);
}
// Display the ObfuscationAttribute properties for each
// type that is visible to users of the assembly.
foreach( Type t in assem.GetTypes() )
{
if (t.IsVisible)
{
object[] tAttrs = t.GetCustomAttributes(
typeof(ObfuscationAttribute), false);
foreach( Attribute a in tAttrs )
{
ShowObfuscation(((ObfuscationAttribute) a),
t.Name);
}
// Display the ObfuscationAttribute properties
// for each member in the type.
foreach( MemberInfo m in t.GetMembers() )
{
object[] mAttrs = m.GetCustomAttributes(
typeof(ObfuscationAttribute), false);
foreach( Attribute a in mAttrs )
{
ShowObfuscation(((ObfuscationAttribute) a),
t.Name + "." + m.Name);
}
}
}
}
}
private static void ShowObfuscateAssembly(
ObfuscateAssemblyAttribute ob)
{
Console.WriteLine("\r\nObfuscateAssemblyAttribute properties:");
Console.WriteLine(" AssemblyIsPrivate: {0}",
ob.AssemblyIsPrivate);
Console.WriteLine(" StripAfterObfuscation: {0}",
ob.StripAfterObfuscation);
}
private static void ShowObfuscation(
ObfuscationAttribute ob, string target)
{
Console.WriteLine("\r\nObfuscationAttribute properties for: {0}",
target);
Console.WriteLine(" Exclude: {0}", ob.Exclude);
Console.WriteLine(" Feature: {0}", ob.Feature);
Console.WriteLine(" StripAfterObfuscation: {0}",
ob.StripAfterObfuscation);
Console.WriteLine(" ApplyToMembers: {0}", ob.ApplyToMembers);
}
}
/* This code example produces the following output:
ObfuscateAssemblyAttribute properties:
AssemblyIsPrivate: False
StripAfterObfuscation: True
ObfuscationAttribute properties for: Type1.MethodA
Exclude: True
Feature: all
StripAfterObfuscation: True
ApplyToMembers: True
ObfuscationAttribute properties for: Type2
Exclude: True
Feature: all
StripAfterObfuscation: True
ApplyToMembers: False
ObfuscationAttribute properties for: Type2.MethodA
Exclude: False
Feature: default
StripAfterObfuscation: False
ApplyToMembers: True
*/
/// <summary>Class used to gather executable and dynamic link library information.</summary>
[ObfuscationAttribute(Exclude = true, ApplyToMembers = true)]
public sealed class Executables
{
/// <summary>Gets the Assembly Build Version.</summary>
public static string AssemblyBuildVersion
{
get { return Assembly.GetEntryAssembly().GetName().Version.Build.ToString(); }
}
/// <summary>Gets the Assembly Copyright information.</summary>
public static string AssemblyCopyright
{
get
{
object[] attributes = Assembly.GetEntryAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
return (attributes != null && attributes.Length > 0) && ((AssemblyCopyrightAttribute)attributes[0] != null) ? ((AssemblyCopyrightAttribute)attributes[0]).Copyright : string.Empty;
}
}
/// <summary>Gets the Assembly Guid.</summary>
public static string AssemblyGuid
{
get
{
object[] attributes = Assembly.GetEntryAssembly().GetCustomAttributes(typeof(GuidAttribute), false);
return attributes != null && attributes.Length > 0 ? ((GuidAttribute)attributes[0]).Value : string.Empty;
}
}
/// <summary>Gets the Assembly Major Version.</summary>
public static string AssemblyMajorVersion
{
get { return Assembly.GetEntryAssembly().GetName().Version.Major.ToString(); }
}
/// <summary>Gets the Assembly Minor Version.</summary>
public static string AssemblyMinorVersion
{
get { return Assembly.GetEntryAssembly().GetName().Version.Minor.ToString(); }
}
/// <summary>Gets the Assembly Revision Version.</summary>
public static string AssemblyRevisionVersion
{
get { return Assembly.GetEntryAssembly().GetName().Version.Revision.ToString(); }
}
/// <summary>Gets the Assembly Title.</summary>
public static string AssemblyTitle
{
get
{
object[] attributes = Assembly.GetEntryAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
return (attributes != null && attributes.Length > 0) && (((AssemblyTitleAttribute)attributes[0]).Title != "") ? ((AssemblyTitleAttribute)attributes[0]).Title : Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().CodeBase);
}
}
/// <summary>Gets the Assembly Version.</summary>
public static string AssemblyVersion
{
get
{
object[] attributes = Assembly.GetEntryAssembly().GetCustomAttributes(typeof(AssemblyVersionAttribute), false);
return attributes != null && attributes.Length > 0 ? ((AssemblyVersionAttribute)attributes[0]).Version : string.Empty;
}
}
}
public static Globals
{
private readonly static string fMyVersion = "1.0.0.0";
[ObfuscationAttribute(Exclude = true)]
public static string MyVersion { get { return fMyVersion; } }
}
/// <summary>Gets the Assembly Version.</summary>
public static string AssemblyVersion
{
get
{
object[] attributes = Assembly.GetEntryAssembly().GetCustomAttributes(typeof(AssemblyVersionAttribute), false);
return attributes != null && attributes.Length > 0 ? ((AssemblyVersionAttribute)attributes[0]).Version : string.Empty;
}
}
using System;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
namespace EE_Q28585763
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Build Version: {0}", Executables.AssemblyBuildVersion);
Console.WriteLine("Copyright: {0}", Executables.AssemblyCopyright);
Console.WriteLine("Guid: {0}", Executables.AssemblyGuid);
Console.WriteLine("Major Version: {0}", Executables.AssemblyMajorVersion);
Console.WriteLine("Minor Version: {0}", Executables.AssemblyMinorVersion);
Console.WriteLine("Revision: {0}", Executables.AssemblyRevisionVersion);
Console.WriteLine("Title: {0}", Executables.AssemblyTitle);
Console.WriteLine("Version: {0}", Executables.AssemblyVersion);
Console.ReadLine();
}
}
/// <summary>Class used to gather executable and dynamic link library information.</summary>
[ObfuscationAttribute(Exclude = true, ApplyToMembers = true)]
public sealed class Executables
{
/// <summary>Gets the Assembly Build Version.</summary>
public static string AssemblyBuildVersion
{
get { return Assembly.GetEntryAssembly().GetName().Version.Build.ToString(); }
}
/// <summary>Gets the Assembly Copyright information.</summary>
public static string AssemblyCopyright
{
get
{
object[] attributes = Assembly.GetEntryAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
return (attributes != null && attributes.Length > 0) && ((AssemblyCopyrightAttribute)attributes[0] != null) ? ((AssemblyCopyrightAttribute)attributes[0]).Copyright : string.Empty;
}
}
/// <summary>Gets the Assembly Guid.</summary>
public static string AssemblyGuid
{
get
{
object[] attributes = Assembly.GetEntryAssembly().GetCustomAttributes(typeof(GuidAttribute), false);
return attributes != null && attributes.Length > 0 ? ((GuidAttribute)attributes[0]).Value : string.Empty;
}
}
/// <summary>Gets the Assembly Major Version.</summary>
public static string AssemblyMajorVersion
{
get { return Assembly.GetEntryAssembly().GetName().Version.Major.ToString(); }
}
/// <summary>Gets the Assembly Minor Version.</summary>
public static string AssemblyMinorVersion
{
get { return Assembly.GetEntryAssembly().GetName().Version.Minor.ToString(); }
}
/// <summary>Gets the Assembly Revision Version.</summary>
public static string AssemblyRevisionVersion
{
get { return Assembly.GetEntryAssembly().GetName().Version.Revision.ToString(); }
}
/// <summary>Gets the Assembly Title.</summary>
public static string AssemblyTitle
{
get
{
object[] attributes = Assembly.GetEntryAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);
return (attributes != null && attributes.Length > 0) && (((AssemblyTitleAttribute)attributes[0]).Title != "") ? ((AssemblyTitleAttribute)attributes[0]).Title : Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().CodeBase);
}
}
/// <summary>Gets the Assembly Version.</summary>
public static string AssemblyVersion
{
get
{
Version version = Assembly.GetEntryAssembly().GetName().Version;
return version != null && version.ToString().Length > 0 ? version.ToString() : string.Empty;
}
}
}
}
Have you tried using the version number at runtime with code like this.
Open in new window