private void TimerCallback(object sync) { Thread.CurrentThread.Name = "CursorMonitorThread"; if (SwitchToInputDesktop) { SwitchToInputDesktop = false; WinDesktop.SwitchThreadToInputDesktop(); } if (!GetCursorPos(out POINT pos)) { if (!WinDesktop.GetThreadDesktop().InputDesktop) { WinDesktop.SwitchThreadToInputDesktop(); } return; } if (pos.Y == screenBounds.Top) { EdgeHit?.Invoke(this, BoundEdge.Top); } else if (pos.Y == screenBounds.Bottom) { EdgeHit?.Invoke(this, BoundEdge.Bottom); } else if (pos.X == screenBounds.Left) { EdgeHit?.Invoke(this, BoundEdge.Left); } else if (pos.X == screenBounds.Right) { EdgeHit?.Invoke(this, BoundEdge.Right); } }
public void Run(string[] args) { Thread.CurrentThread.Name = "Main"; if (WindowsIdentity.GetCurrent().Name != @"NT AUTHORITY\SYSTEM") { ISLogger.Write("Current user: "******"InputshareSP can only be launched from the inputshare service"); Thread.Sleep(3000); return; } //We need to check that the process was launched with the correct args (read and write pipe handles) ISLogger.Write("Process args: ({0})", args.Length); if (args.Length != 2) { ISLogger.Write("Started with invalid args... exiting"); return; } else { foreach (var arg in args) { ISLogger.Write("Param: " + arg); } } WinDesktop.DESKTOPOBJECT desk = WinDesktop.GetThreadDesktop(); ISLogger.Write($"Current desktop: '{desk.Name}' Input desktop: {desk.InputDesktop}"); //We don't want to create a window on a thread that belongs to the default desktop to //prevent shatter attacks. SP will exit if the current thread is not winlogon //TODO - fix spaces in name returned from windesktop.GetThreadDesktop() if (desk.Name.Contains("WinLogon")) { ISLogger.Write($"Failed to start: Current desktop is not 'Winlogon' ({desk.Name})"); return; } dDeskThread = new DefaultDesktopThread(); winLogonMsgWindow = new WinWindow(); winLogonMsgWindow.CreateWindow(true, null, null, true, true); winLogonMsgWindow.DesktopSwitched += WinLogonMsgWindow_DesktopSwitched; winLogonMsgWindow.ClipboardContentChanged += WinLogonMsgWindow_ClipboardContentChanged; outThread = new spOutputThread(); outThread.CreateThread(); curMonitor = new DesktopCursorMonitor(); curMonitor.EdgeHit += CurMonitor_EdgeHit; curMonitor.Start(); curMonitor.SwitchToInputDesktop = true; outThread.SwitchThreadDesktop = true; ipcRead = new AnonPipeClientRead(args[1]); ipcRead.InputDataReceived += IpcClient_InputDataReceived; ipcRead.CopyToClipboardReceived += IpcClient_CopyToClipboardReceived; ipcWrite = new AnonPipeClient(args[0]); ISLogger.Write("IPC client created"); ISLogger.Write("IPC server started"); ISLogger.Write("SP running"); }