示例#1
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            // Sandboxer class
            Sandboxer appSandbox = new Sandboxer();

            LogThis("Executing " + Path.GetFileName(txtApplicationPath.Text));
            try
            {
                // Initialise & Application Execution
                appSandbox.ApplicationInitialise(txtApplicationPath.Text, txtApplicaitonParam.Text, pSet(string.Empty));
            }
            catch (SecurityException ex)
            {
                LogThis("ERROR : " + ex.Action.ToString());
                Console.WriteLine("--- {0} ERROR ---\n", Path.GetFileNameWithoutExtension(txtApplicationPath.Text));
                if (ex.Action.ToString() == "Demand")
                {
                    int cutPoint = ex.Message.ToString().IndexOf(",");
                    LogThis("DEMAND : " + ex.Message.ToString().Substring(0, cutPoint) + "'");
                }
            }


            LogThis("Terminated " + Path.GetFileName(txtApplicationPath.Text));
            ManageHistory();
            LogThis("Ready...");
        }
示例#2
0
        public void ApplicationInitialise(string txtAppPath, string txtAppParam, PermissionSet permSet)
        {
            string appFilePath = Path.GetDirectoryName(txtAppPath);

            string[] appFileParam    = txtAppParam.Split(' ');
            string   appAssemblyName = Path.GetFileNameWithoutExtension(txtAppPath);

            // Application Domain Setup
            AppDomainSetup adSetup = new AppDomainSetup();

            adSetup.ApplicationBase = appFilePath;

            // Strong Name using 'Sandboxer_Key.snk'
            StrongName fullTrustAssembly = typeof(Sandboxer).Assembly.Evidence.GetHostEvidence <StrongName>();

            // Create Application Domain with a random 'ID' value so not all sandbox domains are the same
            Random    rnd       = new Random();
            AppDomain newDomain = AppDomain.CreateDomain("Sandbox" + rnd.Next().ToString(), null, adSetup, permSet, fullTrustAssembly);

            // Object handle
            ObjectHandle handle = Activator.CreateInstanceFrom(
                newDomain,
                typeof(Sandboxer).Assembly.ManifestModule.FullyQualifiedName,
                typeof(Sandboxer).FullName);

            // Execute Application code
            Sandboxer newDomainInstance = (Sandboxer)handle.Unwrap();

            Console.WriteLine("--- {0} STARTED ---", appAssemblyName);
            newDomain.ExecuteAssembly(txtAppPath, appFileParam);
            Console.WriteLine("--- {0} FINISHED ---\n", appAssemblyName);
        }
示例#3
0
        public void cmdManage(string[] args)
        {
            // Help/Permissions list display after the appripriate -h argument entered
            if (args.Contains("-h") || args.Contains("-H"))
            {
                Console.WriteLine(@"Parameters: ""<application path>"" ""<application parameters>"" ""<permissions>""");
                Console.WriteLine("-un = Unrestricted permissions");
                Console.WriteLine("-io = IO permissions");
                Console.WriteLine("-ui = UI permissions");
                Console.WriteLine("-fd = File Dialog permissions");
                Console.WriteLine("-sec = Security permissions");
                Console.WriteLine("-is = Isolated Storage permissions");
                Console.WriteLine("-env = Environment permissions");
                Console.WriteLine("-kc = Key Container permissions");
                Console.WriteLine("-pr = Principal permissions");
                Console.WriteLine("-ref = Reflection permissions");
                Console.WriteLine("-reg = Registry permissions");
                Console.WriteLine("-st = Store permissions");
                Console.WriteLine("-ctd = Check Type Descriptor permissions");
                Console.WriteLine("-web = Web permissions");
            }
            else
            {
                Console.WriteLine("HINT - Use -h for Help & Permissions List");
            }

            // Execute Sandboxer functionality through command line when appropriate amount of arguments given
            if (args.Count() == 3)
            {
                Sandboxer appSandbox = new Sandboxer();
                try
                {
                    appSandbox.ApplicationInitialise(args[0].ToString(), args[1].ToString(), pSet(args[2].ToString()));
                }
                catch (SecurityException ex)
                {
                    Console.WriteLine("ERROR : " + ex.Action.ToString());
                    if (ex.Action.ToString() == "Demand")
                    {
                        int cutPoint = ex.Message.ToString().IndexOf(",");
                        Console.WriteLine("DEMAND : " + ex.Message.ToString().Substring(0, cutPoint) + "'");
                    }
                }
            }
        }