Пример #1
0
        internal static ObjectHandle CreateInstance(string assemblyName, string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes, Evidence securityInfo, ref StackCrawlMark stackMark)
        {
            Assembly assembly;

            if (assemblyName == null)
            {
                assembly = Assembly.nGetExecutingAssembly(ref stackMark);
            }
            else
            {
                assembly = Assembly.InternalLoad(assemblyName, securityInfo, ref stackMark, false);
            }
            if (assembly == null)
            {
                return(null);
            }
            object o = CreateInstance(assembly.GetType(typeName, true, ignoreCase), bindingAttr, binder, args, culture, activationAttributes);

            if (o == null)
            {
                return(null);
            }
            return(new ObjectHandle(o));
        }
Пример #2
0
 public int ExecuteAssembly(String assemblyFile, Evidence assemblySecurity,
                            String[] args)
 {
     return(ExecuteAssembly(assemblyFile, assemblySecurity,
                            args, null, AssemblyHashAlgorithm.None));
 }
Пример #3
0
 public Assembly Load(byte[] rawAssembly, byte[] rawSymbolStore,
                      Evidence assemblySecurity)
 {
     return(Load(rawAssembly, rawSymbolStore, assemblySecurity,
                 Assembly.GetCallingAssembly()));
 }
Пример #4
0
        // Used to switch into other AppDomain and call SetupRemoteDomain.
        //   We cannot simply call through the proxy, because if there
        //   are any remoting sinks registered, they can add non-mscorlib
        //   objects to the message (causing an assembly load exception when
        //   we try to deserialize it on the other side)
        private static object PrepareDataForSetup(String friendlyName,
                                                  AppDomainSetup setup,
                                                  Evidence providedSecurityInfo,
                                                  Evidence creatorsSecurityInfo,
                                                  IntPtr parentSecurityDescriptor,
                                                  string sandboxName,
                                                  string[] propertyNames,
                                                  string[] propertyValues)
        {
            byte[] serializedEvidence      = null;
            bool   generateDefaultEvidence = false;

            AppDomainInitializerInfo initializerInfo = null;

            if (setup != null && setup.AppDomainInitializer != null)
            {
                initializerInfo = new AppDomainInitializerInfo(setup.AppDomainInitializer);
            }

            // will travel x-Ad, drop non-agile data
            AppDomainSetup newSetup = new AppDomainSetup(setup, false);

            // Remove the special AppDomainCompatSwitch entries from the set of name value pairs
            // And add them to the AppDomainSetup
            //
            // This is only supported on CoreCLR through ICLRRuntimeHost2.CreateAppDomainWithManager
            // Desktop code should use System.AppDomain.CreateDomain() or
            // System.AppDomainManager.CreateDomain() and add the flags to the AppDomainSetup
            List <String> compatList = new List <String>();

            if (propertyNames != null && propertyValues != null)
            {
                for (int i = 0; i < propertyNames.Length; i++)
                {
                    if (String.Compare(propertyNames[i], "AppDomainCompatSwitch", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        compatList.Add(propertyValues[i]);
                        propertyNames[i]  = null;
                        propertyValues[i] = null;
                    }
                }

                if (compatList.Count > 0)
                {
                    newSetup.SetCompatibilitySwitches(compatList);
                }
            }

            return(new Object[]
            {
                friendlyName,
                newSetup,
                parentSecurityDescriptor,
                generateDefaultEvidence,
                serializedEvidence,
                initializerInfo,
                sandboxName,
                propertyNames,
                propertyValues
            });
        } // PrepareDataForSetup
Пример #5
0
        public static ObjectHandle CreateInstance(string assemblyName, string typeName, bool ignoreCase,
                                                  BindingFlags bindingAttr, Binder binder, object [] args,
                                                  CultureInfo culture, object [] activationAttributes, Evidence securityInfo)
        {
            Assembly assembly = null;

            if (assemblyName == null)
            {
                assembly = Assembly.GetCallingAssembly();
            }
            else
            {
                assembly = Assembly.Load(assemblyName, securityInfo);
            }
            Type   type = assembly.GetType(typeName, true, ignoreCase);
            object obj  = CreateInstance(type, bindingAttr, binder, args, culture, activationAttributes);

            return((obj != null) ? new ObjectHandle(obj) : null);
        }
Пример #6
0
 internal Assembly LoadAssembly(string assemblyRef, Evidence securityEvidence, bool refOnly)
 {
     throw new System.NotImplementedException();
 }
Пример #7
0
 public virtual AppDomain CreateDomain(string friendlyName, Evidence securityInfo, AppDomainSetup appDomainInfo)
 {
     throw new NotImplementedException();
 }
Пример #8
0
        public int ExecuteAssemblyByName(AssemblyName assemblyName, Evidence assemblySecurity, params string[] args)
        {
            Assembly a = Assembly.Load(assemblyName, assemblySecurity);

            return(ExecuteAssemblyInternal(a, args));
        }
Пример #9
0
 public AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, string dir,
                                              Evidence evidence)
 {
     return(DefineDynamicAssembly(name, access, dir, evidence, null, null, null, false));
 }
Пример #10
0
 public static AppDomain CreateDomain(string friendlyName, Evidence securityInfo, string appBasePath,
                                      string appRelativeSearchPath, bool shadowCopyFiles, AppDomainInitializer adInit, string[] adInitArgs)
 {
     return(CreateDomain(friendlyName, securityInfo, appBasePath, appRelativeSearchPath, shadowCopyFiles));
 }
Пример #11
0
 public int ExecuteAssemblyByName(string assemblyName, Evidence assemblySecurity)
 {
     return(ExecuteAssemblyByName(assemblyName, assemblySecurity, null));
 }
Пример #12
0
 public static AppDomain CreateDomain(string friendlyName, Evidence securityInfo, AppDomainSetup info,
                                      PermissionSet grantSet, params StrongName [] fullTrustAssemblies)
 {
     throw new NotImplementedException();
 }
Пример #13
0
 public static ObjectHandle CreateInstanceFrom(AppDomain domain, string assemblyFile, string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes, Evidence securityAttributes)
 {
     if (domain == null)
     {
         throw new ArgumentNullException("domain");
     }
     return(domain.InternalCreateInstanceFromWithNoSecurity(assemblyFile, typeName, ignoreCase, bindingAttr, binder, args, culture, activationAttributes, securityAttributes));
 }
Пример #14
0
        public static ObjectHandle CreateInstanceFrom(string assemblyFile, string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes, Evidence securityInfo)
        {
            object o = CreateInstance(Assembly.LoadFrom(assemblyFile, securityInfo).GetType(typeName, true, ignoreCase), bindingAttr, binder, args, culture, activationAttributes);

            if (o == null)
            {
                return(null);
            }
            return(new ObjectHandle(o));
        }
Пример #15
0
 public static AppDomain CreateDomain(string friendlyName, Evidence securityInfo)
 {
     return(CreateDomain(friendlyName, securityInfo, null));
 }
Пример #16
0
 public AssemblyBuilder DefineDynamicAssembly(AssemblyName name, AssemblyBuilderAccess access, Evidence evidence,
                                              PermissionSet requiredPermissions,
                                              PermissionSet optionalPermissions,
                                              PermissionSet refusedPermissions)
 {
     return(DefineDynamicAssembly(name, access, null, evidence, requiredPermissions, optionalPermissions,
                                  refusedPermissions, false));
 }
Пример #17
0
        public static AppDomain CreateDomain(string friendlyName, Evidence securityInfo, AppDomainSetup info)
        {
            if (friendlyName == null)
            {
                throw new System.ArgumentNullException("friendlyName");
            }

            AppDomain def = AppDomain.DefaultDomain;

            if (info == null)
            {
                // if null, get default domain's SetupInformation
                if (def == null)
                {
                    info = new AppDomainSetup();                        // we're default!
                }
                else
                {
                    info = def.SetupInformation;
                }
            }
            else
            {
                info = new AppDomainSetup(info);                        // copy
            }
            // todo: allow setup in the other domain
            if (def != null)
            {
                if (!info.Equals(def.SetupInformation))
                {
                    // If not specified use default domain's app base.
                    if (info.ApplicationBase == null)
                    {
                        info.ApplicationBase = def.SetupInformation.ApplicationBase;
                    }
                    if (info.ConfigurationFile == null)
                    {
                        info.ConfigurationFile = Path.GetFileName(def.SetupInformation.ConfigurationFile);
                    }
                }
            }
            else if (info.ConfigurationFile == null)
            {
                info.ConfigurationFile = "[I don't have a config file]";
            }


            AppDomain ad = (AppDomain)RemotingServices.GetDomainProxy(createDomain(friendlyName, info));

            if (securityInfo == null)
            {
                // get default domain's Evidence (unless we're are the default!)
                if (def == null)
                {
                    ad._evidence = null;                                // we'll get them later (GetEntryAssembly)
                }
                else
                {
                    ad._evidence = def.Evidence;                        // new (shallow) copy
                }
            }
            else
            {
                ad._evidence = new Evidence(securityInfo);                      // copy
            }
#endif
#if NET_2_0
        if (info.AppDomainInitializer != null)
        {
            if ((info.AppDomainInitializer.Method.Attributes & MethodAttributes.Static) == 0)
            {
                throw new ArgumentException("Non-static methods cannot be invoked as an appdomain initializer");
            }
            info.AppDomainInitializer(info.AppDomainInitializerArguments);
        }

        return(ad);
    }
Пример #18
0
 public int ExecuteAssembly(string assemblyFile, Evidence assemblySecurity)
 {
     return(ExecuteAssembly(assemblyFile, assemblySecurity, null));
 }
Пример #19
0
 internal Assembly LoadAssemblyRaw(byte[] rawAssembly, byte[] rawSymbolStore, Evidence securityEvidence, bool refonly)
 {
     throw new System.NotImplementedException();
 }
Пример #20
0
        public int ExecuteAssembly(string assemblyFile, Evidence assemblySecurity, string[] args)
        {
            Assembly a = Assembly.LoadFrom(assemblyFile, assemblySecurity);

            return(ExecuteAssemblyInternal(a, args));
        }
Пример #21
0
 protected static AppDomain CreateDomainHelper(string friendlyName, Evidence securityInfo, AppDomainSetup appDomainInfo)
 {
     throw new NotImplementedException();
 }
Пример #22
0
 internal extern Assembly LoadAssembly(string assemblyRef, Evidence securityEvidence, bool refOnly);
Пример #23
0
        } // PrepareDataForSetup

        private static Object Setup(Object arg)
        {
            Contract.Requires(arg != null && arg is Object[]);
            Contract.Requires(((Object[])arg).Length >= 8);

            Object[]       args                     = (Object[])arg;
            String         friendlyName             = (String)args[0];
            AppDomainSetup setup                    = (AppDomainSetup)args[1];
            IntPtr         parentSecurityDescriptor = (IntPtr)args[2];
            bool           generateDefaultEvidence  = (bool)args[3];

            byte[] serializedEvidence = (byte[])args[4];
            AppDomainInitializerInfo initializerInfo = (AppDomainInitializerInfo)args[5];
            string sandboxName = (string)args[6];

            string[] propertyNames  = (string[])args[7]; // can contain null elements
            string[] propertyValues = (string[])args[8]; // can contain null elements
            // extract evidence
            Evidence providedSecurityInfo = null;
            Evidence creatorsSecurityInfo = null;

            AppDomain      ad       = AppDomain.CurrentDomain;
            AppDomainSetup newSetup = new AppDomainSetup(setup, false);

            if (propertyNames != null && propertyValues != null)
            {
                for (int i = 0; i < propertyNames.Length; i++)
                {
                    // We want to set native dll probing directories before any P/Invokes have a
                    // chance to fire. The Path class, for one, has P/Invokes.
                    if (propertyNames[i] == "NATIVE_DLL_SEARCH_DIRECTORIES")
                    {
                        if (propertyValues[i] == null)
                        {
                            throw new ArgumentNullException("NATIVE_DLL_SEARCH_DIRECTORIES");
                        }

                        string paths = propertyValues[i];
                        if (paths.Length == 0)
                        {
                            break;
                        }

                        nSetNativeDllSearchDirectories(paths);
                    }
                }

                for (int i = 0; i < propertyNames.Length; i++)
                {
                    if (propertyNames[i] == "APPBASE") // make sure in sync with Fusion
                    {
                        if (propertyValues[i] == null)
                        {
                            throw new ArgumentNullException("APPBASE");
                        }

                        if (PathInternal.IsPartiallyQualified(propertyValues[i]))
                        {
                            throw new ArgumentException(SR.Argument_AbsolutePathRequired);
                        }

                        newSetup.ApplicationBase = NormalizePath(propertyValues[i], fullCheck: true);
                    }
                    else if (propertyNames[i] == "LOADER_OPTIMIZATION")
                    {
                        if (propertyValues[i] == null)
                        {
                            throw new ArgumentNullException("LOADER_OPTIMIZATION");
                        }

                        switch (propertyValues[i])
                        {
                        case "SingleDomain": newSetup.LoaderOptimization = LoaderOptimization.SingleDomain; break;

                        case "MultiDomain": newSetup.LoaderOptimization = LoaderOptimization.MultiDomain; break;

                        case "MultiDomainHost": newSetup.LoaderOptimization = LoaderOptimization.MultiDomainHost; break;

                        case "NotSpecified": newSetup.LoaderOptimization = LoaderOptimization.NotSpecified; break;

                        default: throw new ArgumentException(SR.Argument_UnrecognizedLoaderOptimization, "LOADER_OPTIMIZATION");
                        }
                    }
                    else if (propertyNames[i] == "TRUSTED_PLATFORM_ASSEMBLIES" ||
                             propertyNames[i] == "PLATFORM_RESOURCE_ROOTS" ||
                             propertyNames[i] == "APP_PATHS" ||
                             propertyNames[i] == "APP_NI_PATHS")
                    {
                        string values = propertyValues[i];
                        if (values == null)
                        {
                            throw new ArgumentNullException(propertyNames[i]);
                        }

                        ad.SetData(propertyNames[i], NormalizeAppPaths(values));
                    }
                    else if (propertyNames[i] != null)
                    {
                        ad.SetData(propertyNames[i], propertyValues[i]);     // just propagate
                    }
                }
            }

            ad.SetupFusionStore(newSetup, null); // makes FusionStore a ref to newSetup

            // technically, we don't need this, newSetup refers to the same object as FusionStore
            // but it's confusing since it isn't immediately obvious whether we have a ref or a copy
            AppDomainSetup adSetup = ad.FusionStore;

            adSetup.InternalSetApplicationTrust(sandboxName);

            // set up the friendly name
            ad.nSetupFriendlyName(friendlyName);

#if FEATURE_COMINTEROP
            if (setup != null && setup.SandboxInterop)
            {
                ad.nSetDisableInterfaceCache();
            }
#endif // FEATURE_COMINTEROP

            ad.CreateAppDomainManager(); // could modify FusionStore's object
            ad.InitializeDomainSecurity(providedSecurityInfo,
                                        creatorsSecurityInfo,
                                        generateDefaultEvidence,
                                        parentSecurityDescriptor,
                                        true);

            // can load user code now
            if (initializerInfo != null)
            {
                adSetup.AppDomainInitializer = initializerInfo.Unwrap();
            }
            RunInitializer(adSetup);

            return(null);
        }
Пример #24
0
 public Assembly Load(string assemblyString, Evidence assemblySecurity)
 {
     return(Load(assemblyString, assemblySecurity, false));
 }
Пример #25
0
 public virtual AppDomain CreateDomain(string friendlyName, Evidence securityInfo, AppDomainSetup appDomainInfo)
 {
     return(AppDomainManager.CreateDomainHelper(friendlyName, securityInfo, appDomainInfo));
 }
Пример #26
0
 internal extern Assembly LoadAssemblyRaw(byte[] rawAssembly, byte[] rawSymbolStore, Evidence securityEvidence, bool refonly);
Пример #27
0
 public Assembly Load(String assemblyString, Evidence assemblySecurity)
 {
     return(Assembly.Load(assemblyString));
 }
Пример #28
0
 public Assembly Load(byte[] rawAssembly, byte[] rawSymbolStore, Evidence securityEvidence)
 {
     return(Load(rawAssembly, rawSymbolStore, securityEvidence, false));
 }
Пример #29
0
        // static

        // FIXME: maybe AppDomain.CreateDomain should be calling this?
        protected static AppDomain CreateDomainHelper(string friendlyName, Evidence securityInfo, AppDomainSetup appDomainInfo)
        {
            return(AppDomain.CreateDomain(friendlyName, securityInfo, appDomainInfo));
        }
Пример #30
0
        public static ObjectHandle CreateInstance(string assemblyName, string typeName, bool ignoreCase, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes, Evidence securityInfo)
        {
            StackCrawlMark lookForMyCaller = StackCrawlMark.LookForMyCaller;

            return(CreateInstance(assemblyName, typeName, ignoreCase, bindingAttr, binder, args, culture, activationAttributes, securityInfo, ref lookForMyCaller));
        }