コード例 #1
0
        public Task DebugProcess(string commandLine, string args, AttachProcessFlags attachFlags, bool debugChildProcesses = false)
        {
            return(RunAsync(() => {
                var options = new DEBUG_CREATE_PROCESS_OPTIONS {
                    CreateFlags = DEBUG_CREATE_PROCESS.DEBUG_PROCESS
                };
                if (!debugChildProcesses)
                {
                    options.CreateFlags |= DEBUG_CREATE_PROCESS.DEBUG_ONLY_THIS_PROCESS;
                }

                Client.CreateProcessAndAttach2Wide(0, commandLine + " " + (args ?? string.Empty), ref options, (uint)Marshal.SizeOf <DEBUG_CREATE_PROCESS_OPTIONS>(),
                                                   null, null, 0, (DEBUG_ATTACH)attachFlags).ThrowIfFailed();
                WaitForEvent().ThrowIfFailed();
            }));
        }
コード例 #2
0
ファイル: Debugger.cs プロジェクト: zforks/KeeThief
        public Debugger LaunchProcess(string commandLine, string workingDirectory)
        {
            IDebugClient5 client  = CreateIDebugClient();
            IDebugControl control = (IDebugControl)client;

            if (string.IsNullOrEmpty(workingDirectory))
            {
                workingDirectory = Environment.CurrentDirectory;
            }

            string env = GetEnvironment();
            DEBUG_CREATE_PROCESS_OPTIONS options = new DEBUG_CREATE_PROCESS_OPTIONS();

            options.CreateFlags = (DEBUG_CREATE_PROCESS)1;
            int hr = client.CreateProcessAndAttach2(0, commandLine, ref options, (uint)Marshal.SizeOf(typeof(DEBUG_CREATE_PROCESS_OPTIONS)), workingDirectory, env, 0, DEBUG_ATTACH.DEFAULT);

            if (hr < 0)
            {
                throw new Exception(Debugger.GetExceptionString("IDebugClient::CreateProcessAndAttach2", hr));
            }

            Debugger debugger = new Debugger(client, control);

            hr = client.SetEventCallbacks(debugger);
            if (hr < 0)
            {
                throw new Exception(Debugger.GetExceptionString("IDebugClient::SetEventCallbacks", hr));
            }

            hr = client.SetOutputCallbacks(debugger);
            if (hr < 0)
            {
                throw new Exception(Debugger.GetExceptionString("IDebugClient::SetOutputCallbacks", hr));
            }

            return(debugger);
        }