/// <summary> /// Constructor /// </summary> /// <remarks>If <paramref name="hashAlgo"/> is an unsupported hash algorithm, then /// <see cref="AssemblyHashAlgorithm.SHA1"/> will be used as the hash algorithm.</remarks> /// <param name="hashAlgo">The algorithm to use</param> public AssemblyHash(AssemblyHashAlgorithm hashAlgo) { switch (hashAlgo) { case AssemblyHashAlgorithm.MD5: hasher = MD5.Create(); break; case AssemblyHashAlgorithm.None: case AssemblyHashAlgorithm.MD2: case AssemblyHashAlgorithm.MD4: case AssemblyHashAlgorithm.SHA1: case AssemblyHashAlgorithm.MAC: case AssemblyHashAlgorithm.SSL3_SHAMD5: case AssemblyHashAlgorithm.HMAC: case AssemblyHashAlgorithm.TLS1PRF: case AssemblyHashAlgorithm.HASH_REPLACE_OWF: default: hasher = SHA1.Create(); break; case AssemblyHashAlgorithm.SHA_256: hasher = SHA256.Create(); break; case AssemblyHashAlgorithm.SHA_384: hasher = SHA384.Create(); break; case AssemblyHashAlgorithm.SHA_512: hasher = SHA512.Create(); break; } }
internal ImmutableArray<byte> GetHash(AssemblyHashAlgorithm algorithmId) { using (HashAlgorithm algorithm = TryGetAlgorithm(algorithmId)) { // ERR_CryptoHashFailed has already been reported: if (algorithm == null) { return ImmutableArray.Create<byte>(); } switch (algorithmId) { case AssemblyHashAlgorithm.None: case AssemblyHashAlgorithm.Sha1: return GetHash(ref _lazySHA1Hash, algorithm); case AssemblyHashAlgorithm.Sha256: return GetHash(ref _lazySHA256Hash, algorithm); case AssemblyHashAlgorithm.Sha384: return GetHash(ref _lazySHA384Hash, algorithm); case AssemblyHashAlgorithm.Sha512: return GetHash(ref _lazySHA512Hash, algorithm); case AssemblyHashAlgorithm.MD5: return GetHash(ref _lazyMD5Hash, algorithm); default: throw ExceptionUtilities.UnexpectedValue(algorithmId); } } }
public AssemblyHash (AssemblyHashAlgorithm algorithm, byte[] value) { _algorithm = algorithm; if (value != null) _value = (byte[]) value.Clone (); else _value = null; }
public void Read(ClrModuleReader reader) { this.HashAlgId = (AssemblyHashAlgorithm)reader.Binary.ReadUInt32(); this.Version = reader.ReadVersion(); this.Flags = (AssemblyFlags)reader.Binary.ReadUInt32(); this.PublicKey = reader.ReadBlob(); this.Name = reader.ReadString(); this.Culture = reader.ReadString(); }
/// <summary> /// Hash data /// </summary> /// <remarks>If <paramref name="hashAlgo"/> is an unsupported hash algorithm, then /// <see cref="AssemblyHashAlgorithm.SHA1"/> will be used as the hash algorithm.</remarks> /// <param name="data">The data</param> /// <param name="hashAlgo">The algorithm to use</param> /// <returns>Hashed data or null if <paramref name="data"/> was <c>null</c></returns> public static byte[] Hash(byte[] data, AssemblyHashAlgorithm hashAlgo) { if (data == null) return null; using (var asmHash = new AssemblyHash(hashAlgo)) { asmHash.Hash(data); return asmHash.ComputeHash(); } }
public AssemblyHash(AssemblyHashAlgorithm algorithm, byte[] value) { _Algorithm = algorithm; _Value = null; if (value != null) { int length = value.Length; _Value = new byte[length]; Array.Copy(value, _Value, length); } }
public AssemblyNameReference(string name, Version version) { if (name == null) throw new ArgumentNullException("name"); this.name = name; this.version = version; this.hash_algorithm = AssemblyHashAlgorithm.None; this.token = new MetadataToken(TokenType.AssemblyRef); }
public AssemblyHash(byte[] value) { this._Algorithm = AssemblyHashAlgorithm.SHA1; this._Value = null; if (value != null) { int length = value.Length; this._Value = new byte[length]; Array.Copy(value, this._Value, length); } }
public AssemblyNameReference(string name, string culture, Version version) { if (name == null) throw new ArgumentNullException ("name"); if (culture == null) throw new ArgumentNullException ("culture"); m_name = name; m_culture = culture; m_version = version; m_hashAlgo = AssemblyHashAlgorithm.None; }
public static IncrementalHash Create(AssemblyHashAlgorithm hashAlgorithm) { if (PortableShim.IncrementalHash.TypeOpt != null) { return new Core(hashAlgorithm); } else { return new Desktop(hashAlgorithm); } }
public AssemblyOptions(AssemblyDef asm) { HashAlgorithm = asm.HashAlgorithm; Version = asm.Version; Attributes = asm.Attributes; PublicKey = asm.PublicKey; Name = asm.Name; Culture = asm.Culture; ClrVersion = Module.ClrVersion.DefaultVersion; CustomAttributes.AddRange(asm.CustomAttributes); DeclSecurities.AddRange(asm.DeclSecurities); }
private void LoadData(CLIFile pFile) { HashAlgId = (AssemblyHashAlgorithm)pFile.ReadUInt32(); MajorVersion = pFile.ReadUInt16(); MinorVersion = pFile.ReadUInt16(); BuildNumber = pFile.ReadUInt16(); RevisionNumber = pFile.ReadUInt16(); Flags = (AssemblyFlags)pFile.ReadUInt32(); PublicKey = pFile.ReadBlobHeap(pFile.ReadHeapIndex(HeapOffsetSizes.Blob32Bit)); Name = pFile.ReadStringHeap(pFile.ReadHeapIndex(HeapOffsetSizes.Strings32Bit)); Culture = pFile.ReadStringHeap(pFile.ReadHeapIndex(HeapOffsetSizes.Strings32Bit)); }
/// <summary> /// Returns the actual FX implementation of HashAlgorithmName for given hash algorithm id. /// </summary> private static object GetHashAlgorithmNameObj(AssemblyHashAlgorithm algorithmId) { switch (algorithmId) { case AssemblyHashAlgorithm.Sha1: return PortableShim.HashAlgorithmName.SHA1; default: // More algorithms can be added as needed. throw ExceptionUtilities.UnexpectedValue(algorithmId); } }
public AssemblyReference(string name, AssemblyAttributes attributes, Version version, AssemblyHashAlgorithm hashAlgorithm, uint publicKey, string culture) : base(new MetaDataRow( (byte)version.Major, (byte)version.Minor, (byte)version.Build, (byte)version.Revision, (uint)attributes, publicKey, 0U, 0U, (uint)hashAlgorithm)) { this._name = name; this._culture = culture; }
public AssemblyHash(AssemblyHashAlgorithm algorithmId, byte[] value) { hashAlg = algorithmId; if(value != null) { hash = new byte [value.Length]; Array.Copy(value, hash, value.Length); } else { hash = null; } }
/// <summary> /// Initializes a new instance of the <see cref="AssemblyRow"/> struct. /// </summary> /// <param name="hashAlgId">The hash alg id.</param> /// <param name="majorVersion">The major version.</param> /// <param name="minorVersion">The minor version.</param> /// <param name="buildNumber">The build number.</param> /// <param name="revision">The revision.</param> /// <param name="flags">The flags.</param> /// <param name="publicKey">The public key.</param> /// <param name="name">The name.</param> /// <param name="culture">The culture.</param> public AssemblyRow(AssemblyHashAlgorithm hashAlgId, ushort majorVersion, ushort minorVersion, ushort buildNumber, ushort revision, AssemblyAttributes flags, HeapIndexToken publicKey, HeapIndexToken name, HeapIndexToken culture) { this.hashAlgId = hashAlgId; this.majorVersion = majorVersion; this.minorVersion = minorVersion; this.buildNumber = buildNumber; this.revisionNumber = revision; this.flags = flags; this.publicKey = publicKey; this.name = name; this.culture = culture; }
/// <summary> /// Initializes a new instance of the <see cref="AssemblyRow"/> struct. /// </summary> /// <param name="hashAlgId">The hash alg id.</param> /// <param name="majorVersion">The major version.</param> /// <param name="minorVersion">The minor version.</param> /// <param name="buildNumber">The build number.</param> /// <param name="revision">The revision.</param> /// <param name="flags">The flags.</param> /// <param name="publicKey">The public key.</param> /// <param name="name">The name.</param> /// <param name="culture">The culture.</param> public AssemblyRow(AssemblyHashAlgorithm hashAlgId, ushort majorVersion, ushort minorVersion, ushort buildNumber, ushort revision, AssemblyAttributes flags, HeapIndexToken publicKey, HeapIndexToken name, HeapIndexToken culture) { HashAlgId = hashAlgId; MajorVersion = majorVersion; MinorVersion = minorVersion; BuildNumber = buildNumber; Revision = revision; Flags = flags; PublicKey = publicKey; Name = name; Culture = culture; }
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 static bool IsSupportedAlgorithm(AssemblyHashAlgorithm algorithmId) { switch (algorithmId) { case AssemblyHashAlgorithm.None: case AssemblyHashAlgorithm.Sha1: case AssemblyHashAlgorithm.Sha256: case AssemblyHashAlgorithm.Sha384: case AssemblyHashAlgorithm.Sha512: case AssemblyHashAlgorithm.MD5: return true; default: return false; } }
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; } }
public static byte[] GetPublicKeyToken(byte[] publicKey, AssemblyHashAlgorithm hashAlgo) { byte[] token = null; if (publicKey != null && publicKey.Length > 0) { HashAlgorithm ha; switch (hashAlgo) { case AssemblyHashAlgorithm.Reserved: ha = MD5.Create(); break; default: ha = SHA1.Create(); break; } byte[] hash = ha.ComputeHash(publicKey); // we need the last 8 bytes in reverse order token = new byte[8]; Array.Copy(hash, (hash.Length - 8), token, 0, 8); Array.Reverse(token, 0, 8); } return token; }
private static HashAlgorithm TryGetAlgorithm(AssemblyHashAlgorithm algorithmId) { switch (algorithmId) { case AssemblyHashAlgorithm.None: case AssemblyHashAlgorithm.Sha1: return new SHA1CryptoServiceProvider(); case AssemblyHashAlgorithm.Sha256: return new SHA256CryptoServiceProvider(); case AssemblyHashAlgorithm.Sha384: return new SHA384CryptoServiceProvider(); case AssemblyHashAlgorithm.Sha512: return new SHA512CryptoServiceProvider(); case AssemblyHashAlgorithm.MD5: return new MD5CryptoServiceProvider(); default: return null; } }
public IAssembly LoadFrom(string assemblyFile, byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm) { return new AssemblyWrap(Assembly.LoadFrom(assemblyFile,hashValue,hashAlgorithm)); }
/// <summary> /// Strong name hashes the .NET file /// </summary> /// <param name="hashAlg">Hash algorithm</param> /// <param name="snSigOffset">Strong name sig offset (relative to start of .NET PE file)</param> /// <param name="snSigSize">Size of strong name signature</param> /// <returns>The strong name hash of the .NET file</returns> private byte[] StrongNameHashData(AssemblyHashAlgorithm hashAlg, long snSigOffset, uint snSigSize) { var reader = new BinaryReader(stream); snSigOffset += baseOffset; var snSigOffsetEnd = snSigOffset + snSigSize; using (var hasher = new AssemblyHash(hashAlg)) { var buffer = new byte[0x8000]; // Hash the DOS header. It's defined to be all data from the start of // the file up to the NT headers. stream.Position = baseOffset + 0x3C; var ntHeadersOffs = reader.ReadUInt32(); stream.Position = baseOffset; hasher.Hash(stream, ntHeadersOffs, buffer); // Hash NT headers, but hash authenticode + checksum as 0s stream.Position += 6; int numSections = reader.ReadUInt16(); stream.Position -= 8; hasher.Hash(stream, 0x18, buffer); // magic + FileHeader var is32bit = reader.ReadUInt16() == 0x010B; stream.Position -= 2; var optHeaderSize = is32bit ? 0x60 : 0x70; if (stream.Read(buffer, 0, optHeaderSize) != optHeaderSize) { throw new IOException("Could not read data"); } // Clear checksum for (var i = 0; i < 4; i++) { buffer[0x40 + i] = 0; } hasher.Hash(buffer, 0, optHeaderSize); const int imageDirsSize = 16 * 8; if (stream.Read(buffer, 0, imageDirsSize) != imageDirsSize) { throw new IOException("Could not read data"); } // Clear authenticode data dir for (var i = 0; i < 8; i++) { buffer[4 * 8 + i] = 0; } hasher.Hash(buffer, 0, imageDirsSize); // Hash section headers var sectHeadersOffs = stream.Position; hasher.Hash(stream, (uint)numSections * 0x28, buffer); // Hash all raw section data but make sure we don't hash the location // where the strong name signature will be stored. for (var i = 0; i < numSections; i++) { stream.Position = sectHeadersOffs + i * 0x28 + 0x10; var sizeOfRawData = reader.ReadUInt32(); var pointerToRawData = reader.ReadUInt32(); stream.Position = baseOffset + pointerToRawData; while (sizeOfRawData > 0) { var pos = stream.Position; if (snSigOffset <= pos && pos < snSigOffsetEnd) { var skipSize = (uint)(snSigOffsetEnd - pos); if (skipSize >= sizeOfRawData) { break; } sizeOfRawData -= skipSize; stream.Position += skipSize; continue; } if (pos >= snSigOffsetEnd) { hasher.Hash(stream, sizeOfRawData, buffer); break; } var maxLen = (uint)Math.Min(snSigOffset - pos, sizeOfRawData); hasher.Hash(stream, maxLen, buffer); sizeOfRawData -= maxLen; } } return(hasher.ComputeHash()); } }
public void __SetAssemblyAlgorithmId(AssemblyHashAlgorithm hashAlgorithm) { this.hashAlgorithm = hashAlgorithm; }
/// <summary> /// Constructor /// </summary> /// <remarks>If <paramref name="hashAlgo"/> is an unsupported hash algorithm, then /// <see cref="AssemblyHashAlgorithm.SHA1"/> will be used as the hash algorithm.</remarks> /// <param name="hashAlgo">The algorithm to use</param> public AssemblyHash(AssemblyHashAlgorithm hashAlgo) =>
public int ExecuteAssembly(string assemblyFile, Evidence assemblySecurity, string[] args, byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm) { #if AVM throw new NotSupportedException(); #else Assembly a = Assembly.LoadFrom(assemblyFile, assemblySecurity, hashValue, hashAlgorithm); return(ExecuteAssemblyInternal(a, args)); #endif }
internal virtual ImmutableArray <byte> GetHash(AssemblyHashAlgorithm algorithmId) { throw ExceptionUtilities.Unreachable; }
/// <summary> /// Creates a new instance of <see cref="CILAssemblyName"/> with specified values. /// </summary> /// <param name="name">Assembly name.</param> /// <param name="major">Major version of the assembly name.</param> /// <param name="minor">Minor version of the assembly name.</param> /// <param name="build">Build number of the assembly name.</param> /// <param name="revision">Revision of the assembly name.</param> /// <param name="hashAlgorithm">The hash algorithm of the assembly name. For more information <see cref="AssemblyHashAlgorithm"/>.</param> /// <param name="flags">Assembly flags of the assembly name. For more information <see cref="AssemblyFlags"/>.</param> /// <param name="pKey">Public key of the assembly name. Specify <c>null</c> or empty array to create assembly name without public key.</param> /// <param name="culture">Culture string of the assembly name. Specify <c>null</c> or empty string to create culture-neutral assembly name.</param> /// <returns>A new <see cref="CILAssemblyName"/> with specified parameters.</returns> public CILAssemblyName(String name, Int32 major, Int32 minor, Int32 build, Int32 revision, AssemblyHashAlgorithm hashAlgorithm = AssemblyHashAlgorithm.None, AssemblyFlags flags = AssemblyFlags.None, Byte[] pKey = null, String culture = null) { this._hashAlgorithm = (Int32)hashAlgorithm; this._flags = (Int32)flags; this._majorVersion = major; this._minorVersion = minor; this._buildNumber = build; this._revision = revision; this._publicKey = pKey.IsNullOrEmpty() ? null : pKey; this._name = name; this._culture = culture; }
internal void SetHashControl(byte[] hash, AssemblyHashAlgorithm hashAlgorithm) { _HashForControl = hash; _HashAlgorithmForControl = hashAlgorithm; }
/// <summary> /// Constructor /// </summary> /// <param name="modulus">Modulus</param> /// <param name="publicExponent">Public exponent</param> /// <param name="hashAlgorithm">Hash algorithm</param> public StrongNamePublicKey(byte[] modulus, byte[] publicExponent, AssemblyHashAlgorithm hashAlgorithm) : this(modulus, publicExponent, hashAlgorithm, SignatureAlgorithm.CALG_RSA_SIGN) { }
public static Assembly LoadFrom(string assemblyFile, System.Security.Policy.Evidence securityEvidence, byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm) { StackCrawlMark lookForMyCaller = StackCrawlMark.LookForMyCaller; return(RuntimeAssembly.InternalLoadFrom(assemblyFile, securityEvidence, hashValue, hashAlgorithm, false, false, ref lookForMyCaller)); }
public static Assembly LoadFrom(string assemblyFile, byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm) { StackCrawlMark lookForMyCaller = StackCrawlMark.LookForMyCaller; return(RuntimeAssembly.InternalLoadFrom(assemblyFile, null, hashValue, hashAlgorithm, false, false, ref lookForMyCaller)); }
internal override ImmutableArray <byte> GetHash(AssemblyHashAlgorithm algorithmId) { return(module.GetHash(algorithmId)); }
internal unsafe void FillName(MonoAssemblyName *native, string codeBase, bool addVersion, bool addPublickey, bool defaultToken, bool assemblyRef) { this.name = RuntimeMarshal.PtrToUtf8String(native->name); this.major = native->major; this.minor = native->minor; this.build = native->build; this.revision = native->revision; this.flags = (AssemblyNameFlags)native->flags; this.hashalg = (AssemblyHashAlgorithm)native->hash_alg; this.versioncompat = AssemblyVersionCompatibility.SameMachine; this.processor_architecture = (ProcessorArchitecture)native->arch; if (addVersion) { this.version = new Version(this.major, this.minor, this.build, this.revision); } this.codebase = codeBase; #if NETCORE if (native->culture != IntPtr.Zero) { this.cultureinfo = CultureInfo.GetCultureInfo(RuntimeMarshal.PtrToUtf8String(native->culture)); } #else if (native->culture != IntPtr.Zero) { this.cultureinfo = CultureInfo.CreateCulture(RuntimeMarshal.PtrToUtf8String(native->culture), assemblyRef); } #endif if (native->public_key != IntPtr.Zero) { this.publicKey = RuntimeMarshal.DecodeBlobArray(native->public_key); this.flags |= AssemblyNameFlags.PublicKey; } else if (addPublickey) { this.publicKey = EmptyArray <byte> .Value; this.flags |= AssemblyNameFlags.PublicKey; } // MonoAssemblyName keeps the public key token as an hexadecimal string if (native->public_key_token [0] != 0) { byte[] keyToken = new byte [8]; for (int i = 0, j = 0; i < 8; ++i) { keyToken [i] = (byte)(RuntimeMarshal.AsciHexDigitValue(native->public_key_token [j++]) << 4); keyToken [i] |= (byte)RuntimeMarshal.AsciHexDigitValue(native->public_key_token [j++]); } this.keyToken = keyToken; } else if (defaultToken) { this.keyToken = EmptyArray <byte> .Value; } }
public AssemblyAlgorithmIdAttribute(AssemblyHashAlgorithm algorithmId) { m_algId = (uint)algorithmId; }
public static Assembly LoadFrom(String assemblyFile, byte [] hashValue, AssemblyHashAlgorithm hashAlgorithm) { throw new NotImplementedException(); }
public AssemblyName() { _HashAlgorithm = AssemblyHashAlgorithm.None; _VersionCompatibility = AssemblyVersionCompatibility.SameMachine; _Flags = AssemblyNameFlags.None; }
public static Assembly LoadFrom(string assemblyFile, byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm) { throw new PlatformNotSupportedException(); }
public static Assembly LoadFrom(string assemblyFile, byte[]?hashValue, AssemblyHashAlgorithm hashAlgorithm) { throw new NotSupportedException(SR.NotSupported_AssemblyLoadFromHash); }
public StrongNameDataHashBuilder(Stream imageStream, AssemblyHashAlgorithm hashAlgorithm) { _imageStream = imageStream ?? throw new ArgumentNullException(nameof(imageStream)); _hashAlgorithm = hashAlgorithm; }
/// <summary> /// Constructor /// </summary> /// <param name="asmName">Assembly name info</param> /// <exception cref="ArgumentNullException">If <paramref name="asmName"/> is <c>null</c></exception> public AssemblyDefUser(AssemblyName asmName) : this(new AssemblyNameInfo(asmName)) { this.hashAlgId = (AssemblyHashAlgorithm)asmName.HashAlgorithm; this.flags = (AssemblyAttributes)asmName.Flags; }
public ObjectHandle CreateComInstanceFrom(string assemblyFile, string typeName, byte [] hashValue, AssemblyHashAlgorithm hashAlgorithm) { return(Activator.CreateComInstanceFrom(assemblyFile, typeName, hashValue, hashAlgorithm)); }
public int ExecuteAssembly (string assemblyFile, string[] args, byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm) { Assembly a = Assembly.LoadFrom (assemblyFile, null, hashValue, hashAlgorithm); return ExecuteAssemblyInternal (a, args); }
// FIXME: What are we missing? public static Assembly LoadFrom(String assemblyFile, Evidence securityEvidence, byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm) { if (assemblyFile == null) { throw new ArgumentNullException("assemblyFile"); } if (assemblyFile == String.Empty) { throw new ArgumentException("Name can't be the empty string", "assemblyFile"); } throw new NotImplementedException(); }
public int ExecuteAssembly(string assemblyFile, System.Security.Policy.Evidence assemblySecurity, string[] args, byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm) { Assembly assembly = Assembly.LoadFrom(assemblyFile, assemblySecurity, hashValue, hashAlgorithm); if (args == null) { args = new string[0]; } return this.nExecuteAssembly(assembly, args); }
/// <summary> /// Workaround for unity mono being weird /// </summary> internal static AssemblyName GetAssemblyName(MetadataReader reader, StringHandle nameHandle, Version version, StringHandle cultureHandle, BlobHandle publicKeyOrTokenHandle, AssemblyHashAlgorithm assemblyHashAlgorithm, AssemblyFlags flags) { var name = reader.GetString(nameHandle); var cultureName = (!cultureHandle.IsNil) ? reader.GetString(cultureHandle) : null; var hashAlgorithm = (System.Configuration.Assemblies.AssemblyHashAlgorithm)assemblyHashAlgorithm; var publicKeyOrToken = !publicKeyOrTokenHandle.IsNil ? reader.GetBlobBytes(publicKeyOrTokenHandle) : null; var assemblyName = new AssemblyName(name); try { assemblyName.Version = version; } catch (NotImplementedException) { } try { assemblyName.CultureName = cultureName; } catch (NotImplementedException) { } try { assemblyName.HashAlgorithm = hashAlgorithm; } catch (NotImplementedException) { } try { assemblyName.Flags = GetAssemblyNameFlags(flags); } catch (NotImplementedException) { } try { assemblyName.ContentType = GetContentTypeFromAssemblyFlags(flags); } catch (NotImplementedException) { } var hasPublicKey = (flags & AssemblyFlags.PublicKey) != 0; if (hasPublicKey) { assemblyName.SetPublicKey(publicKeyOrToken); } else { assemblyName.SetPublicKeyToken(publicKeyOrToken); } return(assemblyName); }
[MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public static Assembly LoadFrom(String assemblyFile, Evidence securityEvidence, byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm) { Contract.Ensures(Contract.Result<Assembly>() != null); StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; return RuntimeAssembly.InternalLoadFrom( assemblyFile, securityEvidence, hashValue, hashAlgorithm, false, false, ref stackMark); }
ImmutableArray <byte> Cci.IFileReference.GetHashValue(AssemblyHashAlgorithm algorithmId) { return(_underlyingModule.GetHash(algorithmId)); }
public AssemblyDefinition(string name, AssemblyAttributes attributes, Version version, AssemblyHashAlgorithm hashAlgorithm, uint publicKey, string culture) : base(new MetaDataRow( (uint)hashAlgorithm, (byte)version.Major, (byte)version.Minor, (byte)version.Build, (byte)version.Revision, (uint)attributes, publicKey, 0U, 0U)) { this.name = name; this.culture = culture; }
public ObjectHandle CreateComInstanceFrom (string assemblyFile, string typeName, byte [] hashValue, AssemblyHashAlgorithm hashAlgorithm) { return Activator.CreateComInstanceFrom (assemblyFile, typeName, hashValue ,hashAlgorithm); }
public override ObjectData GetData(NodeFactory factory, bool relocsOnly = false) { if (relocsOnly) { return(new ObjectData(Array.Empty <byte>(), null, 1, null)); } if (!_emissionCompleted) { foreach (ISignatureEmitter emitter in _signatureEmitters) { emitter.MaterializeSignature(); } _emissionCompleted = true; } MetadataBuilder metadataBuilder = new MetadataBuilder(); AssemblyHashAlgorithm hashAlgorithm = AssemblyHashAlgorithm.None; BlobHandle publicKeyBlob = default(BlobHandle); AssemblyFlags manifestAssemblyFlags = default(AssemblyFlags); Version manifestAssemblyVersion = new Version(0, 0, 0, 0); if ((factory.CompositeImageSettings != null) && factory.CompilationModuleGroup.IsCompositeBuildMode) { if (factory.CompositeImageSettings.PublicKey != null) { hashAlgorithm = AssemblyHashAlgorithm.Sha1; publicKeyBlob = metadataBuilder.GetOrAddBlob(factory.CompositeImageSettings.PublicKey); manifestAssemblyFlags |= AssemblyFlags.PublicKey; } if (factory.CompositeImageSettings.AssemblyVersion != null) { manifestAssemblyVersion = factory.CompositeImageSettings.AssemblyVersion; } } string manifestMetadataAssemblyName = "ManifestMetadata"; metadataBuilder.AddAssembly( metadataBuilder.GetOrAddString(manifestMetadataAssemblyName), manifestAssemblyVersion, culture: default(StringHandle), publicKey: publicKeyBlob, flags: manifestAssemblyFlags, hashAlgorithm: hashAlgorithm); metadataBuilder.AddModule( 0, metadataBuilder.GetOrAddString(manifestMetadataAssemblyName), default(GuidHandle), default(GuidHandle), default(GuidHandle)); // Module type metadataBuilder.AddTypeDefinition( default(TypeAttributes), default(StringHandle), metadataBuilder.GetOrAddString("<Module>"), baseType: default(EntityHandle), fieldList: MetadataTokens.FieldDefinitionHandle(1), methodList: MetadataTokens.MethodDefinitionHandle(1)); foreach (var idAndAssemblyName in _moduleIdToAssemblyNameMap.OrderBy(x => x.Key)) { AssemblyName assemblyName = idAndAssemblyName.Value; AssemblyFlags assemblyFlags = 0; byte[] publicKeyOrToken; if ((assemblyName.Flags & AssemblyNameFlags.PublicKey) != 0) { assemblyFlags |= AssemblyFlags.PublicKey; publicKeyOrToken = assemblyName.GetPublicKey(); } else { publicKeyOrToken = assemblyName.GetPublicKeyToken(); } if ((assemblyName.Flags & AssemblyNameFlags.Retargetable) != 0) { assemblyFlags |= AssemblyFlags.Retargetable; } AssemblyReferenceHandle newHandle = metadataBuilder.AddAssemblyReference( name: metadataBuilder.GetOrAddString(assemblyName.Name), version: assemblyName.Version, culture: metadataBuilder.GetOrAddString(assemblyName.CultureName), publicKeyOrToken: metadataBuilder.GetOrAddBlob(publicKeyOrToken), flags: assemblyFlags, hashValue: default(BlobHandle) /* TODO */); } MetadataRootBuilder metadataRootBuilder = new MetadataRootBuilder(metadataBuilder); BlobBuilder metadataBlobBuilder = new BlobBuilder(); metadataRootBuilder.Serialize(metadataBlobBuilder, methodBodyStreamRva: 0, mappedFieldDataStreamRva: 0); return(new ObjectData( data: metadataBlobBuilder.ToArray(), relocs: Array.Empty <Relocation>(), alignment: 1, definedSymbols: new ISymbolDefinitionNode[] { this })); }
public ObjectHandle CreateComInstanceFrom(string assemblyFile, string typeName, byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm) { if (this == null) { throw new NullReferenceException(); } return Activator.CreateComInstanceFrom(assemblyFile, typeName, hashValue, hashAlgorithm); }
private static AssemblyName ParseAssemblyName(this MetadataReader metadataReader, StringHandle nameHandle, StringHandle cultureHandle, BlobHandle publicKeyTokenHandle, Version version, AssemblyHashAlgorithm assemblyHashAlgorithm, AssemblyFlags flags) { string culture = cultureHandle.IsNil ? "" : metadataReader.GetString(cultureHandle); string name = metadataReader.GetString(nameHandle); AssemblyName assemblyName = new AssemblyName(name); assemblyName.Version = version; #if net452 assemblyName.CultureInfo = CultureInfo.CreateSpecificCulture(culture); #else assemblyName.CultureName = culture; #endif assemblyName.HashAlgorithm = (System.Configuration.Assemblies.AssemblyHashAlgorithm)assemblyHashAlgorithm; assemblyName.Flags = GetAssemblyNameFlags(flags); assemblyName.ContentType = GetContentTypeFromAssemblyFlags(flags); ReadPublicKeyToken(metadataReader, assemblyName, publicKeyTokenHandle, flags); return(assemblyName); }
[MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable internal static RuntimeAssembly InternalLoadFrom(String assemblyFile, Evidence securityEvidence, byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, bool forIntrospection, bool suppressSecurityChecks, ref StackCrawlMark stackMark) { if (assemblyFile == null) throw new ArgumentNullException("assemblyFile"); Contract.EndContractBlock(); #if FEATURE_CAS_POLICY if (securityEvidence != null && !AppDomain.CurrentDomain.IsLegacyCasPolicyEnabled) { throw new NotSupportedException(Environment.GetResourceString("NotSupported_RequiresCasPolicyImplicit")); } #endif // FEATURE_CAS_POLICY AssemblyName an = new AssemblyName(); an.CodeBase = assemblyFile; an.SetHashControl(hashValue, hashAlgorithm); // The stack mark is used for MDA filtering return InternalLoadAssemblyName(an, securityEvidence, null, ref stackMark, true /*thrownOnFileNotFound*/, forIntrospection, suppressSecurityChecks); }
private void Add(AssemblyHashAlgorithm a) { }
[MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable public static Assembly LoadFrom(String assemblyFile, byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm) { StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; return RuntimeAssembly.InternalLoadFrom( assemblyFile, null, hashValue, hashAlgorithm, false, false, ref stackMark); }
internal static RuntimeAssembly InternalLoadFrom(string assemblyFile, System.Security.Policy.Evidence securityEvidence, byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, bool forIntrospection, bool suppressSecurityChecks, ref StackCrawlMark stackMark) { if (assemblyFile == null) { throw new ArgumentNullException("assemblyFile"); } if ((securityEvidence != null) && !AppDomain.CurrentDomain.IsLegacyCasPolicyEnabled) { throw new NotSupportedException(Environment.GetResourceString("NotSupported_RequiresCasPolicyImplicit")); } AssemblyName assemblyRef = new AssemblyName { CodeBase = assemblyFile }; assemblyRef.SetHashControl(hashValue, hashAlgorithm); return(InternalLoadAssemblyName(assemblyRef, securityEvidence, ref stackMark, forIntrospection, suppressSecurityChecks)); }
internal AssemblyName GetAssemblyName(StringHandle nameHandle, Version version, StringHandle cultureHandle, BlobHandle publicKeyOrTokenHandle, AssemblyHashAlgorithm assemblyHashAlgorithm, AssemblyFlags flags) { string name = GetString(nameHandle); string cultureName = (!cultureHandle.IsNil) ? GetString(cultureHandle) : null; var hashAlgorithm = (System.Configuration.Assemblies.AssemblyHashAlgorithm)assemblyHashAlgorithm; byte[] publicKeyOrToken = !publicKeyOrTokenHandle.IsNil ? GetBlobBytes(publicKeyOrTokenHandle) : null; var assemblyName = new AssemblyName(name) { Version = version, CultureName = cultureName, HashAlgorithm = hashAlgorithm, Flags = GetAssemblyNameFlags(flags), ContentType = GetContentTypeFromAssemblyFlags(flags) }; bool hasPublicKey = (flags & AssemblyFlags.PublicKey) != 0; if (hasPublicKey) { assemblyName.SetPublicKey(publicKeyOrToken); } else { assemblyName.SetPublicKeyToken(publicKeyOrToken); } return(assemblyName); }
ImmutableArray <byte> Cci.IFileReference.GetHashValue(AssemblyHashAlgorithm algorithmId) { return(_hashes.GetHash(algorithmId)); }