internal static RuntimeAssembly InternalLoadAssemblyName(AssemblyName assemblyRef, System.Security.Policy.Evidence assemblySecurity, ref StackCrawlMark stackMark, bool forIntrospection, bool suppressSecurityChecks) { if (assemblyRef == null) { throw new ArgumentNullException("assemblyRef"); } assemblyRef = (AssemblyName)assemblyRef.Clone(); if (assemblySecurity != null) { if (!AppDomain.CurrentDomain.IsLegacyCasPolicyEnabled) { throw new NotSupportedException(Environment.GetResourceString("NotSupported_RequiresCasPolicyImplicit")); } if (!suppressSecurityChecks) { new SecurityPermission(SecurityPermissionFlag.ControlEvidence).Demand(); } } string strA = VerifyCodeBase(assemblyRef.CodeBase); if ((strA != null) && !suppressSecurityChecks) { if (string.Compare(strA, 0, "file:", 0, 5, StringComparison.OrdinalIgnoreCase) != 0) { CreateWebPermission(assemblyRef.EscapedCodeBase).Demand(); } else { URLString str2 = new URLString(strA, true); new FileIOPermission(FileIOPermissionAccess.PathDiscovery | FileIOPermissionAccess.Read, str2.GetFileName()).Demand(); } } return(nLoad(assemblyRef, strA, assemblySecurity, null, ref stackMark, true, forIntrospection, suppressSecurityChecks)); }
internal static RuntimeAssembly InternalLoadAssemblyName( AssemblyName assemblyRef, RuntimeAssembly reqAssembly, ref StackCrawlMark stackMark, IntPtr pPrivHostBinder, bool throwOnFileNotFound, IntPtr ptrLoadContextBinder = default(IntPtr)) { if (assemblyRef == null) { throw new ArgumentNullException(nameof(assemblyRef)); } Contract.EndContractBlock(); if (assemblyRef.CodeBase != null) { AppDomain.CheckLoadFromSupported(); } assemblyRef = (AssemblyName)assemblyRef.Clone(); if (assemblyRef.ProcessorArchitecture != ProcessorArchitecture.None) { // PA does not have a semantics for by-name binds for execution assemblyRef.ProcessorArchitecture = ProcessorArchitecture.None; } String codeBase = VerifyCodeBase(assemblyRef.CodeBase); return(nLoad(assemblyRef, codeBase, reqAssembly, ref stackMark, pPrivHostBinder, throwOnFileNotFound, ptrLoadContextBinder)); }
public static void Clone() { AssemblyName an1 = new AssemblyName("MyAssemblyName"); an1.Flags = AssemblyNameFlags.PublicKey | AssemblyNameFlags.EnableJITcompileOptimizer; object an2 = an1.Clone(); Assert.Equal(an1.FullName, ((AssemblyName)an2).FullName); Assert.Equal(AssemblyNameFlags.PublicKey | AssemblyNameFlags.EnableJITcompileOptimizer, ((AssemblyName)an2).Flags); }
internal static RuntimeAssembly InternalLoadAssemblyName( AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, ref StackCrawlMark stackMark, #if FEATURE_HOSTED_BINDER IntPtr pPrivHostBinder, #endif bool throwOnFileNotFound, bool forIntrospection, bool suppressSecurityChecks) { if (assemblyRef == null) { throw new ArgumentNullException("assemblyRef"); } Contract.EndContractBlock(); if (assemblyRef.CodeBase != null) { AppDomain.CheckLoadFromSupported(); } assemblyRef = (AssemblyName)assemblyRef.Clone(); #if FEATURE_VERSIONING if (!forIntrospection && (assemblyRef.ProcessorArchitecture != ProcessorArchitecture.None)) { // PA does not have a semantics for by-name binds for execution assemblyRef.ProcessorArchitecture = ProcessorArchitecture.None; } #endif if (assemblySecurity != null) { #if FEATURE_CAS_POLICY if (!AppDomain.CurrentDomain.IsLegacyCasPolicyEnabled) { throw new NotSupportedException(Environment.GetResourceString("NotSupported_RequiresCasPolicyImplicit")); } #endif // FEATURE_CAS_POLICY if (!suppressSecurityChecks) { #if FEATURE_MONO_CAS #pragma warning disable 618 new SecurityPermission(SecurityPermissionFlag.ControlEvidence).Demand(); #pragma warning restore 618 #endif } } return((RuntimeAssembly)Assembly.Load(assemblyRef)); }
internal static RuntimeAssembly InternalLoadAssemblyName(AssemblyName assemblyRef, ref StackCrawlMark stackMark, AssemblyLoadContext?assemblyLoadContext = null) { assemblyRef = (AssemblyName)assemblyRef.Clone(); if (assemblyRef.ProcessorArchitecture != ProcessorArchitecture.None) { // PA does not have a semantics for by-name binds for execution assemblyRef.ProcessorArchitecture = ProcessorArchitecture.None; } Debug.Assert(assemblyRef.CodeBase == null); return(nLoad(assemblyRef, null, ref stackMark, true, assemblyLoadContext)); }
[System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod internal static Assembly Load(AssemblyName assemblyRef, IntPtr ptrLoadContextBinder) { AssemblyName modifiedAssemblyRef = null; if (assemblyRef != null && assemblyRef.CodeBase != null) { modifiedAssemblyRef = (AssemblyName)assemblyRef.Clone(); modifiedAssemblyRef.CodeBase = null; } else { modifiedAssemblyRef = assemblyRef; } StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; return RuntimeAssembly.InternalLoadAssemblyName(modifiedAssemblyRef, null, ref stackMark, true /*thrownOnFileNotFound*/, ptrLoadContextBinder); }
internal static Assembly Load(AssemblyName assemblyRef, ref StackCrawlMark stackMark, AssemblyLoadContext?assemblyLoadContext) { AssemblyName modifiedAssemblyRef; if (assemblyRef.CodeBase != null) { modifiedAssemblyRef = (AssemblyName)assemblyRef.Clone(); modifiedAssemblyRef.CodeBase = null; } else { modifiedAssemblyRef = assemblyRef; } return(RuntimeAssembly.InternalLoadAssemblyName(modifiedAssemblyRef, ref stackMark, assemblyLoadContext)); }
[System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod internal static Assembly Load(AssemblyName assemblyRef, IntPtr ptrLoadContextBinder) { Contract.Ensures(Contract.Result <Assembly>() != null); Contract.Ensures(!Contract.Result <Assembly>().ReflectionOnly); AssemblyName modifiedAssemblyRef = null; if (assemblyRef != null && assemblyRef.CodeBase != null) { modifiedAssemblyRef = (AssemblyName)assemblyRef.Clone(); modifiedAssemblyRef.CodeBase = null; } else { modifiedAssemblyRef = assemblyRef; } StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller; return(RuntimeAssembly.InternalLoadAssemblyName(modifiedAssemblyRef, null, null, ref stackMark, true /*thrownOnFileNotFound*/, false /*forIntrospection*/, ptrLoadContextBinder)); }
internal static RuntimeAssembly InternalLoadAssemblyName(AssemblyName assemblyRef, ref StackCrawlMark stackMark, AssemblyLoadContext?assemblyLoadContext = null) { #if FEATURE_APPX if (ApplicationModel.IsUap) { if (assemblyRef.CodeBase != null) { throw new NotSupportedException(SR.Format(SR.NotSupported_AppX, "Assembly.LoadFrom")); } } #endif assemblyRef = (AssemblyName)assemblyRef.Clone(); if (assemblyRef.ProcessorArchitecture != ProcessorArchitecture.None) { // PA does not have a semantics for by-name binds for execution assemblyRef.ProcessorArchitecture = ProcessorArchitecture.None; } string?codeBase = VerifyCodeBase(assemblyRef.CodeBase); return(nLoad(assemblyRef, codeBase, null, ref stackMark, true, assemblyLoadContext)); }
internal static RuntimeAssembly InternalLoadAssemblyName( AssemblyName assemblyRef, RuntimeAssembly reqAssembly, ref StackCrawlMark stackMark, IntPtr pPrivHostBinder, bool throwOnFileNotFound, IntPtr ptrLoadContextBinder = default) { if (assemblyRef == null) { throw new ArgumentNullException(nameof(assemblyRef)); } #if FEATURE_APPX if (ApplicationModel.IsUap) { if (assemblyRef.CodeBase != null) { throw new NotSupportedException(SR.Format(SR.NotSupported_AppX, "Assembly.LoadFrom")); } } #endif assemblyRef = (AssemblyName)assemblyRef.Clone(); if (assemblyRef.ProcessorArchitecture != ProcessorArchitecture.None) { // PA does not have a semantics for by-name binds for execution assemblyRef.ProcessorArchitecture = ProcessorArchitecture.None; } string codeBase = VerifyCodeBase(assemblyRef.CodeBase); return(nLoad(assemblyRef, codeBase, reqAssembly, ref stackMark, pPrivHostBinder, throwOnFileNotFound, ptrLoadContextBinder)); }
public void Clone_Self () { an = Assembly.GetExecutingAssembly ().GetName (); AssemblyName clone = (AssemblyName) an.Clone (); Assert.AreEqual (an.CodeBase, clone.CodeBase, "CodeBase"); Assert.AreEqual (an.CultureInfo, clone.CultureInfo, "CultureInfo"); Assert.AreEqual (an.EscapedCodeBase, clone.EscapedCodeBase, "EscapedCodeBase"); Assert.AreEqual (an.Flags, clone.Flags, "Flags"); Assert.AreEqual (an.FullName, clone.FullName, "FullName"); Assert.AreEqual (an.HashAlgorithm, clone.HashAlgorithm, "HashAlgorithm"); Assert.AreEqual (an.KeyPair, clone.KeyPair, "KeyPair"); Assert.AreEqual (an.Name, clone.Name, "Name"); Assert.AreEqual (an.Version, clone.Version, "Version"); Assert.AreEqual (an.VersionCompatibility, clone.VersionCompatibility, "VersionCompatibility"); }
internal static Assembly InternalLoad(AssemblyName assemblyRef, bool stringized, Evidence assemblySecurity, ref StackCrawlMark stackMark) { if (assemblyRef == null) throw new ArgumentNullException("assemblyRef"); assemblyRef=(AssemblyName)assemblyRef.Clone(); if (assemblySecurity != null) new SecurityPermission( SecurityPermissionFlag.ControlEvidence ).Demand(); String codeBase = AppDomain.VerifyCodeBase(assemblyRef.CodeBase); if (codeBase != null) { if (String.Compare( codeBase, 0, s_localFilePrefix, 0, 5, true, CultureInfo.InvariantCulture) != 0) { IPermission perm = CreateWebPermission( assemblyRef.EscapedCodeBase ); if (perm == null) { BCLDebug.Assert( false, "Unable to create System.Net.WebPermission" ); return null; } perm.Demand(); } else { System.Security.Util.URLString urlString = new System.Security.Util.URLString( codeBase, true ); new FileIOPermission( FileIOPermissionAccess.Read, urlString.GetFileName() ).Demand(); } } return nLoad(assemblyRef, codeBase, stringized, assemblySecurity, true, null, ref stackMark); }
internal static Assembly InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, ref StackCrawlMark stackMark, bool forIntrospection) { if (assemblyRef == null) throw new ArgumentNullException("assemblyRef"); assemblyRef = (AssemblyName)assemblyRef.Clone(); if (assemblySecurity != null) new SecurityPermission( SecurityPermissionFlag.ControlEvidence ).Demand(); String codeBase = VerifyCodeBase(assemblyRef.CodeBase); if (codeBase != null) { if (String.Compare( codeBase, 0, s_localFilePrefix, 0, 5, StringComparison.OrdinalIgnoreCase) != 0) { IPermission perm = CreateWebPermission( assemblyRef.EscapedCodeBase ); perm.Demand(); } else { System.Security.Util.URLString urlString = new System.Security.Util.URLString( codeBase, true ); new FileIOPermission( FileIOPermissionAccess.PathDiscovery | FileIOPermissionAccess.Read , urlString.GetFileName() ).Demand(); } } return nLoad(assemblyRef, codeBase, assemblySecurity, null, ref stackMark, true, forIntrospection); }
[System.Security.SecurityCritical] // auto-generated internal AssemblyBuilder(AppDomain domain, AssemblyName name, AssemblyBuilderAccess access, String dir, Evidence evidence, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions, ref StackCrawlMark stackMark, IEnumerable<CustomAttributeBuilder> unsafeAssemblyAttributes, SecurityContextSource securityContextSource) { if (name == null) throw new ArgumentNullException("name"); if (access != AssemblyBuilderAccess.Run #if !FEATURE_CORECLR && access != AssemblyBuilderAccess.Save && access != AssemblyBuilderAccess.RunAndSave #endif // !FEATURE_CORECLR #if FEATURE_REFLECTION_ONLY_LOAD && access != AssemblyBuilderAccess.ReflectionOnly #endif // FEATURE_REFLECTION_ONLY_LOAD #if FEATURE_COLLECTIBLE_TYPES && access != AssemblyBuilderAccess.RunAndCollect #endif // FEATURE_COLLECTIBLE_TYPES ) { throw new ArgumentException(Environment.GetResourceString("Arg_EnumIllegalVal", (int)access), "access"); } if (securityContextSource < SecurityContextSource.CurrentAppDomain || securityContextSource > SecurityContextSource.CurrentAssembly) { throw new ArgumentOutOfRangeException("securityContextSource"); } // Clone the name in case the caller modifies it underneath us. name = (AssemblyName)name.Clone(); #if !FEATURE_CORECLR // Set the public key from the key pair if one has been provided. // (Overwite any public key in the Assembly name, since it's no // longer valid to have a disparity). if (name.KeyPair != null) name.SetPublicKey(name.KeyPair.PublicKey); #endif // If the caller is trusted they can supply identity // evidence for the new assembly. Otherwise we copy the // current grant and deny sets from the caller's assembly, // inject them into the new assembly and mark policy as // resolved. If/when the assembly is persisted and // reloaded, the normal rules for gathering evidence will // be used. if (evidence != null) #pragma warning disable 618 new SecurityPermission(SecurityPermissionFlag.ControlEvidence).Demand(); #pragma warning restore 618 #if FEATURE_COLLECTIBLE_TYPES && !FEATURE_CORECLR // Collectible assemblies require FullTrust. This demand may be removed if we deem the // feature robust enough to be used directly by untrusted API consumers. if (access == AssemblyBuilderAccess.RunAndCollect) new PermissionSet(PermissionState.Unrestricted).Demand(); #endif // FEATURE_COLLECTIBLE_TYPES && !FEATURE_CORECLR // Scan the assembly level attributes for any attributes which modify how we create the // assembly. Currently, we look for any attribute which modifies the security transparency // of the assembly. List<CustomAttributeBuilder> assemblyAttributes = null; DynamicAssemblyFlags assemblyFlags = DynamicAssemblyFlags.None; byte[] securityRulesBlob = null; byte[] aptcaBlob = null; if (unsafeAssemblyAttributes != null) { // Create a copy to ensure that it cannot be modified from another thread // as it is used further below. assemblyAttributes = new List<CustomAttributeBuilder>(unsafeAssemblyAttributes); #pragma warning disable 618 // We deal with legacy attributes here as well for compat foreach (CustomAttributeBuilder attribute in assemblyAttributes) { if (attribute.m_con.DeclaringType == typeof(SecurityTransparentAttribute)) { assemblyFlags |= DynamicAssemblyFlags.Transparent; } else if (attribute.m_con.DeclaringType == typeof(SecurityCriticalAttribute)) { #if !FEATURE_CORECLR SecurityCriticalScope scope = SecurityCriticalScope.Everything; if (attribute.m_constructorArgs != null && attribute.m_constructorArgs.Length == 1 && attribute.m_constructorArgs[0] is SecurityCriticalScope) { scope = (SecurityCriticalScope)attribute.m_constructorArgs[0]; } assemblyFlags |= DynamicAssemblyFlags.Critical; if (scope == SecurityCriticalScope.Everything) #endif // !FEATURE_CORECLR { assemblyFlags |= DynamicAssemblyFlags.AllCritical; } } #if !FEATURE_CORECLR else if (attribute.m_con.DeclaringType == typeof(SecurityRulesAttribute)) { securityRulesBlob = new byte[attribute.m_blob.Length]; Buffer.BlockCopy(attribute.m_blob, 0, securityRulesBlob, 0, securityRulesBlob.Length); } else if (attribute.m_con.DeclaringType == typeof(SecurityTreatAsSafeAttribute)) { assemblyFlags |= DynamicAssemblyFlags.TreatAsSafe; } #endif // !FEATURE_CORECLR #if FEATURE_APTCA else if (attribute.m_con.DeclaringType == typeof(AllowPartiallyTrustedCallersAttribute)) { assemblyFlags |= DynamicAssemblyFlags.Aptca; aptcaBlob = new byte[attribute.m_blob.Length]; Buffer.BlockCopy(attribute.m_blob, 0, aptcaBlob, 0, aptcaBlob.Length); } #endif // FEATURE_APTCA } #pragma warning restore 618 } m_internalAssemblyBuilder = (InternalAssemblyBuilder)nCreateDynamicAssembly(domain, name, evidence, ref stackMark, requiredPermissions, optionalPermissions, refusedPermissions, securityRulesBlob, aptcaBlob, access, assemblyFlags, securityContextSource); m_assemblyData = new AssemblyBuilderData(m_internalAssemblyBuilder, name.Name, access, dir); m_assemblyData.AddPermissionRequests(requiredPermissions, optionalPermissions, refusedPermissions); #if FEATURE_APPX if (AppDomain.ProfileAPICheck) { RuntimeAssembly creator = RuntimeAssembly.GetExecutingAssembly(ref stackMark); if (creator != null && !creator.IsFrameworkAssembly()) m_profileAPICheck = true; } #endif // Make sure that ManifestModule is properly initialized // We need to do this before setting any CustomAttribute InitManifestModule(); if (assemblyAttributes != null) { foreach (CustomAttributeBuilder assemblyAttribute in assemblyAttributes) SetCustomAttribute(assemblyAttribute); } }
internal static RuntimeAssembly InternalLoadAssemblyName(AssemblyName assemblyRef, System.Security.Policy.Evidence assemblySecurity, ref StackCrawlMark stackMark, bool forIntrospection, bool suppressSecurityChecks) { if (assemblyRef == null) { throw new ArgumentNullException("assemblyRef"); } assemblyRef = (AssemblyName) assemblyRef.Clone(); if (assemblySecurity != null) { if (!AppDomain.CurrentDomain.IsLegacyCasPolicyEnabled) { throw new NotSupportedException(Environment.GetResourceString("NotSupported_RequiresCasPolicyImplicit")); } if (!suppressSecurityChecks) { new SecurityPermission(SecurityPermissionFlag.ControlEvidence).Demand(); } } string strA = VerifyCodeBase(assemblyRef.CodeBase); if ((strA != null) && !suppressSecurityChecks) { if (string.Compare(strA, 0, "file:", 0, 5, StringComparison.OrdinalIgnoreCase) != 0) { CreateWebPermission(assemblyRef.EscapedCodeBase).Demand(); } else { URLString str2 = new URLString(strA, true); new FileIOPermission(FileIOPermissionAccess.PathDiscovery | FileIOPermissionAccess.Read, str2.GetFileName()).Demand(); } } return nLoad(assemblyRef, strA, assemblySecurity, null, ref stackMark, true, forIntrospection, suppressSecurityChecks); }
internal static Assembly InternalLoad(AssemblyName assemblyRef, System.Security.Policy.Evidence assemblySecurity, ref StackCrawlMark stackMark, bool forIntrospection) { if (assemblyRef == null) { throw new ArgumentNullException("assemblyRef"); } assemblyRef = (AssemblyName) assemblyRef.Clone(); if (assemblySecurity != null) { new SecurityPermission(SecurityPermissionFlag.ControlEvidence).Demand(); } string strA = VerifyCodeBase(assemblyRef.CodeBase); if (strA != null) { if (string.Compare(strA, 0, "file:", 0, 5, StringComparison.OrdinalIgnoreCase) != 0) { CreateWebPermission(assemblyRef.EscapedCodeBase).Demand(); } else { URLString str2 = new URLString(strA, true); new FileIOPermission(FileIOPermissionAccess.PathDiscovery | FileIOPermissionAccess.Read, str2.GetFileName()).Demand(); } } return nLoad(assemblyRef, strA, assemblySecurity, null, ref stackMark, true, forIntrospection); }
public void Clone_Empty () { an = new AssemblyName (); AssemblyName clone = (AssemblyName) an.Clone (); Assert.IsNull (clone.CodeBase, "CodeBase"); Assert.IsNull (clone.CultureInfo, "CultureInfo"); Assert.IsNull (clone.EscapedCodeBase, "EscapedCodeBase"); Assert.AreEqual (AssemblyNameFlags.None, clone.Flags, "Flags"); Assert.IsNull (clone.FullName, "FullName"); Assert.AreEqual (AssemblyHashAlgorithm.None, clone.HashAlgorithm, "HashAlgorithm"); Assert.IsNull (clone.KeyPair, "KeyPair"); Assert.IsNull (clone.Name, "Name"); Assert.IsNull (clone.Version, "Version"); Assert.AreEqual (AssemblyVersionCompatibility.SameMachine, clone.VersionCompatibility, "VersionCompatibility"); }
public void Clone_Corlib () { an = typeof (int).Assembly.GetName (); AssemblyName clone = (AssemblyName) an.Clone (); Assert.AreEqual (an.CodeBase, clone.CodeBase, "CodeBase"); Assert.AreEqual (an.CultureInfo, clone.CultureInfo, "CultureInfo"); Assert.AreEqual (an.EscapedCodeBase, clone.EscapedCodeBase, "EscapedCodeBase"); Assert.AreEqual (an.Flags, clone.Flags, "Flags"); Assert.AreEqual (an.FullName, clone.FullName, "FullName"); Assert.AreEqual (an.HashAlgorithm, clone.HashAlgorithm, "HashAlgorithm"); Assert.AreEqual (an.KeyPair, clone.KeyPair, "KeyPair"); Assert.AreEqual (an.Name, clone.Name, "Name"); //Assert.AreEqual (an.ProcessorArchitecture, clone.ProcessorArchitecture, "PA"); Assert.AreEqual (an.Version, clone.Version, "Version"); Assert.AreEqual (an.VersionCompatibility, clone.VersionCompatibility, "VersionCompatibility"); Assert.AreEqual (an.GetPublicKey (), clone.GetPublicKey (), "GetPublicKey"); Assert.AreEqual (an.GetPublicKeyToken (), clone.GetPublicKeyToken (), "GetPublicKeyToken"); Assert.AreEqual (an.ToString (), clone.ToString (), "ToString"); }
internal AssemblyBuilder(AppDomain domain, AssemblyName name, AssemblyBuilderAccess access, String dir, Evidence evidence, PermissionSet requiredPermissions, PermissionSet optionalPermissions, PermissionSet refusedPermissions, ref StackCrawlMark stackMark, IEnumerable<CustomAttributeBuilder> unsafeAssemblyAttributes, SecurityContextSource securityContextSource) { if (name == null) throw new ArgumentNullException(nameof(name)); if (access != AssemblyBuilderAccess.Run #if FEATURE_REFLECTION_ONLY_LOAD && access != AssemblyBuilderAccess.ReflectionOnly #endif // FEATURE_REFLECTION_ONLY_LOAD #if FEATURE_COLLECTIBLE_TYPES && access != AssemblyBuilderAccess.RunAndCollect #endif // FEATURE_COLLECTIBLE_TYPES ) { throw new ArgumentException(Environment.GetResourceString("Arg_EnumIllegalVal", (int)access), nameof(access)); } if (securityContextSource < SecurityContextSource.CurrentAppDomain || securityContextSource > SecurityContextSource.CurrentAssembly) { throw new ArgumentOutOfRangeException(nameof(securityContextSource)); } // Clone the name in case the caller modifies it underneath us. name = (AssemblyName)name.Clone(); // If the caller is trusted they can supply identity // evidence for the new assembly. Otherwise we copy the // current grant and deny sets from the caller's assembly, // inject them into the new assembly and mark policy as // resolved. If/when the assembly is persisted and // reloaded, the normal rules for gathering evidence will // be used. if (evidence != null) #pragma warning disable 618 new SecurityPermission(SecurityPermissionFlag.ControlEvidence).Demand(); #pragma warning restore 618 // Scan the assembly level attributes for any attributes which modify how we create the // assembly. Currently, we look for any attribute which modifies the security transparency // of the assembly. List<CustomAttributeBuilder> assemblyAttributes = null; DynamicAssemblyFlags assemblyFlags = DynamicAssemblyFlags.None; byte[] securityRulesBlob = null; byte[] aptcaBlob = null; if (unsafeAssemblyAttributes != null) { // Create a copy to ensure that it cannot be modified from another thread // as it is used further below. assemblyAttributes = new List<CustomAttributeBuilder>(unsafeAssemblyAttributes); #pragma warning disable 618 // We deal with legacy attributes here as well for compat foreach (CustomAttributeBuilder attribute in assemblyAttributes) { if (attribute.m_con.DeclaringType == typeof(SecurityTransparentAttribute)) { assemblyFlags |= DynamicAssemblyFlags.Transparent; } else if (attribute.m_con.DeclaringType == typeof(SecurityCriticalAttribute)) { { assemblyFlags |= DynamicAssemblyFlags.AllCritical; } } } #pragma warning restore 618 } m_internalAssemblyBuilder = (InternalAssemblyBuilder)nCreateDynamicAssembly(domain, name, evidence, ref stackMark, requiredPermissions, optionalPermissions, refusedPermissions, securityRulesBlob, aptcaBlob, access, assemblyFlags, securityContextSource); m_assemblyData = new AssemblyBuilderData(m_internalAssemblyBuilder, name.Name, access, dir); m_assemblyData.AddPermissionRequests(requiredPermissions, optionalPermissions, refusedPermissions); #if FEATURE_APPX if (AppDomain.ProfileAPICheck) { RuntimeAssembly creator = RuntimeAssembly.GetExecutingAssembly(ref stackMark); if (creator != null && !creator.IsFrameworkAssembly()) m_profileAPICheck = true; } #endif // Make sure that ManifestModule is properly initialized // We need to do this before setting any CustomAttribute InitManifestModule(); if (assemblyAttributes != null) { foreach (CustomAttributeBuilder assemblyAttribute in assemblyAttributes) SetCustomAttribute(assemblyAttribute); } }
static Assembly LoadAssembly(AssemblyName name) { Assembly result = null; try { _logger.DebugFormat("Loading assembly '{0}'.", name); result = Assembly.Load(name); } catch (FileLoadException) { _logger.DebugFormat("Cannot load assembly '{0}'.", name); } if (result == null && name.Version != null) { var nameWithoutVersion = (AssemblyName)name.Clone(); nameWithoutVersion.Version = null; result = LoadAssembly(nameWithoutVersion); } return result; }
internal static RuntimeAssembly InternalLoadAssemblyName( AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, ref StackCrawlMark stackMark, #if FEATURE_HOSTED_BINDER IntPtr pPrivHostBinder, #endif bool throwOnFileNotFound, bool forIntrospection, bool suppressSecurityChecks) { if (assemblyRef == null) throw new ArgumentNullException("assemblyRef"); Contract.EndContractBlock(); if (assemblyRef.CodeBase != null) { AppDomain.CheckLoadFromSupported(); } assemblyRef = (AssemblyName)assemblyRef.Clone(); #if FEATURE_VERSIONING if (!forIntrospection && (assemblyRef.ProcessorArchitecture != ProcessorArchitecture.None)) { // PA does not have a semantics for by-name binds for execution assemblyRef.ProcessorArchitecture = ProcessorArchitecture.None; } #endif if (assemblySecurity != null) { #if FEATURE_CAS_POLICY if (!AppDomain.CurrentDomain.IsLegacyCasPolicyEnabled) { throw new NotSupportedException(Environment.GetResourceString("NotSupported_RequiresCasPolicyImplicit")); } #endif // FEATURE_CAS_POLICY if (!suppressSecurityChecks) { #pragma warning disable 618 new SecurityPermission(SecurityPermissionFlag.ControlEvidence).Demand(); #pragma warning restore 618 } } return (RuntimeAssembly) Assembly.Load (assemblyRef); }
public void Clone_Empty () { an = new AssemblyName (); AssemblyName clone = (AssemblyName) an.Clone (); Assert.IsNull (clone.CodeBase, "CodeBase"); Assert.IsNull (clone.CultureInfo, "CultureInfo"); Assert.IsNull (clone.EscapedCodeBase, "EscapedCodeBase"); Assert.AreEqual (AssemblyNameFlags.None, clone.Flags, "Flags"); #if NET_2_0 Assert.AreEqual (String.Empty, clone.FullName, "FullName"); #else Assert.IsNull (clone.FullName, "FullName"); #endif Assert.AreEqual (AssemblyHashAlgorithm.None, clone.HashAlgorithm, "HashAlgorithm"); Assert.IsNull (clone.KeyPair, "KeyPair"); Assert.IsNull (clone.Name, "Name"); #if NET_2_0 Assert.AreEqual (ProcessorArchitecture.None, clone.ProcessorArchitecture, "PA"); #endif Assert.IsNull (clone.Version, "Version"); Assert.AreEqual (AssemblyVersionCompatibility.SameMachine, clone.VersionCompatibility, "VersionCompatibility"); }
internal AssemblyLoader(TypeProvider typeProvider, string filePath) { this.isLocalAssembly = false; this.typeProvider = typeProvider; if (!File.Exists(filePath)) { throw new FileNotFoundException(); } System.Reflection.AssemblyName assemblyName = System.Reflection.AssemblyName.GetAssemblyName(filePath); if (assemblyName != null) { ITypeResolutionService service = (ITypeResolutionService)typeProvider.GetService(typeof(ITypeResolutionService)); if (service != null) { try { this.assembly = service.GetAssembly(assemblyName); if ((((this.assembly == null) && (assemblyName.GetPublicKeyToken() != null)) && ((assemblyName.GetPublicKeyToken().GetLength(0) == 0) && (assemblyName.GetPublicKey() != null))) && (assemblyName.GetPublicKey().GetLength(0) == 0)) { System.Reflection.AssemblyName name = (System.Reflection.AssemblyName)assemblyName.Clone(); name.SetPublicKey(null); name.SetPublicKeyToken(null); this.assembly = service.GetAssembly(name); } } catch { } } if (this.assembly == null) { try { if (MultiTargetingInfo.MultiTargetingUtilities.IsFrameworkReferenceAssembly(filePath)) { this.assembly = System.Reflection.Assembly.Load(assemblyName.FullName); } else { this.assembly = System.Reflection.Assembly.Load(assemblyName); } } catch { } } } if (this.assembly == null) { this.assembly = System.Reflection.Assembly.LoadFrom(filePath); } }
public void Clone_Self () { an = Assembly.GetExecutingAssembly ().GetName (); AssemblyName clone = (AssemblyName) an.Clone (); Assert.AreEqual (an.CodeBase, clone.CodeBase, "CodeBase"); Assert.AreEqual (an.CultureInfo, clone.CultureInfo, "CultureInfo"); Assert.AreEqual (an.EscapedCodeBase, clone.EscapedCodeBase, "EscapedCodeBase"); Assert.AreEqual (an.Flags, clone.Flags, "Flags"); Assert.AreEqual (an.FullName, clone.FullName, "FullName"); Assert.AreEqual (an.HashAlgorithm, clone.HashAlgorithm, "HashAlgorithm"); Assert.AreEqual (an.KeyPair, clone.KeyPair, "KeyPair"); Assert.AreEqual (an.Name, clone.Name, "Name"); #if NET_2_0 //Assert.AreEqual (ProcessorArchitecture.MSIL, clone.ProcessorArchitecture, "PA"); #endif Assert.AreEqual (an.Version, clone.Version, "Version"); Assert.AreEqual (an.VersionCompatibility, clone.VersionCompatibility, "VersionCompatibility"); Assert.AreEqual (an.GetPublicKey (), clone.GetPublicKey (), "GetPublicKey"); Assert.AreEqual (an.GetPublicKeyToken (), clone.GetPublicKeyToken (), "GetPublicKeyToken"); Assert.AreEqual (an.ToString (), clone.ToString (), "ToString"); }
[System.Security.SecurityCritical] // auto-generated internal static RuntimeAssembly InternalLoadAssemblyName( AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, ref StackCrawlMark stackMark, #if FEATURE_HOSTED_BINDER IntPtr pPrivHostBinder, #endif bool throwOnFileNotFound, bool forIntrospection, bool suppressSecurityChecks) { if (assemblyRef == null) throw new ArgumentNullException("assemblyRef"); Contract.EndContractBlock(); if (assemblyRef.CodeBase != null) { AppDomain.CheckLoadFromSupported(); } assemblyRef = (AssemblyName)assemblyRef.Clone(); #if FEATURE_VERSIONING if (!forIntrospection && (assemblyRef.ProcessorArchitecture != ProcessorArchitecture.None)) { // PA does not have a semantics for by-name binds for execution assemblyRef.ProcessorArchitecture = ProcessorArchitecture.None; } #endif if (assemblySecurity != null) { #if FEATURE_CAS_POLICY if (!AppDomain.CurrentDomain.IsLegacyCasPolicyEnabled) { throw new NotSupportedException(Environment.GetResourceString("NotSupported_RequiresCasPolicyImplicit")); } #endif // FEATURE_CAS_POLICY if (!suppressSecurityChecks) { #pragma warning disable 618 new SecurityPermission(SecurityPermissionFlag.ControlEvidence).Demand(); #pragma warning restore 618 } } String codeBase = VerifyCodeBase(assemblyRef.CodeBase); if (codeBase != null && !suppressSecurityChecks) { if (String.Compare( codeBase, 0, s_localFilePrefix, 0, 5, StringComparison.OrdinalIgnoreCase) != 0) { #if FEATURE_FUSION // Of all the binders, Fusion is the only one that understands Web locations IPermission perm = CreateWebPermission( assemblyRef.EscapedCodeBase ); perm.Demand(); #else throw new ArgumentException(Environment.GetResourceString("Arg_InvalidFileName"), "assemblyRef.CodeBase"); #endif } else { System.Security.Util.URLString urlString = new System.Security.Util.URLString( codeBase, true ); new FileIOPermission( FileIOPermissionAccess.PathDiscovery | FileIOPermissionAccess.Read , urlString.GetFileName() ).Demand(); } } return nLoad(assemblyRef, codeBase, assemblySecurity, reqAssembly, ref stackMark, #if FEATURE_HOSTED_BINDER pPrivHostBinder, #endif throwOnFileNotFound, forIntrospection, suppressSecurityChecks); }
internal static RuntimeAssembly InternalLoadAssemblyName( AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, ref StackCrawlMark stackMark, IntPtr pPrivHostBinder, bool throwOnFileNotFound, bool forIntrospection, bool suppressSecurityChecks, IntPtr ptrLoadContextBinder = default(IntPtr)) { if (assemblyRef == null) throw new ArgumentNullException(nameof(assemblyRef)); Contract.EndContractBlock(); if (assemblyRef.CodeBase != null) { AppDomain.CheckLoadFromSupported(); } assemblyRef = (AssemblyName)assemblyRef.Clone(); #if FEATURE_VERSIONING if (!forIntrospection && (assemblyRef.ProcessorArchitecture != ProcessorArchitecture.None)) { // PA does not have a semantics for by-name binds for execution assemblyRef.ProcessorArchitecture = ProcessorArchitecture.None; } #endif if (assemblySecurity != null) { if (!suppressSecurityChecks) { #pragma warning disable 618 new SecurityPermission(SecurityPermissionFlag.ControlEvidence).Demand(); #pragma warning restore 618 } } String codeBase = VerifyCodeBase(assemblyRef.CodeBase); if (codeBase != null && !suppressSecurityChecks) { if (String.Compare( codeBase, 0, s_localFilePrefix, 0, 5, StringComparison.OrdinalIgnoreCase) != 0) { // Of all the binders, Fusion is the only one that understands Web locations throw new ArgumentException(Environment.GetResourceString("Arg_InvalidFileName"), "assemblyRef.CodeBase"); } else { System.Security.Util.URLString urlString = new System.Security.Util.URLString( codeBase, true ); new FileIOPermission( FileIOPermissionAccess.PathDiscovery | FileIOPermissionAccess.Read , urlString.GetFileName() ).Demand(); } } return nLoad(assemblyRef, codeBase, assemblySecurity, reqAssembly, ref stackMark, pPrivHostBinder, throwOnFileNotFound, forIntrospection, suppressSecurityChecks, ptrLoadContextBinder); }