Example #1
0
        public void PeParser_X86StaticallyLinked_FindsEmbeddedPdbPath()
        {
            string pdb         = PeParser.ExtractPdbPath(TestResources.LoadTests_ReleaseX86, MockLogger.Object);
            string expectedPdb = Path.GetFullPath(Path.ChangeExtension(TestResources.LoadTests_ReleaseX86, ".pdb"));

            pdb.Should().Be(expectedPdb);
        }
Example #2
0
        public void PeParser_X86UnicodeName_FindsEmbeddedPdbPath()
        {
            string pdb         = PeParser.ExtractPdbPath(TestResources.UnicodeNameExe, MockLogger.Object);
            string expectedPdb = Path.GetFullPath(Path.ChangeExtension(TestResources.UnicodeNameExe, ".pdb"));

            pdb.Should().Be(expectedPdb);
        }
Example #3
0
        private string FindPdbFile(string binary, string pathExtension)
        {
            string pdb = PeParser.ExtractPdbPath(binary, _logger);

            if (pdb != null && File.Exists(pdb))
            {
                return(pdb);
            }

            pdb = Path.ChangeExtension(binary, ".pdb");
            if (File.Exists(pdb))
            {
                return(pdb);
            }

            pdb = Path.GetFileName(pdb);
            if (pdb == null || File.Exists(pdb))
            {
                return(pdb);
            }

            string path = Environment.GetEnvironmentVariable("PATH");

            if (!string.IsNullOrEmpty(pathExtension))
            {
                path = $"{pathExtension};{path}";
            }
            var pathElements = path?.Split(';');

            return(pathElements?.Select(pe => Path.Combine(pe, pdb)).FirstOrDefault(File.Exists));
        }
Example #4
0
        private string FindPdbFile(string binary, string pathExtension)
        {
            IList <string> attempts = new List <string>();
            string         pdb      = PeParser.ExtractPdbPath(binary, _logger);

            if (pdb != null && File.Exists(pdb))
            {
                return(pdb);
            }
            attempts.Add("parsing from executable");

            pdb = Path.ChangeExtension(binary, ".pdb");
            if (File.Exists(pdb))
            {
                return(pdb);
            }
            attempts.Add($"\"{pdb}\"");

            pdb = Path.GetFileName(pdb);
            if (pdb == null || File.Exists(pdb))
            {
                return(pdb);
            }
            attempts.Add($"\"{pdb}\"");

            string path = Environment.GetEnvironmentVariable("PATH");

            if (!string.IsNullOrEmpty(pathExtension))
            {
                path = $"{pathExtension};{path}";
            }
            var pathElements = path?.Split(';');

            if (path != null)
            {
                foreach (string pathElement in pathElements)
                {
                    string file = Path.Combine(pathElement, pdb);
                    if (File.Exists(file))
                    {
                        return(file);
                    }
                    attempts.Add($"\"{file}\"");
                }
            }

            if (_debugMode)
            {
                _logger.LogInfo("Attempts to find pdb: " + string.Join("::", attempts));
            }

            return(null);
        }
        private string FindPdbFile(string binary, string pathExtension)
        {
            IList <string> attempts = new List <string>();
            string         pdb      = PeParser.ExtractPdbPath(binary, _logger);

            if (pdb != null && File.Exists(pdb))
            {
                return(pdb);
            }
            attempts.Add($"\"{binary}\"");

            pdb = Path.ChangeExtension(binary, ".pdb");
            if (File.Exists(pdb))
            {
                return(pdb);
            }
            attempts.Add($"\"{pdb}\"");

            pdb = Path.GetFileName(pdb);
            if (pdb == null || File.Exists(pdb))
            {
                return(pdb);
            }
            attempts.Add($"\"{pdb}\"");

            string path = Environment.GetEnvironmentVariable("PATH");

            if (!string.IsNullOrEmpty(pathExtension))
            {
                path = $"{pathExtension};{path}";
            }
            var pathElements = path?.Split(';');

            if (path != null)
            {
                foreach (string pathElement in pathElements)
                {
                    string file = Path.Combine(pathElement, pdb);
                    if (File.Exists(file))
                    {
                        return(file);
                    }
                    attempts.Add($"\"{file}\"");
                }
            }

            _logger.DebugInfo(String.Format(Resources.AttemptsToFind, string.Join("::", attempts)));

            return(null);
        }
Example #6
0
        public static string FindPdbFile(string binary, string pathExtension, ILogger logger)
        {
            IList <string> attempts = new List <string>();
            string         pdb      = PeParser.ExtractPdbPath(binary, logger);

            if (pdb != null && File.Exists(pdb))
            {
                return(pdb);
            }
            attempts.Add("parsing from executable");

            pdb = Path.ChangeExtension(binary, ".pdb");
            if (File.Exists(pdb))
            {
                return(pdb);
            }
            attempts.Add($"\"{pdb}\"");

            pdb = Path.GetFileName(pdb);
            if (pdb == null || File.Exists(pdb))
            {
                return(pdb);
            }
            attempts.Add($"\"{pdb}\"");

            string path = Environment.GetEnvironmentVariable("PATH");

            if (!string.IsNullOrEmpty(pathExtension))
            {
                path = $"{pathExtension};{path}";
            }
            var pathElements = path?.Split(';');

            if (path != null)
            {
                foreach (string pathElement in pathElements)
                {
                    try
                    {
                        string file = Path.Combine(pathElement, pdb);
                        if (File.Exists(file))
                        {
                            return(file);
                        }
                        attempts.Add($"\"{file}\"");
                    }
                    catch (Exception e)
                    {
                        string message = $"Exception while searching for the PDB file of binary '{binary}'. ";
                        message += "Do you have some invalid path on your system's PATH environment variable? ";
                        message += $"The according path is '{pathElement}' and will be ignored.";
                        logger.LogWarning(message);
                        logger.DebugWarning($"Exception:{Environment.NewLine}{e}");
                    }
                }
            }

            logger.DebugInfo(String.Format(Resources.AttemptsToFind, string.Join("::", attempts)));

            return(null);
        }
        public void PeParser_X86StaticallyLinked_FindsEmbeddedPdbPath()
        {
            string pdb = PeParser.ExtractPdbPath(TestResources.X86StaticallyLinkedTests, MockLogger.Object);

            pdb.Should().Be(@"C:\prod\gtest-1.7.0\msvc\Debug\StaticallyLinkedGoogleTests.pdb");
        }
        public void PeParser_X86ExternallyLinkedDll_CorrentNumberOfImports()
        {
            var imports = PeParser.ParseImports(TestResources.X86ExternallyLinkedTestsDll, MockLogger.Object);

            imports.Count.Should().Be(1);
        }
Example #9
0
        public void PeParser_X86ExternallyLinkedExe_CorrentNumberOfImports()
        {
            var imports = PeParser.ParseImports(TestResources.DllTests_ReleaseX86, MockLogger.Object);

            imports.Count.Should().Be(14);
        }
        public void PeParser_X86ExternallyLinkedDll_CorrentNumberOfImports()
        {
            var imports = PeParser.ParseImports(TestResources.DllTestsDll_ReleaseX86, MockLogger.Object);

            imports.Should().HaveCount(3);
        }