Beispiel #1
0
 public void AddToDocumentIfEmittable(SymDocument aDocument)
 {
     if (Emit)
     {
         SymNodeToken node = new SymNodeToken(Token);
         aDocument.CurrentNode.Add(node);
     }
 }
Beispiel #2
0
            private static bool TryValidateFileHash(SymDocument doc, CompetitionState competitionState)
            {
                switch (doc.ChecksumAlgorithm)
                {
                case ChecksumAlgorithmKind.Md5:
                    return(ValidateCore(doc.Url, _md5HashesCache, Md5AlgName, doc.Checksum, competitionState));

                case ChecksumAlgorithmKind.Sha1:
                    return(ValidateCore(doc.Url, _sha1HashesCache, Sha1AlgName, doc.Checksum, competitionState));

                default:
                    throw CodeExceptions.UnexpectedArgumentValue(nameof(doc.ChecksumAlgorithm), doc.ChecksumAlgorithm);
                }
            }
Beispiel #3
0
    // this needs a reference to Microsoft.DiaSymReader
    // or redefine its interfaces manually from here https://github.com/dotnet/roslyn/tree/master/src/Dependencies/Microsoft.DiaSymReader
    public static void ValidateChecksums(string filePath)
    {
        if (filePath == null)
        {
            throw new ArgumentNullException(nameof(filePath));
        }

        var dispenser = (IMetaDataDispenser) new CorMetaDataDispenser();
        var import    = dispenser.OpenScope(filePath, 0, typeof(IMetaDataImport).GUID);

        var binder = (ISymUnmanagedBinder) new CorSymBinder_SxS();
        ISymUnmanagedReader reader;

        binder.GetReaderForFile(import, filePath, null, out reader);

        int count;

        reader.GetDocuments(0, out count, null);
        if (count > 0)
        {
            var docs = new ISymUnmanagedDocument[count];
            reader.GetDocuments(count, out count, docs);
            foreach (var d in docs)
            {
                var doc = new SymDocument(d);
                Console.WriteLine(doc.Url);

                if (doc.Checksum.SequenceEqual(doc.ComputeChecksum()))
                {
                    Console.WriteLine(" checksum is valid.");
                }
                else
                {
                    Console.WriteLine(" checksum is not valid.");
                }
            }
        }
    }
Beispiel #4
0
            // BASEDON: http://stackoverflow.com/questions/36649271/check-that-pdb-file-matches-to-the-source
            public static bool TryGetSourceInfo(
                MethodBase method,
                CompetitionState competitionState,
                out string sourceFileName,
                out int firstCodeLine)
            {
                firstCodeLine  = -1;
                sourceFileName = null;

                var methodSymbols = TryGetMethodSymbols(method, competitionState);

                if (methodSymbols != null)
                {
                    int[] startLines;
                    ISymUnmanagedDocument[] documents;

                    if (TryGetDocsAndLines(methodSymbols, competitionState, out documents, out startLines))
                    {
                        Array.Sort(startLines, documents);
                        var doc = new SymDocument(documents[0]);

                        if (TryValidateFileHash(doc, competitionState))
                        {
                            sourceFileName = doc.Url;
                            firstCodeLine  = startLines[0];
                        }
                    }
                    else
                    {
                        // ReSharper disable once PossibleNullReferenceException
                        competitionState.WriteMessage(
                            MessageSource.Analyser, MessageSeverity.SetupError,
                            $"Method {method.DeclaringType.Name}.{method.Name}, no PDB data available.");
                    }
                }

                return(sourceFileName != null);
            }