public void WriteAssemblyPrefix(TextWriter trapFile)
        {
            var def = MdReader.GetAssemblyDefinition();

            trapFile.Write(GetString(def.Name));
            trapFile.Write('_');
            trapFile.Write(def.Version.ToString());
            trapFile.Write(Entities.Type.AssemblyTypeNameSeparator);
        }
Beispiel #2
0
        public void WriteAssemblyPrefix(TextWriter trapFile)
        {
            var def = MdReader.GetAssemblyDefinition();

            trapFile.Write(GetString(def.Name));
            trapFile.Write('_');
            trapFile.Write(def.Version.ToString());
            trapFile.Write("::");
        }
Beispiel #3
0
        private Namespace CreateNamespace(NamespaceDefinitionHandle handle)
        {
            if (handle.IsNil)
            {
                return(GlobalNamespace);
            }
            var nd = MdReader.GetNamespaceDefinition(handle);

            return(Populate(new Namespace(this, GetString(nd.Name), Create(nd.Parent))));
        }
Beispiel #4
0
        private IExtractedEntity CreateGenericHandle(IGenericContext gc, Handle handle)
        {
            IExtractedEntity entity;

            switch (handle.Kind)
            {
            case HandleKind.MethodDefinition:
                entity = new DefinitionMethod(gc, (MethodDefinitionHandle)handle);
                break;

            case HandleKind.MemberReference:
                entity = Create(gc, (MemberReferenceHandle)handle);
                break;

            case HandleKind.MethodSpecification:
                entity = new MethodSpecificationMethod(gc, (MethodSpecificationHandle)handle);
                break;

            case HandleKind.FieldDefinition:
                entity = new DefinitionField(gc.Context, (FieldDefinitionHandle)handle);
                break;

            case HandleKind.TypeReference:
                var tr = new TypeReferenceType(this, (TypeReferenceHandle)handle);
                if (tr.TryGetPrimitiveType(out var pt))
                {
                    // Map special names like `System.Int32` to `int`
                    return(pt);
                }
                entity = tr;
                break;

            case HandleKind.TypeSpecification:
                return(Entities.Type.DecodeType(gc, (TypeSpecificationHandle)handle));

            case HandleKind.TypeDefinition:
                entity = new TypeDefinitionType(this, (TypeDefinitionHandle)handle);
                break;

            case HandleKind.StandaloneSignature:
                var signature = MdReader.GetStandaloneSignature((StandaloneSignatureHandle)handle);
                var method    = signature.DecodeMethodSignature(gc.Context.TypeSignatureDecoder, gc);
                entity = new FunctionPointerType(this, method);
                break;

            default:
                throw new InternalError("Unhandled handle kind " + handle.Kind);
            }

            Populate(entity);
            return(entity);
        }
Beispiel #5
0
        /// <summary>
        /// Gets the short name of a member, without the preceding interface qualifier.
        /// </summary>
        /// <param name="handle">The handle of the name.</param>
        /// <returns>The short name.</returns>
        public string ShortName(StringHandle handle)
        {
            var str = MdReader.GetString(handle);

            if (str.EndsWith(".ctor"))
            {
                return(".ctor");
            }
            if (str.EndsWith(".cctor"))
            {
                return(".cctor");
            }
            var dot = str.LastIndexOf('.');

            return(dot == -1 ? str : str.Substring(dot + 1));
        }
Beispiel #6
0
        private IExtractedEntity Create(IGenericContext gc, MemberReferenceHandle handle)
        {
            var mr = MdReader.GetMemberReference(handle);

            switch (mr.GetKind())
            {
            case MemberReferenceKind.Method:
                return(new MemberReferenceMethod(gc, handle));

            case MemberReferenceKind.Field:
                return(new MemberReferenceField(gc, handle));

            default:
                throw new InternalError("Unhandled member reference handle");
            }
        }
Beispiel #7
0
 /// <summary>
 /// Gets the string for a string handle.
 /// </summary>
 /// <param name="h">The string handle.</param>
 /// <returns>The string.</returns>
 public string GetString(StringHandle h) => MdReader.GetString(h);
        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));
                }
            }
        }