private AssemblyName(AssemblyName other) { codeBase = other.codeBase; culture = other.culture; flags = other.flags; name = other.name; hashAlg = other.hashAlg; keyPair = other.keyPair; version = (version == null ? null : (Version)(other.version.Clone())); versionCompat = other.versionCompat; publicKey = (other.publicKey == null ? null : (byte[])(other.publicKey.Clone())); publicKeyToken = (other.publicKeyToken == null ? null : (byte[])(other.publicKeyToken.Clone())); }
internal AssemblyBuilder(Universe universe, AssemblyName name, string dir, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions) : base(universe) { this.name = name.Name; SetVersionHelper(name.Version); if (!string.IsNullOrEmpty(name.Culture)) { this.culture = name.Culture; } this.flags = name.RawFlags; this.hashAlgorithm = name.HashAlgorithm; if (this.hashAlgorithm == AssemblyHashAlgorithm.None) { this.hashAlgorithm = AssemblyHashAlgorithm.SHA1; } this.keyPair = name.KeyPair; if (this.keyPair != null) { this.publicKey = this.keyPair.PublicKey; } else { byte[] publicKey = name.GetPublicKey(); if (publicKey != null && publicKey.Length != 0) { this.publicKey = (byte[])publicKey.Clone(); } } this.dir = dir ?? "."; this.requiredPermissions = requiredPermissions; this.optionalPermissions = optionalPermissions; this.refusedPermissions = refusedPermissions; if (universe.HasMscorlib && !universe.Mscorlib.__IsMissing && universe.Mscorlib.ImageRuntimeVersion != null) { this.imageRuntimeVersion = universe.Mscorlib.ImageRuntimeVersion; } else { this.imageRuntimeVersion = typeof(object).Assembly.ImageRuntimeVersion; } }
private static AssemblyName CreateAssemblyName(MetadataName name, MetadataName culture, Version version, AssemblyNameFlags flags, byte[] publicKeyOrToken) { var result = new AssemblyName(); result.Name = name.ToString(); if (!culture.IsEmpty) { result.CultureInfo = new CultureInfo(culture.ToString()); } result.Version = version; result.Flags = flags; if (publicKeyOrToken.Length != 0) { if ((result.Flags & AssemblyNameFlags.PublicKey) != 0) { result.SetPublicKey(publicKeyOrToken); } else { result.SetPublicKeyToken(publicKeyOrToken); } } return result; }
internal static ProcessorArchitecture CalculateProcArchIndex(PortableExecutableKinds pek, ImageFileMachine ifm, AssemblyNameFlags flags) { if ((flags & (AssemblyNameFlags)240) == (AssemblyNameFlags)112) { return(ProcessorArchitecture.None); } if ((pek & PortableExecutableKinds.PE32Plus) == PortableExecutableKinds.PE32Plus) { if (ifm != ImageFileMachine.I386) { if (ifm == ImageFileMachine.IA64) { return(ProcessorArchitecture.IA64); } if (ifm == ImageFileMachine.AMD64) { return(ProcessorArchitecture.Amd64); } } else if ((pek & PortableExecutableKinds.ILOnly) == PortableExecutableKinds.ILOnly) { return(ProcessorArchitecture.MSIL); } } else { if (ifm == ImageFileMachine.I386) { return((pek & PortableExecutableKinds.Required32Bit) == PortableExecutableKinds.Required32Bit || (pek & PortableExecutableKinds.ILOnly) != PortableExecutableKinds.ILOnly ? ProcessorArchitecture.X86 : ProcessorArchitecture.MSIL); } if (ifm == ImageFileMachine.ARM) { return(ProcessorArchitecture.Arm); } } return(ProcessorArchitecture.None); }
public AssemblyFlagsAttribute(AssemblyNameFlags assemblyFlags) { m_flags = assemblyFlags; }
public AssemblyName(string assemblyName) { if (assemblyName == null) { throw new ArgumentNullException("assemblyName"); } if (assemblyName == "") { throw new ArgumentException(); } ParsedAssemblyName parsed; switch (Fusion.ParseAssemblyName(assemblyName, out parsed)) { case ParseAssemblyResult.GenericError: case ParseAssemblyResult.DuplicateKey: throw new FileLoadException(); } if (!ParseVersion(parsed.Version, parsed.Retargetable.HasValue, out version)) { throw new FileLoadException(); } name = parsed.Name; if (parsed.Culture != null) { if (parsed.Culture.Equals("neutral", StringComparison.OrdinalIgnoreCase)) { culture = ""; } else if (parsed.Culture == "") { throw new FileLoadException(); } else { culture = new CultureInfo(parsed.Culture).Name; } } if (parsed.PublicKeyToken != null) { if (parsed.PublicKeyToken.Equals("null", StringComparison.OrdinalIgnoreCase)) { publicKeyToken = Empty<byte>.Array; } else if (parsed.PublicKeyToken.Length != 16) { throw new FileLoadException(); } else { publicKeyToken = ParseKey(parsed.PublicKeyToken); } } if (parsed.Retargetable.HasValue) { if (parsed.Culture == null || parsed.PublicKeyToken == null || version == null) { throw new FileLoadException(); } if (parsed.Retargetable.Value) { flags |= AssemblyNameFlags.Retargetable; } } ProcessorArchitecture = parsed.ProcessorArchitecture; if (parsed.WindowsRuntime) { ContentType = AssemblyContentType.WindowsRuntime; } }
internal static ProcessorArchitecture CalculateProcArchIndex(PortableExecutableKinds pek, ImageFileMachine ifm, AssemblyNameFlags flags) { if (((uint)flags & 0xF0) == 0x70) return ProcessorArchitecture.None; if ((pek & System.Reflection.PortableExecutableKinds.PE32Plus) == System.Reflection.PortableExecutableKinds.PE32Plus) { switch (ifm) { case System.Reflection.ImageFileMachine.IA64: return ProcessorArchitecture.IA64; case System.Reflection.ImageFileMachine.AMD64: return ProcessorArchitecture.Amd64; case System.Reflection.ImageFileMachine.I386: if ((pek & System.Reflection.PortableExecutableKinds.ILOnly) == System.Reflection.PortableExecutableKinds.ILOnly) return ProcessorArchitecture.MSIL; break; } } else { if (ifm == System.Reflection.ImageFileMachine.I386) { if ((pek & System.Reflection.PortableExecutableKinds.Required32Bit) == System.Reflection.PortableExecutableKinds.Required32Bit) return ProcessorArchitecture.X86; if ((pek & System.Reflection.PortableExecutableKinds.ILOnly) == System.Reflection.PortableExecutableKinds.ILOnly) return ProcessorArchitecture.MSIL; return ProcessorArchitecture.X86; } if (ifm == System.Reflection.ImageFileMachine.ARM) { return ProcessorArchitecture.Arm; } } return ProcessorArchitecture.None; }
internal void Init(string name, byte[] publicKey, byte[] publicKeyToken, Version version, CultureInfo cultureInfo, AssemblyHashAlgorithm hashAlgorithm, AssemblyVersionCompatibility versionCompatibility, string codeBase, AssemblyNameFlags flags, StrongNameKeyPair keyPair) { this._Name = name; if (publicKey != null) { this._PublicKey = new byte[publicKey.Length]; Array.Copy((Array)publicKey, (Array)this._PublicKey, publicKey.Length); } if (publicKeyToken != null) { this._PublicKeyToken = new byte[publicKeyToken.Length]; Array.Copy((Array)publicKeyToken, (Array)this._PublicKeyToken, publicKeyToken.Length); } if (version != (Version)null) { this._Version = (Version)version.Clone(); } this._CultureInfo = cultureInfo; this._HashAlgorithm = hashAlgorithm; this._VersionCompatibility = versionCompatibility; this._CodeBase = codeBase; this._Flags = flags; this._StrongNameKeyPair = keyPair; }
public static AssemblyNameFlags ExtractAssemblyNameFlags(this AssemblyNameFlags combinedFlags) { return(combinedFlags & unchecked ((AssemblyNameFlags)0xFFFFF10F)); }
internal static AssemblyNameFlags ExtractAssemblyNameFlags(AssemblyNameFlags combinedFlags) { return combinedFlags & unchecked((AssemblyNameFlags)0xFFFFF10F); }
/// <include file='doc\AssemblyName.uex' path='docs/doc[@for="AssemblyName.SetPublicKey"]/*' /> public void SetPublicKey(byte[] publicKey) { _PublicKey = publicKey; _Flags |= AssemblyNameFlags.PublicKey; }
internal static ProcessorArchitecture ExtractProcessorArchitecture(this AssemblyNameFlags flags) { return((ProcessorArchitecture)((((int)flags) >> 4) & 0x7)); }
private AssemblyNameParts Parse() { // Name must come first. string name; Token token = GetNextToken(out name); if (token != Token.String) { ThrowHelper.ThrowFileLoadException_InvalidAssemblyName(_input); } if (name == string.Empty || name.IndexOfAny(s_illegalCharactersInSimpleName) != -1) { ThrowHelper.ThrowFileLoadException_InvalidAssemblyName(_input); } Version?version = null; string? cultureName = null; byte[]? pkt = null; AssemblyNameFlags flags = 0; AttributeKind alreadySeen = default; token = GetNextToken(); while (token != Token.End) { if (token != Token.Comma) { ThrowHelper.ThrowFileLoadException_InvalidAssemblyName(_input); } string attributeName; token = GetNextToken(out attributeName); if (token != Token.String) { ThrowHelper.ThrowFileLoadException_InvalidAssemblyName(_input); } token = GetNextToken(); if (token != Token.Equals) { ThrowHelper.ThrowFileLoadException_InvalidAssemblyName(_input); } string attributeValue; token = GetNextToken(out attributeValue); if (token != Token.String) { ThrowHelper.ThrowFileLoadException_InvalidAssemblyName(_input); } if (attributeName == string.Empty) { ThrowHelper.ThrowFileLoadException_InvalidAssemblyName(_input); } if (attributeName.Equals("Version", StringComparison.OrdinalIgnoreCase)) { RecordNewSeenOrThrow(ref alreadySeen, AttributeKind.Version); version = ParseVersion(attributeValue); } if (attributeName.Equals("Culture", StringComparison.OrdinalIgnoreCase)) { RecordNewSeenOrThrow(ref alreadySeen, AttributeKind.Culture); cultureName = ParseCulture(attributeValue); } if (attributeName.Equals("PublicKey", StringComparison.OrdinalIgnoreCase)) { RecordNewSeenOrThrow(ref alreadySeen, AttributeKind.PublicKeyOrToken); pkt = ParsePKT(attributeValue, isToken: false); flags |= AssemblyNameFlags.PublicKey; } if (attributeName.Equals("PublicKeyToken", StringComparison.OrdinalIgnoreCase)) { RecordNewSeenOrThrow(ref alreadySeen, AttributeKind.PublicKeyOrToken); pkt = ParsePKT(attributeValue, isToken: true); } if (attributeName.Equals("ProcessorArchitecture", StringComparison.OrdinalIgnoreCase)) { RecordNewSeenOrThrow(ref alreadySeen, AttributeKind.ProcessorArchitecture); flags |= (AssemblyNameFlags)(((int)ParseProcessorArchitecture(attributeValue)) << 4); } if (attributeName.Equals("Retargetable", StringComparison.OrdinalIgnoreCase)) { RecordNewSeenOrThrow(ref alreadySeen, AttributeKind.Retargetable); if (attributeValue.Equals("Yes", StringComparison.OrdinalIgnoreCase)) { flags |= AssemblyNameFlags.Retargetable; } else if (attributeValue.Equals("No", StringComparison.OrdinalIgnoreCase)) { // nothing to do } else { ThrowHelper.ThrowFileLoadException_InvalidAssemblyName(_input); } } if (attributeName.Equals("ContentType", StringComparison.OrdinalIgnoreCase)) { RecordNewSeenOrThrow(ref alreadySeen, AttributeKind.ContentType); if (attributeValue.Equals("WindowsRuntime", StringComparison.OrdinalIgnoreCase)) { flags |= (AssemblyNameFlags)(((int)AssemblyContentType.WindowsRuntime) << 9); } else { ThrowHelper.ThrowFileLoadException_InvalidAssemblyName(_input); } } // Desktop compat: If we got here, the attribute name is unknown to us. Ignore it. token = GetNextToken(); } return(new AssemblyNameParts(name, version, cultureName, flags, pkt)); }
public AssemblyFlagsAttribute(AssemblyNameFlags assemblyFlags) { this.flags = (uint)assemblyFlags; }
public AssemblyName(string assemblyName) { if (assemblyName == null) { throw new ArgumentNullException("assemblyName"); } if (assemblyName == "") { throw new ArgumentException(); } ParsedAssemblyName parsed; switch (Fusion.ParseAssemblyName(assemblyName, out parsed)) { case ParseAssemblyResult.GenericError: case ParseAssemblyResult.DuplicateKey: throw new FileLoadException(); } if (!ParseVersion(parsed.Version, parsed.Retargetable.HasValue, out version)) { throw new FileLoadException(); } name = parsed.Name; if (parsed.Culture != null) { if (parsed.Culture.Equals("neutral", StringComparison.OrdinalIgnoreCase)) { culture = ""; } else if (parsed.Culture == "") { throw new FileLoadException(); } else { culture = new CultureInfo(parsed.Culture).Name; } } if (parsed.PublicKeyToken != null) { if (parsed.PublicKeyToken.Equals("null", StringComparison.OrdinalIgnoreCase)) { publicKeyToken = Empty <byte> .Array; } else if (parsed.PublicKeyToken.Length != 16) { throw new FileLoadException(); } else { publicKeyToken = ParseKey(parsed.PublicKeyToken); } } if (parsed.Retargetable.HasValue) { if (parsed.Culture == null || parsed.PublicKeyToken == null || version == null) { throw new FileLoadException(); } if (parsed.Retargetable.Value) { flags |= AssemblyNameFlags.Retargetable; } } ProcessorArchitecture = parsed.ProcessorArchitecture; if (parsed.WindowsRuntime) { ContentType = AssemblyContentType.WindowsRuntime; } }
// // These helpers convert between the combined flags+contentType+processorArchitecture value and the separated parts. // // Since these are only for trusted callers, they do NOT check for out of bound bits. // internal static AssemblyContentType ExtractAssemblyContentType(this AssemblyNameFlags flags) { return((AssemblyContentType)((((int)flags) >> 9) & 0x7)); }
internal static AssemblyNameFlags CombineAssemblyNameFlags(AssemblyNameFlags flags, AssemblyContentType contentType, ProcessorArchitecture processorArchitecture) { return((AssemblyNameFlags)(((int)flags) | (((int)contentType) << 9) | ((int)processorArchitecture << 4))); }
public RoAssemblyName(string?name, Version?version, string?cultureName, byte[]?publicKeyToken, AssemblyNameFlags flags) { // We forcefully normalize the representation so that Equality is dependable and fast. Debug.Assert(name != null); Name = name; Version = version ?? s_Version0000; CultureName = cultureName ?? string.Empty; PublicKeyToken = publicKeyToken ?? Array.Empty <byte>(); Flags = flags; }
public static void Translate(this ITranslator translator, ref AssemblyName assemblyName) { if (!translator.TranslateNullable(assemblyName)) { return; } string name = null; Version version = null; AssemblyNameFlags flags = default; ProcessorArchitecture processorArchitecture = default; CultureInfo cultureInfo = null; AssemblyHashAlgorithm hashAlgorithm = default; AssemblyVersionCompatibility versionCompatibility = default; string codeBase = null; byte[] publicKey = null; byte[] publicKeyToken = null; if (translator.Mode == TranslationDirection.WriteToStream) { name = assemblyName.Name; version = assemblyName.Version; flags = assemblyName.Flags; processorArchitecture = assemblyName.ProcessorArchitecture; cultureInfo = assemblyName.CultureInfo; hashAlgorithm = assemblyName.HashAlgorithm; versionCompatibility = assemblyName.VersionCompatibility; codeBase = assemblyName.CodeBase; publicKey = assemblyName.GetPublicKey(); // TODO: no need to serialize, public key is not used anywhere in context of RAR, only public key token publicKeyToken = assemblyName.GetPublicKeyToken(); } translator.Translate(ref name); translator.Translate(ref version); translator.TranslateEnum(ref flags, (int)flags); translator.TranslateEnum(ref processorArchitecture, (int)processorArchitecture); translator.Translate(ref cultureInfo); translator.TranslateEnum(ref hashAlgorithm, (int)hashAlgorithm); translator.TranslateEnum(ref versionCompatibility, (int)versionCompatibility); translator.Translate(ref codeBase); translator.Translate(ref publicKey); translator.Translate(ref publicKeyToken); if (translator.Mode == TranslationDirection.ReadFromStream) { assemblyName = new AssemblyName { Name = name, Version = version, Flags = flags, ProcessorArchitecture = processorArchitecture, CultureInfo = cultureInfo, HashAlgorithm = hashAlgorithm, VersionCompatibility = versionCompatibility, CodeBase = codeBase, }; assemblyName.SetPublicKey(publicKey); assemblyName.SetPublicKeyToken(publicKeyToken); } }
// Set the public key for the assembly's originator. public void SetPublicKey(byte[] publicKey) { this.publicKey = publicKey; this.flags |= AssemblyNameFlags.PublicKey; }
public void SetPublicKey(byte[] publicKey) { this.publicKey = publicKey; flags = (flags & ~AssemblyNameFlags.PublicKey) | (publicKey == null ? 0 : AssemblyNameFlags.PublicKey); }
public AssemblyFlagsAttribute(uint flags) { m_flags = (AssemblyNameFlags)flags; }
public AssemblyName(string assemblyName) { if (assemblyName == null) { throw new ArgumentNullException("assemblyName"); } if (assemblyName == "") { throw new ArgumentException(); } ParsedAssemblyName parsed; switch (Fusion.ParseAssemblyName(assemblyName, out parsed)) { case ParseAssemblyResult.GenericError: throw new FileLoadException(); case ParseAssemblyResult.DuplicateKey: throw new System.Runtime.InteropServices.COMException(); } name = parsed.Name; if (parsed.Culture != null) { if (parsed.Culture.Equals("neutral", StringComparison.InvariantCultureIgnoreCase)) { culture = ""; } else if (parsed.Culture == "") { throw new FileLoadException(); } else { culture = new CultureInfo(parsed.Culture).Name; } } if (parsed.Version != null && parsed.Version.Major != 65535 && parsed.Version.Minor != 65535) { // our Fusion parser returns -1 for build and revision for incomplete version numbers (and we want 65535) version = new Version(parsed.Version.Major, parsed.Version.Minor, parsed.Version.Build & 0xFFFF, parsed.Version.Revision & 0xFFFF); } if (parsed.PublicKeyToken != null) { if (parsed.PublicKeyToken.Equals("null", StringComparison.InvariantCultureIgnoreCase)) { publicKeyToken = Empty <byte> .Array; } else if (parsed.PublicKeyToken.Length != 16) { throw new FileLoadException(); } else { publicKeyToken = new byte[8]; for (int i = 0, pos = 0; i < publicKeyToken.Length; i++, pos += 2) { publicKeyToken[i] = (byte)("0123456789abcdef".IndexOf(char.ToLowerInvariant(parsed.PublicKeyToken[pos])) * 16 + "0123456789abcdef".IndexOf(char.ToLowerInvariant(parsed.PublicKeyToken[pos + 1]))); } } } if (parsed.Retargetable.HasValue) { if (parsed.Culture == null || parsed.PublicKeyToken == null || parsed.Version == null || parsed.Version.Build == -1 || parsed.Version.Revision == -1) { throw new FileLoadException(); } if (parsed.Retargetable.Value) { flags |= AssemblyNameFlags.Retargetable; } } ProcessorArchitecture = parsed.ProcessorArchitecture; if (parsed.WindowsRuntime) { ContentType = AssemblyContentType.WindowsRuntime; } }
internal AssemblyBuilder(Universe universe, AssemblyName name, string dir, IEnumerable<CustomAttributeBuilder> customAttributes) : base(universe) { this.name = name.Name; SetVersionHelper(name.Version); if (!string.IsNullOrEmpty(name.Culture)) { this.culture = name.Culture; } this.flags = name.RawFlags; this.hashAlgorithm = name.HashAlgorithm; if (this.hashAlgorithm == AssemblyHashAlgorithm.None) { this.hashAlgorithm = AssemblyHashAlgorithm.SHA1; } this.keyPair = name.KeyPair; if (this.keyPair != null) { this.publicKey = this.keyPair.PublicKey; } else { byte[] publicKey = name.GetPublicKey(); if (publicKey != null && publicKey.Length != 0) { this.publicKey = (byte[])publicKey.Clone(); } } this.dir = dir ?? "."; if (customAttributes != null) { this.customAttributes.AddRange(customAttributes); } if (universe.HasMscorlib && !universe.Mscorlib.__IsMissing && universe.Mscorlib.ImageRuntimeVersion != null) { this.imageRuntimeVersion = universe.Mscorlib.ImageRuntimeVersion; } else { this.imageRuntimeVersion = typeof(object).Assembly.ImageRuntimeVersion; } universe.RegisterDynamicAssembly(this); }
public static string ComputeDisplayName(string name, Version?version, string?cultureName, byte[]?pkt, AssemblyNameFlags flags = 0, AssemblyContentType contentType = 0) { const int PUBLIC_KEY_TOKEN_LEN = 8; Debug.Assert(name.Length != 0); var vsb = new ValueStringBuilder(stackalloc char[256]); vsb.AppendQuoted(name); if (version != null) { ushort major = (ushort)version.Major; if (major != ushort.MaxValue) { vsb.Append(", Version="); vsb.AppendSpanFormattable(major); ushort minor = (ushort)version.Minor; if (minor != ushort.MaxValue) { vsb.Append('.'); vsb.AppendSpanFormattable(minor); ushort build = (ushort)version.Build; if (build != ushort.MaxValue) { vsb.Append('.'); vsb.AppendSpanFormattable(build); ushort revision = (ushort)version.Revision; if (revision != ushort.MaxValue) { vsb.Append('.'); vsb.AppendSpanFormattable(revision); } } } } } if (cultureName != null) { if (cultureName.Length == 0) { cultureName = "neutral"; } vsb.Append(", Culture="); vsb.AppendQuoted(cultureName); } if (pkt != null) { if (pkt.Length > PUBLIC_KEY_TOKEN_LEN) { throw new ArgumentException(); } vsb.Append(", PublicKeyToken="); if (pkt.Length == 0) { vsb.Append("null"); } else { HexConverter.EncodeToUtf16(pkt, vsb.AppendSpan(pkt.Length * 2), HexConverter.Casing.Lower); } } if (0 != (flags & AssemblyNameFlags.Retargetable)) { vsb.Append(", Retargetable=Yes"); } if (contentType == AssemblyContentType.WindowsRuntime) { vsb.Append(", ContentType=WindowsRuntime"); } // NOTE: By design (desktop compat) AssemblyName.FullName and ToString() do not include ProcessorArchitecture. return(vsb.ToString()); }
public void SetPublicKey(byte[] publicKey) { _PublicKey = publicKey; if (publicKey == null) _Flags &= ~AssemblyNameFlags.PublicKey; else _Flags |= AssemblyNameFlags.PublicKey; }
public static string ComputeDisplayName(string name, Version version, string cultureName, byte[] pkt, AssemblyNameFlags flags, AssemblyContentType contentType) { const int PUBLIC_KEY_TOKEN_LEN = 8; if (name == string.Empty) { throw new FileLoadException(); } StringBuilder sb = new StringBuilder(); if (name != null) { sb.AppendQuoted(name); } if (version != null) { Version canonicalizedVersion = version.CanonicalizeVersion(); if (canonicalizedVersion.Major != ushort.MaxValue) { sb.Append(", Version="); sb.Append(canonicalizedVersion.Major); if (canonicalizedVersion.Minor != ushort.MaxValue) { sb.Append('.'); sb.Append(canonicalizedVersion.Minor); if (canonicalizedVersion.Build != ushort.MaxValue) { sb.Append('.'); sb.Append(canonicalizedVersion.Build); if (canonicalizedVersion.Revision != ushort.MaxValue) { sb.Append('.'); sb.Append(canonicalizedVersion.Revision); } } } } } if (cultureName != null) { if (cultureName == string.Empty) { cultureName = "neutral"; } sb.Append(", Culture="); sb.AppendQuoted(cultureName); } if (pkt != null) { if (pkt.Length > PUBLIC_KEY_TOKEN_LEN) { throw new ArgumentException(); } sb.Append(", PublicKeyToken="); if (pkt.Length == 0) { sb.Append("null"); } else { foreach (byte b in pkt) { sb.Append(b.ToString("x2", CultureInfo.InvariantCulture)); } } } if (0 != (flags & AssemblyNameFlags.Retargetable)) { sb.Append(", Retargetable=Yes"); } if (contentType == AssemblyContentType.WindowsRuntime) { sb.Append(", ContentType=WindowsRuntime"); } // NOTE: By design (desktop compat) AssemblyName.FullName and ToString() do not include ProcessorArchitecture. return(sb.ToString()); }
public AssemblyName() { _HashAlgorithm = AssemblyHashAlgorithm.None; _VersionCompatibility = AssemblyVersionCompatibility.SameMachine; _Flags = AssemblyNameFlags.None; }
public AssemblyFlagsAttribute(AssemblyNameFlags assemblyFlags) { }
public AssemblyBuilder ConvertTypeLibToAssembly([MarshalAs(UnmanagedType.Interface)] Object typeLib, String asmFileName, TypeLibImporterFlags flags, ITypeLibImporterNotifySink notifySink, byte[] publicKey, StrongNameKeyPair keyPair, String asmNamespace, Version asmVersion) { // Validate the arguments. if (typeLib == null) { throw new ArgumentNullException("typeLib"); } if (asmFileName == null) { throw new ArgumentNullException("asmFileName"); } if (notifySink == null) { throw new ArgumentNullException("notifySink"); } if (String.Empty.Equals(asmFileName)) { throw new ArgumentException(Environment.GetResourceString("Arg_InvalidFileName"), "asmFileName"); } if (asmFileName.Length > Path.MAX_PATH) { throw new ArgumentException(Environment.GetResourceString("IO.PathTooLong"), asmFileName); } if ((flags & TypeLibImporterFlags.PrimaryInteropAssembly) != 0 && publicKey == null && keyPair == null) { throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_PIAMustBeStrongNamed")); } Contract.EndContractBlock(); ArrayList eventItfInfoList = null; // Determine the AssemblyNameFlags AssemblyNameFlags asmNameFlags = AssemblyNameFlags.None; // Retrieve the assembly name from the typelib. AssemblyName asmName = GetAssemblyNameFromTypelib(typeLib, asmFileName, publicKey, keyPair, asmVersion, asmNameFlags); // Create the dynamic assembly that will contain the converted typelib types. AssemblyBuilder asmBldr = CreateAssemblyForTypeLib(typeLib, asmFileName, asmName, (flags & TypeLibImporterFlags.PrimaryInteropAssembly) != 0, (flags & TypeLibImporterFlags.ReflectionOnlyLoading) != 0, (flags & TypeLibImporterFlags.NoDefineVersionResource) != 0); // Define a dynamic module that will contain the contain the imported types. String strNonQualifiedAsmFileName = Path.GetFileName(asmFileName); ModuleBuilder modBldr = asmBldr.DefineDynamicModule(strNonQualifiedAsmFileName, strNonQualifiedAsmFileName); // If the namespace hasn't been specified, then use the assembly name. if (asmNamespace == null) { asmNamespace = asmName.Name; } // Create a type resolve handler that will also intercept resolve ref messages // on the sink interface to build up a list of referenced assemblies. TypeResolveHandler typeResolveHandler = new TypeResolveHandler(modBldr, notifySink); // Add a listener for the type resolve events. AppDomain currentDomain = Thread.GetDomain(); ResolveEventHandler resolveHandler = new ResolveEventHandler(typeResolveHandler.ResolveEvent); ResolveEventHandler asmResolveHandler = new ResolveEventHandler(typeResolveHandler.ResolveAsmEvent); ResolveEventHandler ROAsmResolveHandler = new ResolveEventHandler(typeResolveHandler.ResolveROAsmEvent); currentDomain.TypeResolve += resolveHandler; currentDomain.AssemblyResolve += asmResolveHandler; currentDomain.ReflectionOnlyAssemblyResolve += ROAsmResolveHandler; // Convert the types contained in the typelib into metadata and add them to the assembly. nConvertTypeLibToMetadata(typeLib, asmBldr.InternalAssembly, modBldr.InternalModule, asmNamespace, flags, typeResolveHandler, out eventItfInfoList); // Update the COM types in the assembly. UpdateComTypesInAssembly(asmBldr, modBldr); // If there are any event sources then generate the TCE adapters. if (eventItfInfoList.Count > 0) { new TCEAdapterGenerator().Process(modBldr, eventItfInfoList); } // Remove the listener for the type resolve events. currentDomain.TypeResolve -= resolveHandler; currentDomain.AssemblyResolve -= asmResolveHandler; currentDomain.ReflectionOnlyAssemblyResolve -= ROAsmResolveHandler; // We have finished converting the typelib and now have a fully formed assembly. return(asmBldr); }
[System.Security.SecurityCritical] // auto-generated internal static AssemblyName GetAssemblyNameFromTypelib(Object typeLib, String asmFileName, byte[] publicKey, StrongNameKeyPair keyPair, Version asmVersion, AssemblyNameFlags asmNameFlags) { // Extract the name of the typelib. String strTypeLibName = null; String strDocString = null; int dwHelpContext = 0; String strHelpFile = null; ITypeLib pTLB = (ITypeLib)typeLib; pTLB.GetDocumentation(-1, out strTypeLibName, out strDocString, out dwHelpContext, out strHelpFile); // Retrieve the name to use for the assembly. if (asmFileName == null) { asmFileName = strTypeLibName; } else { Contract.Assert((asmFileName != null) && (asmFileName.Length > 0), "The assembly file name cannot be an empty string!"); String strFileNameNoPath = Path.GetFileName(asmFileName); String strExtension = Path.GetExtension(asmFileName); // Validate that the extension is valid. bool bExtensionValid = ".dll".Equals(strExtension, StringComparison.OrdinalIgnoreCase); // If the extension is not valid then tell the user and quit. if (!bExtensionValid) throw new ArgumentException(Environment.GetResourceString("Arg_InvalidFileExtension")); // The assembly cannot contain the path nor the extension. asmFileName = strFileNameNoPath.Substring(0, strFileNameNoPath.Length - ".dll".Length); } // If the version information was not specified, then retrieve it from the typelib. if (asmVersion == null) { int major; int minor; Marshal.GetTypeLibVersion(pTLB, out major, out minor); asmVersion = new Version(major, minor, 0, 0); } // Create the assembly name for the imported typelib's assembly. AssemblyName AsmName = new AssemblyName(); AsmName.Init( asmFileName, publicKey, null, asmVersion, null, AssemblyHashAlgorithm.None, AssemblyVersionCompatibility.SameMachine, null, asmNameFlags, keyPair); return AsmName; }
internal static AssemblyNameFlags CombineAssemblyNameFlags(AssemblyNameFlags flags, AssemblyContentType contentType, ProcessorArchitecture processorArchitecture) { return (AssemblyNameFlags)(((int)flags) | (((int)contentType) << 9) | ((int)processorArchitecture << 4)); }
public void SetPublicKey (byte[] publicKey) { #if NET_2_0 if (publicKey == null) flags ^= AssemblyNameFlags.PublicKey; else flags |= AssemblyNameFlags.PublicKey; #else flags |= AssemblyNameFlags.PublicKey; #endif this.publicKey = publicKey; }
internal static AssemblyNameFlags ExtractAssemblyNameFlags(AssemblyNameFlags combinedFlags) { return(combinedFlags & unchecked ((AssemblyNameFlags)0xFFFFF10F)); }
internal static ProcessorArchitecture ExtractProcessorArchitecture(AssemblyNameFlags flags) { return (ProcessorArchitecture)((((int)flags) >> 4) & 0x7); }
public AssemblyNameParts(string name, Version?version, string?cultureName, AssemblyNameFlags flags, byte[]?publicKeyOrToken) { _name = name; _version = version; _cultureName = cultureName; _flags = flags; _publicKeyOrToken = publicKeyOrToken; }
// // These helpers convert between the combined flags+contentType+processorArchitecture value and the separated parts. // // Since these are only for trusted callers, they do NOT check for out of bound bits. // internal static AssemblyContentType ExtractAssemblyContentType(AssemblyNameFlags flags) { return (AssemblyContentType)((((int)flags) >> 9) & 0x7); }
public void __SetAssemblyFlags(AssemblyNameFlags flags) { this.__AssemblyFlags = flags; }
public AssemblyFlagsAttribute (AssemblyNameFlags assemblyFlags) { this.flags = (uint)assemblyFlags; }
public static string ComputeDisplayName(string name, Version?version, string?cultureName, byte[]?pkt, AssemblyNameFlags flags = 0, AssemblyContentType contentType = 0) { const int PUBLIC_KEY_TOKEN_LEN = 8; Debug.Assert(name.Length != 0); StringBuilder sb = new StringBuilder(); sb.AppendQuoted(name); if (version != null) { Version canonicalizedVersion = version.CanonicalizeVersion(); if (canonicalizedVersion.Major != ushort.MaxValue) { sb.Append(", Version="); sb.Append(canonicalizedVersion.Major); if (canonicalizedVersion.Minor != ushort.MaxValue) { sb.Append('.'); sb.Append(canonicalizedVersion.Minor); if (canonicalizedVersion.Build != ushort.MaxValue) { sb.Append('.'); sb.Append(canonicalizedVersion.Build); if (canonicalizedVersion.Revision != ushort.MaxValue) { sb.Append('.'); sb.Append(canonicalizedVersion.Revision); } } } } } if (cultureName != null) { if (cultureName.Length == 0) { cultureName = "neutral"; } sb.Append(", Culture="); sb.AppendQuoted(cultureName); } if (pkt != null) { if (pkt.Length > PUBLIC_KEY_TOKEN_LEN) { throw new ArgumentException(); } sb.Append(", PublicKeyToken="); if (pkt.Length == 0) { sb.Append("null"); } else { sb.Append(HexConverter.ToString(pkt, HexConverter.Casing.Lower)); } } if (0 != (flags & AssemblyNameFlags.Retargetable)) { sb.Append(", Retargetable=Yes"); } if (contentType == AssemblyContentType.WindowsRuntime) { sb.Append(", ContentType=WindowsRuntime"); } // NOTE: By design (desktop compat) AssemblyName.FullName and ToString() do not include ProcessorArchitecture. return(sb.ToString()); }
// Handle a deserialization callback on this object. public void OnDeserialization(Object sender) { if(info == null) { return; } name = info.GetString("_Name"); publicKey = (byte[])(info.GetValue ("_PublicKey", typeof(byte[]))); publicKeyToken = (byte[])(info.GetValue ("_PublicKeyToken", typeof(byte[]))); int cultureID = info.GetInt32("_CultureInfo"); if(cultureID != -1) { culture = new CultureInfo(cultureID); } else { culture = null; } codeBase = info.GetString("_CodeBase"); version = (Version)(info.GetValue("_Version", typeof(Version))); hashAlg = (AssemblyHashAlgorithm)(info.GetValue ("_HashAlgorithm", typeof(AssemblyHashAlgorithm))); keyPair = (StrongNameKeyPair)(info.GetValue ("_StrongNameKeyPair", typeof(StrongNameKeyPair))); versionCompat = (AssemblyVersionCompatibility)(info.GetValue ("_VersionCompatibility", typeof(AssemblyVersionCompatibility))); flags = (AssemblyNameFlags)(info.GetValue ("_Flags", typeof(AssemblyNameFlags))); }
internal static ProcessorArchitecture CalculateProcArchIndex(PortableExecutableKinds pek, ImageFileMachine ifm, AssemblyNameFlags flags) { if (((uint)flags & 0xF0) == 0x70) { return(ProcessorArchitecture.None); } if ((pek & System.Reflection.PortableExecutableKinds.PE32Plus) == System.Reflection.PortableExecutableKinds.PE32Plus) { switch (ifm) { case System.Reflection.ImageFileMachine.IA64: return(ProcessorArchitecture.IA64); case System.Reflection.ImageFileMachine.AMD64: return(ProcessorArchitecture.Amd64); case System.Reflection.ImageFileMachine.I386: if ((pek & System.Reflection.PortableExecutableKinds.ILOnly) == System.Reflection.PortableExecutableKinds.ILOnly) { return(ProcessorArchitecture.MSIL); } break; } } else { if (ifm == System.Reflection.ImageFileMachine.I386) { if ((pek & System.Reflection.PortableExecutableKinds.Required32Bit) == System.Reflection.PortableExecutableKinds.Required32Bit) { return(ProcessorArchitecture.X86); } if ((pek & System.Reflection.PortableExecutableKinds.ILOnly) == System.Reflection.PortableExecutableKinds.ILOnly) { return(ProcessorArchitecture.MSIL); } return(ProcessorArchitecture.X86); } if (ifm == System.Reflection.ImageFileMachine.ARM) { return(ProcessorArchitecture.Arm); } } return(ProcessorArchitecture.None); }
public void Flags(AssemblyNameFlags flags) { AssemblyName assemblyName = new AssemblyName("MyAssemblyName"); Assert.Equal(AssemblyNameFlags.None, assemblyName.Flags); assemblyName.Flags = flags; Assert.Equal(flags, assemblyName.Flags); }
public AssemblyFlagsAttribute(int assemblyFlags) { m_flags = (AssemblyNameFlags)assemblyFlags; }
public AssemblyName() { _Flags = AssemblyNameFlags.None; }
internal AssemblyName (SerializationInfo si, StreamingContext sc) { name = si.GetString ("_Name"); codebase = si.GetString ("_CodeBase"); version = (Version)si.GetValue ("_Version", typeof (Version)); publicKey = (byte[])si.GetValue ("_PublicKey", typeof (byte[])); keyToken = (byte[])si.GetValue ("_PublicKeyToken", typeof (byte[])); hashalg = (AssemblyHashAlgorithm)si.GetValue ("_HashAlgorithm", typeof (AssemblyHashAlgorithm)); keypair = (StrongNameKeyPair)si.GetValue ("_StrongNameKeyPair", typeof (StrongNameKeyPair)); versioncompat = (AssemblyVersionCompatibility)si.GetValue ("_VersionCompatibility", typeof (AssemblyVersionCompatibility)); flags = (AssemblyNameFlags)si.GetValue ("_Flags", typeof (AssemblyNameFlags)); int lcid = si.GetInt32 ("_CultureInfo"); if (lcid != -1) cultureinfo = new CultureInfo (lcid); }
public void SetPublicKey (byte[] publicKey) { if (publicKey == null) flags ^= AssemblyNameFlags.PublicKey; else flags |= AssemblyNameFlags.PublicKey; this.publicKey = publicKey; }
public static RuntimeAssemblyName Parse(String s) { Debug.Assert(s != null); AssemblyNameLexer lexer = new AssemblyNameLexer(s); // Name must come first. String name; AssemblyNameLexer.Token token = lexer.GetNext(out name); if (token != AssemblyNameLexer.Token.String) { if (token == AssemblyNameLexer.Token.End) { throw new ArgumentException(SR.Format_StringZeroLength); } else { throw new FileLoadException(); } } if (name == String.Empty) { throw new FileLoadException(); } Version version = null; String cultureName = null; byte[] pkt = null; AssemblyNameFlags flags = 0; LowLevelList <String> alreadySeen = new LowLevelList <String>(); token = lexer.GetNext(); while (token != AssemblyNameLexer.Token.End) { if (token != AssemblyNameLexer.Token.Comma) { throw new FileLoadException(); } String attributeName; token = lexer.GetNext(out attributeName); if (token != AssemblyNameLexer.Token.String) { throw new FileLoadException(); } token = lexer.GetNext(); // Compat note: Inside AppX apps, the desktop CLR's AssemblyName parser skips past any elements that don't follow the "<Something>=<Something>" pattern. // (when running classic Windows apps, such an illegal construction throws an exception as expected.) // Naturally, at least one app unwittingly takes advantage of this. if (token == AssemblyNameLexer.Token.Comma || token == AssemblyNameLexer.Token.End) { continue; } if (token != AssemblyNameLexer.Token.Equals) { throw new FileLoadException(); } String attributeValue; token = lexer.GetNext(out attributeValue); if (token != AssemblyNameLexer.Token.String) { throw new FileLoadException(); } if (attributeName == String.Empty) { throw new FileLoadException(); } for (int i = 0; i < alreadySeen.Count; i++) { if (alreadySeen[i].Equals(attributeName, StringComparison.OrdinalIgnoreCase)) { throw new FileLoadException(); // Cannot specify the same attribute twice. } } alreadySeen.Add(attributeName); if (attributeName.Equals("Version", StringComparison.OrdinalIgnoreCase)) { version = ParseVersion(attributeValue); } if (attributeName.Equals("Culture", StringComparison.OrdinalIgnoreCase)) { cultureName = ParseCulture(attributeValue); } if (attributeName.Equals("PublicKeyToken", StringComparison.OrdinalIgnoreCase)) { pkt = ParsePKT(attributeValue); } if (attributeName.Equals("ProcessorArchitecture", StringComparison.OrdinalIgnoreCase)) { flags |= (AssemblyNameFlags)(((int)ParseProcessorArchitecture(attributeValue)) << 4); } if (attributeName.Equals("Retargetable", StringComparison.OrdinalIgnoreCase)) { if (attributeValue.Equals("Yes", StringComparison.OrdinalIgnoreCase)) { flags |= AssemblyNameFlags.Retargetable; } else if (attributeValue.Equals("No", StringComparison.OrdinalIgnoreCase)) { // nothing to do } else { throw new FileLoadException(); } } if (attributeName.Equals("ContentType", StringComparison.OrdinalIgnoreCase)) { if (attributeValue.Equals("WindowsRuntime", StringComparison.OrdinalIgnoreCase)) { flags |= (AssemblyNameFlags)(((int)AssemblyContentType.WindowsRuntime) << 9); } else { throw new FileLoadException(); } } // Desktop compat: If we got here, the attribute name is unknown to us. Ignore it (as long it's not duplicated.) token = lexer.GetNext(); } return(new RuntimeAssemblyName(name, version, cultureName, flags, pkt)); }
public void OnDeserialization(Object sender) { // Deserialization has already been performed if (m_siInfo == null) return; _Name = m_siInfo.GetString("_Name"); _PublicKey = (byte[]) m_siInfo.GetValue("_PublicKey", typeof(byte[])); _PublicKeyToken = (byte[]) m_siInfo.GetValue("_PublicKeyToken", typeof(byte[])); #if FEATURE_USE_LCID int lcid = (int)m_siInfo.GetInt32("_CultureInfo"); if (lcid != -1) _CultureInfo = new CultureInfo(lcid); #endif _CodeBase = m_siInfo.GetString("_CodeBase"); _Version = (Version) m_siInfo.GetValue("_Version", typeof(Version)); _HashAlgorithm = (AssemblyHashAlgorithm) m_siInfo.GetValue("_HashAlgorithm", typeof(AssemblyHashAlgorithm)); _StrongNameKeyPair = (StrongNameKeyPair) m_siInfo.GetValue("_StrongNameKeyPair", typeof(StrongNameKeyPair)); _VersionCompatibility = (AssemblyVersionCompatibility)m_siInfo.GetValue("_VersionCompatibility", typeof(AssemblyVersionCompatibility)); _Flags = (AssemblyNameFlags) m_siInfo.GetValue("_Flags", typeof(AssemblyNameFlags)); try { _HashAlgorithmForControl = (AssemblyHashAlgorithm) m_siInfo.GetValue("_HashAlgorithmForControl", typeof(AssemblyHashAlgorithm)); _HashForControl = (byte[]) m_siInfo.GetValue("_HashForControl", typeof(byte[])); } catch (SerializationException) { // RTM did not have these defined _HashAlgorithmForControl = AssemblyHashAlgorithm.None; _HashForControl = null; } m_siInfo = null; }
internal static AssemblyName GetAssemblyNameFromTypelib(object typeLib, string asmFileName, byte[] publicKey, StrongNameKeyPair keyPair, Version asmVersion, AssemblyNameFlags asmNameFlags) { string strName = null; string strDocString = null; int dwHelpContext = 0; string strHelpFile = null; ITypeLib typeLibrary = (ITypeLib) typeLib; typeLibrary.GetDocumentation(-1, out strName, out strDocString, out dwHelpContext, out strHelpFile); if (asmFileName == null) { asmFileName = strName; } else { string fileName = Path.GetFileName(asmFileName); string extension = Path.GetExtension(asmFileName); if (!".dll".Equals(extension, StringComparison.OrdinalIgnoreCase)) { throw new ArgumentException(Environment.GetResourceString("Arg_InvalidFileExtension")); } asmFileName = fileName.Substring(0, fileName.Length - ".dll".Length); } if (asmVersion == null) { int num2; int num3; Marshal.GetTypeLibVersion(typeLibrary, out num2, out num3); asmVersion = new Version(num2, num3, 0, 0); } AssemblyName name = new AssemblyName(); name.Init(asmFileName, publicKey, null, asmVersion, null, AssemblyHashAlgorithm.None, AssemblyVersionCompatibility.SameMachine, null, asmNameFlags, keyPair); return name; }
internal void Init(String name, byte[] publicKey, byte[] publicKeyToken, Version version, CultureInfo cultureInfo, AssemblyHashAlgorithm hashAlgorithm, AssemblyVersionCompatibility versionCompatibility, String codeBase, AssemblyNameFlags flags, StrongNameKeyPair keyPair) // Null if ref, matching Assembly if def { _Name = name; if (publicKey != null) { _PublicKey = new byte[publicKey.Length]; Array.Copy(publicKey, _PublicKey, publicKey.Length); } if (publicKeyToken != null) { _PublicKeyToken = new byte[publicKeyToken.Length]; Array.Copy(publicKeyToken, _PublicKeyToken, publicKeyToken.Length); } if (version != null) _Version = (Version) version.Clone(); _CultureInfo = cultureInfo; _HashAlgorithm = hashAlgorithm; _VersionCompatibility = versionCompatibility; _CodeBase = codeBase; _Flags = flags; _StrongNameKeyPair = keyPair; }
[System.Security.SecurityCritical] // auto-generated internal static AssemblyName GetAssemblyNameFromTypelib(Object typeLib, String asmFileName, byte[] publicKey, StrongNameKeyPair keyPair, Version asmVersion, AssemblyNameFlags asmNameFlags) { // Extract the name of the typelib. String strTypeLibName = null; String strDocString = null; int dwHelpContext = 0; String strHelpFile = null; ITypeLib pTLB = (ITypeLib)typeLib; pTLB.GetDocumentation(-1, out strTypeLibName, out strDocString, out dwHelpContext, out strHelpFile); // Retrieve the name to use for the assembly. if (asmFileName == null) { asmFileName = strTypeLibName; } else { Contract.Assert((asmFileName != null) && (asmFileName.Length > 0), "The assembly file name cannot be an empty string!"); String strFileNameNoPath = Path.GetFileName(asmFileName); String strExtension = Path.GetExtension(asmFileName); // Validate that the extension is valid. bool bExtensionValid = ".dll".Equals(strExtension, StringComparison.OrdinalIgnoreCase); // If the extension is not valid then tell the user and quit. if (!bExtensionValid) { throw new ArgumentException(Environment.GetResourceString("Arg_InvalidFileExtension")); } // The assembly cannot contain the path nor the extension. asmFileName = strFileNameNoPath.Substring(0, strFileNameNoPath.Length - ".dll".Length); } // If the version information was not specified, then retrieve it from the typelib. if (asmVersion == null) { int major; int minor; Marshal.GetTypeLibVersion(pTLB, out major, out minor); asmVersion = new Version(major, minor, 0, 0); } // Create the assembly name for the imported typelib's assembly. AssemblyName AsmName = new AssemblyName(); AsmName.Init( asmFileName, publicKey, null, asmVersion, null, AssemblyHashAlgorithm.None, AssemblyVersionCompatibility.SameMachine, null, asmNameFlags, keyPair); return(AsmName); }
/// <summary> /// Default ctor /// </summary> public AssemblyFlagsAttribute(int flags) { this.flags = (AssemblyNameFlags)flags; }