protected override void ProcessRecord()
        {
            base.ProcessRecord();

            string dir = DbgProvider._TryFindDebuggersDir();

            if (!String.IsNullOrEmpty(dir))
            {
                WriteObject(dir);
            }
        } // end ProcessRecord()
Esempio n. 2
0
        } // end _GuestModeCleanup()

        private static int _NormalModeMainWrapper(string[] args)
        {
            //
            // In this case we need to make sure that dbgeng.dll et al get loaded from the
            // proper location (not system32). DbgEngWrapper.dll used to load the right
            // one for us (the one right next to it), until we changed it to be a "pure"
            // .NET assembly (to workaround the appdomain/process-global problem).
            //

            string rootDir      = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            string pathToDbgEng = Path.Combine(rootDir, "Debugger", "dbgeng.dll");

            IntPtr hDbgEng = NativeMethods.LoadLibraryEx(pathToDbgEng,
                                                         IntPtr.Zero,
                                                         LoadLibraryExFlags.LOAD_WITH_ALTERED_SEARCH_PATH);

            if (IntPtr.Zero == hDbgEng)
            {
                throw new Exception("Could not load dbgeng.dll.");
            }

            //
            // Let's also try to fix up the extension path, so that extensions can be found.
            //
            // First, let's add our own root dir, so that dbgshellext can be found.
            //

            StringBuilder sbNewExtPath;
            string        curExtPath = Environment.GetEnvironmentVariable("_NT_DEBUGGER_EXTENSION_PATH");

            if (String.IsNullOrEmpty(curExtPath))
            {
                sbNewExtPath = new StringBuilder();
            }
            else
            {
                sbNewExtPath = new StringBuilder(curExtPath,
                                                 2 * curExtPath.Length);
                sbNewExtPath.Append(';');
            }

            sbNewExtPath.Append(rootDir);

            //
            // Can we even find some other extensions?
            //

            string debuggersDir = DbgProvider._TryFindDebuggersDir();

            if (null != debuggersDir)
            {
                sbNewExtPath.Append(';');
                sbNewExtPath.Append(Path.Combine(debuggersDir, "winxp"));

                sbNewExtPath.Append(';');
                sbNewExtPath.Append(Path.Combine(debuggersDir, "winext"));

                sbNewExtPath.Append(';');
                sbNewExtPath.Append(Path.Combine(debuggersDir, @"winext\arcade"));

                sbNewExtPath.Append(';');
                sbNewExtPath.Append(Path.Combine(debuggersDir, "pri"));

                sbNewExtPath.Append(';');
                sbNewExtPath.Append(debuggersDir);
            }

            Environment.SetEnvironmentVariable("_NT_DEBUGGER_EXTENSION_PATH",
                                               sbNewExtPath.ToString());

            //
            // IDEA: Hmm... maybe if we find a debuggers directory, we should load dbgeng
            // out of there? But what if they are old?
            //

            try
            {
                return(MainWorker(args));
            }
            finally
            {
                NativeMethods.FreeLibrary(hDbgEng);
            }
        } // end _NormalModeMainWrapper()