Exemplo n.º 1
0
        /// <summary>
        /// Metadata locator helper for the DAC.
        /// </summary>
        /// <param name="imagePath">file name and path to module</param>
        /// <param name="imageTimestamp">module timestamp</param>
        /// <param name="imageSize">module image</param>
        /// <param name="localFilePath">local file path of the module</param>
        /// <returns>HRESULT</returns>
        public static int GetICorDebugMetadataLocator(
            [MarshalAs(UnmanagedType.LPWStr)] string imagePath,
            uint imageTimestamp,
            uint imageSize,
            uint pathBufferSize,
            IntPtr pPathBufferSize,
            IntPtr pPathBuffer)
        {
            int hr         = S_OK;
            int actualSize = 0;

            Debug.Assert(pPathBuffer != IntPtr.Zero);
            try
            {
                if (SymbolReader.IsSymbolStoreEnabled())
                {
                    SymbolStoreKey key           = PEFileKeyGenerator.GetKey(imagePath, imageTimestamp, imageSize);
                    string         localFilePath = SymbolReader.GetSymbolFile(key);
                    localFilePath += "\0";              // null terminate the string
                    actualSize     = localFilePath.Length;

                    if (pathBufferSize > actualSize)
                    {
                        Marshal.Copy(localFilePath.ToCharArray(), 0, pPathBuffer, actualSize);
                    }
                    else
                    {
                        hr = E_INSUFFICIENT_BUFFER;
                    }
                }
                else
                {
                    hr = E_FAIL;
                }
            }
            catch (Exception ex) when
                (ex is UnauthorizedAccessException ||
                ex is BadImageFormatException ||
                ex is InvalidVirtualAddressException ||
                ex is IOException)
            {
                hr = E_FAIL;
            }

            if (pPathBufferSize != IntPtr.Zero)
            {
                Marshal.WriteInt32(pPathBufferSize, actualSize);
            }

            return(hr);
        }
Exemplo n.º 2
0
        private PEReader GetPEReader(ModuleInfo module)
        {
            if (!_pathToPeReader.TryGetValue(module.FileName, out PEReader reader))
            {
                Stream stream = null;

                string downloadFilePath = module.FileName;
                if (!File.Exists(downloadFilePath))
                {
                    if (SymbolReader.IsSymbolStoreEnabled())
                    {
                        SymbolStoreKey key = PEFileKeyGenerator.GetKey(Path.GetFileName(downloadFilePath), module.TimeStamp, module.FileSize);
                        if (key != null)
                        {
                            // Now download the module from the symbol server
                            downloadFilePath = SymbolReader.GetSymbolFile(key);
                        }
                    }
                }

                if (!string.IsNullOrEmpty(downloadFilePath))
                {
                    try
                    {
                        stream = File.OpenRead(downloadFilePath);
                    }
                    catch (Exception ex) when(ex is DirectoryNotFoundException || ex is FileNotFoundException || ex is UnauthorizedAccessException || ex is IOException)
                    {
                        Trace.TraceError("GetPEReader: exception {0}", ex);
                    }
                    if (stream != null)
                    {
                        reader = new PEReader(stream);
                        _pathToPeReader.Add(module.FileName, reader);
                    }
                }
            }
            return(reader);
        }