Beispiel #1
0
 public int GetUrl(
     int bufferLength, 
     out int count,
     [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0), Out]char[] url)
 {
     string name = SymReader.MetadataReader.GetString(SymReader.MetadataReader.GetDocument(Handle).Name);
     return InteropUtilities.StringToBuffer(name, bufferLength, out count, url);
 }
Beispiel #2
0
        public int GetName(
            int bufferLength,
            out int count,
            [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0), Out] char[] name)
        {
            var variable = MetadataReader.GetLocalVariable(_handle);
            var str      = MetadataReader.GetString(variable.Name);

            return(InteropUtilities.StringToBuffer(str, bufferLength, out count, name));
        }
Beispiel #3
0
        public int GetSignature(
            int bufferLength,
            out int count,
            [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0), Out] byte[] signature)
        {
            if (_lazySignature == null)
            {
                InitializeValueAndSignature();
            }

            return(InteropUtilities.BytesToBuffer(_lazySignature, bufferLength, out count, signature));
        }
Beispiel #4
0
        public int GetName(
            int bufferLength,
            out int count,
            [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0), Out] char[] name)
        {
            var mdReader = _pdbReader.MetadataReader;
            var constant = mdReader.GetLocalConstant(_handle);

            var str = mdReader.GetString(constant.Name);

            return(InteropUtilities.StringToBuffer(str, bufferLength, out count, name));
        }
Beispiel #5
0
        public int GetChecksum(
            int bufferLength,
            out int count,
            [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0), Out]byte[] checksum)
        {
            var document = SymReader.MetadataReader.GetDocument(Handle);
            if (document.Hash.IsNil)
            {
                count = 0;
                return HResult.S_FALSE;
            }

            var hash = SymReader.MetadataReader.GetBlobBytes(document.Hash);
            return InteropUtilities.BytesToBuffer(hash, bufferLength, out count, checksum);
        }
Beispiel #6
0
        /// <summary>
        /// Get the file name for the line associated with specified offset.
        /// </summary>
        public int GetFileNameFromOffset(
            int offset,
            int bufferLength,
            out int count,
            [In, Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] char[] name)
        {
            if (offset < 0)
            {
                offset = int.MaxValue;
            }

            var debugInfo = MetadataReader.GetMethodDebugInformation(DebugHandle);
            var candidate = debugInfo.Document;

            if (candidate.IsNil)
            {
                // method body spans multiple documents:
                foreach (var sp in GetSequencePoints())
                {
                    if (sp.Offset <= offset)
                    {
                        candidate = sp.Document;
                    }
                    else if (sp.Offset > offset)
                    {
                        break;
                    }
                }

                // offset is negative, or sequence point blob is missing document definition (bad metadata):
                if (candidate.IsNil)
                {
                    count = 0;
                    return(HResult.E_FAIL);
                }
            }

            var    document = MetadataReader.GetDocument(candidate);
            string nameStr  = MetadataReader.GetString(document.Name);

            return(InteropUtilities.StringToBuffer(nameStr, bufferLength, out count, name));
        }
Beispiel #7
0
        public int GetReaderFromStream(
            [MarshalAs(UnmanagedType.Interface)] object metadataImport,
            [MarshalAs(UnmanagedType.Interface)] object stream,
            [MarshalAs(UnmanagedType.Interface)] out ISymUnmanagedReader reader)
        {
            reader = null;

            try
            {
                var comStream = stream as IStream ?? throw new ArgumentNullException(null, nameof(stream));
                var mdImport  = MetadataImport.FromObject(metadataImport) ?? throw new ArgumentException(null, nameof(metadataImport));

                reader = SymReader.CreateFromStream(comStream, new LazyMetadataImport(mdImport));
                return(HResult.S_OK);
            }
            finally
            {
                InteropUtilities.TransferOwnershipOrRelease(ref metadataImport, reader);
            }
        }
        public int GetReaderFromStream(
            [MarshalAs(UnmanagedType.Interface)] object metadataImport,
            [MarshalAs(UnmanagedType.Interface)] object stream,
            [MarshalAs(UnmanagedType.Interface)] out ISymUnmanagedReader reader)
        {
            reader = null;

            try
            {
                IStream comStream = stream as IStream;
                var     mdImport  = metadataImport as IMetadataImport;
                if (mdImport == null || comStream == null)
                {
                    return(HResult.E_INVALIDARG);
                }

                reader = SymReader.CreateFromStream(comStream, new LazyMetadataImport(mdImport));
                return(HResult.S_OK);
            }
            finally
            {
                InteropUtilities.TransferOwnershipOrRelease(ref metadataImport, reader);
            }
        }
Beispiel #9
0
        public int GetChecksum(
            int bufferLength,
            out int count,
            [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0), Out] byte[] checksum)
        {
            // diasymreader returns no checksum for documents once EnC has been performed:
            if (SymReader.Version > 1)
            {
                count = 0;
                return(HResult.S_FALSE);
            }

            var document = PdbReader.MetadataReader.GetDocument(Handle);

            if (document.Hash.IsNil)
            {
                count = 0;
                return(HResult.S_FALSE);
            }

            var hash = PdbReader.MetadataReader.GetBlobBytes(document.Hash);

            return(InteropUtilities.BytesToBuffer(hash, bufferLength, out count, checksum));
        }
        public int GetReaderForFile2(
            [MarshalAs(UnmanagedType.Interface)] object metadataImport,
            [MarshalAs(UnmanagedType.LPWStr)] string fileName,
            [MarshalAs(UnmanagedType.LPWStr)] string searchPath,
            SymUnmanagedSearchPolicy searchPolicy,
            [MarshalAs(UnmanagedType.Interface)] out ISymUnmanagedReader reader)
        {
            reader = null;
            try
            {
                var mdImport = metadataImport as IMetadataImport;
                if (mdImport == null || string.IsNullOrEmpty(fileName))
                {
                    return(HResult.E_INVALIDARG);
                }

                // See DIA: FLocatePdbDefault, FLocateCvFilePathHelper, FLocatePdbSymsrv, FLocateCvFilePathHelper
                //
                // 1) Try open Combine(<PE directory>, <PDB file name>) (unless RestrictReferencePath)
                // 2) Try open PDB path (unless RestrictOriginalPath)
                // 3) Search Paths - semicolon separated paths
                //    a) searchPath parameter
                //    b) registry (unless RestrictRegistry)
                //       Use search paths from registry Software\Microsoft\VisualStudio\MSPDB, value SymbolSearchPath
                //       with environment variables expanded (ExpandEnvironmentStrings)
                //       i) try USER
                //       ii) try MACHINE
                //    c) environment vars
                //        i) _NT_ALT_SYMBOL_PATH
                //       ii) _NT_SYMBOL_PATH
                //       ii) SystemRoot (unless RestrictSystemRoot)
                //
                //    for each search path:
                //       special paths: SRV*<server>, SYMSRV*SYMSRV.DLL*<server> => symbol server (unless RestrictSymsrv)
                //                      CACHE*<cache> => sym cache (unless RestrictSymsrv)
                //
                //       A) try open <path>\symbols\<PE file extension>\<PDB file name>
                //       B) try open <path>\<PE file extension>\<PDB file name>
                //       C) try open <path>\<PDB file name>
                //
                // Each attempt checks if PDB ID matches.
                //
                // Search policy: all is restricted unless explicitly allowed.
                // After opened store to cache if CACHE* given (only the first cache?)

                if (!TryReadCodeViewData(fileName, out var codeViewData, out uint stamp))
                {
                    return(HResult.E_FAIL); // TODO: specific error code (ecToHresult)?
                }

                Guid   guid        = codeViewData.Guid;
                int    age         = codeViewData.Age;
                string pdbFileName = Path.GetFileName(codeViewData.Path);
                var    lazyImport  = new LazyMetadataImport(mdImport);

                // 1) next to the PE file
                if ((searchPolicy & SymUnmanagedSearchPolicy.AllowReferencePathAccess) != 0)
                {
                    string peDirectory = Path.GetDirectoryName(fileName);
                    string pdbFilePath = Path.Combine(peDirectory, pdbFileName);

                    if (TryCreateReaderForMatchingPdb(pdbFilePath, guid, stamp, age, lazyImport, out reader))
                    {
                        return(HResult.S_OK);
                    }
                }

                // 2) PDB path as specified in Debug Directory
                if ((searchPolicy & SymUnmanagedSearchPolicy.AllowOriginalPathAccess) != 0)
                {
                    if (TryCreateReaderForMatchingPdb(codeViewData.Path, guid, stamp, age, lazyImport, out reader))
                    {
                        return(HResult.S_OK);
                    }
                }

                // 3) Search Paths
                string peFileExtension = Path.GetExtension(fileName).TrimStart('.');

                foreach (var searchPaths in GetSearchPathsSequence(searchPath, searchPolicy))
                {
                    if (TryFindMatchingPdb(searchPaths, peFileExtension, pdbFileName, guid, stamp, age, lazyImport, searchPolicy, out reader))
                    {
                        return(HResult.S_OK);
                    }
                }

                return(HResult.E_PDB_NOT_FOUND);
            }
            finally
            {
                InteropUtilities.TransferOwnershipOrRelease(ref metadataImport, reader);
            }
        }