Пример #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(Extractor extractor, TrapWriter trapWriter, string assemblyPath, bool extractPdbs)
            : base(extractor, trapWriter)
        {
            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 <IGenericContext, 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 is not null)
                {
                    Extractor.Logger.Log(Util.Logging.Severity.Info, string.Format("Found PDB information for {0}", assemblyPath));
                }
            }
        }