Esempio n. 1
0
        static void TraceRunningProcess(int pid, TraceOutputOptions options)
        {
            var hProcess = WinProcesses.NativeMethods.OpenProcess(WinProcesses.ProcessAccessFlags.Synchronize, false, pid);

            if (hProcess.IsInvalid)
            {
                Console.Error.WriteLine("ERROR: the process with a given PID was not found or you don't have access to it.");
                return;
            }
            using (TraceCollector kernelTraceCollector = new KernelTraceCollector(pid, Console.Out, options),
                   userTraceCollector = new UserTraceCollector(pid, Console.Out, options)) {
                SetConsoleCtrlCHook(kernelTraceCollector, userTraceCollector);

                ThreadPool.QueueUserWorkItem((o) => {
                    WinHandles.NativeMethods.WaitForSingleObject(hProcess, VsChromium.Core.Win32.Constants.INFINITE);
                    kernelTraceCollector.Stop();
                    userTraceCollector.Stop();

                    stopEvent.Set();
                });

                ThreadPool.QueueUserWorkItem((o) => {
                    kernelTraceCollector.Start();
                });
                ThreadPool.QueueUserWorkItem((o) => {
                    userTraceCollector.Start();
                });

                stopEvent.WaitOne();
            }
        }
Esempio n. 2
0
        static void TraceNewProcess(IEnumerable <string> procargs, bool spawnNewConsoleWindow, TraceOutputOptions options)
        {
            using (var process = new ProcessCreator(procargs)
            {
                SpawnNewConsoleWindow = spawnNewConsoleWindow
            }) {
                process.StartSuspended();

                using (TraceCollector kernelTraceCollector = new KernelTraceCollector(process.ProcessId, Console.Out, options),
                       userTraceCollector = new UserTraceCollector(process.ProcessId, Console.Out, options)) {
                    SetConsoleCtrlCHook(kernelTraceCollector, userTraceCollector);

                    ThreadPool.QueueUserWorkItem((o) => {
                        kernelTraceCollector.Start();
                    });
                    ThreadPool.QueueUserWorkItem((o) => {
                        userTraceCollector.Start();
                    });
                    ThreadPool.QueueUserWorkItem((o) => {
                        process.Join();
                        kernelTraceCollector.Stop();
                        userTraceCollector.Stop();

                        stopEvent.Set();
                    });

                    Thread.Sleep(1000);

                    // resume thread
                    process.Resume();

                    stopEvent.WaitOne();
                }
            }
        }