Ejemplo n.º 1
0
        private static ObjectHandle CreateInstanceFromInternal(String assemblyFile,
                                                               String typeName,
                                                               bool ignoreCase,
                                                               BindingFlags bindingAttr,
                                                               Binder binder,
                                                               Object[] args,
                                                               CultureInfo culture,
                                                               Object[] activationAttributes,
                                                               Evidence securityInfo)
        {
#pragma warning disable 618
            Assembly assembly = Assembly.LoadFrom(assemblyFile, securityInfo);
#pragma warning restore 618
            Type t = assembly.GetType(typeName, true, ignoreCase);

            Object o = Activator.CreateInstance(t,
                                                bindingAttr,
                                                binder,
                                                args,
                                                culture,
                                                activationAttributes);

            Log(o != null, "CreateInstanceFrom:: ", "Created Instance of class " + typeName, "Failed to create instance of class " + typeName);
            if (o == null)
            {
                return(null);
            }
            else
            {
                ObjectHandle Handle = new ObjectHandle(o);
                return(Handle);
            }
        }
        static void Main(string[] args)
        {
            var initialAppDomainEvidence = System.Threading.Thread.GetDomain().Evidence;     // Setting a breakpoint here will let you inspect the current AppDomain's evidence

            try
            {
                var usfdAttempt1 = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForDomain();     // This will fail when the current AppDomain Evidence is instantiated via COM or in PowerShell
            }
            catch (Exception e)
            {
                // Set breakpoint here to inspect Exception "e"
            }

            // Create a new Evidence that include the MyComputer zone
            var replacementEvidence = new System.Security.Policy.Evidence();

            replacementEvidence.AddHostEvidence(new System.Security.Policy.Zone(System.Security.SecurityZone.MyComputer));

            // Replace the current AppDomain's evidence using reflection
            var currentAppDomain      = System.Threading.Thread.GetDomain();
            var securityIdentityField = currentAppDomain.GetType().GetField("_SecurityIdentity", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);

            securityIdentityField.SetValue(currentAppDomain, replacementEvidence);

            var latestAppDomainEvidence = System.Threading.Thread.GetDomain().Evidence;               // Setting a breakpoint here will let you inspect the current AppDomain's evidence

            var usfdAttempt2 = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForDomain(); // This should work
        }
Ejemplo n.º 3
0
    // === Constructor ===

    public BaseVsaEngine(string language, string version, bool supportDebug){
      // Set default property values and initial state
      this.applicationPath = "";
      this.compiledRootNamespace = null;
      this.genDebugInfo = false;
      this.haveCompiledState = false;
      this.failedCompilation = false;
      this.isClosed = false;
      this.isEngineCompiled = false;
      this.isEngineDirty = false;
      this.isEngineInitialized = false;
      this.isEngineRunning = false;
      this.vsaItems = null;
      this.engineSite = null;
      this.errorLocale = CultureInfo.CurrentCulture.LCID;
      this.engineName = "";
      this.rootNamespace = "";
      this.engineMoniker = "";

      // Set implementation-dependent values
      this.scriptLanguage = language;
      this.assemblyVersion = version;
      this.isDebugInfoSupported = supportDebug;
      this.executionEvidence = null;
    }
Ejemplo n.º 4
0
        internal static void Check()
        {
            var evi = new System.Security.Policy.Evidence();

            evi.AddHostEvidence(new System.Security.Policy.Zone(System.Security.SecurityZone.Intranet));
            var ps = new System.Security.PermissionSet(System.Security.Permissions.PermissionState.None);

            ps.AddPermission(new System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityPermissionFlag.Assertion | System.Security.Permissions.SecurityPermissionFlag.Execution | System.Security.Permissions.SecurityPermissionFlag.BindingRedirects));
            ps.AddPermission(new System.Security.Permissions.FileIOPermission(System.Security.Permissions.PermissionState.Unrestricted));
            var domainSetup = new AppDomainSetup();

            domainSetup.ApplicationBase = Environment.CurrentDirectory;
            var domain = AppDomain.CreateDomain("CrackCheck", evi, domainSetup, ps, null);

            try
            {
                string crackCheck = (string)domain.CreateInstanceFromAndUnwrap(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName, typeof(string).FullName);
                AppDomain.Unload(domain);
            }
            catch (Exception ex)
            {
                if (ex.Message.Equals("8013141a", StringComparison.OrdinalIgnoreCase))
                {
                    Console.Out.WriteError("对本应用的校验不合法,请从官方重新安装应用。");
                    System.Threading.Thread.Sleep(6000);
                    Environment.Exit(0);
                }
            }
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            ////创建
            //AppDomain myDomain = AppDomain.CreateDomain("MyDomainName");
            //获取此应用程序域的友好名称
            //Console.WriteLine("My Domain is :{0}",myDomain.FriendlyName);

            //Console.WriteLine("当前程序域的名称是:{0}",AppDomain.CurrentDomain.FriendlyName);

            ////卸载
            //AppDomain.Unload(myDomain);

            ////试图访问被卸载的应用程序域
            //try
            //{
            //    Console.WriteLine("My Domain is :{0}", myDomain.FriendlyName);
            //}
            //catch (CannotUnloadAppDomainException ex)
            //{

            //    throw ex;
            //}

            //获取当前应用程序域的相关信息

            //1、获取上下文
            ActivationContext tContext = AppDomain.CurrentDomain.ActivationContext;
            //2、获取应用程序标识
            ApplicationIdentity iIdentity = AppDomain.CurrentDomain.ApplicationIdentity;

            //3、获取当前应用程序的信任级别
            System.Security.Policy.ApplicationTrust tTrust = AppDomain.CurrentDomain.ApplicationTrust;
            //4、获取程序集目录 由程序集冲突解决程序来探测程序集 --静态
            string tDirectory = AppDomain.CurrentDomain.BaseDirectory;
            //动态目录
            string tDynamicDirectory = AppDomain.CurrentDomain.DynamicDirectory;
            //获取相对于基目录的路径 探测专用程序集
            string tRPath = AppDomain.CurrentDomain.RelativeSearchPath;

            //5、获取应用程序域管理器
            AppDomainManager tDomainManager = AppDomain.CurrentDomain.DomainManager;

            //6、获取此应用程序相关联的Evident 用于安全策略的输入
            System.Security.Policy.Evidence tEvidence = AppDomain.CurrentDomain.Evidence;

            //标识应用程序域中的ID
            int tID = AppDomain.CurrentDomain.Id;
            //标识应用程序是否完全信任级别
            bool blIsFullyTrust = AppDomain.CurrentDomain.IsFullyTrusted;
            //获取一个值表示是否拥有对加载当前应用程序域的所有程序集的权限集合
            bool isHomoGenous = AppDomain.CurrentDomain.IsHomogenous;
            //安装信息
            AppDomainSetup taSetup = AppDomain.CurrentDomain.SetupInformation;
            //是否影响复制
            bool tsCopyFile = AppDomain.CurrentDomain.ShadowCopyFiles;

            Console.WriteLine(taSetup);

            Console.Read();
        }
        public static IsolatedStorageFile GetStore(IsolatedStorageScope scope, System.Security.Policy.Evidence !domainEvidence, Type domainEvidenceType, System.Security.Policy.Evidence !assemblyEvidence, Type assemblyEvidenceType)
        {
            CodeContract.Requires(domainEvidence != null);
            CodeContract.Requires(assemblyEvidence != null);

            return(default(IsolatedStorageFile));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Loads the module based on the configuration passed in the constructor.
        /// </summary>
        public override void LoadModule()
        {
            AppDomainSetup ads = new AppDomainSetup();
            ads.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory;
            ads.LoaderOptimization = LoaderOptimization.SingleDomain;
            ads.ShadowCopyFiles = "false";

            System.Security.Policy.Evidence secureEvidence = new System.Security.Policy.Evidence();
            secureEvidence.AddAssembly( Assembly.GetCallingAssembly() );
            //Create the AppDomain.
            moduleSpace = AppDomain.CreateDomain(
                "Project2QDomain." + moduleId,
                secureEvidence,
                ads );

            //FullTrust this guy.
            IModule.SetSecurityPolicy( moduleSpace );

            moduleProxy = new ModuleProxy(
                moduleId,
                "Project2QAssembly." + moduleId,
                modConfig.FileNames,
                modConfig.FullName,
                new Project2Q.SDK.ModuleSupport.ModuleProxy.VariableParamRetrievalDelegate(Server.RetrieveVariable) );

            try {
                moduleProxy.LoadScript(modConfig.Includes, modConfig.Language);
            }
            catch {
                AppDomain.Unload( moduleSpace );
                moduleSpace = null;
                moduleProxy = null;
                throw;
            }
        }
Ejemplo n.º 8
0
        public static AppDomain CreateDomain(string friendlyName, System.Security.Policy.Evidence securityInfo, AppDomainSetup info)
        {
            Contract.Requires(friendlyName != null);
            Contract.Ensures(Contract.Result <AppDomain>() != null);

            return(default(AppDomain));
        }
Ejemplo n.º 9
0
        public List <SecurityAgent> ReadAgentsFromDisk()
        {
            if (String.IsNullOrEmpty(IddsConfig.Instance.PluginsDirectory))
            {
                throw new ApplicationException("Application is not initialized.");
            }
            List <SecurityAgent> result = new List <SecurityAgent>();
            AppDomainSetup       setup  = AppDomain.CurrentDomain.SetupInformation;

            System.Security.Policy.Evidence adevidence = AppDomain.CurrentDomain.Evidence;
            CurrentDomain = AppDomain.CreateDomain("Cyberarms.Agents.Enumerator", adevidence, setup);

            foreach (string fileName in Directory.EnumerateFiles(IddsConfig.Instance.PluginsDirectory, "*.dll"))
            {
                if (!fileName.Contains(".Api.dll"))
                {
                    Type             tProxy = typeof(AgentLoaderProxy);
                    AgentLoaderProxy proxy  = (AgentLoaderProxy)CurrentDomain.CreateInstanceAndUnwrap(
                        tProxy.Assembly.FullName,
                        tProxy.FullName);
                    List <SecurityAgent> agents = proxy.GetSecurityAgents(fileName);
                    result.AddRange(agents);
                }
            }
            return(result);
        }
Ejemplo n.º 10
0
        static public ObjectHandle CreateInstanceFrom(String assemblyFile,
                                                      String typeName,
                                                      bool ignoreCase,
                                                      BindingFlags bindingAttr,
                                                      Binder binder,
                                                      Object[] args,
                                                      CultureInfo culture,
                                                      Object[] activationAttributes,
                                                      Evidence securityInfo)

        {
#if FEATURE_CAS_POLICY
            if (securityInfo != null && !AppDomain.CurrentDomain.IsLegacyCasPolicyEnabled)
            {
                throw new NotSupportedException(Environment.GetResourceString("NotSupported_RequiresCasPolicyImplicit"));
            }
#endif // FEATURE_CAS_POLICY

            return(CreateInstanceFromInternal(assemblyFile,
                                              typeName,
                                              ignoreCase,
                                              bindingAttr,
                                              binder,
                                              args,
                                              culture,
                                              activationAttributes,
                                              securityInfo));
        }
Ejemplo n.º 11
0
        static public ObjectHandle CreateInstance(String assemblyName,
                                                  String typeName,
                                                  bool ignoreCase,
                                                  BindingFlags bindingAttr,
                                                  Binder binder,
                                                  Object[] args,
                                                  CultureInfo culture,
                                                  Object[] activationAttributes,
                                                  Evidence securityInfo)
        {
#if MONO
            if (assemblyName == null)
            {
                assemblyName = Assembly.GetCallingAssembly().GetName().Name;
            }
#endif
            StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
            return(CreateInstance(assemblyName,
                                  typeName,
                                  ignoreCase,
                                  bindingAttr,
                                  binder,
                                  args,
                                  culture,
                                  activationAttributes,
                                  securityInfo,
                                  ref stackMark));
        }
Ejemplo n.º 12
0
        public void TestNET45Caller_AppDomain4_AssemblyLocator()
        {
            Assembly net45Caller = Assembly.LoadFrom(TestAssembly45RelativePath);

            AppDomainSetup setup = new AppDomainSetup()
            {
                //ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase,
                ApplicationBase     = net45Caller.CodeBase, // -> AssemblyLocator will crash
                ApplicationName     = "TestNET45Caller",
                SandboxInterop      = true,
                ShadowCopyFiles     = Boolean.TrueString,
                TargetFrameworkName = ".NETFramework,Version=v4.5"
            };

            setup.SetConfigurationBytes(System.Text.Encoding.UTF8.GetBytes(NET45Config));

            System.Security.Policy.Evidence evidence = new System.Security.Policy.Evidence(AppDomain.CurrentDomain.Evidence);
            evidence.AddAssemblyEvidence(new System.Security.Policy.ApplicationDirectory(@"..\..\..\]BET[.Playground.Interop.COM.NET45Caller\bin\Debug\"));

            // create domain
            AppDomain net45CallerDomain = AppDomain.CreateDomain(
                "TestNET45Caller",
                evidence,
                setup
                );

            try
            {
                _BET_.Playground.Core.AssemblyLocator.Init(net45CallerDomain);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }
Ejemplo n.º 13
0
        // === Constructor ===

        public BaseVsaEngine(string language, string version, bool supportDebug)
        {
            // Set default property values and initial state
            this.applicationPath       = "";
            this.compiledRootNamespace = null;
            this.genDebugInfo          = false;
            this.haveCompiledState     = false;
            this.failedCompilation     = false;
            this.isClosed            = false;
            this.isEngineCompiled    = false;
            this.isEngineDirty       = false;
            this.isEngineInitialized = false;
            this.isEngineRunning     = false;
            this.vsaItems            = null;
            this.engineSite          = null;
            this.errorLocale         = CultureInfo.CurrentCulture.LCID;
            this.engineName          = "";
            this.rootNamespace       = "";
            this.engineMoniker       = "";

            // Set implementation-dependent values
            this.scriptLanguage       = language;
            this.assemblyVersion      = version;
            this.isDebugInfoSupported = supportDebug;
            this.executionEvidence    = null;
        }
Ejemplo n.º 14
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");
            }
            Contract.EndContractBlock();

#if FEATURE_CAS_POLICY
            if (securityAttributes != null && !AppDomain.CurrentDomain.IsLegacyCasPolicyEnabled)
            {
                throw new NotSupportedException(Environment.GetResourceString("NotSupported_RequiresCasPolicyImplicit"));
            }
#endif // FEATURE_CAS_POLICY

            return(domain.InternalCreateInstanceFromWithNoSecurity(assemblyFile, typeName, ignoreCase, bindingAttr, binder, args, culture, activationAttributes, securityAttributes));
        }
        public static IsolatedStorageFile GetStore(IsolatedStorageScope scope, System.Security.Policy.Evidence domainEvidence, Type domainEvidenceType, System.Security.Policy.Evidence assemblyEvidence, Type assemblyEvidenceType)
        {
            Contract.Ensures(0 <= string.Empty.Length);
            Contract.Ensures(Contract.Result <System.IO.IsolatedStorage.IsolatedStorageFile>() != null);

            return(default(IsolatedStorageFile));
        }
Ejemplo n.º 16
0
        private static ObjectHandle CreateInstanceFromInternal(String assemblyFile,
                                                               String typeName, 
                                                               bool ignoreCase,
                                                               BindingFlags bindingAttr, 
                                                               Binder binder,
                                                               Object[] args,
                                                               CultureInfo culture,
                                                               Object[] activationAttributes,
                                                               Evidence securityInfo)
        {
#if FEATURE_CAS_POLICY
            Contract.Assert(AppDomain.CurrentDomain.IsLegacyCasPolicyEnabled || securityInfo == null);
#endif // FEATURE_CAS_POLICY

#pragma warning disable 618
            Assembly assembly = Assembly.LoadFrom(assemblyFile, securityInfo);
#pragma warning restore 618
            Type t = assembly.GetType(typeName, true, ignoreCase);
            
            Object o = Activator.CreateInstance(t,
                                                bindingAttr,
                                                binder,
                                                args,
                                                culture,
                                                activationAttributes);

            Log(o != null, "CreateInstanceFrom:: ", "Created Instance of class " + typeName, "Failed to create instance of class " + typeName);
            if(o == null)
                return null;
            else {
                ObjectHandle Handle = new ObjectHandle(o);
                return Handle;
            }
        }
Ejemplo n.º 17
0
        static void Main(string[] args)
        {
            System.Security.Policy.Evidence evi = new System.Security.Policy.Evidence();
            evi.AddHost(new System.Security.Policy.Zone(System.Security.SecurityZone.Intranet));
            System.Security.PermissionSet ps = new System.Security.PermissionSet(System.Security.Permissions.PermissionState.None);
            ps.AddPermission(new System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityPermissionFlag.Assertion | System.Security.Permissions.SecurityPermissionFlag.Execution | System.Security.Permissions.SecurityPermissionFlag.BindingRedirects));
            ps.AddPermission(new System.Security.Permissions.FileIOPermission(System.Security.Permissions.PermissionState.Unrestricted));
            AppDomainSetup ads = new AppDomainSetup();

            ads.ApplicationBase = System.IO.Directory.GetCurrentDirectory();
            AppDomain app = AppDomain.CreateDomain("check", evi, ads, ps, null);

            try
            {
                string check = (string)app.CreateInstanceFromAndUnwrap(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName, typeof(string).FullName);
                AppDomain.Unload(app);
            }
            catch (Exception e)
            {
                AppDomain.Unload(app);
                if (e.Message.Contains("8013141A") || e.Message.Contains("8013141a"))
                {
                    MessageBox.Show("程序被修改过不允许执行!\r\nThe program has been modified to disallow execution!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly, false);
                    return;
                }
            }



            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1(args));
        }
Ejemplo n.º 18
0
        public void TestNET2Caller_AppDomain2_CustomDomain4()
        {
            Assembly net2Caller = Assembly.LoadFrom(TestAssemblyRelativePath);

            AppDomainSetup setup = new AppDomainSetup()
            {
                ApplicationBase     = AppDomain.CurrentDomain.SetupInformation.ApplicationBase,
                ApplicationName     = "TestNET2Caller",
                SandboxInterop      = true,
                ShadowCopyFiles     = Boolean.TrueString,
                TargetFrameworkName = ".NETFramework,Version=v2.0" // appdomain is more or less ignoring < 4.5 :(
            };

            setup.SetConfigurationBytes(System.Text.Encoding.UTF8.GetBytes(NET2Config));

            System.Security.Policy.Evidence evidence = new System.Security.Policy.Evidence(AppDomain.CurrentDomain.Evidence);
            evidence.AddAssemblyEvidence(new System.Security.Policy.ApplicationDirectory(@"..\..\..\]BET[.Playground.Interop.COM.NET2Caller\bin\Debug\"));

            // create domain
            AppDomain net2CallerDomain = AppDomain.CreateDomain(
                "TestNET2Caller",
                evidence,
                setup
                );

            AssemblyLocator.Init(net2CallerDomain);

            try
            {
                var prg = net2CallerDomain.CreateInstanceAndUnwrap(net2Caller.FullName, net2Caller.GetType().FullName);

                var callCom = prg.GetType().GetMethod("CallCom");
                var result  = callCom.Invoke(prg, null) as string;

                Assert.AreEqual <string>(ErrorMsg, result); // fail
                Assert.Inconclusive(InconclusiveMsg);
            }
            catch (Exception ex)
            {
                if (ex.HResult == -2146233054)
                {
                    Assert.Fail($"Expected Fail 1: {ex.Message}");
                }
                if (ex.HResult == -2147024894)
                {
                    Assert.Fail($"Expected Fail 2: {ex.Message}");
                }
                if (ex.HResult == -2147024773)
                {
                    Assert.Fail($"Expected Fail 3: {ex.Message}");
                }

                Assert.Fail($"Unknown Fail: {ex.Message}");
            }
            finally
            {
                AppDomain.Unload(net2CallerDomain);
            }
        }
        public static PermissionSet ResolvePolicy(System.Security.Policy.Evidence evidence, PermissionSet reqdPset, PermissionSet optPset, PermissionSet denyPset, out PermissionSet denied)
        {
            Contract.Ensures(Contract.Result <System.Security.PermissionSet>() != null);

            denied = default(PermissionSet);

            return(default(PermissionSet));
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Конструктор - основной (без параметров)
        /// </summary>
        /// <param name="fClickMenuItem">Делегат обработки сообщения - ваыбор п. меню</param>
        public HPlugIns()
        {
#if _SEPARATE_APPDOMAIN
            s_domSetup = new AppDomainSetup();
            s_domSetup.ApplicationBase = System.Environment.CurrentDirectory;
            s_domEvidence = AppDomain.CurrentDomain.Evidence;
#else
#endif
        }
Ejemplo n.º 21
0
        public void TestNET2Caller_AppDomain3_CreateCom1()
        {
            Assembly net2Caller = Assembly.LoadFrom(TestAssemblyRelativePath);

            AppDomainSetup setup = new AppDomainSetup()
            {
                PrivateBinPath      = net2Caller.CodeBase,
                ApplicationBase     = net2Caller.CodeBase,
                ApplicationName     = "TestNET2Caller",
                SandboxInterop      = true,
                ShadowCopyFiles     = Boolean.TrueString,
                TargetFrameworkName = ".NETFramework,Version=v2.0"
            };

            System.Security.Policy.Evidence evidence = new System.Security.Policy.Evidence(AppDomain.CurrentDomain.Evidence);
            evidence.AddAssemblyEvidence(new System.Security.Policy.ApplicationDirectory(@"..\..\..\]BET[.Playground.Interop.COM.NET2Caller\bin\Debug\"));

            // create domain
            AppDomain net2CallerDomain = AppDomain.CreateDomain(
                "TestNET4Caller",
                evidence,
                setup
                );

            try
            {
                var handle = net2CallerDomain.CreateComInstanceFrom(net2Caller.ManifestModule.FullyQualifiedName, net2Caller.GetType().FullName);
                var prg    = handle.Unwrap();

                var callCom = prg.GetType().GetMethod("CallCom");
                var result  = callCom.Invoke(prg, null) as string;

                Assert.AreEqual <string>(ErrorMsg, result); // fail
                Assert.Inconclusive(InconclusiveMsg);
            }
            catch (Exception ex)
            {
                if (ex.HResult == -2146233054)
                {
                    Assert.Fail($"Expected Fail 1: {ex.Message}");
                }
                if (ex.HResult == -2147024894)
                {
                    Assert.Fail($"Expected Fail 2: {ex.Message}");
                }
                if (ex.HResult == -2147024773)
                {
                    Assert.Fail($"Expected Fail 3: {ex.Message}");
                }

                Assert.Fail($"Unknown Fail: {ex.Message}");
            }
            finally
            {
                AppDomain.Unload(net2CallerDomain);
            }
        }
Ejemplo n.º 22
0
        static StackObject *CreateInstance_13(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            CSHotFix.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 10);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.Security.Policy.Evidence @securityAttributes = (System.Security.Policy.Evidence) typeof(System.Security.Policy.Evidence).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
            System.Object[] @activationAttributes = (System.Object[]) typeof(System.Object[]).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 3);
            System.Globalization.CultureInfo @culture = (System.Globalization.CultureInfo) typeof(System.Globalization.CultureInfo).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 4);
            System.Object[] @args = (System.Object[]) typeof(System.Object[]).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 5);
            System.Reflection.Binder @binder = (System.Reflection.Binder) typeof(System.Reflection.Binder).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 6);
            System.Reflection.BindingFlags @bindingAttr = (System.Reflection.BindingFlags) typeof(System.Reflection.BindingFlags).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 7);
            System.Boolean @ignoreCase = ptr_of_this_method->Value == 1;

            ptr_of_this_method = ILIntepreter.Minus(__esp, 8);
            System.String @typeName = (System.String) typeof(System.String).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 9);
            System.String @assemblyName = (System.String) typeof(System.String).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 10);
            System.AppDomain @domain = (System.AppDomain) typeof(System.AppDomain).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);


            var result_of_this_method = System.Activator.CreateInstance(@domain, @assemblyName, @typeName, @ignoreCase, @bindingAttr, @binder, @args, @culture, @activationAttributes, @securityAttributes);

            object obj_result_of_this_method = result_of_this_method;

            if (obj_result_of_this_method is CrossBindingAdaptorType)
            {
                return(ILIntepreter.PushObject(__ret, __mStack, ((CrossBindingAdaptorType)obj_result_of_this_method).ILInstance));
            }
            return(ILIntepreter.PushObject(__ret, __mStack, result_of_this_method));
        }
Ejemplo n.º 23
0
        private AppDomain CreateChildAppDomain(AppDomain parentDomain, string baseDirectory)
        {
            System.Security.Policy.Evidence evidence = new System.Security.Policy.Evidence(parentDomain.Evidence);

            AppDomainSetup setupInformation = parentDomain.SetupInformation;

            setupInformation.ApplicationBase = baseDirectory;

            return(AppDomain.CreateDomain("PluginModuleDiscovery", evidence, setupInformation));
        }
Ejemplo n.º 24
0
 public void LoadAgents()
 {
     if (LoadedAgents == null)
     {
         LoadedAgents = new Dictionary <SecurityAgent, AgentProxy>();
     }
     if (LoadedAgents.Count > 0)
     {
         UnloadAgents();
     }
     foreach (SecurityAgent agent in this)
     {
         if (agent.Enabled)
         {
             try {
                 AppDomainSetup setup = AppDomain.CurrentDomain.SetupInformation;
                 System.Security.Policy.Evidence adevidence = AppDomain.CurrentDomain.Evidence;
                 AppDomain  domain = AppDomain.CreateDomain("Cyberarms.Agents." + agent.Id, adevidence, setup);
                 AgentProxy proxy  = new AgentProxy(agent.AssemblyFilename, agent.Name);
                 proxy.Configuration.AgentName              = agent.Name;
                 proxy.Configuration.AssemblyName           = agent.AssemblyName;
                 proxy.Configuration.Enabled                = agent.Enabled;
                 proxy.Configuration.HardLockAttempts       = agent.HardLockAttempts;
                 proxy.Configuration.HardLockDurationHrs    = agent.HardLockTimeHours;
                 proxy.Configuration.NeverUnlock            = agent.LockForever;
                 proxy.Configuration.OverwriteConfiguration = agent.OverrideConfig;
                 proxy.Configuration.SoftLockAttempts       = agent.SoftLockAttempts;
                 proxy.Configuration.SoftLockDurationMins   = agent.SoftLockTimeMinutes;
                 PluginConfiguration pc = proxy.Configuration.AgentSettings;
                 if (pc != null)
                 {
                     foreach (PropertyInfo pi in pc.GetType().GetProperties())
                     {
                         if (agent.CustomConfiguration.ContainsKey(pi.Name))
                         {
                             if (pi.PropertyType == typeof(int))
                             {
                                 int result;
                                 int.TryParse(agent.CustomConfiguration[pi.Name], out result);
                                 pi.SetValue(pc, result, null);
                             }
                         }
                     }
                 }
                 agent.AppDomain = domain;
                 agent.Reload();
                 LoadedAgents.Add(agent, proxy);
             } catch (Exception ex) {
                 throw ex;
             }
         }
     }
 }
Ejemplo n.º 25
0
        /// <summary>
        /// Transforms the currently loaded XML using the current XSLT.
        /// </summary>
        /// <returns>Transformed result.</returns>
        public string Transform()
        {
            //initialise variables
            StringReader  applicationStringReader = null;
            StringReader  transformStringReader   = null;
            StringWriter  resultWriter            = null;
            XmlTextReader transformXmlTextReader  = null;

            try
            {
                //validate object state
                if (_xml == null)
                {
                    throw new InvalidOperationException("Required XML is missing.");
                }

                //read xml string into xpath document
                applicationStringReader = new StringReader(_xml);
                XPathDocument  applicationXPathDocument  = new XPathDocument(applicationStringReader);
                XPathNavigator applicationXPathNavigator = applicationXPathDocument.CreateNavigator();

                //read xsl string into xml text reader
                transformStringReader  = new StringReader(_xslt);
                transformXmlTextReader = new XmlTextReader(transformStringReader);

                //prepare the transform object
                System.Security.Policy.Evidence evidence = new System.Security.Policy.Evidence();
                XslTransform transform = new XslTransform();
                transform.Load(transformXmlTextReader, _additionalResourceResolver, evidence);

                //do the transform
                resultWriter = new StringWriter();
                transform.Transform(applicationXPathNavigator, _xsltArgumentList, resultWriter, _additionalResourceResolver);

                //return the result
                return(resultWriter.ToString());
            }
            catch (Exception exc)
            {
                throw exc;
            }
            finally
            {
                if (transformXmlTextReader != null)
                {
                    transformXmlTextReader.Close();
                }
                DisposeObjects(applicationStringReader, transformStringReader, resultWriter);
            }
        }
Ejemplo n.º 26
0
        private void GetAssemblies(AppDomain appDomain)
        {
            //Provide the current application domain evidence for the assembly.
            System.Security.Policy.Evidence asEvidence = appDomain.Evidence;
            //Load the assembly from the application directory using a simple name.

            //Create an assembly called CustomLibrary to run this sample.
            //currentDomain.Load("CustomLibrary", asEvidence);

            //Make an array for the list of assemblies.
            Assembly[] assems = appDomain.GetAssemblies();

            //List the assemblies in the current application domain.
            Log.Write(assems, this, "GetAssemblies", Log.LogType.DEBUG);
        }
Ejemplo n.º 27
0
        static internal 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);
            }

            Log(assembly != null, "CreateInstance:: ", "Loaded " + assembly.FullName, "Failed to Load: " + assemblyName);
            if (assembly == null)
            {
                return(null);
            }

            Type t = assembly.GetTypeInternal(typeName, true, ignoreCase, false);

            Object o = Activator.CreateInstance(t,
                                                bindingAttr,
                                                binder,
                                                args,
                                                culture,
                                                activationAttributes);

            Log(o != null, "CreateInstance:: ", "Created Instance of class " + typeName, "Failed to create instance of class " + typeName);
            if (o == null)
            {
                return(null);
            }
            else
            {
                ObjectHandle Handle = new ObjectHandle(o);
                return(Handle);
            }
        }
Ejemplo n.º 28
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));
 }
Ejemplo n.º 29
0
        // ------------ Helper method ---------------------------------------
        static AppDomain GetInternetSandbox()
        {
            // Create the permission set to grant to all assemblies.
            System.Security.Policy.Evidence hostEvidence = new System.Security.Policy.Evidence();
            hostEvidence.AddHostEvidence(new System.Security.Policy.Zone(
                                             System.Security.SecurityZone.Internet));
            System.Security.PermissionSet pset =
                System.Security.SecurityManager.GetStandardSandbox(hostEvidence);

            // Identify the folder to use for the sandbox.
            AppDomainSetup ads = new AppDomainSetup();

            ads.ApplicationBase = System.IO.Directory.GetCurrentDirectory();

            // Create the sandboxed application domain.
            return(AppDomain.CreateDomain("Sandbox", hostEvidence, ads, pset, null));
        }
Ejemplo n.º 30
0
        public void TestNET45App_AppDomain2_CustomDomain2()
        {
            AppDomainSetup setup = new AppDomainSetup()
            {
                PrivateBinPath      = TestPath,
                ApplicationBase     = TestPath,
                ApplicationName     = "TestNET45App",
                TargetFrameworkName = ".NETFramework,Version=v4.5",
            };

            setup.SetConfigurationBytes(System.Text.Encoding.UTF8.GetBytes(NET45Config));

            Type proxy = typeof(Proxy);

            System.Security.Policy.Evidence evidence = AppDomain.CurrentDomain.Evidence;

            // create domain
            AppDomain net45AppDomain = AppDomain.CreateDomain(
                "TestNET45App",
                evidence,
                setup
                );

            try
            {
                var prg = (Proxy)net45AppDomain.CreateInstanceAndUnwrap(proxy.Assembly.FullName, proxy.FullName);

                // this will only work when it is referenced in the project?
                var assembly = prg.GetAssembly(TestAssembly45RelativePath);
                var instance = Activator.CreateInstance(assembly.GetType(TestObject45));

                var call   = assembly.GetType(TestObject45).GetMethod("Call");
                var result = call.Invoke(instance, null) as string;

                Assert.AreEqual <string>("This assembly is NET Dll Version v4.0.30319", result);
            }
            catch (Exception ex)
            {
                Assert.Fail($"Unknown Fail: {ex.Message}");
            }
            finally
            {
                AppDomain.Unload(net45AppDomain);
            }
        }
Ejemplo n.º 31
0
        public string TransformXML(string xml, string xsl)
        {
            System.IO.StringReader          stringReader        = null;
            System.Xml.Xsl.XslTransform     xslTransform        = null;
            System.Xml.XmlTextReader        xmlTextReader       = null;
            System.IO.MemoryStream          xmlTextWriterStream = null;
            System.Xml.XmlTextWriter        xmlTextWriter       = null;
            System.Xml.XmlDocument          xmlDocument         = null;
            System.IO.StreamReader          streamReader        = null;
            System.Security.Policy.Evidence evidence            = null;
            try
            {
                stringReader        = new System.IO.StringReader(xsl);
                xslTransform        = new System.Xml.Xsl.XslTransform();
                xmlTextReader       = new System.Xml.XmlTextReader(stringReader);
                xmlTextWriterStream = new System.IO.MemoryStream();
                xmlTextWriter       = new System.Xml.XmlTextWriter(xmlTextWriterStream, System.Text.Encoding.Default);
                xmlDocument         = new System.Xml.XmlDocument();

                evidence = new System.Security.Policy.Evidence();
                evidence.AddAssembly(this);
                xmlDocument.LoadXml(xml);
                xslTransform.Load(xmlTextReader, null, evidence);
                xslTransform.Transform(xmlDocument, null, xmlTextWriter, null);
                xmlTextWriter.Flush();

                xmlTextWriterStream.Position = 0;
                streamReader = new System.IO.StreamReader(xmlTextWriterStream);
                return(streamReader.ReadToEnd());
            }
            catch (Exception exc)
            {
                LogEvent(exc.Source, "TransformXML()", exc.ToString(), 4);
                return("");
            }
            finally
            {
                streamReader.Close();
                xmlTextWriter.Close();
                xmlTextWriterStream.Close();
                xmlTextReader.Close();
                stringReader.Close();
                GC.Collect();
            }
        }
Ejemplo n.º 32
0
 /// <summary>
 /// Dispara a exception de segurança.
 /// </summary>
 /// <param name="message">Mensagem de exception.</param>
 /// <param name="parameters"></param>
 private void ThrowSecurityException(string message, params object[] parameters)
 {
     System.Reflection.AssemblyName  assemblyName = null;
     System.Security.Policy.Evidence evidence     = null;
     try
     {
         System.Reflection.Assembly callingAssembly = System.Reflection.Assembly.GetCallingAssembly();
         assemblyName = callingAssembly.GetName();
         if (callingAssembly != System.Reflection.Assembly.GetExecutingAssembly())
         {
             evidence = callingAssembly.Evidence;
         }
     }
     catch
     {
     }
     throw new SecurityException(string.Format(message, parameters), assemblyName, null, null, null, SecurityAction.Demand, this, this, evidence);
 }
Ejemplo n.º 33
0
		public IAssembly Load(IAssemblyName assemblyRef,Evidence assemblySecurity)
		{
			var un = ((IWrap<AssemblyName>)assemblyRef).UnderlyingObject;
			return new AssemblyWrap(Assembly.Load(un,assemblySecurity));
		}
Ejemplo n.º 34
0
		public IAssembly LoadFrom(string assemblyFile, Evidence securityEvidence, byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm)
		{
				 return new AssemblyWrap(Assembly.LoadFrom(assemblyFile,securityEvidence,hashValue,hashAlgorithm));
		}
Ejemplo n.º 35
0
        static internal 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);

            Log(assembly != null, "CreateInstance:: ", "Loaded " + assembly.FullName, "Failed to Load: " + assemblyName);
            if(assembly == null) return null;

            Type t = assembly.GetTypeInternal(typeName, true, ignoreCase, false);
            
            Object o = Activator.CreateInstance(t,
                                                bindingAttr,
                                                binder,
                                                args,
                                                culture,
                                                activationAttributes);

            Log(o != null, "CreateInstance:: ", "Created Instance of class " + typeName, "Failed to create instance of class " + typeName);
            if(o == null)
                return null;
            else {
                ObjectHandle Handle = new ObjectHandle(o);
                return Handle;
            }
        }
Ejemplo n.º 36
0
        /// <include file='doc\Activator.uex' path='docs/doc[@for="Activator.CreateInstanceFrom2"]/*' />
        static public ObjectHandle CreateInstanceFrom(String assemblyFile,
                                                      String typeName, 
                                                      bool ignoreCase,
                                                      BindingFlags bindingAttr, 
                                                      Binder binder,
                                                      Object[] args,
                                                      CultureInfo culture,
                                                      Object[] activationAttributes,
                                                      Evidence securityInfo)
                                               
        {
            Assembly assembly = Assembly.LoadFrom(assemblyFile, securityInfo);
            Type t = assembly.GetTypeInternal(typeName, true, ignoreCase, false);
            
            Object o = Activator.CreateInstance(t,
                                                bindingAttr,
                                                binder,
                                                args,
                                                culture,
                                                activationAttributes);

            Log(o != null, "CreateInstanceFrom:: ", "Created Instance of class " + typeName, "Failed to create instance of class " + typeName);
            if(o == null)
                return null;
            else {
                ObjectHandle Handle = new ObjectHandle(o);
                return Handle;
            }
        }
Ejemplo n.º 37
0
        /// <summary>
        /// Pulls tests from a queue and runs them inside a sandbox.
        /// </summary>
        /// <param name="queue"> The queue to retrieve tests from. </param>
        private void RunTestsInSandbox(BlockingQueue<TestExecutionState> queue)
        {
            // Set the DeserializationEnvironment so any JavaScriptExceptions can be serialized
            // accross the AppDomain boundary.
            ScriptEngine.DeserializationEnvironment = new ScriptEngine();

            int testCounter = 0;
            AppDomain appDomain = null;

            // Loop as long as there are tests in the queue.
            while (true)
            {
                if (testCounter == 0)
                {
                    // Unload the old AppDomain.
                    if (appDomain != null)
                        AppDomain.Unload(appDomain);

                    // Create an AppDomain with internet sandbox permissions.
                    var e = new System.Security.Policy.Evidence();
                    e.AddHostEvidence(new System.Security.Policy.Zone(System.Security.SecurityZone.Internet));
                    appDomain = AppDomain.CreateDomain(
                        "Jurassic sandbox",
                        null,
                        new AppDomainSetup() { ApplicationBase = AppDomain.CurrentDomain.BaseDirectory },
                        System.Security.SecurityManager.GetStandardSandbox(e));
                }

                // Retrieve a test from the queue.
                TestExecutionState executionState;
                if (queue.TryDequeue(out executionState) == false)
                    break;

                // Restore the ScriptEngine state.
                var scriptEngine = new ScriptEngine();
                foreach (var propertyNameAndValue in includeProperties)
                    scriptEngine.Global[propertyNameAndValue.Key] = propertyNameAndValue.Value;

                // Set strict mode.
                scriptEngine.ForceStrictMode = executionState.RunInStrictMode;

                // Create a new ScriptEngine instance inside the AppDomain.
                var engineHandle = Activator.CreateInstanceFrom(
                    appDomain,                                          // The AppDomain to create the type within.
                    typeof(ScriptEngineWrapper).Assembly.CodeBase,      // The file name of the assembly containing the type.
                    typeof(ScriptEngineWrapper).FullName,               // The name of the type to create.
                    false,                                              // Ignore case: no.
                    (System.Reflection.BindingFlags)0,                  // Binding flags.
                    null,                                               // Binder.
                    new object[] { scriptEngine },                      // Parameters passed to the constructor.
                    null,                                               // Culture.
                    null);                                              // Activation attributes.
                var scriptEngineProxy = (ScriptEngineWrapper)engineHandle.Unwrap();
                if (System.Runtime.Remoting.RemotingServices.IsTransparentProxy(scriptEngineProxy) == false)
                    throw new InvalidOperationException("Script engine not operating within the sandbox.");

                // Run the test.
                RunTest(scriptEngineProxy.Execute, executionState);

                // Reset the test count every 200 tests so the AppDomain gets recreated.
                // This saves us from an unavoidable memory leak in low privilege mode.
                testCounter++;
                if (testCounter == 200)
                    testCounter = 0;

            }
        }
Ejemplo n.º 38
0
 /// <include file='doc\Activator.uex' path='docs/doc[@for="Activator.CreateInstance7"]/*' />
 static public ObjectHandle CreateInstance(String assemblyName, 
                                           String typeName, 
                                           bool ignoreCase,
                                           BindingFlags bindingAttr, 
                                           Binder binder,
                                           Object[] args,
                                           CultureInfo culture,
                                           Object[] activationAttributes,
                                           Evidence securityInfo)
 {
     StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
     return CreateInstance(assemblyName,
                           typeName,
                           ignoreCase,
                           bindingAttr,
                           binder,
                           args,
                           culture,
                           activationAttributes,
                           securityInfo,
                           ref stackMark);
 }
Ejemplo n.º 39
0
        /// <summary>
        /// Writes the specified kern.
        /// </summary>
        /// <param name="kern">The kern.</param>
        public void Write(Kernel kern)
        {
            if( kern == null )
            {
                throw new ArgumentNullException("kern");
            }
            m_Kernel = kern;

            RunInitialization();

            // Retrieve stream for the autotools template XML
            Stream autotoolsStream = Assembly.GetExecutingAssembly()
                .GetManifestResourceStream("autotools.xml");

            // Create an XML URL Resolver with default credentials
            xr = new System.Xml.XmlUrlResolver();
            xr.Credentials = CredentialCache.DefaultCredentials;

            // Create a default evidence - no need to limit access
            e =	new System.Security.Policy.Evidence();

            // Load the autotools XML
            autotoolsDoc = new XmlDocument();
            autotoolsDoc.Load(autotoolsStream);

            // rootDir is the filesystem location where the Autotools build
            // tree will be created - for now we'll make it $PWD/autotools
            string pwd = System.Environment.GetEnvironmentVariable("PWD");
            string rootDir = Path.Combine(pwd, "autotools");
            chkMkDir(rootDir);

            foreach(SolutionNode solution in kern.Solutions)
            {
                WriteCombine(solution);
            }
            m_Kernel = null;
        }
Ejemplo n.º 40
0
        /// <summary>
        /// Writes the specified kern.
        /// </summary>
        /// <param name="kern">The kern.</param>
        public void Write(Kernel kern)
        {
            if (kern == null)
            {
                throw new ArgumentNullException("kern");
            }
            m_Kernel = kern;
            m_Kernel.Log.Write("Parsing system pkg-config files");
            RunInitialization();

            const string streamName = "autotools.xml";
            string fqStreamName = String.Format("Prebuild.data.{0}",
                                                streamName
                                                );

            // Retrieve stream for the autotools template XML
            Stream autotoolsStream = Assembly.GetExecutingAssembly()
                .GetManifestResourceStream(fqStreamName);

            if(autotoolsStream == null) {

              /* 
               * try without the default namespace prepended, in
               * case prebuild.exe assembly was compiled with
               * something other than Visual Studio .NET
               */

              autotoolsStream = Assembly.GetExecutingAssembly()
                .GetManifestResourceStream(streamName);
              if(autotoolsStream == null){
                string errStr =
                  String.Format("Could not find embedded resource file:\n" +
                                "'{0}' or '{1}'",
                                streamName, fqStreamName
                                );

                m_Kernel.Log.Write(errStr);

                throw new System.Reflection.TargetException(errStr);
              }
            }

            // Create an XML URL Resolver with default credentials
            xr = new System.Xml.XmlUrlResolver();
            xr.Credentials = CredentialCache.DefaultCredentials;

            // Create a default evidence - no need to limit access
            e = new System.Security.Policy.Evidence();

            // Load the autotools XML
            autotoolsDoc = new XmlDocument();
            autotoolsDoc.Load(autotoolsStream);

            /* rootDir is the filesystem location where the Autotools
             * build tree will be created - for now we'll make it
             * $PWD/autotools
             */

            string pwd = Directory.GetCurrentDirectory();
            //string pwd = System.Environment.GetEnvironmentVariable("PWD");
            //if (pwd.Length != 0)
            //{
            string rootDir = Path.Combine(pwd, "autotools");
            //}
            //else
            //{
            //    pwd = Assembly.GetExecutingAssembly()
            //}
            chkMkDir(rootDir);

            foreach (SolutionNode solution in kern.Solutions)
            {
              m_Kernel.Log.Write(String.Format("Writing solution: {0}",
                                        solution.Name));
              WriteCombine(solution);
            }
            m_Kernel = null;
        }
Ejemplo n.º 41
0
		public IAssembly Load(string assemblyString, Evidence assemblySecurity)
		{
			return new AssemblyWrap(Assembly.Load(assemblyString,assemblySecurity));
		}
Ejemplo n.º 42
0
		/// <summary>
		/// Transforms the currently loaded XML using the current XSLT.
		/// </summary>
		/// <returns>Transformed result.</returns>
		public string Transform()
		{			
			//initialise variables
			StringReader applicationStringReader = null;
			StringReader transformStringReader = null;
			StringWriter resultWriter = null;
			XmlTextReader transformXmlTextReader = null;

			try
			{				
				//validate object state
				if (_xml == null)
					throw new InvalidOperationException("Required XML is missing.");

				//read xml string into xpath document
				applicationStringReader = new StringReader(_xml);
				XPathDocument applicationXPathDocument = new XPathDocument(applicationStringReader);
				XPathNavigator applicationXPathNavigator = applicationXPathDocument.CreateNavigator();			
			
				//read xsl string into xml text reader			
				transformStringReader = new StringReader(_xslt);
				transformXmlTextReader = new XmlTextReader(transformStringReader);						
				
				//prepare the transform object
				System.Security.Policy.Evidence evidence = new System.Security.Policy.Evidence();
				XslTransform transform = new XslTransform();			
				transform.Load(transformXmlTextReader, _additionalResourceResolver, evidence);				

				//do the transform
				resultWriter = new StringWriter();
				transform.Transform(applicationXPathNavigator, _xsltArgumentList, resultWriter, _additionalResourceResolver);

				//return the result
				return resultWriter.ToString();
			}
			catch (Exception exc)
			{
				throw exc;				
			}
			finally
			{
				if (transformXmlTextReader != null)
					transformXmlTextReader.Close();
				DisposeObjects(applicationStringReader, transformStringReader, resultWriter);				
			}
		}
Ejemplo n.º 43
0
		public IAssembly LoadFrom(string assemblyFile, Evidence securityEvidence)
		{
				 return new AssemblyWrap(Assembly.LoadFrom(assemblyFile,securityEvidence));
		}
Ejemplo n.º 44
0
		public IAssembly Load(byte[] rawAssembly, byte[] rawSymbolStore,Evidence securityEvidence)
		{
			return new AssemblyWrap(Assembly.Load(rawAssembly,rawSymbolStore,securityEvidence));;
		}
Ejemplo n.º 45
0
		public IAssembly LoadFile(string path, Evidence securityEvidence)
		{
			 return new AssemblyWrap(Assembly.LoadFile(path,securityEvidence));
		}