public virtual IBinaryInfo Visit(IBinaryInfo binaryInfo)
 {
     if (binaryInfo.SymbolInfo!=null)
         Visit(binaryInfo.SymbolInfo);
     if (binaryInfo.DocumentationInfo != null)
         Visit(binaryInfo.DocumentationInfo);
     return binaryInfo;
 }
        public IEnumerable<ISourceInfo> FindSources(IList<IPackageEntry> fileInfos, IBinaryInfo peFile, ISymbolInfo pdbFile)
        {
            string pdbName = Path.GetFileNameWithoutExtension(pdbFile.File.FullPath);
            IList<string> originalPaths;
            using (var peStream = peFile.File.Stream)
            using (var pdbStream = pdbFile.File.Stream)
                originalPaths = pdbSourceExtractor.ReadSources(peStream, pdbStream);

            if (originalPaths.Any())
            {
                string maxCommonOriginalPath = GetMaxCommonPath(originalPaths.Select(o => o.Replace('\\', Path.DirectorySeparatorChar).Replace('/', Path.DirectorySeparatorChar)));
                if (originalPaths.Count == 1)
                    maxCommonOriginalPath = Path.GetDirectoryName(maxCommonOriginalPath);

                //Clean fileInfos
                var originalPathsExtensions = originalPaths.Select(Path.GetExtension).Distinct().ToArray();
                fileInfos = fileInfos.Where(f => originalPathsExtensions.Any(o => string.Equals(Path.GetExtension(f.FullPath), o, StringComparison.OrdinalIgnoreCase))).ToArray();


                string maxCommonFileInfosPath = GetMaxCommonPath(fileInfos.Select(o => o.FullPath.Replace('\\', Path.DirectorySeparatorChar).Replace('/', Path.DirectorySeparatorChar)));
                if (fileInfos.Count == 1)
                    maxCommonFileInfosPath = Path.GetDirectoryName(maxCommonFileInfosPath);


                foreach (var originalPath in originalPaths)
                {
                    var actualPath = GetActualPaths(fileInfos, originalPath.Replace('\\', Path.DirectorySeparatorChar).Replace('/', Path.DirectorySeparatorChar), maxCommonOriginalPath, maxCommonFileInfosPath);

                    string keyPath = Path.Combine(pdbName, originalPath.Substring(maxCommonOriginalPath.Length+1)).Replace('\\', '/');

                    if(log.IsDebugEnabled)
                        log.DebugFormat("Found '{0}' -> '{1}' ('{2}') ", originalPath, actualPath!=null ? actualPath.FullPath : "NOT FOUND", keyPath);

                    if (actualPath != null)
                        using (var stream = actualPath.Stream)
                            yield return new SourceInfo(pdbFile)
                                             {
                                                 OriginalPath = originalPath,
                                                 ActualPath = actualPath,
                                                 KeyPath = keyPath,
                                                 Md5Hash = sourceStoreManager.ReadHash(stream)
                                             };
                    else
                        yield return new SourceInfo(pdbFile)
                                         {
                                             OriginalPath = originalPath,
                                             KeyPath = keyPath,
                                         };

                }
                yield break;
            }

            yield break;
        }
Exemplo n.º 3
0
 public virtual IBinaryInfo Visit(IBinaryInfo binaryInfo)
 {
     if (binaryInfo.SymbolInfo != null)
     {
         Visit(binaryInfo.SymbolInfo);
     }
     if (binaryInfo.DocumentationInfo != null)
     {
         Visit(binaryInfo.DocumentationInfo);
     }
     return(binaryInfo);
 }
        private bool clrCompatible(IBinaryInfo b)
        {
            //Ensure the CLR version itself is sufficent
            if (!clrVersionSufficient(b))
            {
                return(false);
            }

            //If it's not pure IL, then dlls (usually C++/CLI) must be perfectly compatible with the native platform
            if ((b.ClrFlags & BinaryClrFlags.NativeEntryPoint) > 0 ||
                ((b.ClrFlags & BinaryClrFlags.ILOnly) == 0))
            {
                return(nativeCompatible(b));
            }

            //If the architecture of the PE wrapper works in the current environment, we're good.
            if (cpuCompatible(b))
            {
                return(true);
            }

            //If not, we need to handle cases where the CLR or Mono abstract it away.
            //32-bit PEs may be Any CPU
            if (b.NativeTargets.First() == InstructionSets.x86)
            {
                //Preferred32Bit enables running on ARM.
                if ((b.ClrFlags & BinaryClrFlags.Preferred32Bit) > 0 &&
                    env.CpuCompatibility == InstructionSets.ARM)
                {
                    return(true);
                }
                //When Required
                if ((b.ClrFlags & BinaryClrFlags.Required32Bit) == 0)
                {
                    //ILOnly and not 32-bit specific? That's Any CPU!
                    //http://msdn.microsoft.com/en-us/library/system.reflection.portableexecutablekinds(v=vs.110).aspx

                    return(true); //TODO: Does this really include ARM, ARM64, and IA64?
                }
                else
                {
                    //TODO can Required32Bit IL work anywhere except x86?
                    return(false);
                }
            }

            return(false);
        }
 private bool nativeFormatCompatible(IBinaryInfo b)
 {
     if (b.Structure == BinaryStructure.PE && env.PlatformType == PlatformKind.LikeWindows)
     {
         return(true);
     }
     if (b.Structure == BinaryStructure.Mach && env.PlatformType == PlatformKind.LikeOSX)
     {
         return(true);
     }
     if (b.Structure == BinaryStructure.ELF && env.PlatformType == PlatformKind.LikeLinux)
     {
         return(true);
     }
     return(false);
 }
 public bool IsCompatible(IBinaryInfo b)
 {
     //Only executables and fully dynamic libraries may pass
     if (b.Kind != BinaryKind.Dll && b.Kind != BinaryKind.Executable)
     {
         return(false);
     }
     if (b.Structure == BinaryStructure.PE && b.IsDotNet)
     {
         return(clrCompatible(b));
     }
     else
     {
         return(nativeCompatible(b));
     }
 }
Exemplo n.º 7
0
        private PdbSrcSrvSection CreatePdbStrSection(IBinaryInfo binaryInfo)
        {
            var pdbstr = new PdbSrcSrvSection();

            pdbstr.Ini.Add("VERSION", "2");
            pdbstr.Ini.Add("INDEXVERSION", "2");
            pdbstr.Variables.Add("SRCSRVTRG", configuration.ServerUrl + "/src/%fnfile%(%var1%)/%var2%/%fnfile%(%var1%)");
            pdbstr.Variables.Add("SRCSRVCMD", string.Empty);
            pdbstr.Variables.Add("SRCSRVVERCTRL", "http");
            pdbstr.Ini.Add("VERCTRL", "http");

            foreach (var source in binaryInfo.SymbolInfo.SourceInfos)
            {
                pdbstr.Sources.Add(new[] { source.OriginalPath, source.Hash });
            }

            return(pdbstr);
        }
 private bool nativeCompatible(IBinaryInfo b)
 {
     return(nativeFormatCompatible(b) && cpuCompatible(b));
 }
 private bool cpuCompatible(IBinaryInfo b)
 {
     return(b.NativeTargets.Any(t => t == env.CpuCompatibility));
 }
 private bool clrVersionSufficient(IBinaryInfo b)
 {
     return(true); //For now; TODO fixme
 }
 public SymbolInfo(IBinaryInfo binaryInfo)
 {
     BinaryInfo = binaryInfo;
 }
Exemplo n.º 12
0
        private async Task <SymbolStatus> IndexSymbol(IStorageFeed feed, PackageName packageName, IBinaryInfo binaryInfo)
        {
            var symbolStatus = new SymbolStatus(new SymbolName(binaryInfo.Name, binaryInfo.SymbolInfo.Hash));

            try
            {
                Debug.WriteLine("Indexing symbol {0}", symbolStatus.SymbolName);
                await RequestOrSkip(string.Format("pdb/{0}", symbolStatus.SymbolName),
                                    async() =>
                {
                    Debug.WriteLine("Storing symbol {0}", symbolStatus.SymbolName);
                    var symbolItem = feed.GetSymbol(packageName, symbolStatus.SymbolName);

                    var pdbstrSection = CreatePdbStrSection(binaryInfo);
                    using (var inputStream = binaryInfo.SymbolInfo.File.GetStream())
                        using (var tempStream = new MemoryStream())
                            using (var outputStream = await symbolItem.Put())
                            {
                                pdbStoreManager.WriteSrcSrv(inputStream, tempStream, pdbstrSection);
                                tempStream.Position = 0;
                                var symbolFileName  = Path.GetFileName(binaryInfo.SymbolInfo.File.FullPath);
                                fileCompressor.Compress(symbolFileName, tempStream, outputStream);
                            }
                });

                symbolStatus.Stored = true;
                Debug.WriteLine("Stored symbol {0}", symbolStatus.SymbolName);
            }
            catch (Exception e)
            {
                support.TrackException(e, new { packageName });
                symbolStatus.Exception = new ExceptionStatus(e);
            }

            if (binaryInfo.SymbolInfo.SourceInfos != null)
            {
                symbolStatus.SourceStatuses = await ProcessThrottled(
                    5, binaryInfo.SymbolInfo.SourceInfos,
                    async s => await IndexSource(feed, packageName, s));
            }

            return(symbolStatus);
        }
Exemplo n.º 13
0
        private async Task <ImageStatusFile> IndexImage(IStorageFeed feed, PackageName packageName, IBinaryInfo binaryInfo)
        {
            var statusFile = new ImageStatusFile(binaryInfo.File.FullPath, new ImageStatus(new ImageName(binaryInfo.Name, binaryInfo.Hash)));

            //try
            //{
            //    //Debug.WriteLine("Indexing image {0}", imageStatus.ImageName);
            //    //imageStatus.Stored = true;
            //    //Debug.WriteLine("Stored image {0}", imageStatus.ImageName);
            //}
            //catch (Exception e)
            //{
            //    support.TrackException(e);
            //    statusFile.ImageStatus.Exception = new ExceptionStatus(e);
            //}

            if (binaryInfo.SymbolInfo != null)
            {
                statusFile.ImageStatus.SymbolStatus = await IndexSymbol(feed, packageName, binaryInfo);
            }

            return(statusFile);
        }
Exemplo n.º 14
0
 public SymbolInfo(IBinaryInfo binaryInfo)
 {
     BinaryInfo = binaryInfo;
 }
Exemplo n.º 15
0
 public DocumentationInfo(IBinaryInfo binaryInfo)
 {
     BinaryInfo = binaryInfo;
 }
Exemplo n.º 16
0
        public IEnumerable <ISourceInfo> FindSources(IList <IPackageEntry> fileInfos, IBinaryInfo peFile, ISymbolInfo pdbFile)
        {
            string         pdbName = Path.GetFileNameWithoutExtension(pdbFile.File.FullPath);
            IList <string> originalPaths;

            using (var peStream = peFile.File.Stream)
                using (var pdbStream = pdbFile.File.Stream)
                    originalPaths = pdbSourceExtractor.ReadSources(peStream, pdbStream);

            if (originalPaths.Any())
            {
                string maxCommonOriginalPath = GetMaxCommonPath(originalPaths.Select(o => o.Replace('\\', Path.DirectorySeparatorChar).Replace('/', Path.DirectorySeparatorChar)));
                if (originalPaths.Count == 1)
                {
                    maxCommonOriginalPath = Path.GetDirectoryName(maxCommonOriginalPath);
                }

                //Clean fileInfos
                var originalPathsExtensions = originalPaths.Select(Path.GetExtension).Distinct().ToArray();
                fileInfos = fileInfos.Where(f => originalPathsExtensions.Any(o => string.Equals(Path.GetExtension(f.FullPath), o, StringComparison.OrdinalIgnoreCase))).ToArray();


                string maxCommonFileInfosPath = GetMaxCommonPath(fileInfos.Select(o => o.FullPath.Replace('\\', Path.DirectorySeparatorChar).Replace('/', Path.DirectorySeparatorChar)));
                if (fileInfos.Count == 1)
                {
                    maxCommonFileInfosPath = Path.GetDirectoryName(maxCommonFileInfosPath);
                }


                foreach (var originalPath in originalPaths)
                {
                    var actualPath = GetActualPaths(fileInfos, originalPath.Replace('\\', Path.DirectorySeparatorChar).Replace('/', Path.DirectorySeparatorChar), maxCommonOriginalPath, maxCommonFileInfosPath);

                    string keyPath = Path.Combine(pdbName, originalPath.Substring(maxCommonOriginalPath.Length + 1)).Replace('\\', '/');

                    if (log.IsDebugEnabled)
                    {
                        log.DebugFormat("Found '{0}' -> '{1}' ('{2}') ", originalPath, actualPath != null ? actualPath.FullPath : "NOT FOUND", keyPath);
                    }

                    if (actualPath != null)
                    {
                        using (var stream = actualPath.Stream)
                            yield return new SourceInfo(pdbFile)
                                   {
                                       OriginalPath = originalPath,
                                       ActualPath   = actualPath,
                                       KeyPath      = keyPath,
                                       Md5Hash      = sourceStoreManager.ReadHash(stream)
                                   }
                    }
                    ;
                    else
                    {
                        yield return new SourceInfo(pdbFile)
                               {
                                   OriginalPath = originalPath,
                                   KeyPath      = keyPath,
                               }
                    };
                }
                yield break;
            }

            yield break;
        }
 public DocumentationInfo(IBinaryInfo binaryInfo)
 {
     BinaryInfo = binaryInfo;
 }