internal static RuntimeAssembly[] OnReflectionOnlyNamespaceResolveEvent(AppDomain appDomain, RuntimeAssembly assembly, string namespaceName)
 {
     EventHandler<NamespaceResolveEventArgs> eventHandler = ReflectionOnlyNamespaceResolve;
     if (eventHandler != null)
     {
         Delegate[] ds = eventHandler.GetInvocationList();
         int len = ds.Length;
         for (int i = 0; i < len; i++)
         {
             NamespaceResolveEventArgs eventArgs = new NamespaceResolveEventArgs(namespaceName, assembly);
             
             ((EventHandler<NamespaceResolveEventArgs>)ds[i])(appDomain, eventArgs);
             
             Collection<Assembly> assembliesCollection = eventArgs.ResolvedAssemblies;
             if (assembliesCollection.Count > 0)
             {
                 RuntimeAssembly[] retAssemblies = new RuntimeAssembly[assembliesCollection.Count];
                 int retIndex = 0;
                 foreach (Assembly asm in assembliesCollection)
                 {
                     retAssemblies[retIndex] = AppDomain.GetRuntimeAssembly(asm);
                     retIndex++;
                 }
                 return retAssemblies;
             }
         }
     }
     
     return null;
 }
 internal static void CheckAssembly(RuntimeAssembly asm, CodeAccessPermission demand)
 {
     PermissionSet set;
     PermissionSet set2;
     asm.GetGrantSet(out set, out set2);
     CheckHelper(set, set2, demand, PermissionToken.GetToken(demand), RuntimeMethodHandleInternal.EmptyHandle, asm, SecurityAction.Demand, true);
 }
 internal StrongName(StrongNamePublicKeyBlob blob, string name, System.Version version, Assembly assembly)
 {
     if (name == null)
     {
         throw new ArgumentNullException("name");
     }
     if (string.IsNullOrEmpty(name))
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_EmptyStrongName"));
     }
     if (blob == null)
     {
         throw new ArgumentNullException("blob");
     }
     if (version == null)
     {
         throw new ArgumentNullException("version");
     }
     RuntimeAssembly assembly2 = assembly as RuntimeAssembly;
     if ((assembly != null) && (assembly2 == null))
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeAssembly"), "assembly");
     }
     this.m_publicKeyBlob = blob;
     this.m_name = name;
     this.m_version = version;
     this.m_assembly = assembly2;
 }
Example #4
0
        public RuntimeLibrary(
            string type,
            string name,
            string version,
            string hash,
            IReadOnlyList<RuntimeAssetGroup> runtimeAssemblyGroups,
            IReadOnlyList<RuntimeAssetGroup> nativeLibraryGroups,
            IEnumerable<ResourceAssembly> resourceAssemblies,
            IEnumerable<Dependency> dependencies,
            bool serviceable)
            : base(type, name, version, hash, dependencies, serviceable)
        {
            if (runtimeAssemblyGroups == null)
            {
                throw new ArgumentNullException(nameof(runtimeAssemblyGroups));
            }
            if (nativeLibraryGroups == null)
            {
                throw new ArgumentNullException(nameof(nativeLibraryGroups));
            }
            if (resourceAssemblies == null)
            {
                throw new ArgumentNullException(nameof(resourceAssemblies));
            }
            RuntimeAssemblyGroups = runtimeAssemblyGroups;
            ResourceAssemblies = resourceAssemblies.ToArray();
            NativeLibraryGroups = nativeLibraryGroups;

            Assemblies = new RuntimeAssembly[0];
            NativeLibraries = new string[0];
        }
 public EventItfInfo(string strEventItfName, string strSrcItfName, string strEventProviderName, RuntimeAssembly asmImport, RuntimeAssembly asmSrcItf)
 {
     this.m_strEventItfName = strEventItfName;
     this.m_strSrcItfName = strSrcItfName;
     this.m_strEventProviderName = strEventProviderName;
     this.m_asmImport = asmImport;
     this.m_asmSrcItf = asmSrcItf;
 }
        /// <summary>
        ///     Create a factory which can generate evidence for the specified assembly
        /// </summary> 
        private AssemblyEvidenceFactory(RuntimeAssembly targetAssembly, PEFileEvidenceFactory peFileFactory)
        { 
            Contract.Assert(targetAssembly != null); 
            Contract.Assert(peFileFactory != null);
 
            m_targetAssembly = targetAssembly;
            m_peFileFactory = peFileFactory;
        }
 private Stream CaseInsensitiveManifestResourceStreamLookup(RuntimeAssembly satellite, string name)
 {
     StringBuilder builder = new StringBuilder();
     if (this._mediator.LocationInfo != null)
     {
         string str = this._mediator.LocationInfo.Namespace;
         if (str != null)
         {
             builder.Append(str);
             if (name != null)
             {
                 builder.Append(Type.Delimiter);
             }
         }
     }
     builder.Append(name);
     string str2 = builder.ToString();
     CompareInfo compareInfo = CultureInfo.InvariantCulture.CompareInfo;
     string str3 = null;
     foreach (string str4 in satellite.GetManifestResourceNames())
     {
         if (compareInfo.Compare(str4, str2, CompareOptions.IgnoreCase) == 0)
         {
             if (str3 != null)
             {
                 throw new MissingManifestResourceException(Environment.GetResourceString("MissingManifestResource_MultipleBlobs", new object[] { str2, satellite.ToString() }));
             }
             str3 = str4;
         }
     }
     if (FrameworkEventSource.IsInitialized)
     {
         if (str3 != null)
         {
             FrameworkEventSource.Log.ResourceManagerCaseInsensitiveResourceStreamLookupSucceeded(this._mediator.BaseName, this._mediator.MainAssembly, satellite.GetSimpleName(), str2);
         }
         else
         {
             FrameworkEventSource.Log.ResourceManagerCaseInsensitiveResourceStreamLookupFailed(this._mediator.BaseName, this._mediator.MainAssembly, satellite.GetSimpleName(), str2);
         }
     }
     if (str3 == null)
     {
         return null;
     }
     bool skipSecurityCheck = (this._mediator.MainAssembly == satellite) && (this._mediator.CallingAssembly == this._mediator.MainAssembly);
     StackCrawlMark lookForMyCaller = StackCrawlMark.LookForMyCaller;
     Stream stream = satellite.GetManifestResourceStream(str3, ref lookForMyCaller, skipSecurityCheck);
     if ((stream != null) && FrameworkEventSource.IsInitialized)
     {
         FrameworkEventSource.Log.ResourceManagerManifestResourceAccessDenied(this._mediator.BaseName, this._mediator.MainAssembly, satellite.GetSimpleName(), str3);
     }
     return stream;
 }
        internal static TypeForwardedToAttribute[] GetCustomAttribute(RuntimeAssembly assembly)
        {
            Type[] types = null;
            RuntimeAssembly.GetForwardedTypes(assembly.GetNativeHandle(), JitHelpers.GetObjectHandleOnStack(ref types));

            TypeForwardedToAttribute[] attributes = new TypeForwardedToAttribute[types.Length];
            for (int i = 0; i < types.Length; ++i)
                attributes[i] = new TypeForwardedToAttribute(types[i]);

            return attributes;
        }
 internal static TypeForwardedToAttribute[] GetCustomAttribute(RuntimeAssembly assembly)
 {
     Type[] o = null;
     RuntimeAssembly.GetForwardedTypes(assembly.GetNativeHandle(), JitHelpers.GetObjectHandleOnStack<Type[]>(ref o));
     TypeForwardedToAttribute[] attributeArray = new TypeForwardedToAttribute[o.Length];
     for (int i = 0; i < o.Length; i++)
     {
         attributeArray[i] = new TypeForwardedToAttribute(o[i]);
     }
     return attributeArray;
 }
 public EventItfInfo(String strEventItfName,
                     String strSrcItfName,
                     String strEventProviderName,
                     RuntimeAssembly asmImport,
                     RuntimeAssembly asmSrcItf)
 {
     m_strEventItfName = strEventItfName;
     m_strSrcItfName = strSrcItfName;
     m_strEventProviderName = strEventProviderName;
     m_asmImport = asmImport;
     m_asmSrcItf = asmSrcItf;
 }
#pragma warning disable 618
        private static void ThrowSecurityException(RuntimeAssembly asm, PermissionSet granted, PermissionSet refused, RuntimeMethodHandleInternal rmh, SecurityAction action, Object demand, IPermission permThatFailed)
#pragma warning restore 618
        {
            AssemblyName asmName = null;
            Evidence asmEvidence = null;
            if (asm != null)
            {
                // Assert here because reflection will check grants and if we fail the check,
                // there will be an infinite recursion that overflows the stack.
                PermissionSet.s_fullTrust.Assert();
                asmName = asm.GetName();
            }
            throw SecurityException.MakeSecurityException(asmName, asmEvidence, granted, refused, rmh, action, demand, permThatFailed);
        }
Example #12
0
 public sealed override Exception TryResolve(ReflectionDomain reflectionDomain, RuntimeAssembly currentAssembly, bool ignoreCase, out RuntimeType result)
 {
     result = null;
     if (AssemblyName == null)
     {
         return TypeName.TryResolve(reflectionDomain, currentAssembly, ignoreCase, out result);
     }
     else
     {
         RuntimeAssembly newAssembly;
         Exception assemblyLoadException = RuntimeAssembly.TryGetRuntimeAssembly(reflectionDomain, AssemblyName, out newAssembly);
         if (assemblyLoadException != null)
             return assemblyLoadException;
         return TypeName.TryResolve(reflectionDomain, newAssembly, ignoreCase, out result);
     }
 }
 public Hash(Assembly assembly)
 {
     if (assembly == null)
     {
         throw new ArgumentNullException("assembly");
     }
     if (assembly.IsDynamic)
     {
         throw new ArgumentException(Environment.GetResourceString("Security_CannotGenerateHash"), "assembly");
     }
     this.m_hashes = new Dictionary<Type, byte[]>();
     this.m_assembly = assembly as RuntimeAssembly;
     if (this.m_assembly == null)
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeAssembly"), "assembly");
     }
 }
 public ResourceManager(Type resourceSource)
 {
     if (null == resourceSource)
     {
         throw new ArgumentNullException("resourceSource");
     }
     if (!(resourceSource is RuntimeType))
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"));
     }
     this._locationInfo = resourceSource;
     this.MainAssembly = this._locationInfo.Assembly;
     this.BaseNameField = resourceSource.Name;
     this.CommonSatelliteAssemblyInit();
     this.m_callingAssembly = (RuntimeAssembly) Assembly.GetCallingAssembly();
     if ((this.MainAssembly == typeof(object).Assembly) && (this.m_callingAssembly != this.MainAssembly))
     {
         this.m_callingAssembly = null;
     }
 }
Example #15
0
        [System.Security.SecurityCritical]  // auto-generated
        internal static AssemblyName CreateAssemblyName(
            String assemblyString, 
            bool forIntrospection, 
            out RuntimeAssembly assemblyFromResolveEvent)
        {
            if (assemblyString == null)
                throw new ArgumentNullException("assemblyString");
            Contract.EndContractBlock();

            if ((assemblyString.Length == 0) ||
                (assemblyString[0] == '\0'))
                throw new ArgumentException(Environment.GetResourceString("Format_StringZeroLength"));

            if (forIntrospection)
                AppDomain.CheckReflectionOnlyLoadSupported();

            AssemblyName an = new AssemblyName();

            an.Name = assemblyString;
            assemblyFromResolveEvent = null; // instead of an.nInit(out assemblyFromResolveEvent, forIntrospection, true);
            return an;
        }
        internal RuntimeModule(RuntimeAssembly assembly, ICorDebugModule comModule)
        {
            _assembly = assembly;
            _comModule = comModule;

            Symbols = _assembly.Domain.Process.Session.SymbolsServer.GetSymbolsProviderForFile(this.Name);
            if (Symbols != null)
            {
                int index = 0, max = Session.PendingBreakpoints.Count;
                Session.ProgressReporter.Report("Symbol reader present. Finding pending breakpoints to set.");
                while (index < max)
                {
                    if (TrySetBreakpoint(Session.PendingBreakpoints[index]))
                    {
                        max--;
                        Session.PendingBreakpoints.RemoveAt(index);
                    }
                    else
                    {
                        index++;
                    }
                }
            }
        }
Example #17
0
        internal static RuntimeAssembly[] OnReflectionOnlyNamespaceResolveEvent(AppDomain appDomain, RuntimeAssembly assembly, string namespaceName)
        {
            EventHandler <NamespaceResolveEventArgs> eventHandler = ReflectionOnlyNamespaceResolve;

            if (eventHandler != null)
            {
                Delegate[] ds  = eventHandler.GetInvocationList();
                int        len = ds.Length;
                for (int i = 0; i < len; i++)
                {
                    NamespaceResolveEventArgs eventArgs = new NamespaceResolveEventArgs(namespaceName, assembly);

                    ((EventHandler <NamespaceResolveEventArgs>)ds[i])(appDomain, eventArgs);

                    Collection <Assembly> assembliesCollection = eventArgs.ResolvedAssemblies;
                    if (assembliesCollection.Count > 0)
                    {
                        RuntimeAssembly[] retAssemblies = new RuntimeAssembly[assembliesCollection.Count];
                        int retIndex = 0;
                        foreach (Assembly asm in assembliesCollection)
                        {
                            retAssemblies[retIndex] = AppDomain.GetRuntimeAssembly(asm);
                            retIndex++;
                        }
                        return(retAssemblies);
                    }
                }
            }

            return(null);
        }
Example #18
0
 private static extern unsafe bool InternalTryGetRawMetadata(RuntimeAssembly assembly, ref byte *blob, ref int length);
Example #19
0
        public void TrimsDotNiFromDllNames()
        {
            var assembly = RuntimeAssembly.Create("path/to/System.Collections.ni.dll");

            assembly.Name.Name.Should().Be("System.Collections");
        }
        [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable
        private Stream CaseInsensitiveManifestResourceStreamLookup(RuntimeAssembly satellite, String name)
        {
            Contract.Requires(satellite != null, "satellite shouldn't be null; check caller");
            Contract.Requires(name != null, "name shouldn't be null; check caller");

            StringBuilder sb = new StringBuilder();

            if (_mediator.LocationInfo != null)
            {
                String nameSpace = _mediator.LocationInfo.Namespace;
                if (nameSpace != null)
                {
                    sb.Append(nameSpace);
                    if (name != null)
                    {
                        sb.Append(Type.Delimiter);
                    }
                }
            }
            sb.Append(name);

            String      givenName     = sb.ToString();
            CompareInfo comparer      = CultureInfo.InvariantCulture.CompareInfo;
            String      canonicalName = null;

            foreach (String existingName in satellite.GetManifestResourceNames())
            {
                if (comparer.Compare(existingName, givenName, CompareOptions.IgnoreCase) == 0)
                {
                    if (canonicalName == null)
                    {
                        canonicalName = existingName;
                    }
                    else
                    {
                        throw new MissingManifestResourceException(Environment.GetResourceString("MissingManifestResource_MultipleBlobs", givenName, satellite.ToString()));
                    }
                }
            }

#if !FEATURE_CORECLR
            if (FrameworkEventSource.IsInitialized)
            {
                if (canonicalName != null)
                {
                    FrameworkEventSource.Log.ResourceManagerCaseInsensitiveResourceStreamLookupSucceeded(_mediator.BaseName, _mediator.MainAssembly, satellite.GetSimpleName(), givenName);
                }
                else
                {
                    FrameworkEventSource.Log.ResourceManagerCaseInsensitiveResourceStreamLookupFailed(_mediator.BaseName, _mediator.MainAssembly, satellite.GetSimpleName(), givenName);
                }
            }
#endif

            if (canonicalName == null)
            {
                return(null);
            }
            // If we're looking in the main assembly AND if the main
            // assembly was the person who created the ResourceManager,
            // skip a security check for private manifest resources.
            bool           canSkipSecurityCheck = _mediator.MainAssembly == satellite && _mediator.CallingAssembly == _mediator.MainAssembly;
            StackCrawlMark stackMark            = StackCrawlMark.LookForMyCaller;
            Stream         s = satellite.GetManifestResourceStream(canonicalName, ref stackMark, canSkipSecurityCheck);
            // GetManifestResourceStream will return null if we don't have
            // permission to read this stream from the assembly.  For example,
            // if the stream is private and we're trying to access it from another
            // assembly (ie, ResMgr in mscorlib accessing anything else), we
            // require Reflection TypeInformation permission to be able to read
            // this.
#if !FEATURE_CORECLR
            if (s != null)
            {
                if (FrameworkEventSource.IsInitialized)
                {
                    FrameworkEventSource.Log.ResourceManagerManifestResourceAccessDenied(_mediator.BaseName, _mediator.MainAssembly, satellite.GetSimpleName(), canonicalName);
                }
            }
#endif
            return(s);
        }
 internal static extern bool GetNeutralResourcesLanguageAttribute(RuntimeAssembly assemblyHandle, StringHandleOnStack cultureName, out short fallbackLocation);
Example #22
0
 internal static extern IntPtr LoadByName(string libraryName, RuntimeAssembly callingAssembly,
                                          bool hasDllImportSearchPathFlag, uint dllImportSearchPathFlag,
                                          bool throwOnError);
        private RuntimeAssembly OnAssemblyResolveEvent(RuntimeAssembly assembly, String assemblyFullName)
        {
            ResolveEventHandler eventHandler = _AssemblyResolve;

            if (eventHandler == null)
            {
                return null;
            }

#if FEATURE_FUSION
            Delegate[] ds = eventHandler.GetInvocationList();
            int len = ds.Length;
            for (int i = 0; i < len; i++) {
                Assembly asm = ((ResolveEventHandler)ds[i])(this, new ResolveEventArgs(assemblyFullName, assembly));
                RuntimeAssembly ret = GetRuntimeAssembly(asm);
                if (ret != null)
                    return ret;
            }
            
            return null;
#endif // FEATURE_FUSION

#if FEATURE_VERSIONING
            return TryToResolveAssembly(assembly, assemblyFullName, eventHandler, false);
#endif // FEATURE_VERSIONING
        }
 private extern int _nExecuteAssembly(RuntimeAssembly assembly, String[] args);
Example #25
0
 private static extern void nConvertTypeLibToMetadata(Object typeLib, RuntimeAssembly asmBldr, RuntimeModule modBldr, String nameSpace, TypeLibImporterFlags flags, ITypeLibImporterNotifySink notifySink, out ArrayList eventItfInfoList);
Example #26
0
        internal AssemblyBuilder(AppDomain domain,
                                 AssemblyName name,
                                 AssemblyBuilderAccess access,
                                 String dir,
                                 Evidence evidence,
                                 ref StackCrawlMark stackMark,
                                 IEnumerable <CustomAttributeBuilder> unsafeAssemblyAttributes,
                                 SecurityContextSource securityContextSource)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            if (access != AssemblyBuilderAccess.Run &&
                access != AssemblyBuilderAccess.RunAndCollect
                )
            {
                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();

            // 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,
                                                                                        securityRulesBlob,
                                                                                        aptcaBlob,
                                                                                        access,
                                                                                        assemblyFlags,
                                                                                        securityContextSource);

            m_assemblyData = new AssemblyBuilderData(m_internalAssemblyBuilder,
                                                     name.Name,
                                                     access,
                                                     dir);
#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);
                }
            }
        }
Example #27
0
 private static extern IntPtr GetLoadContextForAssembly(RuntimeAssembly assembly);
Example #28
0
 private static extern RuntimeModule GetInMemoryAssemblyModule(RuntimeAssembly assembly);
Example #29
0
 static IntPtr LoadByName(string libraryName, RuntimeAssembly callingAssembly, bool hasDllImportSearchPathFlag, uint dllImportSearchPathFlag, bool throwOnError) => throw new NotImplementedException();
Example #30
0
        public void MergesRuntimeAndCompileLibrariesForPortable()
        {
            var result = Save(Create(
                                  "Target",
                                  "runtime",
                                  true,
                                  compileLibraries: new[]
            {
                new CompilationLibrary(
                    "package",
                    "PackageName",
                    "1.2.3",
                    "HASH",
                    new [] { "ref/Banana.dll" },
                    new [] {
                    new Dependency("Fruits.Abstract.dll", "2.0.0")
                },
                    true
                    )
            },
                                  runtimeLibraries: new[]
            {
                new RuntimeLibrary(
                    "package",
                    "PackageName",
                    "1.2.3",
                    "HASH",
                    new [] { RuntimeAssembly.Create("Banana.dll") },
                    new ResourceAssembly[] {},
                    new []
                {
                    new RuntimeTarget("win7-x64",
                                      new [] { RuntimeAssembly.Create("Banana.Win7-x64.dll") },
                                      new [] { "Banana.Win7-x64.so" }
                                      )
                },
                    new [] {
                    new Dependency("Fruits.Abstract.dll", "2.0.0")
                },
                    true
                    ),
            }));

            // targets
            var targets      = result.Should().HavePropertyAsObject("targets").Subject;
            var target       = targets.Should().HavePropertyAsObject("Target").Subject;
            var library      = target.Should().HavePropertyAsObject("PackageName/1.2.3").Subject;
            var dependencies = library.Should().HavePropertyAsObject("dependencies").Subject;

            dependencies.Should().HavePropertyValue("Fruits.Abstract.dll", "2.0.0");
            library.Should().HavePropertyAsObject("runtime")
            .Subject.Should().HaveProperty("Banana.dll");

            library.Should().HavePropertyAsObject("compile")
            .Subject.Should().HaveProperty("ref/Banana.dll");

            var runtimeTargets = library.Should().HavePropertyAsObject("runtimeTargets").Subject;

            var runtimeAssembly = runtimeTargets.Should().HavePropertyAsObject("Banana.Win7-x64.dll").Subject;

            runtimeAssembly.Should().HavePropertyValue("rid", "win7-x64");
            runtimeAssembly.Should().HavePropertyValue("assetType", "runtime");

            var nativeLibrary = runtimeTargets.Should().HavePropertyAsObject("Banana.Win7-x64.so").Subject;

            nativeLibrary.Should().HavePropertyValue("rid", "win7-x64");
            nativeLibrary.Should().HavePropertyValue("assetType", "native");

            //libraries
            var libraries = result.Should().HavePropertyAsObject("libraries").Subject;

            library = libraries.Should().HavePropertyAsObject("PackageName/1.2.3").Subject;
            library.Should().HavePropertyValue("sha512", "HASH");
            library.Should().HavePropertyValue("type", "package");
            library.Should().HavePropertyValue("serviceable", true);
        }
 private void OnAssemblyLoadEvent(RuntimeAssembly LoadedAssembly)
 {
     AssemblyLoadEventHandler eventHandler = AssemblyLoad;
     if (eventHandler != null) {
         AssemblyLoadEventArgs ea = new AssemblyLoadEventArgs(LoadedAssembly);
         eventHandler(this, ea);
     }
 }
Example #32
0
        private static RuntimeAssembly?InvokeResolveEvent(ResolveEventHandler?eventHandler, RuntimeAssembly assembly, string name)
        {
            if (eventHandler == null)
            {
                return(null);
            }

            var args = new ResolveEventArgs(name, assembly);

            foreach (ResolveEventHandler handler in eventHandler.GetInvocationList())
            {
                Assembly?asm = handler(AppDomain.CurrentDomain, args);
#if CORECLR
                if (eventHandler == AssemblyResolve && AssemblyLoadContext.IsTracingEnabled())
                {
                    AssemblyLoadContext.TraceAssemblyResolveHandlerInvoked(
                        name,
                        handler.Method.Name,
                        asm?.FullName,
                        asm != null && !asm.IsDynamic ? asm.Location : null);
                }
#endif // CORECLR
                RuntimeAssembly?ret = GetRuntimeAssembly(asm);
                if (ret != null)
                {
                    return(ret);
                }
            }

            return(null);
        }
 // Called by VM - code:CLRPrivTypeCacheReflectionOnlyWinRT::RaiseNamespaceResolveEvent
 private RuntimeAssembly[] OnReflectionOnlyNamespaceResolveEvent(RuntimeAssembly assembly, string namespaceName)
 {
     return System.Runtime.InteropServices.WindowsRuntime.WindowsRuntimeMetadata.OnReflectionOnlyNamespaceResolveEvent(this, assembly, namespaceName);
 }
Example #34
0
 private RuntimeModule(RuntimeAssembly assembly)
     : base()
 {
     _assembly = assembly;
 }
Example #35
0
        private bool ShouldUseSatelliteAssemblyResourceLookupUnderAppX(RuntimeAssembly resourcesAssembly)
        {
            bool fUseSatelliteAssemblyResourceLookupUnderAppX = resourcesAssembly.IsFrameworkAssembly();
            
#if FEATURE_CORECLR     
            if (!fUseSatelliteAssemblyResourceLookupUnderAppX)
            {
                // Check to see if the assembly is under PLATFORM_RESOURCE_ROOTS. If it is, then we should use satellite assembly lookup for it.
                String platformResourceRoots = (String)(AppDomain.CurrentDomain.GetData("PLATFORM_RESOURCE_ROOTS"));
                if ((platformResourceRoots != null) && (platformResourceRoots != String.Empty))
                {
                    string resourceAssemblyPath = resourcesAssembly.Location;
                    
                    // Loop through the PLATFORM_RESOURCE_ROOTS and see if the assembly is contained in it.
                    foreach(string pathPlatformResourceRoot in platformResourceRoots.Split(Path.PathSeparator))
                    {
                        if (resourceAssemblyPath.StartsWith(pathPlatformResourceRoot, StringComparison.CurrentCultureIgnoreCase))
                        {
                            // Found the resource assembly to be present in one of the PLATFORM_RESOURCE_ROOT, so stop the enumeration loop.
                            fUseSatelliteAssemblyResourceLookupUnderAppX = true;
                            break;
                        }
                    }
                }
            }
#endif // FEATURE_CORECLR
            return fUseSatelliteAssemblyResourceLookupUnderAppX;
            
        }
Example #36
0
        [System.Security.SecurityCritical]  // auto-generated
        private unsafe void Init(String name,
                                 MethodAttributes attributes,
                                 CallingConventions callingConvention,
                                 Type returnType,
                                 Type[] signature,
                                 Type owner,
                                 Module m,
                                 bool skipVisibility,
                                 bool transparentMethod,
                                 ref StackCrawlMark stackMark)
        {
            DynamicMethod.CheckConsistency(attributes, callingConvention);

            // check and store the signature
            if (signature != null)
            {
                m_parameterTypes = new RuntimeType[signature.Length];
                for (int i = 0; i < signature.Length; i++)
                {
                    if (signature[i] == null)
                    {
                        throw new ArgumentException(Environment.GetResourceString("Arg_InvalidTypeInSignature"));
                    }
                    m_parameterTypes[i] = signature[i].UnderlyingSystemType as RuntimeType;
                    if (m_parameterTypes[i] == null || !(m_parameterTypes[i] is RuntimeType) || m_parameterTypes[i] == (RuntimeType)typeof(void))
                    {
                        throw new ArgumentException(Environment.GetResourceString("Arg_InvalidTypeInSignature"));
                    }
                }
            }
            else
            {
                m_parameterTypes = Array.Empty <RuntimeType>();
            }

            // check and store the return value
            m_returnType = (returnType == null) ? (RuntimeType)typeof(void) : returnType.UnderlyingSystemType as RuntimeType;
            if ((m_returnType == null) || !(m_returnType is RuntimeType) || m_returnType.IsByRef)
            {
                throw new NotSupportedException(Environment.GetResourceString("Arg_InvalidTypeInRetType"));
            }

            if (transparentMethod)
            {
                Contract.Assert(owner == null && m == null, "owner and m cannot be set for transparent methods");
                m_module = GetDynamicMethodsModule();
                if (skipVisibility)
                {
                    m_restrictedSkipVisibility = true;
                }

#if FEATURE_COMPRESSEDSTACK
                m_creationContext = CompressedStack.Capture();
#endif // FEATURE_COMPRESSEDSTACK
            }
            else
            {
                Contract.Assert(m != null || owner != null, "PerformSecurityCheck should ensure that either m or owner is set");
                Contract.Assert(m == null || !m.Equals(s_anonymouslyHostedDynamicMethodsModule), "The user cannot explicitly use this assembly");
                Contract.Assert(m == null || owner == null, "m and owner cannot both be set");

                if (m != null)
                {
                    m_module = m.ModuleHandle.GetRuntimeModule(); // this returns the underlying module for all RuntimeModule and ModuleBuilder objects.
                }
                else
                {
                    RuntimeType rtOwner = null;
                    if (owner != null)
                    {
                        rtOwner = owner.UnderlyingSystemType as RuntimeType;
                    }

                    if (rtOwner != null)
                    {
                        if (rtOwner.HasElementType || rtOwner.ContainsGenericParameters ||
                            rtOwner.IsGenericParameter || rtOwner.IsInterface)
                        {
                            throw new ArgumentException(Environment.GetResourceString("Argument_InvalidTypeForDynamicMethod"));
                        }

                        m_typeOwner = rtOwner;
                        m_module    = rtOwner.GetRuntimeModule();
                    }
                }

                m_skipVisibility = skipVisibility;
            }

            // initialize remaining fields
            m_ilGenerator  = null;
            m_fInitLocals  = true;
            m_methodHandle = null;

            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

#if FEATURE_APPX
            if (AppDomain.ProfileAPICheck)
            {
                if (m_creatorAssembly == null)
                {
                    m_creatorAssembly = RuntimeAssembly.GetExecutingAssembly(ref stackMark);
                }

                if (m_creatorAssembly != null && !m_creatorAssembly.IsFrameworkAssembly())
                {
                    m_profileAPICheck = true;
                }
            }
#endif // FEATURE_APPX

            m_dynMethod = new RTDynamicMethod(this, name, attributes, callingConvention);
        }
Example #37
0
        [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable
        public ResourceManager(String baseName, Assembly assembly)
        {
            if (null==baseName)
                throw new ArgumentNullException("baseName");

            if (null==assembly)
                throw new ArgumentNullException("assembly");
            Contract.EndContractBlock();

            if (!(assembly is RuntimeAssembly))
                throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeAssembly"));

            MainAssembly = assembly;
            BaseNameField = baseName;

            SetAppXConfiguration();

            CommonAssemblyInit();

            m_callingAssembly = (RuntimeAssembly)Assembly.GetCallingAssembly();
            // Special case for mscorlib - protect mscorlib's private resources.
            // This isn't for security reasons, but to ensure we can make
            // breaking changes to mscorlib's internal resources without 
            // assuming users may have taken a dependency on them.
            if (assembly == typeof(Object).Assembly && m_callingAssembly != assembly)
            {
                m_callingAssembly = null;
            }
        }
        [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var have to be marked non-inlineable
        public ResourceSet GrovelForResourceSet(CultureInfo culture, Dictionary <String, ResourceSet> localResourceSets, bool tryParents, bool createIfNotExists, ref StackCrawlMark stackMark)
        {
            Contract.Assert(culture != null, "culture shouldn't be null; check caller");
            Contract.Assert(localResourceSets != null, "localResourceSets shouldn't be null; check caller");

            ResourceSet     rs        = null;
            Stream          stream    = null;
            RuntimeAssembly satellite = null;

            // 1. Fixups for ultimate fallbacks
            CultureInfo lookForCulture = UltimateFallbackFixup(culture);

            // 2. Look for satellite assembly or main assembly, as appropriate
            if (lookForCulture.HasInvariantCultureName && _mediator.FallbackLoc == UltimateResourceFallbackLocation.MainAssembly)
            {
                // don't bother looking in satellites in this case
                satellite = _mediator.MainAssembly;
            }
#if RESOURCE_SATELLITE_CONFIG
            // If our config file says the satellite isn't here, don't ask for it.
            else if (!lookForCulture.HasInvariantCultureName && !_mediator.TryLookingForSatellite(lookForCulture))
            {
                satellite = null;
            }
#endif
            else
            {
                satellite = GetSatelliteAssembly(lookForCulture, ref stackMark);

                if (satellite == null)
                {
                    bool raiseException = (culture.HasInvariantCultureName && (_mediator.FallbackLoc == UltimateResourceFallbackLocation.Satellite));
                    // didn't find satellite, give error if necessary
                    if (raiseException)
                    {
                        HandleSatelliteMissing();
                    }
                }
            }

            // get resource file name we'll search for. Note, be careful if you're moving this statement
            // around because lookForCulture may be modified from originally requested culture above.
            String fileName = _mediator.GetResourceFileName(lookForCulture);

            // 3. If we identified an assembly to search; look in manifest resource stream for resource file
            if (satellite != null)
            {
                // Handle case in here where someone added a callback for assembly load events.
                // While no other threads have called into GetResourceSet, our own thread can!
                // At that point, we could already have an RS in our hash table, and we don't
                // want to add it twice.
                lock (localResourceSets)
                {
                    if (localResourceSets.TryGetValue(culture.Name, out rs))
                    {
#if !FEATURE_CORECLR
                        if (FrameworkEventSource.IsInitialized)
                        {
                            FrameworkEventSource.Log.ResourceManagerFoundResourceSetInCacheUnexpected(_mediator.BaseName, _mediator.MainAssembly, culture.Name);
                        }
#endif
                    }
                }

                stream = GetManifestResourceStream(satellite, fileName, ref stackMark);
            }

#if !FEATURE_CORECLR
            if (FrameworkEventSource.IsInitialized)
            {
                if (stream != null)
                {
                    FrameworkEventSource.Log.ResourceManagerStreamFound(_mediator.BaseName, _mediator.MainAssembly, culture.Name, satellite, fileName);
                }
                else
                {
                    FrameworkEventSource.Log.ResourceManagerStreamNotFound(_mediator.BaseName, _mediator.MainAssembly, culture.Name, satellite, fileName);
                }
            }
#endif

            // 4a. Found a stream; create a ResourceSet if possible
            if (createIfNotExists && stream != null && rs == null)
            {
#if !FEATURE_CORECLR
                if (FrameworkEventSource.IsInitialized)
                {
                    FrameworkEventSource.Log.ResourceManagerCreatingResourceSet(_mediator.BaseName, _mediator.MainAssembly, culture.Name, fileName);
                }
#endif
                rs = CreateResourceSet(stream, satellite);
            }
            else if (stream == null && tryParents)
            {
                // 4b. Didn't find stream; give error if necessary
                bool raiseException = culture.HasInvariantCultureName;
                if (raiseException)
                {
                    HandleResourceStreamMissing(fileName);
                }
            }

#if !FEATURE_CORECLR
            if (!createIfNotExists && stream != null && rs == null)
            {
                if (FrameworkEventSource.IsInitialized)
                {
                    FrameworkEventSource.Log.ResourceManagerNotCreatingResourceSet(_mediator.BaseName, _mediator.MainAssembly, culture.Name);
                }
            }
#endif

            return(rs);
        }
Example #39
0
        [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable
        public ResourceManager(Type resourceSource)
        {
            if (null==resourceSource)
                throw new ArgumentNullException("resourceSource");
            Contract.EndContractBlock();

            if (!(resourceSource is RuntimeType))
                throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeType"));

            _locationInfo = resourceSource;
            MainAssembly = _locationInfo.Assembly;
            BaseNameField = resourceSource.Name;
            
            SetAppXConfiguration();

            CommonAssemblyInit();

            m_callingAssembly = (RuntimeAssembly)Assembly.GetCallingAssembly();
            // Special case for mscorlib - protect mscorlib's private resources.
            if (MainAssembly == typeof(Object).Assembly && m_callingAssembly != MainAssembly)
            {
                m_callingAssembly = null;
            }
        }
Example #40
0
 public EventItfInfo(string strEventItfName, string strSrcItfName, string strEventProviderName, RuntimeAssembly asmImport, RuntimeAssembly asmSrcItf)
 {
     this.m_strEventItfName      = strEventItfName;
     this.m_strSrcItfName        = strSrcItfName;
     this.m_strEventProviderName = strEventProviderName;
     this.m_asmImport            = asmImport;
     this.m_asmSrcItf            = asmSrcItf;
 }
Example #41
0
        public void UsesFileNameAsAssemblyNameInCreate()
        {
            var assembly = RuntimeAssembly.Create("path/to/System.Collections.dll");

            assembly.Name.Name.Should().Be("System.Collections");
        }
Example #42
0
 private static extern Object nConvertAssemblyToTypeLib(RuntimeAssembly assembly, String strTypeLibName, TypeLibExporterFlags flags, ITypeLibExporterNotifySink notifySink);
Example #43
0
 private static void OnAssemblyLoad(RuntimeAssembly assembly)
 {
     AssemblyLoad?.Invoke(null /* AppDomain */, new AssemblyLoadEventArgs(assembly));
 }
Example #44
0
 private Hash(Hash hash)
 {
     this.m_assembly = hash.m_assembly;
     this.m_rawData  = hash.m_rawData;
     this.m_hashes   = new Dictionary <Type, byte[]>((IDictionary <Type, byte[]>)hash.m_hashes);
 }
Example #45
0
 public override AssemblyName[] GetReferencedAssemblies() => RuntimeAssembly.GetReferencedAssemblies(this);
 internal static extern void PublishAnonymouslyHostedDynamicMethodsAssembly(RuntimeAssembly assemblyHandle);
Example #47
0
 [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod
 public override Assembly GetSatelliteAssembly(CultureInfo culture, Version?version) =>
 RuntimeAssembly.InternalGetSatelliteAssembly(this, culture, version, true) !;
 internal int nExecuteAssembly(RuntimeAssembly assembly, String[] args)
 {
     return _nExecuteAssembly(assembly, args);
 }
 // This method is called by the VM.
 private static void OnAssemblyLoad(RuntimeAssembly assembly)
 {
     AssemblyLoad?.Invoke(AppDomain.CurrentDomain, new AssemblyLoadEventArgs(assembly));
 }
        private RuntimeAssembly OnReflectionOnlyAssemblyResolveEvent(RuntimeAssembly  assembly, String assemblyFullName)
        {
            ResolveEventHandler eventHandler = ReflectionOnlyAssemblyResolve;
            if (eventHandler != null) {

                Delegate[] ds = eventHandler.GetInvocationList();
                int len = ds.Length;
                for (int i = 0; i < len; i++) {
                    Assembly asm = ((ResolveEventHandler)ds[i])(this, new ResolveEventArgs(assemblyFullName, assembly));
                    RuntimeAssembly ret = GetRuntimeAssembly(asm);
                    if (ret != null)
                        return ret;
                }
            }

            return null;
        }
 // This method is called by the VM.
 private static RuntimeAssembly?OnResourceResolve(RuntimeAssembly assembly, string resourceName)
 {
     return(InvokeResolveEvent(ResourceResolve, assembly, resourceName));
 }
        private bool IsAssemblyOnAptcaVisibleList(RuntimeAssembly assembly)
        {
            if (_aptcaVisibleAssemblies == null)
                return false;

            AssemblyName assemblyName = assembly.GetName();
            String name = assemblyName.GetNameWithPublicKey();

            name = name.ToUpperInvariant();

            int index = Array.BinarySearch<string>(_aptcaVisibleAssemblies, name,
                                                   StringComparer.OrdinalIgnoreCase);
            return (index >=0);

        }
 // This method is called by the VM
 private static RuntimeAssembly?OnTypeResolve(RuntimeAssembly assembly, string typeName)
 {
     return(InvokeResolveEvent(TypeResolve, assembly, typeName));
 }
Example #54
0
 [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable
 private void Init()
 {
     m_callingAssembly = (RuntimeAssembly)Assembly.GetCallingAssembly();
 }
 // This method is called by the VM.
 private static RuntimeAssembly?OnAssemblyResolve(RuntimeAssembly assembly, string assemblyFullName)
 {
     return(InvokeResolveEvent(AssemblyResolve, assembly, assemblyFullName));
 }
Example #56
0
        [MethodImplAttribute(MethodImplOptions.NoInlining)] // Methods containing StackCrawlMark local var has to be marked non-inlineable
        public ResourceManager(String baseName, Assembly assembly, Type usingResourceSet)
        {
            if (null==baseName)
                throw new ArgumentNullException("baseName");
            if (null==assembly)
                throw new ArgumentNullException("assembly");
            Contract.EndContractBlock();

#if !FEATURE_CORECLR
            // This constructor is not designed to be used under AppX and is not in the Win8 profile.
            // However designers may use them even if they are running under AppX since they are
            // not subject to the restrictions of the Win8 profile.
            Contract.Assert(!AppDomain.IsAppXModel() || AppDomain.IsAppXDesignMode());
#endif

            if (!(assembly is RuntimeAssembly))
                throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeAssembly"));

            MainAssembly = assembly;
            BaseNameField = baseName;
    
            if (usingResourceSet != null && (usingResourceSet != _minResourceSet) && !(usingResourceSet.IsSubclassOf(_minResourceSet)))
                throw new ArgumentException(Environment.GetResourceString("Arg_ResMgrNotResSet"), "usingResourceSet");
            _userResourceSet = usingResourceSet;

            CommonAssemblyInit();
            m_callingAssembly = (RuntimeAssembly)Assembly.GetCallingAssembly();
            // Special case for mscorlib - protect mscorlib's private resources.
            // This isn't for security reasons, but to ensure we can make
            // breaking changes to mscorlib's internal resources without 
            // assuming users may have taken a dependency on them.
            if (assembly == typeof(Object).Assembly && m_callingAssembly != assembly)
                m_callingAssembly = null;
        }
        private static RuntimeAssembly?InvokeResolveEvent(ResolveEventHandler eventHandler, RuntimeAssembly assembly, string name)
        {
            if (eventHandler == null)
            {
                return(null);
            }

            var args = new ResolveEventArgs(name, assembly);

            foreach (ResolveEventHandler handler in eventHandler.GetInvocationList())
            {
                Assembly?       asm = handler(AppDomain.CurrentDomain, args);
                RuntimeAssembly?ret = GetRuntimeAssembly(asm);
                if (ret != null)
                {
                    return(ret);
                }
            }

            return(null);
        }
Example #58
0
        private void OnDeserialized(StreamingContext ctx)
        {
            _resourceSets = new Dictionary<String, ResourceSet>();
            _lastUsedResourceCache = new CultureNameResourceSetPair();
            // set up resource groveler, depending on whether this ResourceManager
            // is looking for files or assemblies
            ResourceManagerMediator mediator = new ResourceManagerMediator(this);
            if (UseManifest)
            {
                resourceGroveler = new ManifestBasedResourceGroveler(mediator);
            }
            else
            {
                resourceGroveler = new FileBasedResourceGroveler(mediator);
            }

            // correct callingAssembly for v2
            if (this.m_callingAssembly == null)
            {
                this.m_callingAssembly = (RuntimeAssembly)_callingAssembly;
            }

            // v2 does this lazily
            if (UseManifest && this._neutralResourcesCulture == null)
            {
                _neutralResourcesCulture = ManifestBasedResourceGroveler.GetNeutralResourcesLanguage(MainAssembly, ref _fallbackLoc);
            }
        }
Example #59
0
 extern static IntPtr GetLoadContextForAssembly(RuntimeAssembly rtAsm);