static bool ReadCustomAttributeValue(CustomAttributeHandle handle, PEModule module, out int value) { // PEModule.cs var valueBlob = module.GetCustomAttributeValueOrThrow(handle); if (!valueBlob.IsNil) { // TODO: error checking offset in range var reader = module.MetadataReader.GetBlobReader(valueBlob); if (reader.Length > 4) { // check prolog if (reader.ReadByte() == 1 && reader.ReadByte() == 0) { // read Int32 if (reader.RemainingBytes >= 4) { value = reader.ReadInt32(); return(true); } } } } value = default; return(false); }
private static ImmutableArray <ImmutableArray <string> > GetGroupedImportStrings(Compilation compilation, string methodName, out ImmutableArray <string> externAliasStrings) { Assert.NotNull(compilation); Assert.NotNull(methodName); using (var exebits = new MemoryStream()) { using (var pdbbits = new MemoryStream()) { compilation.Emit(exebits, pdbbits); exebits.Position = 0; using (var module = new PEModule(new PEReader(exebits, PEStreamOptions.LeaveOpen), metadataOpt: IntPtr.Zero, metadataSizeOpt: 0)) { var metadataReader = module.MetadataReader; MethodDefinitionHandle methodHandle = metadataReader.MethodDefinitions.Single(mh => metadataReader.GetString(metadataReader.GetMethodDefinition(mh).Name) == methodName); int methodToken = metadataReader.GetToken(methodHandle); // Create a SymReader, rather than a raw COM object, because // SymReader implements ISymUnmanagedReader3 and the COM object // might not. pdbbits.Position = 0; var reader = SymReaderFactory.CreateReader(pdbbits); return(reader.GetCSharpGroupedImportStrings(methodToken, methodVersion: 1, externAliasStrings: out externAliasStrings)); } } } }
private static IEnumerable <string> GetSupportedLanguages(PEModule peModule, CustomAttributeHandle customAttrHandle) { // The DiagnosticAnalyzerAttribute has one constructor, which has a string parameter for the // first supported language and an array parameter for addition supported languages. // Parse the argument blob to extract the languages. BlobReader argsReader = peModule.GetMemoryReaderOrThrow(peModule.GetCustomAttributeValueOrThrow(customAttrHandle)); if (argsReader.Length > 4) { // Arguments are present--check prologue. if (argsReader.ReadByte() == 1 && argsReader.ReadByte() == 0) { string firstLanguageName; if (!PEModule.CrackStringInAttributeValue(out firstLanguageName, ref argsReader)) { return(SpecializedCollections.EmptyEnumerable <string>()); } ImmutableArray <string> additionalLanguageNames; if (PEModule.CrackStringArrayInAttributeValue(out additionalLanguageNames, ref argsReader)) { if (additionalLanguageNames.Length == 0) { return(SpecializedCollections.SingletonEnumerable(firstLanguageName)); } return(additionalLanguageNames.Insert(0, firstLanguageName)); } } } return(SpecializedCollections.EmptyEnumerable <string>()); }
private static IEnumerable <string> ReadLanguagesFromAttribute(ref BlobReader argsReader) { if (argsReader.Length > 4) { // Arguments are present--check prologue. if (argsReader.ReadByte() == 1 && argsReader.ReadByte() == 0) { string firstLanguageName; if (!PEModule.CrackStringInAttributeValue(out firstLanguageName, ref argsReader)) { return(SpecializedCollections.EmptyEnumerable <string>()); } ImmutableArray <string> additionalLanguageNames; if (PEModule.CrackStringArrayInAttributeValue(out additionalLanguageNames, ref argsReader)) { if (additionalLanguageNames.Length == 0) { return(SpecializedCollections.SingletonEnumerable(firstLanguageName)); } return(additionalLanguageNames.Insert(0, firstLanguageName)); } } } return(SpecializedCollections.EmptyEnumerable <string>()); }
private static string GetSupportedLanguage(PEModule peModule, CustomAttributeHandle customAttrHandle) { // The DiagnosticAnalyzerAttribute has two constructors: // 1. Paramterless - means that the analyzer is applicable to any language. // 2. Single string parameter specifying the language. // Parse the argument blob to extract these two cases. BlobReader argsReader = peModule.GetMemoryReaderOrThrow(peModule.GetCustomAttributeValueOrThrow(customAttrHandle)); // Single string parameter if (argsReader.Length > 4) { // check prologue if (argsReader.ReadByte() == 1 && argsReader.ReadByte() == 0) { string languageName; if (PEModule.CrackStringInAttributeValue(out languageName, ref argsReader)) { return(languageName); } } } // otherwise the attribute is applicable to all languages. else { return(string.Empty); } return(null); }
private static FlowAnalysisAnnotations DecodeFlowAnalysisAttributes( PEModule module, FieldDefinitionHandle handle ) { FlowAnalysisAnnotations annotations = FlowAnalysisAnnotations.None; if (module.HasAttribute(handle, AttributeDescription.AllowNullAttribute)) { annotations |= FlowAnalysisAnnotations.AllowNull; } if (module.HasAttribute(handle, AttributeDescription.DisallowNullAttribute)) { annotations |= FlowAnalysisAnnotations.DisallowNull; } if (module.HasAttribute(handle, AttributeDescription.MaybeNullAttribute)) { annotations |= FlowAnalysisAnnotations.MaybeNull; } if (module.HasAttribute(handle, AttributeDescription.NotNullAttribute)) { annotations |= FlowAnalysisAnnotations.NotNull; } return(annotations); }
internal static void VerifyIL( this ImmutableArray <byte> assembly, string qualifiedName, string expectedIL, [CallerLineNumber] int expectedValueSourceLine = 0, [CallerFilePath] string expectedValueSourcePath = null) { var parts = qualifiedName.Split('.'); if (parts.Length != 2) { throw new NotImplementedException(); } using (var module = new PEModule(new PEReader(assembly), metadataOpt: IntPtr.Zero, metadataSizeOpt: 0)) { var reader = module.MetadataReader; var typeDef = reader.GetTypeDef(parts[0]); var methodName = parts[1]; var methodHandle = reader.GetMethodDefHandle(typeDef, methodName); var methodBody = module.GetMethodBodyOrThrow(methodHandle); var pooled = PooledStringBuilder.GetInstance(); var builder = pooled.Builder; var writer = new StringWriter(pooled.Builder); var visualizer = new MetadataVisualizer(reader, writer); visualizer.VisualizeMethodBody(methodBody, methodHandle, emitHeader: false); var actualIL = pooled.ToStringAndFree(); AssertEx.AssertEqualToleratingWhitespaceDifferences(expectedIL, actualIL, escapeQuotes: true, expectedValueSourcePath: expectedValueSourcePath, expectedValueSourceLine: expectedValueSourceLine); } }
private static ImmutableArray <ImmutableArray <string> > GetGroupedImportStrings(Compilation compilation, string methodName, out ImmutableArray <string> externAliasStrings) { Assert.NotNull(compilation); Assert.NotNull(methodName); using (var exebits = new MemoryStream()) { using (var pdbbits = new MemoryStream()) { compilation.Emit(exebits, pdbbits); exebits.Position = 0; using (var module = new PEModule(new PEReader(exebits, PEStreamOptions.LeaveOpen), metadataOpt: IntPtr.Zero, metadataSizeOpt: 0)) { var metadataReader = module.MetadataReader; MethodDefinitionHandle methodHandle = metadataReader.MethodDefinitions.Single(mh => metadataReader.GetString(metadataReader.GetMethodDefinition(mh).Name) == methodName); int methodToken = metadataReader.GetToken(methodHandle); pdbbits.Position = 0; ISymUnmanagedReader reader = (ISymUnmanagedReader)TempPdbReader.CreateUnmanagedReader(pdbbits); return(reader.GetCSharpGroupedImportStrings(methodToken, methodVersion: 1, externAliasStrings: out externAliasStrings)); } } } }
/// <exception cref="BadImageFormatException">The PE image format is invalid.</exception> /// <exception cref="IOException">IO error while reading the metadata. See <see cref="Exception.InnerException"/> for details.</exception> /// <exception cref="ObjectDisposedException">The object has been disposed.</exception> private Data GetOrCreateData() { if (_lazyData == null) { ModuleMetadata[] modules = _initialModules; List <ModuleMetadata> moduleBuilder = null; bool createdModulesUsed = false; try { if (_moduleFactoryOpt != null) { Debug.Assert(_initialModules.Length == 1); var additionalModuleNames = _initialModules[0].GetModuleNames(); if (additionalModuleNames.Length > 0) { moduleBuilder = new List <ModuleMetadata>(1 + additionalModuleNames.Length); moduleBuilder.Add(_initialModules[0]); foreach (string moduleName in additionalModuleNames) { moduleBuilder.Add(_moduleFactoryOpt(moduleName)); } modules = moduleBuilder.ToArray(); } } PEModule[] pemodules = new PEModule[modules.Length]; for (int i = 0; i < modules.Length; i++) { pemodules[i] = modules[i].Module; } var assembly = new PEAssembly(this, pemodules); var newData = new Data(modules, assembly); createdModulesUsed = Interlocked.CompareExchange(ref _lazyData, newData, null) == null; } finally { if (moduleBuilder != null && !createdModulesUsed) { // dispose unused modules created above: for (int i = _initialModules.Length; i < moduleBuilder.Count; i++) { moduleBuilder[i].Dispose(); } } } } if (_lazyData.IsDisposed) { throw new ObjectDisposedException(nameof(AssemblyMetadata)); } return(_lazyData); }
protected DefinitionMap(PEModule module, IEnumerable<SemanticEdit> edits) { Debug.Assert(module != null); Debug.Assert(edits != null); this.module = module; this.mappedMethods = GetMappedMethods(edits); }
protected DefinitionMap(PEModule module, IEnumerable<SemanticEdit> edits) { Debug.Assert(module != null); Debug.Assert(edits != null); this.module = module; this.methodMap = GenerateMethodMap(edits); }
protected DefinitionMap(PEModule module, IEnumerable <SemanticEdit> edits) { Debug.Assert(module != null); Debug.Assert(edits != null); this.module = module; this.methodUpdates = GetMethodUpdates(edits); }
public PEModuleSymbol(PEAssemblySymbol assembly, PEModule module, MetadataImportOptions importOptions, int ordinal) { _assembly = assembly; _module = module; _ordinal = ordinal; this.ImportOptions = importOptions; _namespace = new PEGlobalNamespaceSymbol(this); }
private ModuleMetadata(ModuleMetadata metadata) { this.module = metadata.Module; // This instance will not be the owner of the // resources backing the metadata. this.isImageOwner = false; }
internal PEModuleSymbol( RetargetingAssemblySymbol assemblySymbol, PEModule module, MetadataImportOptions importOptions, int ordinal ) : this((AssemblySymbol)assemblySymbol, module, importOptions, ordinal) { Debug.Assert(ordinal > 0); }
// creates a copy private ModuleMetadata(ModuleMetadata metadata) : base(isImageOwner: false, id: metadata.Id) { _module = metadata.Module; // ensure that we keep the owner rooted so that it can't get GC'ed why we're alive. _owner = metadata._owner; // however, as we're not the image owner, we will never dispose the owner. Only the single image owner can be responsible for that. _disposeOwner = false; }
private static IEnumerable <string> GetDiagnosticsAnalyzerSupportedLanguages(PEModule peModule, CustomAttributeHandle customAttrHandle) { // The DiagnosticAnalyzerAttribute has one constructor, which has a string parameter for the // first supported language and an array parameter for additional supported languages. // Parse the argument blob to extract the languages. BlobReader argsReader = peModule.GetMemoryReaderOrThrow(peModule.GetCustomAttributeValueOrThrow(customAttrHandle)); return(ReadLanguagesFromAttribute(ref argsReader)); }
// creates a copy private ModuleMetadata(ModuleMetadata metadata) : base(isImageOwner: false, id: metadata.Id) { _module = metadata.Module; // note: we intentionally do not pass the _onDispose callback to the copy. Only the owner owns the callback // and controls calling it. This does mean that the callback (and underlying memory it holds onto) may // disappear once the owner is disposed or GC'd. But that's ok as that is expected semantics. Once an image // owner is gone, all copies are no longer in a valid state for use. }
private ModuleMetadata(PEReader peReader, IDisposable?owner, bool disposeOwner) : base(isImageOwner: true, id: MetadataId.CreateNewId()) { // If we've been asked to dispose the owner, then we better have an owner to dispose. Debug.Assert(!disposeOwner || owner is not null); _module = new PEModule(this, peReader: peReader, metadataOpt: IntPtr.Zero, metadataSizeOpt: 0, includeEmbeddedInteropTypes: false, ignoreAssemblyRefs: false); _owner = owner; _disposeOwner = disposeOwner; }
/// <remarks> /// Caller is responsible for freeing any allocated ArrayBuilders. /// </remarks> private static void AddModule(PEModule module, int referenceIndex, ResolvedReference[] referenceMap, ref ArrayBuilder <PEModule> modules) { if (modules == null) { modules = ArrayBuilder <PEModule> .GetInstance(); } referenceMap[referenceIndex] = new ResolvedReference(modules.Count, MetadataImageKind.Module); modules.Add(module); }
public CSharpDefinitionMap( PEModule module, IEnumerable <SemanticEdit> edits, MetadataDecoder metadataDecoder, CSharpSymbolMatcher mapToMetadata, CSharpSymbolMatcher mapToPrevious) : base(module, edits, mapToMetadata, mapToPrevious) { Debug.Assert(metadataDecoder != null); _metadataDecoder = metadataDecoder; }
private ModuleMetadata( IntPtr metadata, int size, Action?onDispose, bool includeEmbeddedInteropTypes, bool ignoreAssemblyRefs) : base(isImageOwner: true, id: MetadataId.CreateNewId()) { _module = new PEModule(this, peReader: null, metadataOpt: metadata, metadataSizeOpt: size, includeEmbeddedInteropTypes: includeEmbeddedInteropTypes, ignoreAssemblyRefs: ignoreAssemblyRefs); _onDispose = onDispose; }
public PortableExternAliasRecord( string alias, TModuleSymbol owningModule, PEModule owningPEModule, AssemblyReferenceHandle targetAssemblyHandle) : base(alias) { _owningModule = owningModule; _owningPEModule = owningPEModule; _targetAssemblyHandle = targetAssemblyHandle; }
private void btnRemoveModule_Click(object sender, EventArgs e) { if (lsvModules.SelectedIndices.Count > 0) { int index = lsvModules.SelectedIndices[0]; PEModule m = codeCoverage_.Modules[index]; log("Removed module " + m.Path + " from modules list"); codeCoverage_.Modules.RemoveAt(index); lsvModules.Items.RemoveAt(index); } }
/// <summary> /// Returns true if the field should be imported. Visibility /// and the value of <paramref name="importOptions"/> are considered /// </summary> public static bool ShouldImportField(this PEModule module, FieldDefinitionHandle field, MetadataImportOptions importOptions) { try { var flags = module.GetFieldDefFlagsOrThrow(field); return(ShouldImportField(flags, importOptions)); } catch (BadImageFormatException) { return(true); } }
private ModuleMetadata(PEReader peReader) : base(isImageOwner: true, id: MetadataId.CreateNewId()) { _module = new PEModule( this, peReader: peReader, metadataOpt: IntPtr.Zero, metadataSizeOpt: 0, includeEmbeddedInteropTypes: false, ignoreAssemblyRefs: false ); }
private static bool DoSignaturesMatch( PEModule module, MetadataDecoder metadataDecoder, ParamInfo <TypeSymbol>[] propertyParams, PEMethodSymbol getMethod, ParamInfo <TypeSymbol>[] getMethodParams, PEMethodSymbol setMethod, ParamInfo <TypeSymbol>[] setMethodParams) { Debug.Assert((getMethodParams == null) == ((object)getMethod == null)); Debug.Assert((setMethodParams == null) == ((object)setMethod == null)); bool hasGetMethod = getMethodParams != null; bool hasSetMethod = setMethodParams != null; if (hasGetMethod && !metadataDecoder.DoPropertySignaturesMatch(propertyParams, getMethodParams, comparingToSetter: false, compareParamByRef: true, compareReturnType: true)) { return(false); } if (hasSetMethod && !metadataDecoder.DoPropertySignaturesMatch(propertyParams, setMethodParams, comparingToSetter: true, compareParamByRef: true, compareReturnType: true)) { return(false); } if (hasGetMethod && hasSetMethod) { var lastPropertyParamIndex = propertyParams.Length - 1; var getHandle = getMethodParams[lastPropertyParamIndex].Handle; var setHandle = setMethodParams[lastPropertyParamIndex].Handle; var getterHasParamArray = !getHandle.IsNil && module.HasParamsAttribute(getHandle); var setterHasParamArray = !setHandle.IsNil && module.HasParamsAttribute(setHandle); if (getterHasParamArray != setterHasParamArray) { return(false); } if ((getMethod.IsExtern != setMethod.IsExtern) || // (getMethod.IsAbstract != setMethod.IsAbstract) || // NOTE: Dev10 accepts one abstract accessor (getMethod.IsSealed != setMethod.IsSealed) || #if !XSHARP // In XSharp we allow to override just one (getMethod.IsOverride != setMethod.IsOverride) || #endif (getMethod.IsStatic != setMethod.IsStatic)) { return(false); } } return(true); }
private PEModuleSymbol(AssemblySymbol assemblySymbol, PEModule module, MetadataImportOptions importOptions, int ordinal) { Debug.Assert((object)assemblySymbol != null); Debug.Assert(module != null); _assemblySymbol = assemblySymbol; _ordinal = ordinal; _module = module; this.ImportOptions = importOptions; _globalNamespace = new PEGlobalNamespaceSymbol(this); this.MetadataLocation = ImmutableArray.Create <MetadataLocation>(new MetadataLocation(this)); }
public static bool ShouldImportMethod( this PEModule module, MethodDefinitionHandle methodDef, MetadataImportOptions importOptions ) { try { var flags = module.GetMethodDefFlagsOrThrow(methodDef); // If the method is virtual, it must be accessible, although // it may be an explicit (private) interface implementation. // Otherwise, we need to check the accessibility. if ((flags & MethodAttributes.Virtual) == 0) { switch (flags & MethodAttributes.MemberAccessMask) { case MethodAttributes.Private: case MethodAttributes.PrivateScope: if (importOptions != MetadataImportOptions.All) { return(false); } break; case MethodAttributes.Assembly: if (importOptions == MetadataImportOptions.Public) { return(false); } break; } } } catch (BadImageFormatException) { } try { // As in the native C# compiler (see IMPORTER::ImportMethod), drop any method prefixed // with "_VtblGap". They should be impossible to call/implement/etc. // BREAK: The native VB compiler does not drop such methods, but it produces unverifiable // code when they are called, so the break is acceptable. // TODO: Keep some record of vtable gaps (DevDiv #17472). var name = module.GetMethodDefNameOrThrow(methodDef); return(!name.StartsWith(VTableGapMethodNamePrefix, StringComparison.Ordinal)); } catch (BadImageFormatException) { return(true); } }
private static string GetFullyQualifiedTypeName(TypeDefinition typeDef, PEModule peModule) { var declaringType = typeDef.GetDeclaringType(); // Non nested type - simply get the full name if (declaringType.IsNil) { return(peModule.GetFullNameOrThrow(typeDef.Namespace, typeDef.Name)); } else { var declaringTypeDef = peModule.MetadataReader.GetTypeDefinition(declaringType); return(GetFullyQualifiedTypeName(declaringTypeDef, peModule) + "+" + peModule.MetadataReader.GetString(typeDef.Name)); } }
internal int GetLocalSignatureToken(MethodDefinitionHandle methodHandle) { if (!_includeLocalSignatures) { return(0); } using (var module = new PEModule(new PEReader(ImmutableArray.CreateRange(this.FullImage)), metadataOpt: IntPtr.Zero, metadataSizeOpt: 0)) { var reader = module.MetadataReader; var methodIL = module.GetMethodBodyOrThrow(methodHandle); var localSignatureHandle = methodIL.LocalSignature; return(reader.GetToken(localSignatureHandle)); } }
public CSharpDefinitionMap( PEModule module, IEnumerable <SemanticEdit> edits, MetadataDecoder metadataDecoder, SymbolMatcher mapToMetadata, SymbolMatcher mapToPrevious) : base(module, edits) { Debug.Assert(mapToMetadata != null); Debug.Assert(metadataDecoder != null); this.mapToMetadata = mapToMetadata; this.mapToPrevious = mapToPrevious ?? mapToMetadata; this.metadataDecoder = metadataDecoder; }
public CSharpDefinitionMap( PEModule module, IEnumerable<SemanticEdit> edits, MetadataDecoder metadataDecoder, SymbolMatcher mapToMetadata, SymbolMatcher mapToPrevious) : base(module, edits) { Debug.Assert(mapToMetadata != null); Debug.Assert(metadataDecoder != null); this.mapToMetadata = mapToMetadata; this.mapToPrevious = mapToPrevious ?? mapToMetadata; this.metadataDecoder = metadataDecoder; }
public DefinitionMap( PEModule module, MetadataDecoder metadataDecoder, SymbolMatcher mapToMetadata, SymbolMatcher mapToPrevious, IReadOnlyDictionary<MethodSymbol, MethodDefinitionEntry> methodMap) { Debug.Assert(module != null); Debug.Assert(metadataDecoder != null); Debug.Assert(mapToMetadata != null); Debug.Assert(methodMap != null); this.module = module; this.metadataDecoder = metadataDecoder; this.mapToMetadata = mapToMetadata; this.mapToPrevious = mapToPrevious ?? mapToMetadata; this.methodMap = methodMap; }
private PEModuleSymbol(AssemblySymbol assemblySymbol, PEModule module, MetadataImportOptions importOptions, int ordinal) { Debug.Assert((object)assemblySymbol != null); Debug.Assert(module != null); _assemblySymbol = assemblySymbol; _ordinal = ordinal; _module = module; this.ImportOptions = importOptions; _globalNamespace = new PEGlobalNamespaceSymbol(this); this.MetadataLocation = ImmutableArray.Create<MetadataLocation>(new MetadataLocation(this)); }
private static bool DoSignaturesMatch( PEModule module, MetadataDecoder metadataDecoder, MetadataDecoder.ParamInfo[] propertyParams, PEMethodSymbol getMethod, MetadataDecoder.ParamInfo[] getMethodParams, PEMethodSymbol setMethod, MetadataDecoder.ParamInfo[] setMethodParams) { Debug.Assert((getMethodParams == null) == ((object)getMethod == null)); Debug.Assert((setMethodParams == null) == ((object)setMethod == null)); bool hasGetMethod = getMethodParams != null; bool hasSetMethod = setMethodParams != null; if (hasGetMethod && !metadataDecoder.DoPropertySignaturesMatch(propertyParams, getMethodParams, comparingToSetter: false, compareParamByRef: true, compareReturnType: true)) { return false; } if (hasSetMethod && !metadataDecoder.DoPropertySignaturesMatch(propertyParams, setMethodParams, comparingToSetter: true, compareParamByRef: true, compareReturnType: true)) { return false; } if (hasGetMethod && hasSetMethod) { var lastPropertyParamIndex = propertyParams.Length - 1; var getHandle = getMethodParams[lastPropertyParamIndex].Handle; var setHandle = setMethodParams[lastPropertyParamIndex].Handle; var getterHasParamArray = !getHandle.IsNil && module.HasParamsAttribute(getHandle); var setterHasParamArray = !setHandle.IsNil && module.HasParamsAttribute(setHandle); if (getterHasParamArray != setterHasParamArray) { return false; } if ((getMethod.IsExtern != setMethod.IsExtern) || // (getMethod.IsAbstract != setMethod.IsAbstract) || // NOTE: Dev10 accepts one abstract accessor (getMethod.IsSealed != setMethod.IsSealed) || (getMethod.IsOverride != setMethod.IsOverride) || (getMethod.IsStatic != setMethod.IsStatic)) { return false; } } return true; }
private static ImmutableArray<ImmutableArray<string>> GetGroupedImportStrings(Compilation compilation, string methodName, out ImmutableArray<string> externAliasStrings) { Assert.NotNull(compilation); Assert.NotNull(methodName); using (var exebits = new MemoryStream()) { using (var pdbbits = new MemoryStream()) { compilation.Emit(exebits, pdbbits); exebits.Position = 0; using (var module = new PEModule(new PEReader(exebits, PEStreamOptions.LeaveOpen), metadataOpt: IntPtr.Zero, metadataSizeOpt: 0)) { var metadataReader = module.MetadataReader; MethodDefinitionHandle methodHandle = metadataReader.MethodDefinitions.Single(mh => metadataReader.GetString(metadataReader.GetMethodDefinition(mh).Name) == methodName); int methodToken = metadataReader.GetToken(methodHandle); pdbbits.Position = 0; ISymUnmanagedReader reader = (ISymUnmanagedReader)TempPdbReader.CreateUnmanagedReader(pdbbits); return reader.GetCSharpGroupedImportStrings(methodToken, methodVersion: 1, externAliasStrings: out externAliasStrings); } } } }
internal int GetLocalSignatureToken(MethodDefinitionHandle methodHandle) { if (!_includeLocalSignatures) { return 0; } using (var module = new PEModule(new PEReader(ImmutableArray.CreateRange(this.FullImage)), metadataOpt: IntPtr.Zero, metadataSizeOpt: 0)) { var reader = module.MetadataReader; var methodIL = module.GetMethodBodyOrThrow(methodHandle); var localSignatureHandle = methodIL.LocalSignature; return reader.GetToken(localSignatureHandle); } }
private ModuleMetadata(PEReader peReader) : base(isImageOwner: true, id: MetadataId.CreateNewId()) { _module = new PEModule(this, peReader: peReader, metadataOpt: IntPtr.Zero, metadataSizeOpt: 0, includeEmbeddedInteropTypes: false, ignoreAssemblyRefs: false); }
private ModuleMetadata(PEReader peReader) { this.module = new PEModule(peReader: peReader, metadataReader: null); this.isImageOwner = true; }
private ModuleMetadata(PEReader peReader) : base(isImageOwner: true) { _module = new PEModule(peReader: peReader, metadataOpt: IntPtr.Zero, metadataSizeOpt: 0); }
private static ImmutableArray<ImmutableArray<string>> GetGroupedImportStrings(Compilation compilation, string methodName, out ImmutableArray<string> externAliasStrings) { Assert.NotNull(compilation); Assert.NotNull(methodName); using (var exebits = new MemoryStream()) { using (var pdbbits = new MemoryStream()) { compilation.Emit(exebits, pdbbits); exebits.Position = 0; using (var module = new PEModule(new PEReader(exebits, PEStreamOptions.LeaveOpen), metadataOpt: IntPtr.Zero, metadataSizeOpt: 0)) { var metadataReader = module.MetadataReader; MethodDefinitionHandle methodHandle = metadataReader.MethodDefinitions.Single(mh => metadataReader.GetString(metadataReader.GetMethodDefinition(mh).Name) == methodName); int methodToken = metadataReader.GetToken(methodHandle); // Create a SymReader, rather than a raw COM object, because // SymReader implements ISymUnmanagedReader3 and the COM object // might not. pdbbits.Position = 0; using (var reader = new SymReader(pdbbits.ToArray())) { return reader.GetCSharpGroupedImportStrings(methodToken, methodVersion: 1, externAliasStrings: out externAliasStrings); } } } } }
// creates a copy private ModuleMetadata(ModuleMetadata metadata) : base(isImageOwner: false, id: metadata.Id) { _module = metadata.Module; }
private ModuleMetadata(IntPtr metadata, int size, bool includeEmbeddedInteropTypes) : base(isImageOwner: true, id: MetadataId.CreateNewId()) { _module = new PEModule(this, peReader: null, metadataOpt: metadata, metadataSizeOpt: size, includeEmbeddedInteropTypes: includeEmbeddedInteropTypes); }
private ModuleMetadata(PEReader peReader) : base(isImageOwner: true, id: MetadataId.CreateNewId()) { _module = new PEModule(this, peReader: peReader, metadataOpt: IntPtr.Zero, metadataSizeOpt: 0); }
internal PEModuleSymbol(SourceAssemblySymbol assemblySymbol, PEModule module, MetadataImportOptions importOptions, int ordinal) : this((AssemblySymbol)assemblySymbol, module, importOptions, ordinal) { Debug.Assert(ordinal > 0); }
private ModuleMetadata(MetadataReader metadataReader) { this.module = new PEModule(peReader: null, metadataReader: metadataReader); this.isImageOwner = true; }