Пример #1
0
        public Context(Extraction.Context cx, string assemblyPath, bool extractPdbs)
        {
            this.cx              = cx;
            this.assemblyPath    = assemblyPath;
            stream               = File.OpenRead(assemblyPath);
            peReader             = new PEReader(stream, PEStreamOptions.PrefetchEntireImage);
            mdReader             = peReader.GetMetadataReader();
            TypeSignatureDecoder = new Entities.TypeSignatureDecoder(this);

            globalNamespace            = new Lazy <Entities.Namespace>(() => Populate(new Entities.Namespace(this, GetId(""), null)));
            systemNamespace            = new Lazy <Entities.Namespace>(() => Populate(new Entities.Namespace(this, "System")));
            genericHandleFactory       = new CachedFunction <GenericContext, Handle, ILabelledEntity>(CreateGenericHandle);
            namespaceFactory           = new CachedFunction <StringHandle, Entities.Namespace>(n => CreateNamespace(mdReader.GetString(n)));
            namespaceDefinitionFactory = new CachedFunction <NamespaceDefinitionHandle, Entities.Namespace>(CreateNamespace);
            sourceFiles     = new CachedFunction <PDB.ISourceFile, Entities.PdbSourceFile>(path => new Entities.PdbSourceFile(this, path));
            folders         = new CachedFunction <string, Entities.Folder>(path => new Entities.Folder(this, path));
            sourceLocations = new CachedFunction <PDB.Location, Entities.PdbSourceLocation>(location => new Entities.PdbSourceLocation(this, location));

            defaultGenericContext = new EmptyContext(this);

            var def = mdReader.GetAssemblyDefinition();

            AssemblyPrefix = GetId(def.Name) + "_" + def.Version.ToString() + "::";

            if (extractPdbs)
            {
                pdb = PDB.PdbReader.Create(assemblyPath, peReader);
                if (pdb != null)
                {
                    cx.Extractor.Logger.Log(Util.Logging.Severity.Info, string.Format("Found PDB information for {0}", assemblyPath));
                }
            }
        }
Пример #2
0
        public Context(Extraction.Context cx, string assemblyPath, bool extractPdbs)
        {
            this.Cx              = cx;
            this.AssemblyPath    = assemblyPath;
            stream               = File.OpenRead(assemblyPath);
            PeReader             = new PEReader(stream, PEStreamOptions.PrefetchEntireImage);
            MdReader             = PeReader.GetMetadataReader();
            TypeSignatureDecoder = new Entities.TypeSignatureDecoder(this);

            globalNamespace            = new Lazy <Entities.Namespace>(() => Populate(new Entities.Namespace(this, "", null)));
            systemNamespace            = new Lazy <Entities.Namespace>(() => Populate(new Entities.Namespace(this, "System")));
            genericHandleFactory       = new CachedFunction <GenericContext, Handle, IExtractedEntity>(CreateGenericHandle);
            namespaceFactory           = new CachedFunction <StringHandle, Entities.Namespace>(n => CreateNamespace(MdReader.GetString(n)));
            namespaceDefinitionFactory = new CachedFunction <NamespaceDefinitionHandle, Entities.Namespace>(CreateNamespace);
            sourceFiles     = new CachedFunction <PDB.ISourceFile, Entities.PdbSourceFile>(path => new Entities.PdbSourceFile(this, path));
            folders         = new CachedFunction <PathTransformer.ITransformedPath, Entities.Folder>(path => new Entities.Folder(this, path));
            sourceLocations = new CachedFunction <PDB.Location, Entities.PdbSourceLocation>(location => new Entities.PdbSourceLocation(this, location));

            defaultGenericContext = new EmptyContext(this);

            if (extractPdbs)
            {
                Pdb = PDB.PdbReader.Create(assemblyPath, PeReader);
                if (Pdb != null)
                {
                    cx.Extractor.Logger.Log(Util.Logging.Severity.Info, string.Format("Found PDB information for {0}", assemblyPath));
                }
            }
        }
Пример #3
0
 /// <summary>
 /// Main entry point to the CIL extractor.
 /// Call this to extract a given assembly.
 /// </summary>
 /// <param name="layout">The trap layout.</param>
 /// <param name="assemblyPath">The full path of the assembly to extract.</param>
 /// <param name="logger">The logger.</param>
 /// <param name="nocache">True to overwrite existing trap file.</param>
 /// <param name="extractPdbs">Whether to extract PDBs.</param>
 /// <param name="trapFile">The path of the trap file.</param>
 /// <param name="extracted">Whether the file was extracted (false=cached).</param>
 public static void ExtractCIL(Layout layout, string assemblyPath, ILogger logger, bool nocache, bool extractPdbs, TrapWriter.CompressionMode trapCompression, out string trapFile, out bool extracted)
 {
     trapFile  = "";
     extracted = false;
     try
     {
         var canonicalPathCache      = CanonicalPathCache.Create(logger, 1000);
         var pathTransformer         = new PathTransformer(canonicalPathCache);
         var extractor               = new Extractor(false, assemblyPath, logger, pathTransformer);
         var transformedAssemblyPath = pathTransformer.Transform(assemblyPath);
         var project = layout.LookupProjectOrDefault(transformedAssemblyPath);
         using var trapWriter = project.CreateTrapWriter(logger, transformedAssemblyPath.WithSuffix(".cil"), trapCompression, discardDuplicates: true);
         trapFile             = trapWriter.TrapFile;
         if (nocache || !System.IO.File.Exists(trapFile))
         {
             var cx = new Extraction.Context(extractor, trapWriter);
             ExtractCIL(cx, assemblyPath, extractPdbs);
             extracted = true;
         }
     }
     catch (Exception ex)  // lgtm[cs/catch-of-all-exceptions]
     {
         logger.Log(Severity.Error, string.Format("Exception extracting {0}: {1}", assemblyPath, ex));
     }
 }
Пример #4
0
 static void ExtractCIL(Extraction.Context cx, string assemblyPath, bool extractPdbs)
 {
     using (var cilContext = new Context(cx, assemblyPath, extractPdbs))
     {
         cilContext.Populate(new Assembly(cilContext));
         cilContext.cx.PopulateAll();
     }
 }
Пример #5
0
 /// <summary>
 /// Main entry point to the CIL extractor.
 /// Call this to extract a given assembly.
 /// </summary>
 /// <param name="layout">The trap layout.</param>
 /// <param name="assemblyPath">The full path of the assembly to extract.</param>
 /// <param name="logger">The logger.</param>
 /// <param name="nocache">True to overwrite existing trap file.</param>
 /// <param name="extractPdbs">Whether to extract PDBs.</param>
 /// <param name="trapFile">The path of the trap file.</param>
 /// <param name="extracted">Whether the file was extracted (false=cached).</param>
 public static void ExtractCIL(Layout layout, string assemblyPath, ILogger logger, bool nocache, bool extractPdbs, out string trapFile, out bool extracted)
 {
     trapFile  = "";
     extracted = false;
     try
     {
         var extractor = new Extractor(false, assemblyPath, logger);
         var project   = layout.LookupProjectOrDefault(assemblyPath);
         using (var trapWriter = project.CreateTrapWriter(logger, assemblyPath + ".cil", true))
         {
             trapFile = trapWriter.TrapFile;
             if (nocache || !System.IO.File.Exists(trapFile))
             {
                 var cx = new Extraction.Context(extractor, null, trapWriter, null);
                 ExtractCIL(cx, assemblyPath, extractPdbs);
                 extracted = true;
             }
         }
     }
     catch (Exception ex)  // lgtm[cs/catch-of-all-exceptions]
     {
         logger.Log(Severity.Error, string.Format("Exception extracting {0}: {1}", assemblyPath, ex));
     }
 }
 /// <summary>
 /// Initializes the entity, but does not generate any trap code.
 /// </summary>
 public sealed override TEntity Create(Extraction.Context cx, TInit init)
 {
     return(Create((Context)cx, init));
 }