Exemple #1
0
        static string?GetVersionStringFromModule(DbgShimState dbgShimState, uint pid, IntPtr ps, out string coreclrFilename)
        {
            var sb = new StringBuilder(0x1000);

            coreclrFilename = Marshal.PtrToStringUni(ps) !;
            int hr = dbgShimState.CreateVersionStringFromModule !(pid, coreclrFilename, sb, (uint)sb.Capacity, out uint verLen);

            if (hr != 0)
            {
                sb.EnsureCapacity((int)verLen);
                hr = dbgShimState.CreateVersionStringFromModule(pid, coreclrFilename, sb, (uint)sb.Capacity, out verLen);
            }
            return(hr < 0 ? null : sb.ToString());
        }
Exemple #2
0
        static DbgShimState?GetOrCreateDbgShimState(string?runtimePath, string?dbgshimPath)
        {
            var          paths = GetDbgShimPaths(runtimePath, dbgshimPath);
            DbgShimState?dbgShimState;

            foreach (var path in paths)
            {
                if (dbgShimStateDict.TryGetValue(path, out dbgShimState))
                {
                    return(dbgShimState);
                }
            }

            if (paths.Count == 0)
            {
                return(null);
            }
            dbgshimPath = paths[0];

            // Use the same flags as dbgshim.dll uses when it loads mscordbi.dll
            var handle = NativeMethods.LoadLibraryEx(dbgshimPath, IntPtr.Zero, NativeMethods.LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | NativeMethods.LOAD_LIBRARY_SEARCH_DEFAULT_DIRS);

            if (handle == IntPtr.Zero)
            {
                return(null);                   // eg. it's x86 but we're x64 or vice versa, or it's not a valid PE file
            }
            dbgShimState          = new DbgShimState();
            dbgShimState.Filename = dbgshimPath;
            dbgShimState.Handle   = handle;
            dbgShimState.GetStartupNotificationEvent = GetDelegate <GetStartupNotificationEvent>(handle, "GetStartupNotificationEvent");
            dbgShimState.CloseCLREnumeration         = GetDelegate <CloseCLREnumeration>(handle, "CloseCLREnumeration");
            dbgShimState.EnumerateCLRs = GetDelegate <EnumerateCLRs>(handle, "EnumerateCLRs");
            dbgShimState.CreateVersionStringFromModule         = GetDelegate <CreateVersionStringFromModule>(handle, "CreateVersionStringFromModule");
            dbgShimState.CreateDebuggingInterfaceFromVersionEx = GetDelegate <CreateDebuggingInterfaceFromVersionEx>(handle, "CreateDebuggingInterfaceFromVersionEx");
            if (dbgShimState.GetStartupNotificationEvent is null ||
                dbgShimState.CloseCLREnumeration is null ||
                dbgShimState.EnumerateCLRs is null ||
                dbgShimState.CreateVersionStringFromModule is null ||
                dbgShimState.CreateDebuggingInterfaceFromVersionEx is null)
            {
                NativeMethods.FreeLibrary(handle);
                return(null);
            }

            dbgShimStateDict.Add(dbgShimState.Filename, dbgShimState);
            return(dbgShimState);
        }