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); }
public void WriteAssemblyPrefix(TextWriter trapFile) { var def = MdReader.GetAssemblyDefinition(); trapFile.Write(GetString(def.Name)); trapFile.Write('_'); trapFile.Write(def.Version.ToString()); trapFile.Write("::"); }
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)))); }
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); }
/// <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)); }
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"); } }
/// <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)); } } }