public static string FindWinDbg() { // Lets try a few common places before failing. List <string> pgPaths = new List <string>(); pgPaths.Add(@"c:\"); pgPaths.Add(Environment.GetEnvironmentVariable("SystemDrive")); pgPaths.Add(Environment.GetEnvironmentVariable("ProgramFiles")); if (Environment.GetEnvironmentVariable("ProgramW6432") != null) { pgPaths.Add(Environment.GetEnvironmentVariable("ProgramW6432")); } if (Environment.GetEnvironmentVariable("ProgramFiles") != null) { pgPaths.Add(Environment.GetEnvironmentVariable("ProgramFiles")); } if (Environment.GetEnvironmentVariable("ProgramFiles(x86)") != null) { pgPaths.Add(Environment.GetEnvironmentVariable("ProgramFiles(x86)")); } List <string> dbgPaths = new List <string>(); dbgPaths.Add("Debuggers"); dbgPaths.Add("Debugger"); dbgPaths.Add("Debugging Tools for Windows"); dbgPaths.Add("Debugging Tools for Windows (x64)"); dbgPaths.Add("Debugging Tools for Windows (x86)"); dbgPaths.Add("Windows Kits\\8.0\\Debuggers\\x64"); dbgPaths.Add("Windows Kits\\8.0\\Debuggers\\x86"); dbgPaths.Add("Windows Kits\\8.1\\Debuggers\\x64"); dbgPaths.Add("Windows Kits\\8.1\\Debuggers\\x86"); foreach (string path in pgPaths) { foreach (string dpath in dbgPaths) { string pathCheck = Path.Combine(path, dpath); if (Directory.Exists(pathCheck) && File.Exists(Path.Combine(pathCheck, "dbgeng.dll"))) { //verify x64 vs x86 var type = FileInfoImpl.GetMachineType(Path.Combine(pathCheck, "dbgeng.dll")); if (Environment.Is64BitProcess && type != Platform.Architecture.x64) { continue; } else if (!Environment.Is64BitProcess && type != Platform.Architecture.x86) { continue; } return(pathCheck); } } } return(null); }
public WindowsDebuggerHybrid(IAgent agent, string name, Dictionary <string, Variant> args) : base(agent, name, args) { //var color = Console.ForegroundColor; if (!Environment.Is64BitProcess && Environment.Is64BitOperatingSystem) { //Console.ForegroundColor = ConsoleColor.Yellow; //Console.WriteLine("\nError: Cannot use the 32bit version of Peach 3 on a 64bit operating system."); //Console.ForegroundColor = color; //return; throw new PeachException("Error: Cannot use the 32bit version of Peach 3 on a 64bit operating system."); } else if (Environment.Is64BitProcess && !Environment.Is64BitOperatingSystem) { //Console.ForegroundColor = ConsoleColor.Yellow; //Console.WriteLine("\nError: Cannot use the 64bit version of Peach 3 on a 32bit operating system."); //Console.ForegroundColor = color; throw new PeachException("Error: Cannot use the 64bit version of Peach 3 on a 32bit operating system."); } if (args.ContainsKey("CommandLine")) { _commandLine = (string)args["CommandLine"]; } else if (args.ContainsKey("ProcessName")) { _processName = (string)args["ProcessName"]; } else if (args.ContainsKey("KernelConnectionString")) { _hybrid = false; _kernelConnectionString = (string)args["KernelConnectionString"]; } else if (args.ContainsKey("Service")) { _service = (string)args["Service"]; } else { throw new PeachException("Error, WindowsDebugEngine started with out a CommandLine, ProcessName, KernelConnectionString or Service parameter."); } if (args.ContainsKey("SymbolsPath")) { _symbolsPath = (string)args["SymbolsPath"]; } if (args.ContainsKey("StartOnCall")) { _startOnCall = (string)args["StartOnCall"]; } if (args.ContainsKey("WaitForExitOnCall")) { _waitForExitOnCall = (string)args["WaitForExitOnCall"]; } if (args.ContainsKey("WaitForExitTimeout") && !int.TryParse((string)args["WaitForExitTimeout"], out _waitForExitTimeout)) { throw new PeachException("Error, 'WaitForExitTimeout' is not a valid number."); } if (args.ContainsKey("WinDbgPath")) { _winDbgPath = (string)args["WinDbgPath"]; var type = FileInfoImpl.GetMachineType(Path.Combine(_winDbgPath, "dbgeng.dll")); if (Environment.Is64BitProcess && type != Platform.Architecture.x64) { throw new PeachException("Error, provided WinDbgPath is not x64."); } else if (!Environment.Is64BitProcess && type != Platform.Architecture.x86) { throw new PeachException("Error, provided WinDbgPath is not x86."); } } else { _winDbgPath = FindWinDbg(); if (_winDbgPath == null) { throw new PeachException("Error, unable to locate WinDbg, please specify using 'WinDbgPath' parameter."); } } if (args.ContainsKey("RestartOnEachTest") && ((string)args["RestartOnEachTest"]).ToLower() == "true") { _restartOnEachTest = true; } if (args.ContainsKey("IgnoreFirstChanceGuardPage") && ((string)args["IgnoreFirstChanceGuardPage"]).ToLower() == "true") { _ignoreFirstChanceGuardPage = true; } if (args.ContainsKey("IgnoreSecondChanceGuardPage") && ((string)args["IgnoreSecondChanceGuardPage"]).ToLower() == "true") { _ignoreSecondChanceGuardPage = true; } if (args.ContainsKey("NoCpuKill") && ((string)args["NoCpuKill"]).ToLower() == "true") { _noCpuKill = true; } if (args.ContainsKey("FaultOnEarlyExit") && ((string)args["FaultOnEarlyExit"]).ToLower() == "true") { _faultOnEarlyExit = true; } if (args.ContainsKey("CpuPollInterval")) { _cpuPollInterval = Convert.ToInt32((string)args["CpuPollInterval"]); } // Register IPC Channel for connecting to debug process //_ipcChannel = new IpcChannel("Peach.Core_" + (new Random().Next().ToString())); //ChannelServices.RegisterChannel(_ipcChannel, false); }