public ClipboardBackup()
 {
     UIPermission clipBoard = new UIPermission(PermissionState.None)
     {
         Clipboard = UIPermissionClipboard.AllClipboard
     };
 }
Exemple #2
0
        private void SetUpInputHooks()
        {
            IKeyboardInputSink sink;

            new UIPermission(PermissionState.Unrestricted).Assert(); //BlessedAssert
            try
            {
                _inputPostFilter = new HwndWrapperHook(BrowserInteropHelper.PostFilterInput);
                HwndSource hwndSource = base.HwndSourceWindow;
                hwndSource.HwndWrapper.AddHookLast(_inputPostFilter);

                sink = (IKeyboardInputSink)hwndSource;
            }
            finally
            {
                UIPermission.RevertAll();
            }
            new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Assert(); //BlessedAssert
            try
            {
                Debug.Assert(sink.KeyboardInputSite == null);
                sink.KeyboardInputSite = new KeyInputSite(new SecurityCriticalData <IKeyboardInputSink>(sink));
            }
            finally
            {
                SecurityPermission.RevertAll();
            }
        }
Exemple #3
0
    // </Snippet2>
    // <Snippet3>
    // Union creates a new permission that is the union of the current permission
    // and the specified permission.
    private static void UnionDemo()
    {
        UIPermission uiPerm1 = new UIPermission(UIPermissionWindow.SafeTopLevelWindows);
        UIPermission uiPerm2 = new UIPermission(UIPermissionWindow.SafeSubWindows);
        UIPermission p3      = (UIPermission)uiPerm1.Union(uiPerm2);

        try
        {
            if (p3 != null)
            {
                Console.WriteLine("The union of " + uiPerm1.Window.ToString() +
                                  " and \n\t" + uiPerm2.Window.ToString() + " is \n\t"
                                  + p3.Window.ToString() + "\n");
            }
            else
            {
                Console.WriteLine("The union of " + uiPerm1.Window.ToString() +
                                  " and \n\t" + uiPerm2.Window.ToString() + " is null.\n");
            }
        }
        catch (SystemException e)
        {
            Console.WriteLine("The union of " + uiPerm1.Window.ToString() +
                              " and \n\t" + uiPerm2.Window.ToString() + " failed.");

            Console.WriteLine(e.Message);
        }
    }
        public void Union_DifferentPermissions()
        {
            UIPermission       a = new UIPermission(PermissionState.None);
            SecurityPermission b = new SecurityPermission(PermissionState.None);

            a.Union(b);
        }
Exemple #5
0
        // Copies the internal strokes to the IDataObject
        protected override void DoCopy(IDataObject dataObject)
        {
            // samgeo - Presharp issue
            // Presharp gives a warning when local IDisposable variables are not closed
            // in this case, we can't call Dispose since it will also close the underlying stream
            // which needs to be open for consumers to read
#pragma warning disable 1634, 1691
#pragma warning disable 6518

            // Save the data in the data object.
            MemoryStream stream = new MemoryStream();
            Strokes.Save(stream);
            stream.Position = 0;
            (new UIPermission(UIPermissionClipboard.AllClipboard)).Assert();//BlessedAssert
            try
            {
                dataObject.SetData(StrokeCollection.InkSerializedFormat, stream);
            }
            finally
            {
                UIPermission.RevertAssert();
            }
#pragma warning restore 6518
#pragma warning restore 1634, 1691
        }
        public void IsSubsetOf_DifferentPermissions()
        {
            UIPermission       a = new UIPermission(PermissionState.None);
            SecurityPermission b = new SecurityPermission(PermissionState.None);

            a.IsSubsetOf(b);
        }
        /// <summary>
        /// 过滤消息
        /// Filters out a message before it is dispatched
        /// </summary>
        /// <param name="m">The message to be dispatched. You cannot modify
        /// this message</param>
        /// <returns>true to filter the message and prevent it from being
        /// dispatched; false to allow the message to continue to the next
        /// filter or control</returns>
        public bool PreFilterMessage(ref Message m)
        {
            //确保有一个client
            // make sure we have a client
            if (this.Client == null)
            {
                return(false);
            }

            //确保消息是一个鼠标消息
            // make sure the message is a mouse message
            if ((m.Msg >= (int)I3WindowMessage.WM_MOUSEMOVE && m.Msg <= (int)I3WindowMessage.WM_XBUTTONDBLCLK) ||
                (m.Msg >= (int)I3WindowMessage.WM_NCMOUSEMOVE && m.Msg <= (int)I3WindowMessage.WM_NCXBUTTONUP))
            {
                //尝试获取目标控件
                // try to get the target control
                UIPermission uiPermission = new UIPermission(UIPermissionWindow.AllWindows);
                uiPermission.Demand();
                Control target = Control.FromChildHandle(m.HWnd);

                //实际上鼠标消息的过滤,是由client来实现的
                return(this.Client.ProcessMouseMessage(target, (I3WindowMessage)m.Msg, m.WParam.ToInt32(), m.LParam.ToInt32()));
            }

            //不是鼠标消息,返回false,消息可以继续派发
            return(false);
        }
Exemple #8
0
 public void SetClipboardSettings()
 {
     try {
         var permission = new UIPermission(UIPermissionClipboard.AllClipboard);
         if (Clipboard.ContainsData("UPDATEDATAv3"))
         {
             var rawClipboarData = (string)Clipboard.GetData("UPDATEDATAv3");
             var clipboardData   = new Dictionary <string, string>();
             foreach (string dataItem in rawClipboarData.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries))
             {
                 clipboardData.Add(
                     dataItem.Split(new[] { '#' })[0],
                     dataItem.Split(new[] { '#' })[1]
                     );
             }
             //UpdateURL = clipboardData["updateUrl"];
             ProjektID = clipboardData["projectId"];
             PublicKey = clipboardData["publicKey"];
         }
         else
         {
             MessageBox.Show("Es konnten keine Updateinformationen in der Zwischenablage gefunden werden.", "updateSystem.NET",
                             MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         }
         RefreshDesigner();
     }
     catch (Exception ex) {
         MessageBox.Show(
             string.Format("Die Updateeinstellungen konnten aufgrund eines Fehlers nicht übernommen werden:\r\n{0}", ex.ToString()),
             "updateSystem.Net", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Exemple #9
0
        // Loads any steps
        protected override void OnLoad(System.EventArgs e)
        {
            base.OnLoad(e);

            if (!DesignMode)
            {
                OnLoadSteps(EventArgs.Empty);

                if (FirstStepName == "")
                {
                    throw new InvalidOperationException("FirstStepName must be be a non-empty string.");
                }

                ResetSteps();

                SetCurrentStep(FirstStepName, StepDirection.InitialStep);
            }
            else
            {
                UpdateLayout(currentLayout);
            }

            UIPermission uiP = new UIPermission(UIPermissionWindow.AllWindows);

            uiP.Demand();
        }
Exemple #10
0
        internal HwndStylusInputProvider(HwndSource source)
        {
            InputManager inputManager = InputManager.Current;
            StylusLogic  stylusLogic  = inputManager.StylusLogic;

            IntPtr sourceHandle;

            (new UIPermission(PermissionState.Unrestricted)).Assert();
            try //Blessed Assert this is for RegisterInputManager and RegisterHwndforinput
            {
                // Register ourselves as an input provider with the input manager.
                _site = new SecurityCriticalDataClass <InputProviderSite>(inputManager.RegisterInputProvider(this));

                sourceHandle = source.Handle;
            }
            finally
            {
                UIPermission.RevertAssert();
            }

            stylusLogic.RegisterHwndForInput(inputManager, source);
            _source      = new SecurityCriticalDataClass <HwndSource>(source);
            _stylusLogic = new SecurityCriticalDataClass <StylusLogic>(stylusLogic);

            // Enables multi-touch input
            UnsafeNativeMethods.SetProp(new HandleRef(this, sourceHandle), "MicrosoftTabletPenServiceProperty", new HandleRef(null, new IntPtr(MultiTouchEnabledFlag)));
        }
Exemple #11
0
        private static object NotifySource(Object args)
        {
            object[]           argsArray = (object[])args;
            PresentationSource source    = argsArray[0] as PresentationSource;

            if (source != null && !source.IsDisposed)
            {
                bool needAsserts = System.Security.SecurityManager.CurrentThreadRequiresSecurityContextCapture();
                if (needAsserts)
                {
                    // permission required to set RootVisual
                    new UIPermission(UIPermissionWindow.AllWindows).Assert();
                }

                // setting the RootVisual to itself triggers the logic to
                // add to the AutomationEvents list
                source.RootVisual = source.RootVisual;

                if (needAsserts)
                {
                    UIPermission.RevertAssert();
                }
            }
            return(null);
        }
        /// <summary>
        /// Filters out a message before it is dispatched
        /// </summary>
        /// <param name="m">The message to be dispatched. You cannot modify
        /// this message</param>
        /// <returns>true to filter the message and prevent it from being
        /// dispatched; false to allow the message to continue to the next
        /// filter or control</returns>
        public bool PreFilterMessage(ref Message m)
        {
            // make sure we have a client
            if (this.Client == null)
            {
                return(false);
            }

            // make sure the message is a key message
            if (m.Msg != (int)I3WindowMessage.WM_KEYDOWN && m.Msg != (int)I3WindowMessage.WM_SYSKEYDOWN &&
                m.Msg != (int)I3WindowMessage.WM_KEYUP && m.Msg != (int)I3WindowMessage.WM_SYSKEYUP)
            {
                return(false);
            }

            // try to get the target control
            UIPermission uiPermission = new UIPermission(UIPermissionWindow.AllWindows);

            uiPermission.Demand();
            Control target = Control.FromChildHandle(m.HWnd);

            try
            {
                return(this.Client.ProcessKeyMessage(target, (I3WindowMessage)m.Msg, m.WParam.ToInt32(), m.LParam.ToInt32()));
            }
            catch
            {
                return(true);
            }
        }
Exemple #13
0
        public void Intersect_DifferentPermissions()
        {
            UIPermission       a = new UIPermission(PermissionState.None);
            SecurityPermission b = new SecurityPermission(PermissionState.None);

            a.Intersect(b);
        }
Exemple #14
0
 internal static void DemandUnrestrictedUIPermission()
 {
     if (_unrestrictedUIPermission == null)
     {
         _unrestrictedUIPermission = new UIPermission(PermissionState.Unrestricted);
     }
     _unrestrictedUIPermission.Demand();
 }
Exemple #15
0
 internal static void DemandUIWindowPermission()
 {
     if (_allWindowsUIPermission == null)
     {
         _allWindowsUIPermission = new UIPermission(UIPermissionWindow.AllWindows);
     }
     _allWindowsUIPermission.Demand();
 }
Exemple #16
0
        public void FromXml_WrongTagCase()
        {
            UIPermission    uip = new UIPermission(PermissionState.None);
            SecurityElement se  = uip.ToXml();

            se.Tag = "IPERMISSION";             // instead of IPermission
            uip.FromXml(se);
        }
Exemple #17
0
            protected override IStackWalk CreateStackWalk()
            {
                UIPermission permission = new UIPermission(PermissionState.Unrestricted);

                permission.Clipboard = attribute.Clipboard;
                permission.Window    = attribute.Window;
                return(permission);
            }
Exemple #18
0
 internal static void DemandAllClipboardPermission()
 {
     if (_uiPermissionAllClipboard == null)
     {
         _uiPermissionAllClipboard = new UIPermission(UIPermissionClipboard.AllClipboard);
     }
     _uiPermissionAllClipboard.Demand();
 }
Exemple #19
0
        public void UIPermission_Clipboard_Own()
        {
            UIPermission uip = new UIPermission(UIPermissionClipboard.OwnClipboard);

            Assert.AreEqual(UIPermissionClipboard.OwnClipboard, uip.Clipboard, "Clipboard");
            Assert.AreEqual(UIPermissionWindow.NoWindows, uip.Window, "Window");
            Assert.IsFalse(uip.IsUnrestricted(), "IsUnrestricted");
        }
Exemple #20
0
        public void UIPermission_Windows_SafeTopLevelWindows()
        {
            UIPermission uip = new UIPermission(UIPermissionWindow.SafeTopLevelWindows);

            Assert.AreEqual(UIPermissionClipboard.NoClipboard, uip.Clipboard, "Clipboard");
            Assert.AreEqual(UIPermissionWindow.SafeTopLevelWindows, uip.Window, "Window");
            Assert.IsFalse(uip.IsUnrestricted(), "IsUnrestricted");
        }
Exemple #21
0
        public static Point ClientToScreen(Point ptClient, PresentationSource presentationSource)
        {
            // For now we only know how to use HwndSource.
            HwndSource inputSource = presentationSource as HwndSource;

            if (inputSource == null)
            {
                return(ptClient);
            }

            // Convert the point to screen coordinates.
            NativeMethods.POINT ptScreen = new NativeMethods.POINT((int)ptClient.X, (int)ptClient.Y);

            // MITIGATION: AVALON_RTL_AND_WIN32RTL
            //
            // When a window is marked with the WS_EX_LAYOUTRTL style, Win32
            // mirrors the coordinates during the various translation APIs.
            //
            // Avalon also sets up mirroring transforms so that we properly
            // mirror the output since we render to DirectX, not a GDI DC.
            //
            // Unfortunately, this means that our coordinates are already mirrored
            // by Win32, and Avalon mirrors them again.  To work around this
            // problem, we un-mirror the coordinates from Win32 before hit-testing
            // in Avalon.
            //

            //
            // Assert for unamanaged code permission to get to the handle.
            // Note that we can't use HwndSource.UnsecureHandle here - as this method is called cross-assembly
            //
            HandleRef handleRef;

            new UIPermission(UIPermissionWindow.AllWindows).Assert(); // BlessedAssert:
            try
            {
                handleRef = new HandleRef(inputSource, inputSource.Handle);
            }
            finally
            {
                UIPermission.RevertAssert();
            }

            int windowStyle = UnsafeNativeMethods.GetWindowLong(handleRef, NativeMethods.GWL_EXSTYLE);

            if ((windowStyle & NativeMethods.WS_EX_LAYOUTRTL) == NativeMethods.WS_EX_LAYOUTRTL)
            {
                NativeMethods.RECT rcClient = new NativeMethods.RECT();
                SafeNativeMethods.GetClientRect(handleRef, ref rcClient);
                ptScreen.x = rcClient.right - ptScreen.x;
            }

            UnsafeNativeMethods.ClientToScreen(handleRef, ptScreen);

            return(new Point(ptScreen.x, ptScreen.y));
        }
Exemple #22
0
        internal CUIPermControls(IPermission perm, Object oParent) : base(perm, oParent)
        {
            // If they don't have a permission for this permission set, we will
            // feed our property page a 'none' permission state.

            if (perm == null)
            {
                m_perm = new UIPermission(PermissionState.None);
            }
        }// CUIPermControls
Exemple #23
0
        public void IsSubsetOf()
        {
            UIPermission unrestricted = new UIPermission(PermissionState.Unrestricted);
            UIPermission empty        = new UIPermission(PermissionState.None);

            Assert.IsFalse(unrestricted.IsSubsetOf(empty), "unrestricted.IsSubsetOf (empty)");
            Assert.IsTrue(empty.IsSubsetOf(unrestricted), "empty.IsSubsetOf (unrestricted)");
            Assert.IsTrue(empty.IsSubsetOf(null), "empty.IsSubsetOf (null)");
            Assert.IsFalse(unrestricted.IsSubsetOf(null), "unrestricted.IsSubsetOf (null)");
        }
Exemple #24
0
        public void Unrestricted()
        {
            UIPermissionAttribute a = new UIPermissionAttribute(SecurityAction.Assert);

            a.Unrestricted = true;
            UIPermission perm = (UIPermission)a.CreatePermission();

            Assert.AreEqual(UIPermissionClipboard.AllClipboard, perm.Clipboard, "Unrestricted-Clipboard");
            Assert.AreEqual(UIPermissionWindow.AllWindows, perm.Window, "Unrestricted-Window");
        }
Exemple #25
0
        // Updated May 20, 2003, switched from event handler to overriding the protected method
        protected override void OnLoad(System.EventArgs e)
        {
            base.OnLoad(e);

            UpdateLayout(pageLayout);

            UIPermission uiP = new UIPermission(UIPermissionWindow.AllWindows);

            uiP.Demand();
        }
Exemple #26
0
        public void FromXml_NoVersion()
        {
            UIPermission    uip = new UIPermission(PermissionState.None);
            SecurityElement se  = uip.ToXml();

            SecurityElement w = new SecurityElement(se.Tag);

            w.AddAttribute("class", se.Attribute("class"));
            uip.FromXml(w);
        }
Exemple #27
0
        public void FromXml_NoClass()
        {
            UIPermission    uip = new UIPermission(PermissionState.None);
            SecurityElement se  = uip.ToXml();

            SecurityElement w = new SecurityElement(se.Tag);

            w.AddAttribute("version", se.Attribute("version"));
            uip.FromXml(w);
            // doesn't even care of the class attribute presence
        }
Exemple #28
0
        public void FromXml_WrongClass()
        {
            UIPermission    uip = new UIPermission(PermissionState.None);
            SecurityElement se  = uip.ToXml();

            SecurityElement w = new SecurityElement(se.Tag);

            w.AddAttribute("class", "Wrong" + se.Attribute("class"));
            w.AddAttribute("version", se.Attribute("version"));
            uip.FromXml(w);
            // doesn't care of the class name at that stage
            // anyway the class has already be created so...
        }
 internal HwndKeyboardInputProvider(HwndSource source)
 {
     (new UIPermission(PermissionState.Unrestricted)).Assert();
     try //Blessed assert for InputManager.Current.RegisterInputProvider
     {
         _site = new SecurityCriticalDataClass <InputProviderSite>(InputManager.Current.RegisterInputProvider(this));
     }
     finally
     {
         UIPermission.RevertAssert();
     }
     _source = new SecurityCriticalDataClass <HwndSource>(source);
 }
 internal static void InitializeHostFilterInput()
 {
     (new UIPermission(PermissionState.Unrestricted)).Assert(); // Blessed assert
     try
     {
         ComponentDispatcher.ThreadFilterMessage +=
             new ThreadMessageEventHandler(HostFilterInput);
     }
     finally
     {
         UIPermission.RevertAssert();
     }
 }
    private static void CallUnmanagedCodeWithoutPermission()
    {
        try
        {
            // The UnmanagedCode security check is disbled on the call
            // below. However, the unmanaged call only displays UI. The
            // security will be ensured by only allowing the unmanaged
            // call if there is a UI permission.
            UIPermission uiPermission =
               new UIPermission(PermissionState.Unrestricted);
            uiPermission.Demand();

            Console.WriteLine("Attempting to call unmanaged code without UnmanagedCode permission.");
            NativeMethods.puts("Hello World!");
            NativeMethods._flushall();
            Console.WriteLine("Called unmanaged code without UnmanagedCode permission.");
        }
        catch (SecurityException)
        {
            Console.WriteLine("Caught Security Exception attempting to call unmanaged code.");
        }
    }
Exemple #32
0
 public static void UIPermissionCallMethods()
 {
     UIPermission uip = new UIPermission(new PermissionState());
     UIPermission uip2 = new UIPermission(new UIPermissionClipboard());
     UIPermission uip3 = new UIPermission(new UIPermissionWindow());
     UIPermission uip4 = new UIPermission(new UIPermissionWindow(), new UIPermissionClipboard());
     IPermission ip = uip.Copy();
     IPermission ip2 = uip.Intersect(ip);
     bool testbool = uip.IsSubsetOf(ip);
     testbool = uip.IsUnrestricted();
     ip2 = uip.Union(ip);
     SecurityElement se = new SecurityElement("");
     uip.FromXml(se);
     se = uip.ToXml();
 }