コード例 #1
0
ファイル: TraceSession.cs プロジェクト: yusrul/wtrace
        public void TraceRunningProcess(int pid, bool traceChildProcesses, bool collectDriverStats)
        {
            using (var hProcess = Kernel32.OpenProcess(Kernel32.ACCESS_MASK.StandardRight.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 TraceCollector(KernelTraceEventParser.KernelSessionName),
                       customTraceCollector = new TraceCollector(WinTraceUserTraceSessionName)) {
                    InitializeSystemHandlers(kernelTraceCollector, collectDriverStats);
                    InitializeProcessHandlers(kernelTraceCollector, customTraceCollector,
                                              pid, traceChildProcesses);

                    ThreadPool.QueueUserWorkItem((o) => {
                        Kernel32.WaitForSingleObject(hProcess, Constants.INFINITE);
                        StopCollectors(kernelTraceCollector, customTraceCollector);
                        stopEvent.Set();
                    });

                    stopTraceCollectors = () => {
                        StopCollectors(kernelTraceCollector, customTraceCollector);
                    };

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

                    stopEvent.WaitOne();
                }
            }
        }
コード例 #2
0
ファイル: TraceSession.cs プロジェクト: yusrul/wtrace
 private void InitializeSystemHandlers(TraceCollector kernelCollector, bool collectDriverStats)
 {
     kernelCollector.AddHandler(new SystemConfigTraceEventHandler(traceOutput));
     if (collectDriverStats)
     {
         kernelCollector.AddHandler(new IsrDpcTraceEventHandler(traceOutput));
     }
 }
コード例 #3
0
ファイル: TraceSession.cs プロジェクト: yusrul/wtrace
        private void StopCollector(TraceCollector collector)
        {
            collector.Stop();

            if (printSummary)
            {
                collector.PrintSummary();
            }
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: dbgche/wtrace
        static void SetConsoleCtrlCHook(TraceCollector kernelCollector, TraceCollector userCollector)
        {
            // Set up Ctrl-C to stop both user mode and kernel mode sessions
            Console.CancelKeyPress += (object sender, ConsoleCancelEventArgs cancelArgs) => {
                cancelArgs.Cancel = true;
                kernelCollector.Stop();
                userCollector.Stop();

                stopEvent.Set();
            };
        }
コード例 #5
0
ファイル: TraceSession.cs プロジェクト: yusrul/wtrace
        private void StopCollectors(TraceCollector collector1, TraceCollector collector2)
        {
            collector1.Stop();
            collector2.Stop();

            if (printSummary)
            {
                collector1.PrintSummary();
                collector2.PrintSummary();
            }
        }
コード例 #6
0
ファイル: TraceSession.cs プロジェクト: yusrul/wtrace
        private void InitializeProcessHandlers(TraceCollector kernelCollector, TraceCollector customCollector,
                                               int pid, bool traceChildProcesses)
        {
            kernelCollector.AddHandler(new FileIOTraceEventHandler(pid, traceOutput));
            kernelCollector.AddHandler(new AlpcTraceEventHandler(pid, traceOutput));
            kernelCollector.AddHandler(new NetworkTraceEventHandler(pid, traceOutput));
            kernelCollector.AddHandler(new ProcessThreadsTraceEventHandler(pid, traceOutput, traceChildProcesses ?
                                                                           (int processId) => { InitializeProcessHandlers(kernelCollector, customCollector, processId, true); } : emptyAction));

            // DISABLED ON PURPOSE:
            // kernelCollector.AddHandler(new RegistryTraceEventHandler(pid, traceOutput)); // TODO: strange and sometimes missing key names

            customCollector.AddHandler(new EventHandlers.PowerShell.PowerShellTraceEventHandler(pid, traceOutput));
            customCollector.AddHandler(new EventHandlers.Rpc.RpcTraceEventHandler(pid, traceOutput));
        }
コード例 #7
0
ファイル: TraceSession.cs プロジェクト: yusrul/wtrace
        public void TraceSystemOnly()
        {
            using (TraceCollector kernelTraceCollector = new TraceCollector(KernelTraceEventParser.KernelSessionName)) {
                InitializeSystemHandlers(kernelTraceCollector, true);

                stopTraceCollectors = () => {
                    StopCollector(kernelTraceCollector);
                };

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

                stopEvent.WaitOne();
            }
        }
コード例 #8
0
ファイル: TraceSession.cs プロジェクト: yusrul/wtrace
        public void TraceNewProcess(IEnumerable <string> procargs, bool spawnNewConsoleWindow,
                                    bool traceChildProcesses, bool collectDriverStats)
        {
            using (var process = new ProcessCreator(procargs)
            {
                SpawnNewConsoleWindow = spawnNewConsoleWindow
            }) {
                process.StartSuspended();

                using (TraceCollector kernelTraceCollector = new TraceCollector(KernelTraceEventParser.KernelSessionName),
                       customTraceCollector = new TraceCollector(WinTraceUserTraceSessionName)) {
                    InitializeSystemHandlers(kernelTraceCollector, collectDriverStats);
                    InitializeProcessHandlers(kernelTraceCollector, customTraceCollector,
                                              process.ProcessId, traceChildProcesses);

                    ThreadPool.QueueUserWorkItem((o) => {
                        process.Join();
                        StopCollectors(kernelTraceCollector, customTraceCollector);
                        stopEvent.Set();
                    });

                    stopTraceCollectors = () => {
                        StopCollectors(kernelTraceCollector, customTraceCollector);
                    };

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

                    Thread.Sleep(1000);

                    // resume thread
                    process.Resume();

                    stopEvent.WaitOne();
                }
            }
        }