public static DebugAttach AttachAD7(int pid, int portNum, Guid debugId, string debugOptions) { bool isTarget64Bit = NativeMethods.Is64BitProcess(pid); bool isAttacher64Bit = Environment.Is64BitProcess; if (isAttacher64Bit != isTarget64Bit) { // attaching from 32-bit to 64-bit or vice versa. We need to start a new process to handle the attach // Create the event that will be used for signaling in our local process here, we'll open it in the // remote process and dup it there... The remote process will communicate the error & language // version back to us via its exit code. IntPtr eventHandle; string name; do { name = Guid.NewGuid().ToString(); eventHandle = NativeMethods.CreateEvent(IntPtr.Zero, false, false, name); } while (eventHandle == IntPtr.Zero); try { string args = String.Format("ATTACH_AD7 {0} {1} {2} \"{3}\" {4}", pid, portNum, debugId, debugOptions, name); var process = isTarget64Bit ? Create64BitProcess(args) : Create32BitProcess(args); var attachDoneEvent = AutoResetEvent.OpenExisting(name); process.WaitForExit(); return(new DebugAttach(attachDoneEvent, (ConnErrorMessages)(process.ExitCode & 0xffff), process.ExitCode >> 16)); } finally { NativeMethods.CloseHandle(eventHandle); } } return(AttachAD7Worker(pid, portNum, debugId, debugOptions)); }
public void Display(PleaseWaitMsg pleaseWaitMsg) { try { if (!String.IsNullOrEmpty(pleaseWaitMsg.iconFileName)) { iconFile = Win32Function.getIconFromFile(pleaseWaitMsg.iconFileName); icon.Image = iconFile.ToBitmap(); } } catch { } dialog.Text = pleaseWaitMsg.title; msg.Text = pleaseWaitMsg.msg; dialog.ClientSize = new Size(Math.Max(msg.Width + 100, 250), 70); msg.Location = new Point(dialog.ClientSize.Width / 2 - msg.Width / 2, 12); dialog.Show(null); try { EventWaitHandle pleaseWaitDialogEvent = AutoResetEvent.OpenExisting("pleaseWaitDialogEvent"); while (!pleaseWaitDialogEvent.WaitOne(10, false)) { Application.DoEvents(); } } catch { } }
private static bool OnlyOneCopy() { bool isnew; s_setup_mutex = new Mutex(true, SETUP_MUTEX_NAME, out isnew); RestoreEvent = null; try { #if RELEASE RestoreEvent = AutoResetEvent.OpenExisting(EVENT_NAME); RestoreEvent.Set(); return(false); } catch (WaitHandleCannotBeOpenedException) { #endif string user = Environment.UserDomainName + "\\" + Environment.UserName; EventWaitHandleSecurity evh_sec = new EventWaitHandleSecurity(); EventWaitHandleAccessRule rule = new EventWaitHandleAccessRule(user, EventWaitHandleRights.Synchronize | EventWaitHandleRights.Modify, AccessControlType.Allow); evh_sec.AddAccessRule(rule); bool was_created; RestoreEvent = new EventWaitHandle(false, EventResetMode.AutoReset, EVENT_NAME, out was_created, evh_sec); } catch (Exception) { } return(true); }
public static int Main(string[] args) { int pid, portNum; Guid debugId; if (args.Length == 1 && args[0] == "CHECK") { return(RunCheck()); } else if (args.Length != 4 || !Int32.TryParse(args[0], out pid) || !Int32.TryParse(args[1], out portNum) || !Guid.TryParse(args[2], out debugId)) { Help(); return(-1); } EventWaitHandle doneEvent; try { doneEvent = AutoResetEvent.OpenExisting(args[3]); } catch { Help(); return(-2); } var res = AttachWorker(pid, portNum, debugId, doneEvent); return(((int)res._error) | (res._langVersion << 16)); }
public static int Main(string[] args) { if (args.Length < 1) { return(Help()); } switch (args[0]) { case "CHECK": if (args.Length != 1) { return(Help()); } return(RunCheck()); case "ATTACH_AD7": { int pid, portNum; Guid debugId; if (args.Length != 6 || !Int32.TryParse(args[1], out pid) || !Int32.TryParse(args[2], out portNum) || !Guid.TryParse(args[3], out debugId) ) { return(Help()); } string debugOptions = args[4]; EventWaitHandle doneEvent; try { doneEvent = AutoResetEvent.OpenExisting(args[5]); } catch { Console.Error.WriteLine("Could not open event " + args[5]); return(Help(-2)); } var res = AttachAD7Worker(pid, portNum, debugId, debugOptions, doneEvent); return(((int)res._error) | (res._langVersion << 16)); }; case "ATTACH_DKM": { int pid; if (args.Length != 2 || !Int32.TryParse(args[1], out pid)) { return(Help()); } return((int)AttachDkmWorker(pid)); }; default: return(Help()); } }
public IAutoResetEvent OpenExisting(string name, EventWaitHandleRights rights) { return(new AutoResetEventWrap(AutoResetEvent.OpenExisting(name, rights) as AutoResetEvent)); }
public IAutoResetEvent OpenExisting(string name) { return(new AutoResetEventWrap(AutoResetEvent.OpenExisting(name) as AutoResetEvent)); }