Beispiel #1
0
        public int ProvideLibrary(string fileName, int timestamp, int sizeOfImage, out IntPtr hModule)
        {
            CLRMetaHost mh = new CLRMetaHost();

            foreach (CLRRuntimeInfo rti in mh.EnumerateInstalledRuntimes())
            {
                string versionString = rti.GetVersionString();
                if (versionString.StartsWith("v2."))
                {
                    continue;
                }

                string libPath = Path.Combine(rti.GetRuntimeDirectory(), fileName);
                if (DoesFileMatch(libPath, timestamp, sizeOfImage))
                {
                    hModule = LoadLibrary(libPath);
                    if (hModule != IntPtr.Zero)
                    {
                        UpdateLastLoaded(fileName, libPath);
                        return(0);
                    }
                    else
                    {
                        return(-1);
                    }
                }
            }

            // not found
            hModule = IntPtr.Zero;
            return(-1);
        }
Beispiel #2
0
        public static ICorDebug GetDebugger(string debuggerVersion)
        {
            CLRMetaHost    mh              = new CLRMetaHost();
            CLRRuntimeInfo rti             = mh.GetRuntime(debuggerVersion);
            ICorDebug      rawDebuggingAPI = rti.GetLegacyICorDebugInterface();

            if (rawDebuggingAPI == null)
            {
                throw new ArgumentException("Cannot be null.", "rawDebugggingAPI");
            }
            rawDebuggingAPI.Initialize();
            rawDebuggingAPI.SetManagedHandler(new MyHandler());
            return(rawDebuggingAPI);
        }
Beispiel #3
0
        public static ICorDebug GetDebuggerForProcess(int processID, string minimumVersion, DebuggerCallBacks callBacks = null)
        {
            CLRMetaHost    mh = new CLRMetaHost();
            CLRRuntimeInfo highestLoadedRuntime = null;

            foreach (var runtime in mh.EnumerateLoadedRuntimes(processID))
            {
                if (highestLoadedRuntime == null ||
                    string.Compare(highestLoadedRuntime.GetVersionString(), runtime.GetVersionString(), StringComparison.OrdinalIgnoreCase) < 0)
                {
                    highestLoadedRuntime = runtime;
                }
            }
            if (highestLoadedRuntime == null)
            {
                throw new ApplicationException("Could not enumerate .NET runtimes on the system.");
            }

            var runtimeVersion = highestLoadedRuntime.GetVersionString();

            if (string.Compare(runtimeVersion, minimumVersion, StringComparison.OrdinalIgnoreCase) < 0)
            {
                throw new ApplicationException("Runtime in process " + runtimeVersion + " below the minimum of " + minimumVersion);
            }

            ICorDebug rawDebuggingAPI = highestLoadedRuntime.GetLegacyICorDebugInterface();

            if (rawDebuggingAPI == null)
            {
                throw new ArgumentException("Cannot be null.", "rawDebugggingAPI");
            }

            rawDebuggingAPI.Initialize();
            if (callBacks == null)
            {
                callBacks = new DebuggerCallBacks();
            }

            rawDebuggingAPI.SetManagedHandler(callBacks);
            return(rawDebuggingAPI);
        }