Exemplo n.º 1
0
        private ChecksumAlgorithmType ChecksumAlgorithmForFullPdb()
        {
            string fileName  = Path.GetFileName(this.FileName);
            string extension = Path.GetExtension(fileName);
            string pdbPath   = this.FileName.Replace(fileName, fileName.Replace(extension, ".pdb"));

            if (!File.Exists(pdbPath))
            {
                return(ChecksumAlgorithmType.Unknown);
            }

            using var pdbStream = new FileStream(pdbPath, FileMode.Open, FileAccess.Read);

            var    metadataProvider     = new SymMetadataProvider(this.metadataReader);
            object importer             = SymUnmanagedReaderFactory.CreateSymReaderMetadataImport(metadataProvider);
            ISymUnmanagedReader3 reader = SymUnmanagedReaderFactory.CreateReaderWithMetadataImport <ISymUnmanagedReader3>(pdbStream, importer, SymUnmanagedReaderCreationOptions.UseComRegistry);

            try
            {
                Guid algorithm = Guid.Empty;
                foreach (ISymUnmanagedDocument document in reader.GetDocuments())
                {
                    document.GetChecksumAlgorithmId(ref algorithm);
                    return(algorithm == sha256guid ? ChecksumAlgorithmType.Sha256 : ChecksumAlgorithmType.Sha1);
                }
            }
            finally
            {
                _ = ((ISymUnmanagedDispose)reader).Destroy();
            }

            return(ChecksumAlgorithmType.Unknown);
        }
Exemplo n.º 2
0
        public static ISymUnmanagedReader5 CreateReader(Stream pdbStream, Stream peStream)
        {
            pdbStream.Position = 0;
            bool isPortable = pdbStream.ReadByte() == 'B' && pdbStream.ReadByte() == 'S' && pdbStream.ReadByte() == 'J' && pdbStream.ReadByte() == 'B';

            pdbStream.Position = 0;

            var metadataProvider = new SymMetadataProvider(peStream);

            if (isPortable)
            {
                return((ISymUnmanagedReader5) new SymBinder().GetReaderFromStream(
                           pdbStream,
                           SymUnmanagedReaderFactory.CreateSymReaderMetadataImport(metadataProvider)));
            }
            else
            {
                return(SymUnmanagedReaderFactory.CreateReader <ISymUnmanagedReader5>(pdbStream, metadataProvider));
            }
        }