예제 #1
0
        public void Convert_VersionInfo()
        {
            // arrange
            var sut         = new Converter();
            var versionInfo = new ClrMd.VersionInfo()
            {
                Major    = 1,
                Minor    = 2,
                Revision = 3,
                Patch    = 4
            };

            // act
            // assert
            var res = sut.Convert(versionInfo);

            res.Major.Should().Be(1);
            res.Minor.Should().Be(2);
            res.Revision.Should().Be(3);
            res.Patch.Should().Be(4);
        }
예제 #2
0
        public void GetVersionInfo(ulong addr, out VersionInfo version)
        {
            version = new VersionInfo();

            uint index;
            ulong baseAddr;
            int hr = _symbols.GetModuleByOffset(addr, 0, out index, out baseAddr);
            if (hr != 0)
                return;

            uint needed = 0;
            hr = GetModuleVersionInformation(index, baseAddr, "\\", null, 0, out needed);
            if (hr != 0)
                return;

            byte[] buffer = new byte[needed];
            hr = GetModuleVersionInformation(index, baseAddr, "\\", buffer, needed, out needed);
            if (hr != 0)
                return;

            version.Minor = (ushort)Marshal.ReadInt16(buffer, 8);
            version.Major = (ushort)Marshal.ReadInt16(buffer, 10);
            version.Patch = (ushort)Marshal.ReadInt16(buffer, 12);
            version.Revision = (ushort)Marshal.ReadInt16(buffer, 14);

            return;
        }
예제 #3
0
        public void GetVersionInfo(ulong baseAddress, out VersionInfo version)
        {
            DumpModule module = _dumpReader.TryLookupModuleByAddress(baseAddress);

            version = module != null?GetVersionInfo(module) : new VersionInfo();
        }
예제 #4
0
        internal static void GetVersionInfo(IDataReader dataReader, ulong baseAddress, ElfFile loadedFile, out VersionInfo version)
        {
            foreach (ElfProgramHeader programHeader in loadedFile.ProgramHeaders)
            {
                if (programHeader.Type == ElfProgramHeaderType.Load && programHeader.IsWritable)
                {
                    long loadAddress = programHeader.VirtualAddress;
                    long loadSize    = programHeader.VirtualSize;
                    GetVersionInfo(dataReader, baseAddress + (ulong)loadAddress, (ulong)loadSize, out version);
                    return;
                }
            }

            version = default;
        }
예제 #5
0
 public void GetVersionInfo(ulong baseAddress, out VersionInfo version)
 {
     DumpModule module = m_dumpReader.TryLookupModuleByAddress(baseAddress);
     version = (module != null) ? GetVersionInfo(module) : new VersionInfo();
 }
예제 #6
0
 public static Version ConvertToVersion(VersionInfo versionInfo)
 {
     return new Version(versionInfo.Major, versionInfo.Minor, versionInfo.Revision, versionInfo.Patch);
 }
예제 #7
0
        internal static bool GetVersionInfo(this IDataReader dataReader, ulong baseAddress, ElfFile loadedFile, out VersionInfo version)
        {
            foreach (ElfProgramHeader programHeader in loadedFile.ProgramHeaders)
            {
                if (programHeader.Type == ElfProgramHeaderType.Load && programHeader.IsWritable)
                {
                    return(GetVersionInfo(dataReader, baseAddress + programHeader.VirtualAddress, programHeader.VirtualSize, out version));
                }
            }

            version = default;
            return(false);
        }
예제 #8
0
        public void GetVersionInfo(ulong addr, out VersionInfo version)
        {
            StringBuilder filename = new StringBuilder(1024);
            GetModuleFileNameExA(_process, new IntPtr((long)addr), filename, filename.Capacity);

            int major, minor, revision, patch;
            if (NativeMethods.GetFileVersion(filename.ToString(), out major, out minor, out revision, out patch))
                version = new VersionInfo(major, minor, revision, patch);
            else
                version = new VersionInfo();
        }
예제 #9
0
        /// <summary>
        /// Returns the filename of the dac dll for the requests to the symbol server
        /// </summary>
        public static string GetDacRequestFileName(ClrFlavor flavor, Architecture currentArchitecture, Architecture targetArchitecture, VersionInfo version, Platform platform)
        {
            // Linux never has a "long" named DAC
            if (platform == Platform.Linux)
            {
                return(c_linuxCoreDacFileName);
            }

            var dacNameBase = flavor == ClrFlavor.Core ? c_coreDacFileNameBase : c_desktopDacFileNameBase;

            return($"{dacNameBase}_{currentArchitecture}_{targetArchitecture}_{version.Major}.{version.Minor}.{version.Revision}.{version.Patch:D2}.dll");
        }
예제 #10
0
        /// <summary>
        /// Returns the filename of the dac dll according to the specified parameters
        /// </summary>
        public static string GetDacRequestFileName(ClrFlavor flavor, Runtime.Architecture currentArchitecture, Runtime.Architecture targetArchitecture, VersionInfo clrVersion)
        {
            string dacName = flavor == ClrFlavor.Core ? "mscordaccore" : "mscordacwks";

            return(string.Format("{0}_{1}_{2}_{3}.{4}.{5}.{6:D2}.dll", dacName, currentArchitecture, targetArchitecture, clrVersion.Major, clrVersion.Minor, clrVersion.Revision, clrVersion.Patch));
        }
예제 #11
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
                };

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

            ClrInfo[] result = versions.ToArray();
            Array.Sort(result);
            return(result);
        }
예제 #12
0
 /// <summary>
 ///     Converts the specified version information.
 /// </summary>
 /// <param name="versionInfo">The version information.</param>
 /// <returns>VersionInfo.</returns>
 public VersionInfo Convert(ClrMd.VersionInfo versionInfo) => new VersionInfo(versionInfo.Major,
                                                                              versionInfo.Minor, versionInfo.Revision, versionInfo.Patch);
예제 #13
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";

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

                if (isLinux)
                {
                    dacLocation = Path.ChangeExtension(dacLocation, ".so");
                }

                if (isLinux)
                {
                    if (!File.Exists(dacLocation))
                    {
                        dacLocation = Path.GetFileName(dacLocation);
                    }
                }
                else if (!File.Exists(dacLocation) || !PlatformFunctions.IsEqualFileVersion(dacLocation, module.Version))
                {
                    dacLocation = null;
                }

                VersionInfo version         = module.Version;
                string      dacAgnosticName = DacInfo.GetDacRequestFileName(flavor, Architecture, Architecture, version);
                string      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
                };

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

            var result = versions.ToArray();

            Array.Sort(result);
            return(result);
        }
예제 #14
0
        /// <summary>
        /// Returns the filename of the dac dll according to the specified parameters
        /// </summary>
        public static string GetDacRequestFileName(ClrFlavor flavor, Runtime.Architecture currentArchitecture, Runtime.Architecture targetArchitecture, VersionInfo clrVersion)
        {
            if (flavor == ClrFlavor.Native)
                return targetArchitecture == Runtime.Architecture.Amd64 ? "mrt100dac_winamd64.dll" : "mrt100dac_winx86.dll";

            string dacName = flavor == ClrFlavor.CoreCLR ? "mscordaccore" : "mscordacwks";
            return string.Format("{0}_{1}_{2}_{3}.{4}.{5}.{6:D2}.dll", dacName, currentArchitecture, targetArchitecture, clrVersion.Major, clrVersion.Minor, clrVersion.Revision, clrVersion.Patch);
        }
예제 #15
0
        internal static bool GetVersionInfo(this IDataReader dataReader, ulong startAddress, ulong size, out VersionInfo version)
        {
            // (int)size underflow will result in returning 0 here, so this is acceptable
            ulong address = dataReader.SearchMemory(startAddress, (int)size, PlatformFunctions.s_versionString);

            if (address == 0)
            {
                version = default;
                return(false);
            }

            Span <byte> bytes = stackalloc byte[64];
            int         read  = dataReader.Read(address + (uint)PlatformFunctions.s_versionLength, bytes);

            if (read > 0)
            {
                bytes   = bytes.Slice(0, read);
                version = ParseAsciiVersion(bytes);
                return(true);
            }

            version = default;
            return(false);
        }
 public void GetVersionInfo(ulong baseAddress, out VersionInfo version)
 {
     _impl.GetVersionInfo(baseAddress, out version);
 }
예제 #17
0
        /// <summary>
        /// Returns the file name of the DAC dll for the requests to the symbol server.
        /// </summary>
        public static string GetDacRequestFileName(ClrFlavor flavor, Architecture currentArchitecture, Architecture targetArchitecture, VersionInfo version, OSPlatform platform)
        {
            // Linux never has a "long" named DAC
            if (platform == OSPlatform.Linux)
            {
                // if running on Windows and the target is Linux return the cross-OS DAC name
                return(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? c_coreDacFileName : c_linuxCoreDacFileName);
            }

            if (platform == OSPlatform.OSX)
            {
                return(c_macOSCoreDacFileName);
            }

            var dacNameBase = flavor == ClrFlavor.Core ? c_coreDacFileNameBase : c_desktopDacFileNameBase;

            return($"{dacNameBase}_{currentArchitecture}_{targetArchitecture}_{version.Major}.{version.Minor}.{version.Revision}.{version.Patch:D2}.dll");
        }
예제 #18
0
        internal static bool IsEqualFileVersion(string file, VersionInfo version)
        {
            int major, minor, revision, patch;
            if (!GetFileVersion(file, out major, out minor, out revision, out patch))
                return false;

            return major == version.Major && minor == version.Minor && revision == version.Revision && patch == version.Patch;
        }
예제 #19
0
파일: internal.cs 프로젝트: zha0/DbgShell
 public void GetVersionInfo(ulong baseAddress, out VersionInfo version)
 {
     _reader.GetVersionInfo(baseAddress, out version);
     _file.WriteLine("GetVersionInfo - {0:x} {1}", baseAddress, version.ToString());
 }
예제 #20
0
        private static VersionInfo GetVersionInfo(DumpModule module)
        {
            var raw = module.Raw;
            var version = raw.VersionInfo;
            int minor = unchecked((ushort)version.dwFileVersionMS);
            int major = (ushort)(version.dwFileVersionMS >> 16);
            int patch = unchecked((ushort)version.dwFileVersionLS);
            int rev = (ushort)(version.dwFileVersionLS >> 16);

            var versionInfo = new VersionInfo(major, minor, rev, patch);
            return versionInfo;
        }
예제 #21
0
 public void GetVersionInfo(ulong baseAddress, out VersionInfo version)
 {
     // TODO
     Debug.WriteLine($"GetVersionInfo not yet implemented: addr={baseAddress:x}");
     version = new VersionInfo();
 }
예제 #22
0
 public void GetVersionInfo(ulong baseAddress, out VersionInfo version)
 {
     m_reader.GetVersionInfo(baseAddress, out version);
     m_file.WriteLine("GetVersionInfo - {0:x} {1}", baseAddress, version.ToString());
 }
예제 #23
0
        internal static unsafe void GetVersionInfo(IDataReader dataReader, ulong address, ulong size, out VersionInfo version)
        {
            Span <byte> buffer     = stackalloc byte[s_versionLength];
            ulong       endAddress = address + size;

            while (address < endAddress)
            {
                bool result = dataReader.ReadMemory(address, buffer, out int read);
                if (!result || read < s_versionLength)
                {
                    address += (uint)s_versionLength;
                    continue;
                }

                if (!buffer.SequenceEqual(s_versionString))
                {
                    address++;
                    continue;
                }

                address += (uint)s_versionLength;

                StringBuilder builder = new StringBuilder();
                while (address < endAddress)
                {
                    Span <byte> bytes = stackalloc byte[1];
                    result = dataReader.ReadMemory(address, bytes, out read);
                    if (!result || read < bytes.Length)
                    {
                        break;
                    }

                    if (bytes[0] == '\0')
                    {
                        break;
                    }

                    if (bytes[0] == ' ')
                    {
                        try
                        {
                            Version v = Version.Parse(builder.ToString());
                            version = new VersionInfo(v.Major, v.Minor, v.Build, v.Revision);
                            return;
                        }
                        catch (FormatException)
                        {
                            break;
                        }
                    }

                    Span <char> chars = stackalloc char[1];
                    fixed(byte *bytesPtr = &MemoryMarshal.GetReference(bytes))
                    fixed(char *charsPtr = &MemoryMarshal.GetReference(chars))
                    {
                        _ = Encoding.ASCII.GetChars(bytesPtr, bytes.Length, charsPtr, chars.Length);
                    }

                    _ = builder.Append(chars[0]);
                    address++;
                }

                break;
            }

            version = default;
        }