Files
2026-06-04 11:42:34 +02:00

672 lines
24 KiB
C#

using System;
using System.Configuration.Assemblies;
using System.Globalization;
using System.IO;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Security;
using System.Security.Cryptography;
using System.Text;
using Mono.Security;
using Mono.Security.Cryptography;
namespace System.Reflection
{
/// <summary>Describes an assembly's unique identity in full.</summary>
// Token: 0x0200022E RID: 558
[ComDefaultInterface(typeof(_AssemblyName))]
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
[Serializable]
public sealed class AssemblyName : ICloneable, ISerializable, _AssemblyName, IDeserializationCallback
{
/// <summary>Initializes a new instance of the <see cref="T:System.Reflection.AssemblyName" /> class.</summary>
// Token: 0x06001D7A RID: 7546 RVA: 0x0006E218 File Offset: 0x0006C418
public AssemblyName()
{
this.versioncompat = AssemblyVersionCompatibility.SameMachine;
}
/// <summary>Initializes a new instance of the <see cref="T:System.Reflection.AssemblyName" /> class with the specified display name.</summary>
/// <param name="assemblyName">The display name of the assembly, as returned by the <see cref="P:System.Reflection.AssemblyName.FullName" /> property.</param>
/// <exception cref="T:System.ArgumentNullException">
/// <paramref name="assemblyName" /> is null.</exception>
/// <exception cref="T:System.ArgumentException">
/// <paramref name="assemblyName" /> is a zero length string.</exception>
// Token: 0x06001D7B RID: 7547 RVA: 0x0006E228 File Offset: 0x0006C428
public AssemblyName(string assemblyName)
{
if (assemblyName == null)
{
throw new ArgumentNullException("assemblyName");
}
if (assemblyName.Length < 1)
{
throw new ArgumentException("assemblyName cannot have zero length.");
}
if (!AssemblyName.ParseName(this, assemblyName))
{
throw new FileLoadException("The assembly name is invalid.");
}
}
// Token: 0x06001D7C RID: 7548 RVA: 0x0006E27C File Offset: 0x0006C47C
internal AssemblyName(SerializationInfo si, StreamingContext sc)
{
this.name = si.GetString("_Name");
this.codebase = si.GetString("_CodeBase");
this.version = (Version)si.GetValue("_Version", typeof(Version));
this.publicKey = (byte[])si.GetValue("_PublicKey", typeof(byte[]));
this.keyToken = (byte[])si.GetValue("_PublicKeyToken", typeof(byte[]));
this.hashalg = (AssemblyHashAlgorithm)((int)si.GetValue("_HashAlgorithm", typeof(AssemblyHashAlgorithm)));
this.keypair = (StrongNameKeyPair)si.GetValue("_StrongNameKeyPair", typeof(StrongNameKeyPair));
this.versioncompat = (AssemblyVersionCompatibility)((int)si.GetValue("_VersionCompatibility", typeof(AssemblyVersionCompatibility)));
this.flags = (AssemblyNameFlags)((int)si.GetValue("_Flags", typeof(AssemblyNameFlags)));
int @int = si.GetInt32("_CultureInfo");
if (@int != -1)
{
this.cultureinfo = new CultureInfo(@int);
}
}
/// <summary>Maps a set of names to a corresponding set of dispatch identifiers.</summary>
/// <param name="riid">Reserved for future use. Must be IID_NULL.</param>
/// <param name="rgszNames">Passed-in array of names to be mapped.</param>
/// <param name="cNames">Count of the names to be mapped.</param>
/// <param name="lcid">The locale context in which to interpret the names.</param>
/// <param name="rgDispId">Caller-allocated array that receives the IDs corresponding to the names.</param>
/// <exception cref="T:System.NotImplementedException">Late-bound access using the COM IDispatch interface is not supported.</exception>
// Token: 0x06001D7D RID: 7549 RVA: 0x0006E3B0 File Offset: 0x0006C5B0
void _AssemblyName.GetIDsOfNames([In] ref Guid riid, IntPtr rgszNames, uint cNames, uint lcid, IntPtr rgDispId)
{
throw new NotImplementedException();
}
/// <summary>Retrieves the type information for an object, which can then be used to get the type information for an interface.</summary>
/// <param name="iTInfo">The type information to return.</param>
/// <param name="lcid">The locale identifier for the type information.</param>
/// <param name="ppTInfo">Receives a pointer to the requested type information object.</param>
/// <exception cref="T:System.NotImplementedException">Late-bound access using the COM IDispatch interface is not supported.</exception>
// Token: 0x06001D7E RID: 7550 RVA: 0x0006E3B8 File Offset: 0x0006C5B8
void _AssemblyName.GetTypeInfo(uint iTInfo, uint lcid, IntPtr ppTInfo)
{
throw new NotImplementedException();
}
/// <summary>Retrieves the number of type information interfaces that an object provides (either 0 or 1).</summary>
/// <param name="pcTInfo">Points to a location that receives the number of type information interfaces provided by the object.</param>
/// <exception cref="T:System.NotImplementedException">Late-bound access using the COM IDispatch interface is not supported.</exception>
// Token: 0x06001D7F RID: 7551 RVA: 0x0006E3C0 File Offset: 0x0006C5C0
void _AssemblyName.GetTypeInfoCount(out uint pcTInfo)
{
throw new NotImplementedException();
}
/// <summary>Provides access to properties and methods exposed by an object.</summary>
/// <param name="dispIdMember">Identifies the member.</param>
/// <param name="riid">Reserved for future use. Must be IID_NULL.</param>
/// <param name="lcid">The locale context in which to interpret arguments.</param>
/// <param name="wFlags">Flags describing the context of the call.</param>
/// <param name="pDispParams">Pointer to a structure containing an array of arguments, an array of argument DispIDs for named arguments, and counts for the number of elements in the arrays.</param>
/// <param name="pVarResult">Pointer to the location where the result is to be stored.</param>
/// <param name="pExcepInfo">Pointer to a structure that contains exception information.</param>
/// <param name="puArgErr">The index of the first argument that has an error.</param>
/// <exception cref="T:System.NotImplementedException">Late-bound access using the COM IDispatch interface is not supported.</exception>
// Token: 0x06001D80 RID: 7552 RVA: 0x0006E3C8 File Offset: 0x0006C5C8
void _AssemblyName.Invoke(uint dispIdMember, [In] ref Guid riid, uint lcid, short wFlags, IntPtr pDispParams, IntPtr pVarResult, IntPtr pExcepInfo, IntPtr puArgErr)
{
throw new NotImplementedException();
}
// Token: 0x06001D81 RID: 7553
[MethodImpl(MethodImplOptions.InternalCall)]
private static extern bool ParseName(AssemblyName aname, string assemblyName);
/// <summary>Gets or sets a value that identifies the processor and bits-per-word of the platform targeted by an executable.</summary>
/// <returns>One of the <see cref="T:System.Reflection.ProcessorArchitecture" /> values that identifies the processor and bits-per-word of the platform targeted by an executable.</returns>
// Token: 0x1700054D RID: 1357
// (get) Token: 0x06001D82 RID: 7554 RVA: 0x0006E3D0 File Offset: 0x0006C5D0
// (set) Token: 0x06001D83 RID: 7555 RVA: 0x0006E3D8 File Offset: 0x0006C5D8
[MonoTODO("Not used, as the values are too limited; Mono supports more")]
public ProcessorArchitecture ProcessorArchitecture
{
get
{
return this.processor_architecture;
}
set
{
this.processor_architecture = value;
}
}
/// <summary>Gets or sets the simple name of the assembly. This is usually, but not necessarily, the file name of the manifest file of the assembly, minus its extension.</summary>
/// <returns>A String that is the simple name of the assembly.</returns>
// Token: 0x1700054E RID: 1358
// (get) Token: 0x06001D84 RID: 7556 RVA: 0x0006E3E4 File Offset: 0x0006C5E4
// (set) Token: 0x06001D85 RID: 7557 RVA: 0x0006E3EC File Offset: 0x0006C5EC
public string Name
{
get
{
return this.name;
}
set
{
this.name = value;
}
}
/// <summary>Gets or sets the location of the assembly as a URL.</summary>
/// <returns>A string that is the URL location of the assembly. </returns>
// Token: 0x1700054F RID: 1359
// (get) Token: 0x06001D86 RID: 7558 RVA: 0x0006E3F8 File Offset: 0x0006C5F8
// (set) Token: 0x06001D87 RID: 7559 RVA: 0x0006E400 File Offset: 0x0006C600
public string CodeBase
{
get
{
return this.codebase;
}
set
{
this.codebase = value;
}
}
/// <summary>Gets the URI, including escape characters, that represents the codebase.</summary>
/// <returns>A URI with escape characters.</returns>
// Token: 0x17000550 RID: 1360
// (get) Token: 0x06001D88 RID: 7560 RVA: 0x0006E40C File Offset: 0x0006C60C
public string EscapedCodeBase
{
get
{
if (this.codebase == null)
{
return null;
}
return Uri.EscapeString(this.codebase, false, true, true);
}
}
/// <summary>Gets or sets the culture supported by the assembly.</summary>
/// <returns>A <see cref="T:System.Globalization.CultureInfo" /> object representing the culture supported by the assembly.</returns>
// Token: 0x17000551 RID: 1361
// (get) Token: 0x06001D89 RID: 7561 RVA: 0x0006E42C File Offset: 0x0006C62C
// (set) Token: 0x06001D8A RID: 7562 RVA: 0x0006E434 File Offset: 0x0006C634
public CultureInfo CultureInfo
{
get
{
return this.cultureinfo;
}
set
{
this.cultureinfo = value;
}
}
/// <summary>Gets or sets the attributes of the assembly.</summary>
/// <returns>An <see cref="T:System.Reflection.AssemblyNameFlags" /> object representing the attributes of the assembly.</returns>
// Token: 0x17000552 RID: 1362
// (get) Token: 0x06001D8B RID: 7563 RVA: 0x0006E440 File Offset: 0x0006C640
// (set) Token: 0x06001D8C RID: 7564 RVA: 0x0006E448 File Offset: 0x0006C648
public AssemblyNameFlags Flags
{
get
{
return this.flags;
}
set
{
this.flags = value;
}
}
/// <summary>Gets the full name of the assembly, also known as the display name.</summary>
/// <returns>A string that is the full name of the assembly, also known as the display name.</returns>
// Token: 0x17000553 RID: 1363
// (get) Token: 0x06001D8D RID: 7565 RVA: 0x0006E454 File Offset: 0x0006C654
public string FullName
{
get
{
if (this.name == null)
{
return string.Empty;
}
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.Append(this.name);
if (this.Version != null)
{
stringBuilder.Append(", Version=");
stringBuilder.Append(this.Version.ToString());
}
if (this.cultureinfo != null)
{
stringBuilder.Append(", Culture=");
if (this.cultureinfo.LCID == CultureInfo.InvariantCulture.LCID)
{
stringBuilder.Append("neutral");
}
else
{
stringBuilder.Append(this.cultureinfo.Name);
}
}
byte[] array = this.InternalGetPublicKeyToken();
if (array != null)
{
if (array.Length == 0)
{
stringBuilder.Append(", PublicKeyToken=null");
}
else
{
stringBuilder.Append(", PublicKeyToken=");
for (int i = 0; i < array.Length; i++)
{
stringBuilder.Append(array[i].ToString("x2"));
}
}
}
if ((this.Flags & AssemblyNameFlags.Retargetable) != AssemblyNameFlags.None)
{
stringBuilder.Append(", Retargetable=Yes");
}
return stringBuilder.ToString();
}
}
/// <summary>Gets or sets the hash algorithm used by the assembly manifest.</summary>
/// <returns>An AssemblyHashAlgorithm object representing the hash algorithm used by the assembly manifest.</returns>
// Token: 0x17000554 RID: 1364
// (get) Token: 0x06001D8E RID: 7566 RVA: 0x0006E58C File Offset: 0x0006C78C
// (set) Token: 0x06001D8F RID: 7567 RVA: 0x0006E594 File Offset: 0x0006C794
public AssemblyHashAlgorithm HashAlgorithm
{
get
{
return this.hashalg;
}
set
{
this.hashalg = value;
}
}
/// <summary>Gets or sets the public and private cryptographic key pair that is used to create a strong name signature for the assembly.</summary>
/// <returns>A <see cref="T:System.Reflection.StrongNameKeyPair" /> object containing the public and private cryptographic key pair to be used to create a strong name for the assembly.</returns>
// Token: 0x17000555 RID: 1365
// (get) Token: 0x06001D90 RID: 7568 RVA: 0x0006E5A0 File Offset: 0x0006C7A0
// (set) Token: 0x06001D91 RID: 7569 RVA: 0x0006E5A8 File Offset: 0x0006C7A8
public StrongNameKeyPair KeyPair
{
get
{
return this.keypair;
}
set
{
this.keypair = value;
}
}
/// <summary>Gets or sets the major, minor, build, and revision numbers of the assembly.</summary>
/// <returns>A <see cref="T:System.Version" /> object representing the major, minor, build, and revision numbers of the assembly.</returns>
// Token: 0x17000556 RID: 1366
// (get) Token: 0x06001D92 RID: 7570 RVA: 0x0006E5B4 File Offset: 0x0006C7B4
// (set) Token: 0x06001D93 RID: 7571 RVA: 0x0006E5BC File Offset: 0x0006C7BC
public Version Version
{
get
{
return this.version;
}
set
{
this.version = value;
if (value == null)
{
this.major = (this.minor = (this.build = (this.revision = 0)));
}
else
{
this.major = value.Major;
this.minor = value.Minor;
this.build = value.Build;
this.revision = value.Revision;
}
}
}
/// <summary>Gets or sets the information related to the assembly's compatibility with other assemblies.</summary>
/// <returns>An AssemblyVersionCompatibility object representing information about the assembly's compatibility with other assemblies.</returns>
// Token: 0x17000557 RID: 1367
// (get) Token: 0x06001D94 RID: 7572 RVA: 0x0006E634 File Offset: 0x0006C834
// (set) Token: 0x06001D95 RID: 7573 RVA: 0x0006E63C File Offset: 0x0006C83C
public AssemblyVersionCompatibility VersionCompatibility
{
get
{
return this.versioncompat;
}
set
{
this.versioncompat = value;
}
}
/// <summary>Returns the full name of the assembly, also known as the display name.</summary>
/// <returns>A String that is the full name of the assembly, or the class name if the full name of the assembly cannot be determined.</returns>
// Token: 0x06001D96 RID: 7574 RVA: 0x0006E648 File Offset: 0x0006C848
public override string ToString()
{
string fullName = this.FullName;
return (fullName == null) ? base.ToString() : fullName;
}
/// <summary>Gets the public key of the assembly.</summary>
/// <returns>An array of type byte containing the public key of the assembly.</returns>
/// <exception cref="T:System.Security.SecurityException">A public key was provided (for example, by using the <see cref="M:System.Reflection.AssemblyName.SetPublicKey(System.Byte[])" /> method), but no public key token was provided. </exception>
// Token: 0x06001D97 RID: 7575 RVA: 0x0006E670 File Offset: 0x0006C870
public byte[] GetPublicKey()
{
return this.publicKey;
}
/// <summary>Gets the public key token, which is the last 8 bytes of the SHA-1 hash of the public key under which the application or assembly is signed.</summary>
/// <returns>An array of type byte containing the public key token.</returns>
// Token: 0x06001D98 RID: 7576 RVA: 0x0006E678 File Offset: 0x0006C878
public byte[] GetPublicKeyToken()
{
if (this.keyToken != null)
{
return this.keyToken;
}
if (this.publicKey == null)
{
return null;
}
if (this.publicKey.Length == 0)
{
return new byte[0];
}
if (!this.IsPublicKeyValid)
{
throw new SecurityException("The public key is not valid.");
}
this.keyToken = this.ComputePublicKeyToken();
return this.keyToken;
}
// Token: 0x17000558 RID: 1368
// (get) Token: 0x06001D99 RID: 7577 RVA: 0x0006E6E0 File Offset: 0x0006C8E0
private bool IsPublicKeyValid
{
get
{
if (this.publicKey.Length == 16)
{
int i = 0;
int num = 0;
while (i < this.publicKey.Length)
{
num += (int)this.publicKey[i++];
}
if (num == 4)
{
return true;
}
}
byte b = this.publicKey[0];
if (b != 6)
{
if (b != 7)
{
if (b == 0)
{
if (this.publicKey.Length > 12 && this.publicKey[12] == 6)
{
try
{
CryptoConvert.FromCapiPublicKeyBlob(this.publicKey, 12);
return true;
}
catch (CryptographicException)
{
}
}
}
}
}
else
{
try
{
CryptoConvert.FromCapiPublicKeyBlob(this.publicKey);
return true;
}
catch (CryptographicException)
{
}
}
return false;
}
}
// Token: 0x06001D9A RID: 7578 RVA: 0x0006E7F0 File Offset: 0x0006C9F0
private byte[] InternalGetPublicKeyToken()
{
if (this.keyToken != null)
{
return this.keyToken;
}
if (this.publicKey == null)
{
return null;
}
if (this.publicKey.Length == 0)
{
return new byte[0];
}
if (!this.IsPublicKeyValid)
{
throw new SecurityException("The public key is not valid.");
}
return this.ComputePublicKeyToken();
}
// Token: 0x06001D9B RID: 7579 RVA: 0x0006E84C File Offset: 0x0006CA4C
private byte[] ComputePublicKeyToken()
{
HashAlgorithm hashAlgorithm = SHA1.Create();
byte[] array = hashAlgorithm.ComputeHash(this.publicKey);
byte[] array2 = new byte[8];
Array.Copy(array, array.Length - 8, array2, 0, 8);
Array.Reverse(array2, 0, 8);
return array2;
}
/// <summary>Returns a value indicating whether the loader resolves two assembly names to the same assembly.</summary>
/// <returns>true if the loader resolves <paramref name="definition" /> to the same assembly as <paramref name="reference" />; otherwise, false.</returns>
/// <param name="reference">The reference assembly name.</param>
/// <param name="definition">The assembly name that is compared to the reference assembly.</param>
// Token: 0x06001D9C RID: 7580 RVA: 0x0006E88C File Offset: 0x0006CA8C
[MonoTODO]
public static bool ReferenceMatchesDefinition(AssemblyName reference, AssemblyName definition)
{
if (reference == null)
{
throw new ArgumentNullException("reference");
}
if (definition == null)
{
throw new ArgumentNullException("definition");
}
if (reference.Name != definition.Name)
{
return false;
}
throw new NotImplementedException();
}
/// <summary>Sets the public key identifying the assembly.</summary>
/// <param name="publicKey">A byte array containing the public key of the assembly. </param>
// Token: 0x06001D9D RID: 7581 RVA: 0x0006E8D8 File Offset: 0x0006CAD8
public void SetPublicKey(byte[] publicKey)
{
if (publicKey == null)
{
this.flags ^= AssemblyNameFlags.PublicKey;
}
else
{
this.flags |= AssemblyNameFlags.PublicKey;
}
this.publicKey = publicKey;
}
/// <summary>Sets the public key token, which is the last 8 bytes of the SHA-1 hash of the public key under which the application or assembly is signed.</summary>
/// <param name="publicKeyToken">A byte array containing the public key token of the assembly. </param>
// Token: 0x06001D9E RID: 7582 RVA: 0x0006E914 File Offset: 0x0006CB14
public void SetPublicKeyToken(byte[] publicKeyToken)
{
this.keyToken = publicKeyToken;
}
/// <summary>Gets serialization information with all of the data needed to recreate an instance of this AssemblyName.</summary>
/// <param name="info">The object to be populated with serialization information. </param>
/// <param name="context">The destination context of the serialization. </param>
/// <exception cref="T:System.ArgumentNullException">
/// <paramref name="info" /> is null. </exception>
// Token: 0x06001D9F RID: 7583 RVA: 0x0006E920 File Offset: 0x0006CB20
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
if (info == null)
{
throw new ArgumentNullException("info");
}
info.AddValue("_Name", this.name);
info.AddValue("_PublicKey", this.publicKey);
info.AddValue("_PublicKeyToken", this.keyToken);
info.AddValue("_CultureInfo", (this.cultureinfo == null) ? (-1) : this.cultureinfo.LCID);
info.AddValue("_CodeBase", this.codebase);
info.AddValue("_Version", this.Version);
info.AddValue("_HashAlgorithm", this.hashalg);
info.AddValue("_HashAlgorithmForControl", AssemblyHashAlgorithm.None);
info.AddValue("_StrongNameKeyPair", this.keypair);
info.AddValue("_VersionCompatibility", this.versioncompat);
info.AddValue("_Flags", this.flags);
info.AddValue("_HashForControl", null);
}
/// <summary>Makes a copy of this AssemblyName object.</summary>
/// <returns>An object that is a copy of this AssemblyName object.</returns>
// Token: 0x06001DA0 RID: 7584 RVA: 0x0006EA2C File Offset: 0x0006CC2C
public object Clone()
{
return new AssemblyName
{
name = this.name,
codebase = this.codebase,
major = this.major,
minor = this.minor,
build = this.build,
revision = this.revision,
version = this.version,
cultureinfo = this.cultureinfo,
flags = this.flags,
hashalg = this.hashalg,
keypair = this.keypair,
publicKey = this.publicKey,
keyToken = this.keyToken,
versioncompat = this.versioncompat
};
}
/// <summary>Implements the <see cref="T:System.Runtime.Serialization.ISerializable" /> interface and is called back by the deserialization event when deserialization is complete.</summary>
/// <param name="sender">The source of the deserialization event. </param>
// Token: 0x06001DA1 RID: 7585 RVA: 0x0006EAE8 File Offset: 0x0006CCE8
public void OnDeserialization(object sender)
{
this.Version = this.version;
}
/// <summary>Gets the AssemblyName for a given file.</summary>
/// <returns>An AssemblyName object representing the given file.</returns>
/// <param name="assemblyFile">The path for the assembly whose AssemblyName is to be returned. </param>
/// <exception cref="T:System.ArgumentNullException">
/// <paramref name="assemblyFile" /> is null. </exception>
/// <exception cref="T:System.ArgumentException">
/// <paramref name="assemblyFile" /> is invalid, such as an assembly with an invalid culture. </exception>
/// <exception cref="T:System.IO.FileNotFoundException">
/// <paramref name="assemblyFile" /> is not found. </exception>
/// <exception cref="T:System.Security.SecurityException">The caller does not have path discovery permission. </exception>
/// <exception cref="T:System.BadImageFormatException">
/// <paramref name="assemblyFile" /> is not a valid assembly. </exception>
/// <exception cref="T:System.IO.FileLoadException">An assembly or module was loaded twice with two different sets of evidence. </exception>
/// <PermissionSet>
/// <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
/// </PermissionSet>
// Token: 0x06001DA2 RID: 7586 RVA: 0x0006EAF8 File Offset: 0x0006CCF8
public static AssemblyName GetAssemblyName(string assemblyFile)
{
if (assemblyFile == null)
{
throw new ArgumentNullException("assemblyFile");
}
AssemblyName assemblyName = new AssemblyName();
Assembly.InternalGetAssemblyName(Path.GetFullPath(assemblyFile), assemblyName);
return assemblyName;
}
// Token: 0x040009EB RID: 2539
private string name;
// Token: 0x040009EC RID: 2540
private string codebase;
// Token: 0x040009ED RID: 2541
private int major;
// Token: 0x040009EE RID: 2542
private int minor;
// Token: 0x040009EF RID: 2543
private int build;
// Token: 0x040009F0 RID: 2544
private int revision;
// Token: 0x040009F1 RID: 2545
private CultureInfo cultureinfo;
// Token: 0x040009F2 RID: 2546
private AssemblyNameFlags flags;
// Token: 0x040009F3 RID: 2547
private AssemblyHashAlgorithm hashalg;
// Token: 0x040009F4 RID: 2548
private StrongNameKeyPair keypair;
// Token: 0x040009F5 RID: 2549
private byte[] publicKey;
// Token: 0x040009F6 RID: 2550
private byte[] keyToken;
// Token: 0x040009F7 RID: 2551
private AssemblyVersionCompatibility versioncompat;
// Token: 0x040009F8 RID: 2552
private Version version;
// Token: 0x040009F9 RID: 2553
private ProcessorArchitecture processor_architecture;
}
}