Exemplo n.º 1
0
        private ClrInfo[] InitVersions()
        {
            List <ClrInfo> versions = new List <ClrInfo>();

            foreach (ModuleInfo module in EnumerateModules())
            {
                if (!ClrInfoProvider.IsSupportedRuntime(module, out var flavor, out var platform))
                {
                    continue;
                }

                string dacFileName = ClrInfoProvider.GetDacFileName(flavor, platform);
                string dacLocation = Path.Combine(Path.GetDirectoryName(module.FileName), dacFileName);

                if (platform == Platform.Linux)
                {
                    if (File.Exists(dacLocation))
                    {
                        // Works around issue https://github.com/dotnet/coreclr/issues/20205
                        int    processId     = Process.GetCurrentProcess().Id;
                        string tempDirectory = Path.Combine(Path.GetTempPath(), "clrmd" + processId);
                        Directory.CreateDirectory(tempDirectory);

                        string symlink = Path.Combine(tempDirectory, dacFileName);
                        if (LinuxFunctions.symlink(dacLocation, symlink) == 0)
                        {
                            dacLocation = symlink;
                        }
                    }
                    else
                    {
                        dacLocation = dacFileName;
                    }
                }
                else if (!File.Exists(dacLocation) || !PlatformFunctions.IsEqualFileVersion(dacLocation, module.Version))
                {
                    dacLocation = null;
                }

                VersionInfo version         = module.Version;
                string      dacAgnosticName = ClrInfoProvider.GetDacRequestFileName(flavor, Architecture, Architecture, version, platform);
                string      dacRegularName  = ClrInfoProvider.GetDacRequestFileName(flavor, IntPtr.Size == 4 ? Architecture.X86 : Architecture.Amd64, Architecture, version, platform);

                DacInfo dacInfo = new DacInfo(_dataReader, dacAgnosticName, Architecture)
                {
                    FileSize  = module.FileSize,
                    TimeStamp = module.TimeStamp,
                    FileName  = dacRegularName,
                    Version   = module.Version
                };

                versions.Add(new ClrInfo(this, flavor, module, dacInfo, dacLocation));
            }

            ClrInfo[] result = versions.ToArray();
            Array.Sort(result);
            return(result);
        }
Exemplo n.º 2
0
        public bool GetVersionInfo(ulong baseAddress, out VersionInfo version)
        {
            ElfFile?file = GetElfFile(baseAddress);

            if (file is null)
            {
                version = default;
                return(false);
            }

            return(LinuxFunctions.GetVersionInfo(this, baseAddress, file, out version));
        }
Exemplo n.º 3
0
        public void GetVersionInfo(ulong baseAddress, out VersionInfo version)
        {
            ElfLoadedImage image = _core.LoadedImages.First(image => (ulong)image.BaseAddress == baseAddress);
            ElfFile?       file  = image.Open();

            if (file is null)
            {
                version = default;
            }
            else
            {
                LinuxFunctions.GetVersionInfo(this, baseAddress, file, out version);
            }
        }
Exemplo n.º 4
0
        private ModuleInfo CreateModuleInfo(ElfLoadedImage image)
        {
            ElfFile?file = image.Open();

            VersionInfo version;
            int         filesize  = (int)image.Size;
            int         timestamp = 0;

            if (file is null)
            {
                using PEImage pe = image.OpenAsPEImage();
                filesize         = pe.IndexFileSize;
                timestamp        = pe.IndexTimeStamp;
                version          = pe.GetFileVersionInfo()?.VersionInfo ?? default;
            }
            else
            {
                LinuxFunctions.GetVersionInfo(this, (ulong)image.BaseAddress, file, out version);
            }

            return(new ModuleInfo((ulong)image.BaseAddress, filesize, timestamp, image.Path, image._containsExecutable, default, version));
Exemplo n.º 5
0
#pragma warning disable 0618
        private ClrInfo[] InitVersions()
        {
            List <ClrInfo> versions = new List <ClrInfo>();

            foreach (ModuleInfo module in EnumerateModules())
            {
                string clrName = Path.GetFileNameWithoutExtension(module.FileName).ToLower();

                if (clrName != "clr" && clrName != "mscorwks" && clrName != "coreclr" && clrName != "mrt100_app" && clrName != "libcoreclr")
                {
                    continue;
                }

                ClrFlavor flavor;
                switch (clrName)
                {
                case "mrt100_app":
                    _native = module;
                    continue;

                case "libcoreclr":
                case "coreclr":
                    flavor = ClrFlavor.Core;
                    break;

                default:
                    flavor = ClrFlavor.Desktop;
                    break;
                }

                bool isLinux = clrName == "libcoreclr";

                const string LinuxDacFileName = "libmscordaccore.so";

                string dacLocation = Path.Combine(Path.GetDirectoryName(module.FileName), isLinux ? LinuxDacFileName : DacInfo.GetDacFileName(flavor, Architecture));

                if (isLinux)
                {
                    if (File.Exists(dacLocation))
                    {
                        // Works around issue https://github.com/dotnet/coreclr/issues/20205
                        int    processId     = Process.GetCurrentProcess().Id;
                        string tempDirectory = Path.Combine(Path.GetTempPath(), "clrmd" + processId.ToString());
                        Directory.CreateDirectory(tempDirectory);

                        string symlink = Path.Combine(tempDirectory, LinuxDacFileName);
                        if (LinuxFunctions.symlink(dacLocation, symlink) == 0)
                        {
                            dacLocation = symlink;
                        }
                    }
                    else
                    {
                        dacLocation = LinuxDacFileName;
                    }
                }
                else if (!File.Exists(dacLocation) || !PlatformFunctions.IsEqualFileVersion(dacLocation, module.Version))
                {
                    dacLocation = null;
                }

                VersionInfo version = module.Version;
                string      dacAgnosticName;
                string      dacFileName;
                if (isLinux)
                {
                    // Linux never has a "long" named DAC
                    dacAgnosticName = LinuxDacFileName;
                    dacFileName     = LinuxDacFileName;
                }
                else
                {
                    dacAgnosticName = DacInfo.GetDacRequestFileName(flavor, Architecture, Architecture, version);
                    dacFileName     = DacInfo.GetDacRequestFileName(flavor, IntPtr.Size == 4 ? Architecture.X86 : Architecture.Amd64, Architecture, version);
                }

                DacInfo dacInfo = new DacInfo(_dataReader, dacAgnosticName, Architecture)
                {
                    FileSize  = module.FileSize,
                    TimeStamp = module.TimeStamp,
                    FileName  = dacFileName,
                    Version   = module.Version
                };

                module.IsRuntime = true; //strange logic here (originally from the ClrInfo constructor)

                versions.Add(new ClrInfo(this, flavor, module, dacInfo, dacLocation));
            }

            ClrInfo[] result = versions.ToArray();
            Array.Sort(result);
            return(result);
        }