protected override unsafe int OnExitProcess(CorDebugProcess pProcess) { ExitProcess?.Invoke(this, pProcess); return(Continue()); }
public void Main() { pInfo = NativeHelpers.CreateProcess( applicationName: null, commandLine: opt.Process, //flags: CreateProcessFlags.DEBUG_ONLY_THIS_PROCESS | CreateProcessFlags.DETACHED_PROCESS flags: CreateProcessFlags.DETACHED_PROCESS | CreateProcessFlags.DEBUG_PROCESS ); if (pInfo.dwProcessId == decimal.Zero) { Environment.Exit(-1); } var _ = NativeMethods.DebugActiveProcess(pInfo.dwProcessId); var code = Marshal.GetLastWin32Error(); NativeMethods.DebugSetProcessKillOnExit(false); if (opt.LoadDLL) { LoadDLL += (IntPtr address) => { Console.WriteLine($"ModLoad: {address.Address()} {LoadedDlls[address]}"); } } ; if (opt.UnloadDLL) { UnloadDLL += (IntPtr address) => { Console.WriteLine($"ModUnLoad: {address.Address()} {LoadedDlls[address]}"); } } ; if (opt.CreateProcess) { CreateProcess += Console.WriteLine; } if (opt.ExitProcess) { ExitProcess += Console.WriteLine; } if (opt.CreateThread) { CreateThread += Console.WriteLine; } if (opt.ExitThread) { ExitThread += Console.WriteLine; } if (opt.Exception) { Exception += Console.WriteLine; } debuggee = Process.GetProcessById(pInfo.dwProcessId); Console.WriteLine($@"{debuggee.ProcessName} started for debugging: PID: {pInfo.dwProcessId}"); Loop(debuggee); }