Exemplo n.º 1
0
        public void Start()
        {
            new Thread(() => {
                dwRenderThread = WinAPI.GetCurrentThreadId();
                for (;;)
                {
                    DesktopSwitch.PollAutoDesktopThreadSwitch(dwRenderThread);

                    if (Base.TheBox)
                    {
                        Thread.Sleep(150);
                        continue;
                    }

                    if (ForceErase)
                    {
                        var hWnd   = WinAPI.GetDesktopWindow();
                        ForceErase = false;
                        if (!WinAPI.RedrawWindow(hWnd, IntPtr.Zero, IntPtr.Zero, WinAPI.RedrawWindowFlags.Erase | WinAPI.RedrawWindowFlags.Invalidate | WinAPI.RedrawWindowFlags.AllChildren))
                        {
                            Console.Beep();
                        }
                    }

                    if (Messages.Count != 0)
                    {
                        Render();
                    }

                    foreach (var msg in MessagesTimeout.ToArray())
                    {
                        if (msg.Item2 < DateTime.Now)
                        {
                            RemoveMessage(msg.Item1);
                            MessagesTimeout.Remove(msg);
                        }
                    }

                    Thread.Sleep(16);
                }
            }).Start();
        }
Exemplo n.º 2
0
        static void Main()
        {
            Environment.CurrentDirectory = @"C:\Users\User\Documents\Visual Studio 2017\Projects\socon\socon\bin\Debug";
            uint dwSessionId;

            WinAPI.ProcessIdToSessionId((uint)Process.GetCurrentProcess().Id, out dwSessionId);
            if (dwSessionId == 0)
            {
                ServiceBase.Run(new Svc());
            }

#if DEBUGGER
            while (!Debugger.IsAttached)
            {
                Thread.Sleep(100);
            }
#endif

            //WinAPI.SetPriorityClass(WinAPI.GetCurrentProcess(), WinAPI.PriorityClass.REALTIME_PRIORITY_CLASS);

            AppDomain.CurrentDomain.UnhandledException += NBug.Handler.UnhandledException;
            //Application.ThreadException += NBug.Handler.ThreadException;
            Settings.LoadSettings();
            soconwnt.EnablePrivileges();
            DesktopSwitch.Init();
            ETW.Listener.Listen();
            Commands.Commands.PopulateCommands();
            Hooks.InstallHooks();
            Base.CurrentKeyboardInput = new Keyboard.KeyboardFilter();
            Base.CurrentKeyboardInput.PressedInHoldTime = TimeSpan.FromMilliseconds(Settings.Keyboard.PressedInHoldTime);
            Base.CurrentKeyboardInput.PressedInInterval = TimeSpan.FromMilliseconds(Settings.Keyboard.PressedInInterval);
            new Thread(Base.CurrentKeyboardInput.ThreadStart).Start();
            Render.ImportantMessage.Instance = new Render.ImportantMessage();
            Render.ImportantMessage.Instance.Start();
            Render.DefaultSource.Instance = new Render.DefaultSource();
            Plugins.Init.Load();

            new Thread(() => {
                for (;;)
                {
                    if (!Base.TheBox)
                    {
                        Thread.Sleep(1000);
                        continue;
                    }

                    /*if (WinAPI.GetForegroundWindow() != Base.hWnd) {
                     *      Console.WriteLine("SWITCH!");
                     *      Base.Exit();
                     *      Base.InitShow();
                     *      aa++;
                     *      if (aa > 50)
                     *              Debugger.Break();
                     *      return;
                     * }*/

                    List <IntPtr> windows = new List <IntPtr>();

                    /*WinAPI.EnumWindows((IntPtr wnd, IntPtr param) => {
                     *      int dwProcessId;
                     *      //WinAPI.GetWindowThreadProcessId(wnd, out dwProcessId);
                     *      //if (Process.GetProcessById(dwProcessId).ProcessName == "csrss")
                     *      windows.Add(wnd);
                     *      if (wnd == new IntPtr(0x10010)) {
                     *              Debugger.Break();
                     *      }
                     *      return true;
                     * }, IntPtr.Zero);*/



                    /*var str = new StringBuilder(256);
                     * int status;
                     * int dwProcessId;
                     * var name = new byte[256];
                     * uint lengthNeeded;
                     *
                     * IntPtr hDesktop = WinAPI.OpenInputDesktop(0, false, WinAPI.DESKTOP_ACCESS.GENERIC_ALL);
                     * WinAPI.GetUserObjectInformation(hDesktop, WinAPI.UOI_NAME, name, (uint)name.Length, out lengthNeeded);
                     *
                     * IntPtr hOldDesktop = WinAPI.GetThreadDesktop(WinAPI.GetCurrentThreadId());
                     * WinAPI.SetThreadDesktop(hDesktop);
                     * var wnd = WinAPI.GetForegroundWindow();
                     * var desk = WinAPI.GetDesktopWindow();
                     *
                     * for (int x = 0;x < 2;x++) {
                     *      WinAPI.GetWindowThreadProcessId(wnd, out dwProcessId);
                     *      if ((status = WinAPI.GetClassName(wnd, str, str.Capacity)) == 0)
                     *              Render.DefaultSource.Instance.PushTextError(String.Format("Failed to get class name of {0:8:X} ({1})", wnd, status));
                     *      else
                     *              Render.DefaultSource.Instance.PushTextNormal(
                     *                      String.Format("Desktop {0,8:X} {1} -> {2} window {3,8:X}: {4} ({5})",
                     *                              hDesktop.ToInt64(),
                     *                              Encoding.UTF8.GetString(name),
                     *                              x == 0 ? "Foreground" : "Desktop",
                     *                              wnd,
                     *                              str.ToString(),
                     *                              Process.GetProcessById(dwProcessId).ProcessName));
                     *      wnd = desk;
                     * }
                     *
                     * WinAPI.SetThreadDesktop(hOldDesktop);*/

                    /*foreach (var window in windows) {
                     *      var str = new StringBuilder(256);
                     *      int status;
                     *      int dwProcessId;
                     *      /*WinAPI.GetWindowThreadProcessId(window, out dwProcessId);
                     *
                     *      if ((status = WinAPI.GetClassName(window, str, str.Capacity)) == 0)
                     *              Render.DefaultSource.Instance.PushTextError(String.Format("Failed to get class name of {0:8:X} ({1})", window, status));
                     *      else {
                     *              if (str.ToString().StartsWith("#327"))
                     *                      Render.DefaultSource.Instance.PushTextCenter(String.Format("Window {0,8:X}: {1} ({2})", window, str.ToString(), Process.GetProcessById(dwProcessId).ProcessName));
                     *              else
                     *                      Render.DefaultSource.Instance.PushTextNormal(String.Format("Window {0,8:X}: {1} ({2})", window, str.ToString(), Process.GetProcessById(dwProcessId).ProcessName));
                     *      }*
                     * }*/

                    Thread.Sleep(1000);
                }
            }).Start();
        }