示例#1
0
 public static SymbolReader TryCreateEmbeddedPortablePdbReader(PdbReaderContext pdbContext, Metadata metadata)
 {
     if (metadata == null)
     {
         return(null);
     }
     try {
         if (!pdbContext.HasDebugInfo)
         {
             return(null);
         }
         var embeddedDir = pdbContext.TryGetDebugDirectoryEntry(ImageDebugType.EmbeddedPortablePdb);
         if (embeddedDir == null)
         {
             return(null);
         }
         var reader = pdbContext.CreateReader(embeddedDir.PointerToRawData, embeddedDir.SizeOfData);
         if (reader.Length < 8)
         {
             return(null);
         }
         // "MPDB" = 0x4244504D
         if (reader.ReadUInt32() != 0x4244504D)
         {
             return(null);
         }
         uint uncompressedSize = reader.ReadUInt32();
         // If this fails, see the (hopefully) updated spec:
         //		https://github.com/dotnet/corefx/blob/master/src/System.Reflection.Metadata/specs/PE-COFF.md#embedded-portable-pdb-debug-directory-entry-type-17
         bool newVersion = (uncompressedSize & 0x80000000) != 0;
         Debug.Assert(!newVersion);
         if (newVersion)
         {
             return(null);
         }
         var decompressedBytes = new byte[uncompressedSize];
         using (var deflateStream = new DeflateStream(reader.AsStream(), CompressionMode.Decompress)) {
             int pos = 0;
             while (pos < decompressedBytes.Length)
             {
                 int read = deflateStream.Read(decompressedBytes, pos, decompressedBytes.Length - pos);
                 if (read == 0)
                 {
                     break;
                 }
                 pos += read;
             }
             if (pos != decompressedBytes.Length)
             {
                 return(null);
             }
             var stream = ByteArrayDataReaderFactory.Create(decompressedBytes, filename: null);
             return(TryCreate(pdbContext, stream, isEmbeddedPortablePdb: true));
         }
     }
     catch (IOException) {
     }
     return(null);
 }
        public static SymbolReader Create(PdbReaderOptions options, Metadata metadata, byte[] pdbData)
        {
            var pdbContext = new PdbReaderContext(metadata.PEImage, options);

            if (!pdbContext.HasDebugInfo)
            {
                return(null);
            }
            return(CreateCore(pdbContext, metadata, ByteArrayDataReaderFactory.Create(pdbData, filename: null)));
        }
 public static DataReaderFactory TryCreateDataReaderFactory(string filename)
 {
     try {
         if (!File.Exists(filename))
         {
             return(null);
         }
         // Don't use memory mapped I/O
         return(ByteArrayDataReaderFactory.Create(File.ReadAllBytes(filename), filename));
     }
     catch (IOException) {
     }
     catch (UnauthorizedAccessException) {
     }
     catch (SecurityException) {
     }
     return(null);
 }