Exemplo n.º 1
0
        public DialogResult ShowDialog()
        {
            Application.DoEvents();

            Bitmap bmpBack = UIUtil.CreateScreenshot();

            if (bmpBack != null)
            {
                UIUtil.DimImage(bmpBack);
            }

            DialogResult dr = DialogResult.None;

            try
            {
                uint   uOrgThreadId = NativeMethods.GetCurrentThreadId();
                IntPtr pOrgDesktop  = NativeMethods.GetThreadDesktop(uOrgThreadId);

                string strName = "D" + Guid.NewGuid().ToString();
                strName = strName.Replace(@"+", string.Empty);
                strName = strName.Replace(@"/", string.Empty);
                strName = strName.Replace(@"=", string.Empty);

                NativeMethods.DesktopFlags deskFlags =
                    NativeMethods.DesktopFlags.CreateMenu |
                    NativeMethods.DesktopFlags.CreateWindow |
                    NativeMethods.DesktopFlags.ReadObjects |
                    NativeMethods.DesktopFlags.WriteObjects |
                    NativeMethods.DesktopFlags.SwitchDesktop;

                IntPtr pNewDesktop = NativeMethods.CreateDesktop(strName,
                                                                 null, IntPtr.Zero, 0, deskFlags, IntPtr.Zero);

                SecureThreadParams stp = new SecureThreadParams();
                stp.BackgroundBitmap = bmpBack;
                stp.ThreadDesktop    = pNewDesktop;

                Thread th = new Thread(this.SecureDialogThread);
                th.CurrentCulture   = Thread.CurrentThread.CurrentCulture;
                th.CurrentUICulture = Thread.CurrentThread.CurrentUICulture;
                th.Start(stp);
                th.Join();

                NativeMethods.SwitchDesktop(pOrgDesktop);
                NativeMethods.SetThreadDesktop(pOrgDesktop);

                NativeMethods.CloseDesktop(pNewDesktop);
                NativeMethods.CloseDesktop(pOrgDesktop);

                dr = stp.Result;
            }
            catch (Exception) { Debug.Assert(false); }

            return(dr);
        }
Exemplo n.º 2
0
		public DialogResult ShowDialog()
		{
			Application.DoEvents();

			Bitmap bmpBack = UIUtil.CreateScreenshot();
			if(bmpBack != null) UIUtil.DimImage(bmpBack);

			DialogResult dr = DialogResult.None;

			try
			{
				uint uOrgThreadId = NativeMethods.GetCurrentThreadId();
				IntPtr pOrgDesktop = NativeMethods.GetThreadDesktop(uOrgThreadId);

				string strName = "D" + Guid.NewGuid().ToString();
				strName = strName.Replace(@"+", string.Empty);
				strName = strName.Replace(@"/", string.Empty);
				strName = strName.Replace(@"=", string.Empty);

				NativeMethods.DesktopFlags deskFlags =
					NativeMethods.DesktopFlags.CreateMenu |
					NativeMethods.DesktopFlags.CreateWindow |
					NativeMethods.DesktopFlags.ReadObjects |
					NativeMethods.DesktopFlags.WriteObjects |
					NativeMethods.DesktopFlags.SwitchDesktop;

				IntPtr pNewDesktop = NativeMethods.CreateDesktop(strName,
					null, IntPtr.Zero, 0, deskFlags, IntPtr.Zero);

				SecureThreadParams stp = new SecureThreadParams();
				stp.BackgroundBitmap = bmpBack;
				stp.ThreadDesktop = pNewDesktop;

				Thread th = new Thread(this.SecureDialogThread);
				th.CurrentCulture = Thread.CurrentThread.CurrentCulture;
				th.CurrentUICulture = Thread.CurrentThread.CurrentUICulture;
				th.Start(stp);
				th.Join();

				NativeMethods.SwitchDesktop(pOrgDesktop);
				NativeMethods.SetThreadDesktop(pOrgDesktop);

				NativeMethods.CloseDesktop(pNewDesktop);
				NativeMethods.CloseDesktop(pOrgDesktop);

				dr = stp.Result;
			}
			catch(Exception) { Debug.Assert(false); }

			return dr;
		}
Exemplo n.º 3
0
        private void SecureDialogThread(object oParam)
        {
            try
            {
                SecureThreadParams stp = oParam as SecureThreadParams;
                if (stp == null)
                {
                    Debug.Assert(false); return;
                }

                NativeMethods.SetThreadDesktop(stp.ThreadDesktop);

                BackgroundForm formBack = new BackgroundForm(
                    stp.BackgroundBitmap);
                formBack.Show();

                NativeMethods.SwitchDesktop(stp.ThreadDesktop);

                stp.Result = m_form.ShowDialog(formBack);

                formBack.Hide();
            }
            catch (Exception) { Debug.Assert(false); }
        }
Exemplo n.º 4
0
        public DialogResult ShowDialog(out object objResult, object objConstructParam)
        {
            objResult = null;

            ProcessMessagesEx();

            ClipboardEventChainBlocker ccb = new ClipboardEventChainBlocker();
            byte[] pbClipHash = ClipboardUtil.ComputeHash();

            Bitmap bmpBack = UIUtil.CreateScreenshot();
            if(bmpBack != null) UIUtil.DimImage(bmpBack);

            DialogResult dr = DialogResult.None;
            try
            {
                uint uOrgThreadId = NativeMethods.GetCurrentThreadId();
                IntPtr pOrgDesktop = NativeMethods.GetThreadDesktop(uOrgThreadId);

                string strName = "D" + Convert.ToBase64String(
                    Guid.NewGuid().ToByteArray(), Base64FormattingOptions.None);
                strName = strName.Replace(@"+", string.Empty);
                strName = strName.Replace(@"/", string.Empty);
                strName = strName.Replace(@"=", string.Empty);

                NativeMethods.DesktopFlags deskFlags =
                    NativeMethods.DesktopFlags.CreateMenu |
                    NativeMethods.DesktopFlags.CreateWindow |
                    NativeMethods.DesktopFlags.ReadObjects |
                    NativeMethods.DesktopFlags.WriteObjects |
                    NativeMethods.DesktopFlags.SwitchDesktop;

                IntPtr pNewDesktop = NativeMethods.CreateDesktop(strName,
                    null, IntPtr.Zero, 0, deskFlags, IntPtr.Zero);
                if(pNewDesktop == IntPtr.Zero)
                    throw new InvalidOperationException();

                SecureThreadParams stp = new SecureThreadParams();
                stp.BackgroundBitmap = bmpBack;
                stp.ThreadDesktop = pNewDesktop;
                stp.FormConstructParam = objConstructParam;

                Thread th = new Thread(this.SecureDialogThread);
                th.CurrentCulture = Thread.CurrentThread.CurrentCulture;
                th.CurrentUICulture = Thread.CurrentThread.CurrentUICulture;
                th.Start(stp);
                th.Join();

                if(!NativeMethods.SwitchDesktop(pOrgDesktop)) { Debug.Assert(false); }
                NativeMethods.SetThreadDesktop(pOrgDesktop);

                if(!NativeMethods.CloseDesktop(pNewDesktop)) { Debug.Assert(false); }
                NativeMethods.CloseDesktop(pOrgDesktop);

                dr = stp.DialogResult;
                objResult = stp.ResultObject;
            }
            catch(Exception) { Debug.Assert(false); }

            byte[] pbNewClipHash = ClipboardUtil.ComputeHash();
            if((pbClipHash != null) && (pbNewClipHash != null) &&
                !MemUtil.ArraysEqual(pbClipHash, pbNewClipHash))
                ClipboardUtil.Clear();
            ccb.Release();

            if(bmpBack != null) bmpBack.Dispose();

            // If something failed, show the dialog on the normal desktop
            if(dr == DialogResult.None)
            {
                Form f = m_fnConstruct(objConstructParam);
                dr = f.ShowDialog();
                objResult = m_fnResultBuilder(f);
                UIUtil.DestroyForm(f);
            }

            return dr;
        }
Exemplo n.º 5
0
        public DialogResult ShowDialog(out object objResult, object objConstructParam)
        {
            objResult = null;

            ProcessMessagesEx();

            ClipboardEventChainBlocker ccb = new ClipboardEventChainBlocker();

            byte[] pbClipHash = ClipboardUtil.ComputeHash();

            Bitmap bmpBack = UIUtil.CreateScreenshot();

            if (bmpBack != null)
            {
                UIUtil.DimImage(bmpBack);
            }

            DialogResult dr = DialogResult.None;

            try
            {
                uint   uOrgThreadId = NativeMethods.GetCurrentThreadId();
                IntPtr pOrgDesktop  = NativeMethods.GetThreadDesktop(uOrgThreadId);

                string strName = "D" + Convert.ToBase64String(
                    Guid.NewGuid().ToByteArray(), Base64FormattingOptions.None);
                strName = strName.Replace(@"+", string.Empty);
                strName = strName.Replace(@"/", string.Empty);
                strName = strName.Replace(@"=", string.Empty);

                NativeMethods.DesktopFlags deskFlags =
                    NativeMethods.DesktopFlags.CreateMenu |
                    NativeMethods.DesktopFlags.CreateWindow |
                    NativeMethods.DesktopFlags.ReadObjects |
                    NativeMethods.DesktopFlags.WriteObjects |
                    NativeMethods.DesktopFlags.SwitchDesktop;

                IntPtr pNewDesktop = NativeMethods.CreateDesktop(strName,
                                                                 null, IntPtr.Zero, 0, deskFlags, IntPtr.Zero);
                if (pNewDesktop == IntPtr.Zero)
                {
                    throw new InvalidOperationException();
                }

                SecureThreadParams stp = new SecureThreadParams();
                stp.BackgroundBitmap   = bmpBack;
                stp.ThreadDesktop      = pNewDesktop;
                stp.FormConstructParam = objConstructParam;

                Thread th = new Thread(this.SecureDialogThread);
                th.CurrentCulture   = Thread.CurrentThread.CurrentCulture;
                th.CurrentUICulture = Thread.CurrentThread.CurrentUICulture;
                th.Start(stp);
                th.Join();

                if (!NativeMethods.SwitchDesktop(pOrgDesktop))
                {
                    Debug.Assert(false);
                }
                NativeMethods.SetThreadDesktop(pOrgDesktop);

                if (!NativeMethods.CloseDesktop(pNewDesktop))
                {
                    Debug.Assert(false);
                }
                NativeMethods.CloseDesktop(pOrgDesktop);

                dr        = stp.DialogResult;
                objResult = stp.ResultObject;
            }
            catch (Exception) { Debug.Assert(false); }

            byte[] pbNewClipHash = ClipboardUtil.ComputeHash();
            if ((pbClipHash != null) && (pbNewClipHash != null) &&
                !MemUtil.ArraysEqual(pbClipHash, pbNewClipHash))
            {
                ClipboardUtil.Clear();
            }
            ccb.Release();

            if (bmpBack != null)
            {
                bmpBack.Dispose();
            }

            // If something failed, show the dialog on the normal desktop
            if (dr == DialogResult.None)
            {
                Form f = m_fnConstruct(objConstructParam);
                dr        = f.ShowDialog();
                objResult = m_fnResultBuilder(f);
                UIUtil.DestroyForm(f);
            }

            return(dr);
        }
Exemplo n.º 6
0
        private void SecureDialogThread(object oParam)
        {
            BackgroundForm formBack = null;

            try
            {
                SecureThreadParams stp = (oParam as SecureThreadParams);
                if (stp == null)
                {
                    Debug.Assert(false); return;
                }

                if (!NativeMethods.SetThreadDesktop(stp.ThreadDesktop))
                {
                    Debug.Assert(false);
                    return;
                }

                ProcessMessagesEx();

                // Test whether we're really on the secure desktop
                if (NativeMethods.GetThreadDesktop(NativeMethods.GetCurrentThreadId()) !=
                    stp.ThreadDesktop)
                {
                    Debug.Assert(false);
                    return;
                }

                // Creating a window on the new desktop spawns a CtfMon.exe child
                // process by default. On Windows Vista, this process is terminated
                // correctly when the desktop is closed. However, on Windows 7 it
                // isn't terminated (probably a bug); creating multiple desktops
                // accumulates CtfMon.exe child processes. In order to prevent this,
                // we simply disable IME for the new desktop thread (CtfMon.exe then
                // isn't loaded automatically).
                try { NativeMethods.ImmDisableIME(0); }                 // Always false on 2000/XP
                catch (Exception) { Debug.Assert(!WinUtil.IsAtLeastWindows2000); }

                ProcessMessagesEx();

                formBack = new BackgroundForm(stp.BackgroundBitmap);
                formBack.Show();

                ProcessMessagesEx();

                if (!NativeMethods.SwitchDesktop(stp.ThreadDesktop))
                {
                    Debug.Assert(false);
                }

                ProcessMessagesEx();

                Form f = m_fnConstruct(stp.FormConstructParam);
                if (f == null)
                {
                    Debug.Assert(false); return;
                }

                if (Program.Config.UI.SecureDesktopPlaySound)
                {
                    UIUtil.PlayUacSound();
                }

                stp.DialogResult = f.ShowDialog(formBack);
                stp.ResultObject = m_fnResultBuilder(f);

                UIUtil.DestroyForm(f);
            }
            catch (Exception) { Debug.Assert(false); }
            finally
            {
                if (formBack != null)
                {
                    try
                    {
                        formBack.Close();
                        UIUtil.DestroyForm(formBack);
                    }
                    catch (Exception) { Debug.Assert(false); }
                }
            }
        }
Exemplo n.º 7
0
        public DialogResult ShowDialog()
        {
            ProcessMessagesEx();

            ClipboardEventChainBlocker ccb = new ClipboardEventChainBlocker();
            byte[] pbClipHash = ClipboardUtil.ComputeHash();

            Bitmap bmpBack = UIUtil.CreateScreenshot();
            if(bmpBack != null) UIUtil.DimImage(bmpBack);

            DialogResult dr = DialogResult.None;
            try
            {
                uint uOrgThreadId = NativeMethods.GetCurrentThreadId();
                IntPtr pOrgDesktop = NativeMethods.GetThreadDesktop(uOrgThreadId);

                string strName = "D" + Convert.ToBase64String(
                    Guid.NewGuid().ToByteArray(), Base64FormattingOptions.None);
                strName = strName.Replace(@"+", string.Empty);
                strName = strName.Replace(@"/", string.Empty);
                strName = strName.Replace(@"=", string.Empty);

                NativeMethods.DesktopFlags deskFlags =
                    NativeMethods.DesktopFlags.CreateMenu |
                    NativeMethods.DesktopFlags.CreateWindow |
                    NativeMethods.DesktopFlags.ReadObjects |
                    NativeMethods.DesktopFlags.WriteObjects |
                    NativeMethods.DesktopFlags.SwitchDesktop;

                IntPtr pNewDesktop = NativeMethods.CreateDesktop(strName,
                    null, IntPtr.Zero, 0, deskFlags, IntPtr.Zero);
                if(pNewDesktop == IntPtr.Zero)
                {
                    Debug.Assert(false);
                    return DialogResult.Cancel;
                }

                SecureThreadParams stp = new SecureThreadParams();
                stp.BackgroundBitmap = bmpBack;
                stp.ThreadDesktop = pNewDesktop;

                Thread th = new Thread(this.SecureDialogThread);
                th.CurrentCulture = Thread.CurrentThread.CurrentCulture;
                th.CurrentUICulture = Thread.CurrentThread.CurrentUICulture;
                th.Start(stp);
                th.Join();

                if(!NativeMethods.SwitchDesktop(pOrgDesktop)) { Debug.Assert(false); }
                NativeMethods.SetThreadDesktop(pOrgDesktop);

                if(!NativeMethods.CloseDesktop(pNewDesktop)) { Debug.Assert(false); }
                NativeMethods.CloseDesktop(pOrgDesktop);

                dr = stp.Result;
            }
            catch(Exception) { Debug.Assert(false); }

            byte[] pbNewClipHash = ClipboardUtil.ComputeHash();
            if((pbClipHash != null) && (pbNewClipHash != null) &&
                !MemUtil.ArraysEqual(pbClipHash, pbNewClipHash))
                ClipboardUtil.Clear();
            ccb.Release();

            if(bmpBack != null) bmpBack.Dispose();
            return dr;
        }