Exemple #1
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);
                }
            }
        }
Exemple #2
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));
        }
Exemple #3
0
        // NOTE: This is just a private helper because OracleClient V1.1 shipped
        // with a different argument name and it's a breaking change to not use
        // the same argument names in V2.0 (VB Named Parameter Binding--Ick)
        private void EnlistDistributedTransactionHelper(System.EnterpriseServices.ITransaction transaction)
        {
            System.Security.PermissionSet permissionSet = new System.Security.PermissionSet(System.Security.Permissions.PermissionState.None);
            permissionSet.AddPermission(SqlConnection.ExecutePermission); // MDAC 81476
            permissionSet.AddPermission(new System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode));
            permissionSet.Demand();

            SqlClientEventSource.Log.TryTraceEvent("<prov.DbConnectionHelper.EnlistDistributedTransactionHelper|RES|TRAN> {0}, Connection enlisting in a transaction.", ObjectID);
            SysTx.Transaction indigoTransaction = null;

            if (null != transaction)
            {
                indigoTransaction = SysTx.TransactionInterop.GetTransactionFromDtcTransaction((SysTx.IDtcTransaction)transaction);
            }

            RepairInnerConnection();
            // NOTE: since transaction enlistment involves round trips to the
            // server, we don't want to lock here, we'll handle the race conditions
            // elsewhere.
            InnerConnection.EnlistTransaction(indigoTransaction);

            // NOTE: If this outer connection were to be GC'd while we're
            // enlisting, the pooler would attempt to reclaim the inner connection
            // while we're attempting to enlist; not sure how likely that is but
            // we should consider a GC.KeepAlive(this) here.
            GC.KeepAlive(this);
        }
Exemple #4
0
        public static void StartADemo(AppWidgetFactory appWidgetFactory)
        {
            if (usedMainThread)
            {
                System.AppDomainSetup domainSetup = new AppDomainSetup();
                domainSetup.ApplicationBase = ".";
                System.AppDomain newDomain = null;

                bool usePermissionTest = false;
                if (usePermissionTest)
                {
                    System.Security.PermissionSet permissionSet = new System.Security.PermissionSet(System.Security.Permissions.PermissionState.None);
                    permissionSet.AddPermission(new System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityPermissionFlag.Execution));
                    permissionSet.AddPermission(new System.Security.Permissions.FileIOPermission(System.Security.Permissions.PermissionState.Unrestricted));

                    newDomain = System.AppDomain.CreateDomain(appWidgetFactory.GetAppParameters().title, null, domainSetup, permissionSet, null);
                }
                else
                {
                    newDomain = System.AppDomain.CreateDomain(appWidgetFactory.GetAppParameters().title);
                }

                string[] args = { appWidgetFactory.GetAppParameters().title };
                newDomain.ExecuteAssembly("./DemoRunner.exe", args);
                //System.AppDomain.Unload(newDomain);
            }
            else
            {
                usedMainThread = true;
                appWidgetFactory.CreateWidgetAndRunInWindow();
                //appWidgetFactory.CreateWidgetAndRunInWindow(AppWidgetFactory.ValidDepthVaules.Depth32, AppWidgetFactory.RenderSurface.OpenGL);
            }
        }
Exemple #5
0
        /// <summary/>
        public static void Transform(System.Xaml.XamlReader reader, System.Xaml.XamlWriter writer, System.Xaml.Permissions.XamlAccessLevel accessLevel, bool requestReflectionPermission)
        {
            if (requestReflectionPermission)
            {
                System.Security.PermissionSet permissions = new System.Security.PermissionSet(System.Security.Permissions.PermissionState.None);
                permissions.AddPermission(new System.Xaml.Permissions.XamlLoadPermission(accessLevel));
                permissions.AddPermission(new System.Security.Permissions.ReflectionPermission(System.Security.Permissions.ReflectionPermissionFlag.RestrictedMemberAccess));
                permissions.Assert();
            }
            else
            {
                new System.Xaml.Permissions.XamlLoadPermission(accessLevel).Assert();
            }

            System.Xaml.XamlServices.Transform(reader, writer);
        }
Exemple #6
0
        private void yesBtn_Click(object sender, EventArgs e)
        {
            try
            {
                XmlDocument xDoc = new XmlDocument();
                //string sourceFilePath = string.Format("{0}{1}{2}{3}{4}{5}{6}", Environment.Is64BitOperatingSystem ? Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) : Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), System.IO.Path.DirectorySeparatorChar, "bLoyal", System.IO.Path.DirectorySeparatorChar, "Dinerware Integration", System.IO.Path.DirectorySeparatorChar, "DinerwareConfigurationFile.xml");
                //if (!System.IO.File.Exists(sourceFilePath))
                //    sourceFilePath = string.Format("{0}{1}{2}{3}{4}{5}{6}", Environment.Is64BitOperatingSystem ? Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86) : Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), System.IO.Path.DirectorySeparatorChar, "bLoyal", System.IO.Path.DirectorySeparatorChar, "Workstation", System.IO.Path.DirectorySeparatorChar, "DinerwareConfigurationFile.xml");
                var    configuration  = new ConfigurationHelper(true);
                string sourceFilePath = configuration.GetFilePath();

                xDoc.Load(@"" + sourceFilePath);
                xDoc.DocumentElement.SelectSingleNode("EnablebLoyal").InnerText = "true";
                var permissionSet   = new System.Security.PermissionSet(System.Security.Permissions.PermissionState.None);
                var writePermission = new System.Security.Permissions.FileIOPermission(System.Security.Permissions.FileIOPermissionAccess.Write, @"" + sourceFilePath);
                permissionSet.AddPermission(writePermission);
                if (permissionSet.IsSubsetOf(AppDomain.CurrentDomain.PermissionSet))
                {
                    xDoc.Save(@"" + sourceFilePath);
                }
            }
            catch (Exception ex)
            {
                _logger.WriteLogError(ex, "yesBtn_Click");
                this.Close();
            }
            var config = ConfigurationHelper.NewInstance; // Update the Configuration Instance

            this.Close();
        }
Exemple #7
0
        public static int Load([MarshalAs(UnmanagedType.LPWStr)]String inParam)
        {
            try
            {
                lock (_lock)
                {
                    _injectCount++;
                    if (_easyHookDomain == null)
                    {
                        System.Security.PermissionSet ps = new System.Security.PermissionSet(System.Security.Permissions.PermissionState.Unrestricted);
                        ps.AddPermission(new System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityPermissionFlag.AllFlags));
                        // Evidence of null means use the current appdomain evidence
                        _easyHookDomain = AppDomain.CreateDomain("EasyHook", null, new AppDomainSetup()
                        {
                            ApplicationBase = Path.GetDirectoryName(typeof(Loader).Assembly.Location),
                            // ShadowCopyFiles = "true", // copies assemblies from ApplicationBase into cache, leaving originals unlocked and updatable
                        }, ps);
                    }
                }

                int result = -1;

                // Load the EasyHook assembly in the child AppDomain by using the proxy class
                Type proxyType = typeof(LoadEasyHookProxy);
                if (proxyType.Assembly != null)
                {
                    // This is where the currentDomain.AssemblyResolve that we setup within the static 
                    // constructor is required.
                    var proxy = (LoadEasyHookProxy)_easyHookDomain.CreateInstanceFrom(
                                    proxyType.Assembly.Location,
                                    proxyType.FullName).Unwrap();

                    // Loads EasyHook.dll into the AppDomain, which in turn loads the target assembly
                    result = proxy.Load(inParam);
                }

                //result = new LoadEasyHookProxy().Load(inParam);
                return result;
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("Exception occured within Loader.Load: " + e.ToString());
            }
            finally
            {
                lock (_lock)
                {
                    _injectCount--;
                }
            }

            // Failed
            return -1;
        }
Exemple #8
0
        public static int Load([MarshalAs(UnmanagedType.LPWStr)] String inParam)
        {
            try
            {
                lock (_lock)
                {
                    _injectCount++;
                    if (_easyHookDomain == null)
                    {
                        System.Security.PermissionSet ps = new System.Security.PermissionSet(System.Security.Permissions.PermissionState.Unrestricted);
                        ps.AddPermission(new System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityPermissionFlag.AllFlags));
                        // Evidence of null means use the current appdomain evidence
                        _easyHookDomain = AppDomain.CreateDomain("EasyHook", null, new AppDomainSetup()
                        {
                            ApplicationBase = Path.GetDirectoryName(typeof(Loader).Assembly.Location),
                            // ShadowCopyFiles = "true", // copies assemblies from ApplicationBase into cache, leaving originals unlocked and updatable
                        }, ps);
                    }
                }

                int result = -1;

                // Load the EasyHook assembly in the child AppDomain by using the proxy class
                Type proxyType = typeof(LoadEasyHookProxy);
                if (proxyType.Assembly != null)
                {
                    // This is where the currentDomain.AssemblyResolve that we setup within the static
                    // constructor is required.
                    var proxy = (LoadEasyHookProxy)_easyHookDomain.CreateInstanceFrom(
                        proxyType.Assembly.Location,
                        proxyType.FullName).Unwrap();

                    // Loads EasyHook.dll into the AppDomain, which in turn loads the target assembly
                    result = proxy.Load(inParam);
                }

                //result = new LoadEasyHookProxy().Load(inParam);
                return(result);
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("Exception occured within Loader.Load: " + e.ToString());
            }
            finally
            {
                lock (_lock)
                {
                    _injectCount--;
                }
            }

            // Failed
            return(-1);
        }
Exemple #9
0
 private void yesBtn_Click(object sender, EventArgs e)
 {
     try
     {
         XmlDocument xDoc           = new XmlDocument();
         string      sourceFilePath = string.Format("{0}{1}{2}{3}{4}{5}{6}", Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), System.IO.Path.DirectorySeparatorChar, "bLoyal", System.IO.Path.DirectorySeparatorChar, "Dinerware Integration", System.IO.Path.DirectorySeparatorChar, "DinerwareConfigurationFile.xml");
         xDoc.Load(@"" + sourceFilePath);
         xDoc.DocumentElement.SelectSingleNode("EnablebLoyal").InnerText = "true";
         var    permissionSet    = new System.Security.PermissionSet(System.Security.Permissions.PermissionState.None);
         string sourceFolderPath = string.Format("{0}{1}{2}{3}{4}", Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), System.IO.Path.DirectorySeparatorChar, "bLoyal", System.IO.Path.DirectorySeparatorChar, "Dinerware Integration");
         var    writePermission  = new System.Security.Permissions.FileIOPermission(System.Security.Permissions.FileIOPermissionAccess.Write, @"" + sourceFolderPath);
         permissionSet.AddPermission(writePermission);
         if (permissionSet.IsSubsetOf(AppDomain.CurrentDomain.PermissionSet))
         {
             xDoc.Save(@"" + sourceFilePath);
         }
     }
     catch (Exception ex)
     {
     }
     this.Close();
 }
        void CreateAppDomain()
        {
            System.AppDomainSetup pythonAppDomainSetup = new AppDomainSetup();
            pythonAppDomainSetup.ApplicationBase = ".";

            bool usePermissionTest = false;

            if (usePermissionTest)
            {
                System.Security.PermissionSet permissionSet = new System.Security.PermissionSet(System.Security.Permissions.PermissionState.None);
                permissionSet.AddPermission(new System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityPermissionFlag.Execution));
                //permissionSet.AddPermission(new System.Security.Permissions.FileIOPermission(System.Security.Permissions.PermissionState.Unrestricted));

                compilerAppDomain = System.AppDomain.CreateDomain("Python App Domain", null, pythonAppDomainSetup, permissionSet, null);
            }
            else
            {
                compilerAppDomain = System.AppDomain.CreateDomain("Python App Domain");
            }

            Dictionary <string, object> options = new Dictionary <string, object>();

            options["Debug"] = true;
        }
        [System.Security.SecuritySafeCritical]  // auto-generated
        private static EraInfo[] GetErasFromRegistry()
        {
            // Look in the registry key and see if we can find any ranges
            int iFoundEras = 0;
            EraInfo[] registryEraRanges = null;
#if !MONO            
            try
            {
                // Need to access registry
                PermissionSet permSet = new PermissionSet(PermissionState.None);
                permSet.AddPermission(new RegistryPermission(RegistryPermissionAccess.Read, c_japaneseErasHivePermissionList));
                permSet.Assert();
                RegistryKey key = RegistryKey.GetBaseKey(RegistryKey.HKEY_LOCAL_MACHINE).OpenSubKey(c_japaneseErasHive, false);

                // Abort if we didn't find anything
                if (key == null) return null;

                // Look up the values in our reg key
                String[] valueNames = key.GetValueNames();
                if (valueNames != null && valueNames.Length > 0)
                {
                    registryEraRanges = new EraInfo[valueNames.Length];

                    // Loop through the registry and read in all the values
                    for (int i = 0; i < valueNames.Length; i++)
                    {
                        // See if the era is a valid date
                        EraInfo era = GetEraFromValue(valueNames[i], key.GetValue(valueNames[i]).ToString());

                        // continue if not valid
                        if (era == null) continue;

                        // Remember we found one.
                        registryEraRanges[iFoundEras] = era;
                        iFoundEras++;                        
                    }
                }
            }
            catch (System.Security.SecurityException)
            {
                // If we weren't allowed to read, then just ignore the error
                return null;
            }
            catch (System.IO.IOException)
            {
                // If key is being deleted just ignore the error
                return null;
            }
            catch (System.UnauthorizedAccessException)
            {
                // Registry access rights permissions, just ignore the error
                return null;
            }

            //
            // If we didn't have valid eras, then fail
            // should have at least 4 eras
            //
            if (iFoundEras < 4) return null;

            //
            // Now we have eras, clean them up.
            //
            // Clean up array length
            Array.Resize(ref registryEraRanges, iFoundEras);

            // Sort them
            Array.Sort(registryEraRanges, CompareEraRanges);

            // Clean up era information
            for (int i = 0; i < registryEraRanges.Length; i++)
            {
                // eras count backwards from length to 1 (and are 1 based indexes into string arrays)
                registryEraRanges[i].era = registryEraRanges.Length - i;

                // update max era year
                if (i == 0)
                {
                    // First range is 'til the end of the calendar
                    registryEraRanges[0].maxEraYear = GregorianCalendar.MaxYear - registryEraRanges[0].yearOffset;
                }
                else
                {
                    // Rest are until the next era (remember most recent era is first in array)
                    registryEraRanges[i].maxEraYear = registryEraRanges[i-1].yearOffset + 1 - registryEraRanges[i].yearOffset;
                }
            }
#endif
            // Return our ranges
            return registryEraRanges;
        }
        // NOTE: This is just a private helper because OracleClient V1.1 shipped
        // with a different argument name and it's a breaking change to not use
        // the same argument names in V2.0 (VB Named Parameter Binding--Ick)
        private void EnlistDistributedTransactionHelper(System.EnterpriseServices.ITransaction transaction) {
            System.Security.PermissionSet permissionSet = new System.Security.PermissionSet(System.Security.Permissions.PermissionState.None);
            permissionSet.AddPermission(CONNECTIONOBJECTNAME.ExecutePermission); // MDAC 81476
            permissionSet.AddPermission(new System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode));
            permissionSet.Demand();

            Bid.Trace( "<prov.DbConnectionHelper.EnlistDistributedTransactionHelper|RES|TRAN> %d#, Connection enlisting in a transaction.\n", ObjectID);
            SysTx.Transaction indigoTransaction = null;

            if (null != transaction) {
                indigoTransaction = SysTx.TransactionInterop.GetTransactionFromDtcTransaction((SysTx.IDtcTransaction)transaction);
            }

            RepairInnerConnection();
            // NOTE: since transaction enlistment involves round trips to the
            // server, we don't want to lock here, we'll handle the race conditions
            // elsewhere.
            InnerConnection.EnlistTransaction(indigoTransaction);

            // NOTE: If this outer connection were to be GC'd while we're
            // enlisting, the pooler would attempt to reclaim the inner connection
            // while we're attempting to enlist; not sure how likely that is but
            // we should consider a GC.KeepAlive(this) here.
            GC.KeepAlive(this);
        }
        [System.Security.SecuritySafeCritical]  // auto-generated
        private static EraInfo[] GetErasFromRegistry()
        {
            // Look in the registry key and see if we can find any ranges
            int iFoundEras = 0;

            EraInfo[] registryEraRanges = null;

            try
            {
                // Need to access registry
                PermissionSet permSet = new PermissionSet(PermissionState.None);
                permSet.AddPermission(new RegistryPermission(RegistryPermissionAccess.Read, c_japaneseErasHivePermissionList));
                permSet.Assert();
                RegistryKey key = Registry.LocalMachine.OpenSubKey(c_japaneseErasHive, writable: false);

                // Abort if we didn't find anything
                if (key == null)
                {
                    return(null);
                }

                // Look up the values in our reg key
                String[] valueNames = key.GetValueNames();
                if (valueNames != null && valueNames.Length > 0)
                {
                    registryEraRanges = new EraInfo[valueNames.Length];

                    // Loop through the registry and read in all the values
                    for (int i = 0; i < valueNames.Length; i++)
                    {
                        // See if the era is a valid date
                        EraInfo era = GetEraFromValue(valueNames[i], key.GetValue(valueNames[i]).ToString());

                        // continue if not valid
                        if (era == null)
                        {
                            continue;
                        }

                        // Remember we found one.
                        registryEraRanges[iFoundEras] = era;
                        iFoundEras++;
                    }
                }
            }
            catch (System.Security.SecurityException)
            {
                // If we weren't allowed to read, then just ignore the error
                return(null);
            }
            catch (System.IO.IOException)
            {
                // If key is being deleted just ignore the error
                return(null);
            }
            catch (System.UnauthorizedAccessException)
            {
                // Registry access rights permissions, just ignore the error
                return(null);
            }

            //
            // If we didn't have valid eras, then fail
            // should have at least 4 eras
            //
            if (iFoundEras < 4)
            {
                return(null);
            }

            //
            // Now we have eras, clean them up.
            //
            // Clean up array length
            Array.Resize(ref registryEraRanges, iFoundEras);

            // Sort them
            Array.Sort(registryEraRanges, CompareEraRanges);

            // Clean up era information
            for (int i = 0; i < registryEraRanges.Length; i++)
            {
                // eras count backwards from length to 1 (and are 1 based indexes into string arrays)
                registryEraRanges[i].era = registryEraRanges.Length - i;

                // update max era year
                if (i == 0)
                {
                    // First range is 'til the end of the calendar
                    registryEraRanges[0].maxEraYear = GregorianCalendar.MaxYear - registryEraRanges[0].yearOffset;
                }
                else
                {
                    // Rest are until the next era (remember most recent era is first in array)
                    registryEraRanges[i].maxEraYear = registryEraRanges[i - 1].yearOffset + 1 - registryEraRanges[i].yearOffset;
                }
            }

            // Return our ranges
            return(registryEraRanges);
        }
Exemple #14
0
        public static int Load([MarshalAs(UnmanagedType.LPWStr)] String inParam)
        {
            try
            {
                lock (_lock)
                {
                    try
                    {
                        _injectCount++;
                        if (_easyHookDomain == null)
                        {
                            System.Security.PermissionSet ps = new System.Security.PermissionSet(System.Security.Permissions.PermissionState.Unrestricted);
                            ps.AddPermission(new System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityPermissionFlag.AllFlags));
                            // Evidence of null means use the current appdomain evidence
                            _easyHookDomain = AppDomain.CreateDomain("EasyHook", null, new AppDomainSetup()
                            {
                                ApplicationBase = Path.GetDirectoryName(typeof(Loader).Assembly.Location),
                                // ShadowCopyFiles = "true", // copies assemblies from ApplicationBase into cache, leaving originals unlocked and updatable
                            }, ps);
                        }
                    }
                    catch (OutOfMemoryException ome)
                    {
                        // Creation of AppDomain failed, so fall back to using default domain (means it cannot be unloaded)

                        // The reason is there could be an issue with the target application's stack commit size.
                        // The default stack commit size must be <= 253952 (or 0x3E000) - due to bug in .NET Framework,
                        // this can be checked with dumpbin.exe and edited with editbin.exe.

                        // Load EasyHook and the target assembly
                        LoadEasyHookProxy lp = new LoadEasyHookProxy();
                        return(lp.Load(inParam));
                    }
                }

                int result = -1;

                // Load the EasyHook assembly in the child AppDomain by using the proxy class
                Type proxyType = typeof(LoadEasyHookProxy);
                if (proxyType.Assembly != null)
                {
                    // This is where the currentDomain.AssemblyResolve that we setup within the static
                    // constructor is required.
                    var proxy = (LoadEasyHookProxy)_easyHookDomain.CreateInstanceFrom(
                        proxyType.Assembly.Location,
                        proxyType.FullName).Unwrap();

                    // Loads EasyHook.dll into the AppDomain, which in turn loads the target assembly
                    result = proxy.Load(inParam);
                }

                //result = new LoadEasyHookProxy().Load(inParam);
                return(result);
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("Exception occurred within Loader.Load: " + e.ToString());
            }
            finally
            {
                lock (_lock)
                {
                    _injectCount--;
                }
            }

            // Failed
            return(-1);
        }
 protected internal override System.Security.PermissionSet CreatePermissionSet()
 {
     System.Security.PermissionSet permissionSet = new System.Security.PermissionSet(System.Security.Permissions.PermissionState.None);
     permissionSet.AddPermission(new SqlClientPermission(this));
     return(permissionSet);
 }
 private System.Security.PermissionSet GetPermissionSet(ISecurityAttribute securityAttribute) {
   var result = new System.Security.PermissionSet(System.Security.Permissions.PermissionState.None);
   foreach (var attribute in securityAttribute.Attributes) {
     var permission = this.GetPermission(securityAttribute.Action, attribute);
     if (permission == null) continue; //not a trusted permission
     result.AddPermission(permission);
   }
   return result;
 }
        void CreateAppDomain()
        {
            System.AppDomainSetup pythonAppDomainSetup = new AppDomainSetup();
            pythonAppDomainSetup.ApplicationBase = ".";

            bool usePermissionTest = false;
            if (usePermissionTest)
            {
                System.Security.PermissionSet permissionSet = new System.Security.PermissionSet(System.Security.Permissions.PermissionState.None);
                permissionSet.AddPermission(new System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityPermissionFlag.Execution));
                //permissionSet.AddPermission(new System.Security.Permissions.FileIOPermission(System.Security.Permissions.PermissionState.Unrestricted));

                compilerAppDomain = System.AppDomain.CreateDomain("Python App Domain", null, pythonAppDomainSetup, permissionSet, null);
            }
            else
            {
                compilerAppDomain = System.AppDomain.CreateDomain("Python App Domain");
            }

            Dictionary<string, object> options = new Dictionary<string, object>();
            options["Debug"] = true;
        }
Exemple #18
0
        public static int Load([MarshalAs(UnmanagedType.LPWStr)]String inParam)
        {
            try
            {
                lock (_lock)
                {
                    try
                    {
                        _injectCount++;
                        if (_easyHookDomain == null)
                        {
                            System.Security.PermissionSet ps = new System.Security.PermissionSet(System.Security.Permissions.PermissionState.Unrestricted);
                            ps.AddPermission(new System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityPermissionFlag.AllFlags));
                            // Evidence of null means use the current appdomain evidence
                            _easyHookDomain = AppDomain.CreateDomain("EasyHook", null, new AppDomainSetup()
                            {
                                ApplicationBase = Path.GetDirectoryName(typeof(Loader).Assembly.Location),
                                // ShadowCopyFiles = "true", // copies assemblies from ApplicationBase into cache, leaving originals unlocked and updatable
                            }, ps);
                        }
                    }
                    catch (OutOfMemoryException ome)
                    {
                        // Creation of AppDomain failed, so fall back to using default domain (means it cannot be unloaded)
                        
                        // The reason is there could be an issue with the target application's stack commit size.
                        // The default stack commit size must be <= 253952 (or 0x3E000) - due to bug in .NET Framework, 
                        // this can be checked with dumpbin.exe and edited with editbin.exe.

                        // Load EasyHook and the target assembly
                        LoadEasyHookProxy lp = new LoadEasyHookProxy();
                        lp.Load(inParam);
                        return 1;
                    }
                }

                int result = -1;

                // Load the EasyHook assembly in the child AppDomain by using the proxy class
                Type proxyType = typeof(LoadEasyHookProxy);
                if (proxyType.Assembly != null)
                {
                    // This is where the currentDomain.AssemblyResolve that we setup within the static 
                    // constructor is required.
                    var proxy = (LoadEasyHookProxy)_easyHookDomain.CreateInstanceFrom(
                                    proxyType.Assembly.Location,
                                    proxyType.FullName).Unwrap();

                    // Loads EasyHook.dll into the AppDomain, which in turn loads the target assembly
                    result = proxy.Load(inParam);
                }

                //result = new LoadEasyHookProxy().Load(inParam);
                return result;
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("Exception occurred within Loader.Load: " + e.ToString());
            }
            finally
            {
                lock (_lock)
                {
                    _injectCount--;
                }
            }

            // Failed
            return -1;
        }