Example #1
0
        public void GetReaderForFile_SearchPaths_SubDir1()
        {
            var importer = new SymMetadataImport(new MemoryStream(TestResources.Documents.PortableDll));

            string tempDir     = Path.Combine(Path.GetDirectoryName(PortableShim.Path.GetTempFileName()), Guid.NewGuid().ToString());
            string searchDir   = Path.Combine(tempDir, "Dir");
            string peFilePath  = Path.Combine(tempDir, "Documents.dll");
            string pdbFilePath = Path.Combine(searchDir, "dll", "Documents.pdb");

            Directory.CreateDirectory(tempDir);
            Directory.CreateDirectory(Path.GetDirectoryName(pdbFilePath));
            PortableShim.File.WriteAllBytes(peFilePath, TestResources.Documents.PortableDll);
            PortableShim.File.WriteAllBytes(pdbFilePath, TestResources.Documents.PortablePdb);

            string searchPath = searchDir;

            ISymUnmanagedReader symReader;

            Assert.Equal(HResult.S_OK, SymBinder.GetReaderForFile(importer, peFilePath, searchPath, out symReader));

            int actualCount;

            Assert.Equal(HResult.S_OK, symReader.GetDocuments(0, out actualCount, null));
            Assert.Equal(13, actualCount);

            ((ISymUnmanagedDispose)symReader).Destroy();

            Directory.Delete(tempDir, recursive: true);
        }
        public void GetReaderForFile_NextToPE()
        {
            var importer = new SymMetadataImport(new MemoryStream(TestResources.Documents.PortableDll));

            string tempDir     = Path.Combine(Path.GetDirectoryName(Path.GetTempFileName()), Guid.NewGuid().ToString());
            string peFilePath  = Path.Combine(tempDir, "Documents.dll");
            string pdbFilePath = Path.Combine(tempDir, "Documents.pdb");

            Directory.CreateDirectory(tempDir);
            File.WriteAllBytes(peFilePath, TestResources.Documents.PortableDll);
            File.WriteAllBytes(pdbFilePath, TestResources.Documents.PortablePdb);

            string searchPath = null;

            ISymUnmanagedReader symReader;

            Assert.Equal(HResult.S_OK, SymBinder.GetReaderForFile(importer, peFilePath, searchPath, out symReader));

            int actualCount;

            Assert.Equal(HResult.S_OK, symReader.GetDocuments(0, out actualCount, null));
            Assert.Equal(13, actualCount);

            // check that metadata import hasn't been disposed:
            Assert.NotNull(((SymReader)symReader).GetMetadataImport());

            ((ISymUnmanagedDispose)symReader).Destroy();

            Directory.Delete(tempDir, recursive: true);
        }
Example #3
0
        private static SymReader CreateSymReaderFromResource(string name, out MetadataReader mdReader)
        {
            var importer = new SymMetadataImport(TestResources.ResourceHelper.GetResourceStream(name + ".dll"));

            mdReader = importer.MetadataReader;
            return(new SymReader(new PortablePdbReader(TestResources.ResourceHelper.GetResourceStream(name + ".pdbx"), importer)));
        }
Example #4
0
        public void GetReaderForFile()
        {
            var importer = new SymMetadataImport(new MemoryStream(TestResources.Documents.Dll));

            string filePath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());

            File.WriteAllBytes(filePath, TestResources.Documents.Pdb);

            string searchPath = null;

            ISymUnmanagedReader symReader;

            Assert.Equal(HResult.S_OK, SymBinder.GetReaderForFile(importer, filePath, searchPath, out symReader));

            int actualCount;

            Assert.Equal(HResult.S_OK, symReader.GetDocuments(0, out actualCount, null));
            Assert.Equal(11, actualCount);

            Assert.Equal(HResult.S_FALSE, ((ISymUnmanagedDispose)symReader).Destroy());
            Assert.Equal(HResult.S_OK, ((ISymUnmanagedDispose)symReader).Destroy());

            Assert.Throws <ObjectDisposedException>(() => symReader.GetDocuments(0, out actualCount, null));

            File.Delete(filePath);
        }
Example #5
0
        private static SymReader CreateSymReaderFromResource(KeyValuePair <byte[], byte[]> peAndPdb, out MetadataReader mdReader)
        {
            var importer = new SymMetadataImport(new MemoryStream(peAndPdb.Key));

            mdReader = importer.MetadataReader;
            return(new SymReader(new PortablePdbReader(peAndPdb.Value, peAndPdb.Value.Length, importer)));
        }
        public static ISymUnmanagedReader5 CreateSymReaderFromEmbeddedPortablePdb(byte[] peImage)
        {
            var importer = new SymMetadataImport(new MemoryStream(peImage));
            var peStream = new MemoryStream(peImage);
            var peReader = new PEReader(peStream);

            var embeddedEntry = peReader.ReadDebugDirectory().Single(e => e.Type == DebugDirectoryEntryType.EmbeddedPortablePdb);

            peStream.Position = embeddedEntry.DataPointer;

            return((ISymUnmanagedReader5) new SymBinder().GetReaderFromStream(peStream, importer));
        }
Example #7
0
        public void GetReaderFromStream()
        {
            var importer = new SymMetadataImport(new MemoryStream(TestResources.Documents.PortableDll));
            var stream   = new MemoryStream(TestResources.Documents.PortablePdb);

            ISymUnmanagedReader symReader = SymBinder.GetReaderFromStream(stream, importer);

            int actualCount;

            Assert.Equal(HResult.S_OK, symReader.GetDocuments(0, out actualCount, null));
            Assert.Equal(13, actualCount);

            Assert.Equal(HResult.S_FALSE, ((ISymUnmanagedDispose)symReader).Destroy());
            Assert.Equal(HResult.S_OK, ((ISymUnmanagedDispose)symReader).Destroy());

            Assert.Throws <ObjectDisposedException>(() => symReader.GetDocuments(0, out actualCount, null));
        }
        public void GetReaderFromStream_PortableEmbedded()
        {
            var importer = new SymMetadataImport(new MemoryStream(TestResources.MiscEmbedded.Dll));
            var peStream = new MemoryStream(TestResources.MiscEmbedded.Dll);
            var peReader = new PEReader(peStream);

            var embeddedEntry = peReader.ReadDebugDirectory().Single(e => e.Type == DebugDirectoryEntryType.EmbeddedPortablePdb);

            peStream.Position = embeddedEntry.DataPointer;

            ISymUnmanagedReader symReader = SymBinder.GetReaderFromStream(peStream, importer);

            AssertEx.Equal(new[] { @"C:\MiscEmbedded.cs" }, symReader.GetDocuments().Select(d => d.GetName()));

            Assert.Equal(HResult.S_FALSE, ((ISymUnmanagedDispose)symReader).Destroy());
            Assert.Equal(HResult.S_OK, ((ISymUnmanagedDispose)symReader).Destroy());

            Assert.Throws <ObjectDisposedException>(() => symReader.GetDocuments());
        }
Example #9
0
        public void GetReaderForFile_MatchingNotFound()
        {
            var importer = new SymMetadataImport(new MemoryStream(TestResources.Documents.PortableDll));

            string tempDir            = Path.Combine(Path.GetDirectoryName(PortableShim.Path.GetTempFileName()), Guid.NewGuid().ToString());
            string searchDir          = Path.Combine(tempDir, "Dir");
            string peFilePath         = Path.Combine(tempDir, "Documents.dll");
            string anotherPdbFilePath = Path.Combine(searchDir, "symbols", "dll", "Documents.pdb");

            Directory.CreateDirectory(tempDir);
            Directory.CreateDirectory(Path.GetDirectoryName(anotherPdbFilePath));
            PortableShim.File.WriteAllBytes(peFilePath, TestResources.Documents.PortableDll);
            PortableShim.File.WriteAllBytes(anotherPdbFilePath, TestResources.Async.PortablePdb);

            string searchPath = searchDir;

            ISymUnmanagedReader symReader;

            Assert.Equal(HResult.E_PDB_NOT_FOUND, SymBinder.GetReaderForFile(importer, peFilePath, searchPath, out symReader));
            Assert.Null(symReader);

            Directory.Delete(tempDir, recursive: true);
        }