Exemple #1
0
        CodeViewDebugData ReadCodeViewDebugData(DebugDirectory debugDir)
        {
            Debug.Assert(debugDir.Type == ImageDebugType.CodeView);
            //Console.WriteLine("ReadCodeViewDebugData: Debug directory with AddressOfRawData 0x" + debugDir.AddressOfRawData.ToString("x"));

            // sanity check read size
            if (debugDir.SizeOfData > 1000)
            {
                Console.WriteLine("ReadCodeViewDebugData: SizeOfData > 1000 - assuming bad data");
                return(null);
            }

            BinaryReader reader;

            if (!TryReadAtRVA((int)debugDir.AddressOfRawData, (int)debugDir.SizeOfData, out reader))
            {
                Console.WriteLine("ReadCodeViewDebugData: Unable to read rva=0x" + debugDir.AddressOfRawData.ToString("x") + " size=" + debugDir.SizeOfData);
                return(null);
            }
            int signature = reader.ReadInt32();

            if (signature != PEFileConstants.CodeViewSignature)
            {
                Console.WriteLine("ReadCodeViewDebugData: Invalid codeview signature Expected: " + PEFileConstants.CodeViewSignature + " Actual: " + signature);
                return(null);
            }
            CodeViewDebugData codeView = new CodeViewDebugData();

            codeView.Signature = new Guid(reader.ReadBytes(16));
            codeView.Age       = (int)reader.ReadUInt32();
            codeView.PdbPath   = reader.ReadNullTerminatedString(Encoding.UTF8);
            //Console.WriteLine("ReadCodeViewDebugData: PdbPath=" + codeView.PdbPath + " Age=" + codeView.Age + " Signature="+codeView.Signature);
            return(codeView);
        }
Exemple #2
0
        static string GetPdbFileForModule(string fileName)
        {
            string retVal;

            // look in the "cache" of already successfully opened
            if (s_pdbFileForModule.TryGetValue(fileName, out retVal))
            {
                return(retVal);
            }

            retVal = null;
            CodeViewDebugData cvdd = CvDataFromPE(fileName);

            if (cvdd != null)
            {
                if (s_symStore == null)
                {
                    s_symStore = SymStore.FromPath(s_symbolServerPath);
                }

                if (s_symStore != null)
                {
                    Stream         pdbStream;
                    string         indexString   = cvdd.Signature.ToString().Replace("-", "").ToUpper() + cvdd.Age.ToString();
                    string         localFileName = Path.GetFileName(cvdd.PdbPath);
                    SymStoreResult symResult     = new SymStoreResult();
                    if (s_symStore.TryGetFile(localFileName, indexString, symResult, out pdbStream))
                    {
                        retVal = symResult.CachedPath;
                    }
                }
            }

            s_pdbFileForModule.Add(fileName, retVal);
            return(retVal);
        }