Exemple #1
0
		public CorStandAloneSig(CorModuleDef readerModule, uint rid, GenericParamContext gpContext) {
			this.readerModule = readerModule;
			this.rid = rid;
			this.origRid = rid;
			this.gpContext = gpContext;
			Initialize_NoLock();
		}
Exemple #2
0
 public CorTypeSpec(CorModuleDef readerModule, uint rid, GenericParamContext gpContext)
 {
     this.readerModule = readerModule;
     this.rid = rid;
     this.origRid = rid;
     this.gpContext = gpContext;
 }
Exemple #3
0
		public CorMethodSpec(CorModuleDef readerModule, uint rid, GenericParamContext gpContext) {
			this.readerModule = readerModule;
			this.rid = rid;
			origRid = rid;
			this.gpContext = gpContext;
			Initialize_NoLock();
		}
Exemple #4
0
		public CorInterfaceImpl(CorModuleDef readerModule, uint rid, GenericParamContext gpContext) {
			this.readerModule = readerModule;
			this.rid = rid;
			this.origRid = rid;
			this.gpContext = gpContext;
			Initialize_NoLock();
		}
Exemple #5
0
		protected override void InitializeSecurityAttributes() {
			var mdi = readerModule.MetaDataImport;
			uint token = OriginalToken.Raw;
			var data = MDAPI.GetPermissionSetBlob(mdi, token) ?? new byte[0];
			var gpContext = new GenericParamContext();
			var tmp = DeclSecurityReader.Read(readerModule, data, gpContext);
			Interlocked.CompareExchange(ref securityAttributes, tmp, null);
		}
Exemple #6
0
		public void Read(MethodDef method) {
			this.gpContext = GenericParamContext.Create(method);
			this.parameters = method.Parameters;
			SetLocals(GetLocals(method));

			maxStackSize = (ushort)reader.ReadInt32();
			ReadInstructionsNumBytes(reader.ReadUInt32());
			ReadExceptionHandlers();
		}
 CustomAttributeReader(ModuleDefMD readerModule, uint offset, GenericParamContext gpContext)
 {
     this.module = readerModule;
     this.reader = readerModule.BlobStream.CreateStream(offset);
     this.ownReader = true;
     this.genericArguments = null;
     this.recursionCounter = new RecursionCounter();
     this.verifyReadAllBytes = false;
     this.gpContext = gpContext;
 }
 CustomAttributeReader(ModuleDef module, IBinaryReader reader, bool ownRerader, GenericParamContext gpContext)
 {
     this.module = module;
     this.reader = reader;
     this.ownReader = ownRerader;
     this.genericArguments = null;
     this.recursionCounter = new RecursionCounter();
     this.verifyReadAllBytes = false;
     this.gpContext = gpContext;
 }
			public ITypeDefOrRef ResolveTypeDefOrRef(uint codedToken, GenericParamContext gpContext) {
				uint token;
				if (!CodedToken.TypeDefOrRef.Decode(codedToken, out token))
					return null;
				uint rid = MDToken.ToRID(token);
				switch (MDToken.ToTable(token)) {
				case Table.TypeDef:		return new TypeDefDndbg(mdi, rid);
				case Table.TypeRef:		return new TypeRefDndbg(mdi, rid);
				case Table.TypeSpec:	return new TypeSpecDndbg(mdi, rid, this);
				}
				return null;
			}
		static Instruction arithmetic_read(BinaryReader reader, IInstructionOperandResolver resolver, GenericParamContext gpContext) {
			switch (reader.ReadByte()) {
			case 0: return OpCodes.Add.ToInstruction();
			case 1: return OpCodes.Add_Ovf.ToInstruction();
			case 2: return OpCodes.Add_Ovf_Un.ToInstruction();
			case 3: return OpCodes.Sub.ToInstruction();
			case 4: return OpCodes.Sub_Ovf.ToInstruction();
			case 5: return OpCodes.Sub_Ovf_Un.ToInstruction();
			case 6: return OpCodes.Mul.ToInstruction();
			case 7: return OpCodes.Mul_Ovf.ToInstruction();
			case 8: return OpCodes.Mul_Ovf_Un.ToInstruction();
			case 9: return OpCodes.Div.ToInstruction();
			case 10: return OpCodes.Div_Un.ToInstruction();
			case 11: return OpCodes.Rem.ToInstruction();
			case 12: return OpCodes.Rem_Un.ToInstruction();
			default: throw new ApplicationException("Invalid opcode");
			}
		}
 /// <summary>
 /// Reads custom attribute named arguments
 /// </summary>
 /// <param name="module">Owner module</param>
 /// <param name="stream">A stream positioned at the the first byte of the CA blob</param>
 /// <param name="numNamedArgs">Number of named arguments to read from <paramref name="stream"/></param>
 /// <param name="gpContext">Generic parameter context</param>
 /// <returns>A list of <see cref="CANamedArgument"/>s or <c>null</c> if some error
 /// occurred.</returns>
 internal static List <CANamedArgument> ReadNamedArguments(ModuleDef module, IBinaryReader stream, int numNamedArgs, GenericParamContext gpContext)
 {
     try {
         using (var reader = new CustomAttributeReader(module, stream, false, gpContext))
             return(reader.ReadNamedArguments(numNamedArgs));
     }
     catch (CABlobParserException) {
         return(null);
     }
     catch (IOException) {
         return(null);
     }
 }
 /// <summary>
 /// Reads a custom attribute
 /// </summary>
 /// <param name="module">Owner module</param>
 /// <param name="stream">A stream positioned at the the first byte of the CA blob</param>
 /// <param name="ctor">Custom attribute constructor</param>
 /// <param name="gpContext">Generic parameter context</param>
 /// <returns>A new <see cref="CustomAttribute"/> instance or <c>null</c> if one of the
 /// args is <c>null</c> or if we failed to parse the CA blob</returns>
 public static CustomAttribute Read(ModuleDef module, IBinaryReader stream, ICustomAttributeType ctor, GenericParamContext gpContext)
 {
     if (stream == null || ctor == null)
     {
         return(null);
     }
     try {
         using (var reader = new CustomAttributeReader(module, stream, gpContext))
             return(reader.Read(ctor));
     }
     catch (CABlobParserException) {
         return(null);
     }
     catch (IOException) {
         return(null);
     }
 }
 /// <summary>
 /// Reads a custom attribute
 /// </summary>
 /// <param name="readerModule">Reader module</param>
 /// <param name="ctor">Custom attribute constructor</param>
 /// <param name="offset">Offset of custom attribute in the #Blob stream</param>
 /// <param name="gpContext">Generic parameter context</param>
 /// <returns>A new <see cref="CustomAttribute"/> instance</returns>
 public static CustomAttribute Read(ModuleDefMD readerModule, ICustomAttributeType ctor, uint offset, GenericParamContext gpContext)
 {
     using (var reader = new CustomAttributeReader(readerModule, offset, gpContext)) {
         try {
             if (ctor == null)
             {
                 return(reader.CreateRaw(ctor));
             }
             return(reader.Read(ctor));
         }
         catch (CABlobParserException) {
             return(reader.CreateRaw(ctor));
         }
         catch (IOException) {
             return(reader.CreateRaw(ctor));
         }
     }
 }
Exemple #14
0
        /// <summary>
        /// Reads a <c>DeclSecurity</c> blob
        /// </summary>
        /// <param name="module">Module that will own the returned list</param>
        /// <param name="signature"><c>DeclSecurity</c> stream that will be owned by us</param>
        /// <param name="gpContext">Generic parameter context</param>
        /// <returns>A list of <see cref="SecurityAttribute"/>s</returns>
        public static IList <SecurityAttribute> Read(ModuleDef module, DataReader signature, GenericParamContext gpContext)
        {
            var reader = new DeclSecurityReader(module, signature, gpContext);

            return(reader.Read());
        }
Exemple #15
0
 /// <summary>
 /// Reads a <c>DeclSecurity</c> blob
 /// </summary>
 /// <param name="module">Module that will own the returned list</param>
 /// <param name="sig"><c>#Blob</c> offset of <c>DeclSecurity</c> signature</param>
 /// <param name="gpContext">Generic parameter context</param>
 /// <returns>A list of <see cref="SecurityAttribute"/>s</returns>
 public static IList <SecurityAttribute> Read(ModuleDefMD module, uint sig, GenericParamContext gpContext) => Read(module, module.BlobStream.CreateReader(sig), gpContext);
Exemple #16
0
        /// <summary>
        /// Reads a method body
        /// </summary>
        /// <param name="method">Method</param>
        /// <param name="rva">Method RVA</param>
        /// <param name="implAttrs">Method impl attrs</param>
        /// <param name="gpContext">Generic parameter context</param>
        /// <returns>A <see cref="MethodBody"/> or <c>null</c> if none</returns>
        internal MethodBody ReadMethodBody(MethodDefMD method, RVA rva, MethodImplAttributes implAttrs, GenericParamContext gpContext)
        {
            MethodBody mb;
            var mDec = methodDecrypter;
            if (mDec != null && mDec.GetMethodBody(method.OrigRid, rva, method.Parameters, gpContext, out mb)) {
                var cilBody = mb as CilBody;
                if (cilBody != null)
                    return InitializeBodyFromPdb(cilBody, method.OrigRid);
                return mb;
            }

            if (rva == 0)
                return null;
            var codeType = implAttrs & MethodImplAttributes.CodeTypeMask;
            if (codeType == MethodImplAttributes.IL)
                return InitializeBodyFromPdb(ReadCilBody(method.Parameters, rva, gpContext), method.OrigRid);
            if (codeType == MethodImplAttributes.Native)
                return new NativeMethodBody(rva);
            return null;
        }
Exemple #17
0
        /// <summary>
        /// Reads a <see cref="MarshalType"/> from <see cref="reader"/>
        /// </summary>
        /// <param name="module">Owner module</param>
        /// <param name="reader">A reader that will be owned by us</param>
        /// <param name="gpContext">Generic parameter context</param>
        /// <returns>A new <see cref="MarshalType"/> instance</returns>
        public static MarshalType Read(ModuleDef module, DataReader reader, GenericParamContext gpContext)
        {
            var marshalReader = new MarshalBlobReader(module, ref reader, gpContext);

            return(marshalReader.Read());
        }
 private MarshalBlobReader(ModuleDef module, IBinaryReader reader, GenericParamContext gpContext)
 {
     this.module    = module;
     this.reader    = reader;
     this.gpContext = gpContext;
 }
Exemple #19
0
 /// <summary>
 /// Reads a <see cref="MarshalType"/> from the <c>#Blob</c> heap
 /// </summary>
 /// <param name="module">Module</param>
 /// <param name="sig">Blob offset</param>
 /// <param name="gpContext">Generic parameter context</param>
 /// <returns>A new <see cref="MarshalType"/> instance</returns>
 public static MarshalType Read(ModuleDefMD module, uint sig, GenericParamContext gpContext) => Read(module, module.BlobStream.CreateReader(sig), gpContext);
 /// <summary>
 ///     Reads a <see cref="MarshalType" /> from <paramref name="data" />
 /// </summary>
 /// <param name="module">Owner module</param>
 /// <param name="data">Marshal data</param>
 /// <param name="gpContext">Generic parameter context</param>
 /// <returns>A new <see cref="MarshalType" /> instance</returns>
 public static MarshalType Read(ModuleDef module, byte[] data, GenericParamContext gpContext)
 {
     return(Read(module, MemoryImageStream.Create(data), gpContext));
 }
 /// <summary>
 ///     Reads a <see cref="MarshalType" /> from the <c>#Blob</c> heap
 /// </summary>
 /// <param name="module">Module</param>
 /// <param name="sig">Blob offset</param>
 /// <param name="gpContext">Generic parameter context</param>
 /// <returns>A new <see cref="MarshalType" /> instance</returns>
 public static MarshalType Read(ModuleDefMD module, uint sig, GenericParamContext gpContext)
 {
     return(Read(module, module.BlobStream.CreateStream(sig), gpContext));
 }
Exemple #22
0
 MarshalBlobReader(ModuleDef module, ref DataReader reader, GenericParamContext gpContext)
 {
     this.module    = module;
     this.reader    = reader;
     this.gpContext = gpContext;
 }
Exemple #23
0
 /// <summary>
 /// Resolves a token
 /// </summary>
 /// <param name="token">The metadata token</param>
 /// <param name="gpContext">Generic parameter context</param>
 /// <returns>A <see cref="IMDTokenProvider"/> or <c>null</c> if <paramref name="token"/> is invalid</returns>
 public override IMDTokenProvider ResolveToken(uint token, GenericParamContext gpContext)
 {
     uint rid = MDToken.ToRID(token);
     switch (MDToken.ToTable(token)) {
     case Table.Module:			return ResolveModule(rid);
     case Table.TypeRef:			return ResolveTypeRef(rid);
     case Table.TypeDef:			return ResolveTypeDef(rid);
     case Table.Field:			return ResolveField(rid);
     case Table.Method:			return ResolveMethod(rid);
     case Table.Param:			return ResolveParam(rid);
     case Table.InterfaceImpl:	return ResolveInterfaceImpl(rid, gpContext);
     case Table.MemberRef:		return ResolveMemberRef(rid, gpContext);
     case Table.Constant:		return ResolveConstant(rid);
     case Table.DeclSecurity:	return ResolveDeclSecurity(rid);
     case Table.ClassLayout:		return ResolveClassLayout(rid);
     case Table.StandAloneSig:	return ResolveStandAloneSig(rid, gpContext);
     case Table.Event:			return ResolveEvent(rid);
     case Table.Property:		return ResolveProperty(rid);
     case Table.ModuleRef:		return ResolveModuleRef(rid);
     case Table.TypeSpec:		return ResolveTypeSpec(rid, gpContext);
     case Table.ImplMap:			return ResolveImplMap(rid);
     case Table.Assembly:		return ResolveAssembly(rid);
     case Table.AssemblyRef:		return ResolveAssemblyRef(rid);
     case Table.File:			return ResolveFile(rid);
     case Table.ExportedType:	return ResolveExportedType(rid);
     case Table.ManifestResource:return ResolveManifestResource(rid);
     case Table.GenericParam:	return ResolveGenericParam(rid);
     case Table.MethodSpec:		return ResolveMethodSpec(rid, gpContext);
     case Table.GenericParamConstraint: return ResolveGenericParamConstraint(rid, gpContext);
     }
     return null;
 }
Exemple #24
0
 /// <summary>
 /// Reads a type signature from the #Blob stream
 /// </summary>
 /// <param name="sig">#Blob stream offset of signature</param>
 /// <param name="gpContext">Generic parameter context</param>
 /// <returns>A new <see cref="TypeSig"/> instance or <c>null</c> if
 /// <paramref name="sig"/> is invalid.</returns>
 public TypeSig ReadTypeSignature(uint sig, GenericParamContext gpContext)
 {
     return SignatureReader.ReadTypeSig(this, sig, gpContext);
 }
Exemple #25
0
 /// <summary>
 /// Reads a new <see cref="GenericParamConstraintMD"/> instance. This one is not cached.
 /// </summary>
 /// <param name="rid">Row ID</param>
 /// <param name="gpContext">Generic parameter context</param>
 /// <returns>A new <see cref="GenericParamConstraintMD"/> instance</returns>
 internal GenericParamConstraintMD ReadGenericParamConstraint(uint rid, GenericParamContext gpContext)
 {
     return new GenericParamConstraintMD(this, rid, gpContext);
 }
Exemple #26
0
 /// <summary>
 /// Reads a <see cref="MarshalType"/> from <paramref name="data"/>
 /// </summary>
 /// <param name="module">Owner module</param>
 /// <param name="data">Marshal data</param>
 /// <param name="gpContext">Generic parameter context</param>
 /// <returns>A new <see cref="MarshalType"/> instance</returns>
 public static MarshalType Read(ModuleDef module, byte[] data, GenericParamContext gpContext) => Read(module, ByteArrayDataReaderFactory.CreateReader(data), gpContext);
Exemple #27
0
 /// <summary>
 /// Reads a <see cref="CustomAttribute"/>
 /// </summary>
 /// <param name="caRid">Custom attribute rid</param>
 /// <param name="gpContext">Generic parameter context</param>
 /// <returns>A new <see cref="CustomAttribute"/> instance or <c>null</c> if
 /// <paramref name="caRid"/> is invalid</returns>
 public CustomAttribute ReadCustomAttribute(uint caRid, GenericParamContext gpContext)
 {
     var caRow = TablesStream.ReadCustomAttributeRow(caRid);
     if (caRow == null)
         return null;
     return CustomAttributeReader.Read(this, ResolveCustomAttributeType(caRow.Type, gpContext), caRow.Value, gpContext);
 }
Exemple #28
0
 /// <summary>
 /// Reads a <see cref="CallingConventionSig"/> signature
 /// </summary>
 /// <param name="module">The module where the signature is located in</param>
 /// <param name="signature">The signature reader</param>
 /// <param name="gpContext">Generic parameter context</param>
 /// <returns>A new <see cref="CallingConventionSig"/> instance or <c>null</c> if
 /// <paramref name="signature"/> is invalid.</returns>
 public static CallingConventionSig ReadSig(ModuleDefMD module, DataReader signature, GenericParamContext gpContext) =>
 ReadSig(module, module.CorLibTypes, signature, gpContext);
Exemple #29
0
 /// <summary>
 /// Resolves a <see cref="ICustomAttributeType"/>
 /// </summary>
 /// <param name="codedToken">A <c>CustomAttributeType</c> coded token</param>
 /// <param name="gpContext">Generic parameter context</param>
 /// <returns>A <see cref="ICustomAttributeType"/> or <c>null</c> if <paramref name="codedToken"/> is invalid</returns>
 public ICustomAttributeType ResolveCustomAttributeType(uint codedToken, GenericParamContext gpContext)
 {
     uint token;
     if (!CodedToken.CustomAttributeType.Decode(codedToken, out token))
         return null;
     uint rid = MDToken.ToRID(token);
     switch (MDToken.ToTable(token)) {
     case Table.Method:		return ResolveMethod(rid);
     case Table.MemberRef:	return ResolveMemberRef(rid, gpContext);
     }
     return null;
 }
Exemple #30
0
 /// <summary>
 /// Reads a <see cref="CallingConventionSig"/> signature
 /// </summary>
 /// <param name="helper">Token resolver</param>
 /// <param name="corLibTypes">A <see cref="ICorLibTypes"/> instance</param>
 /// <param name="signature">The signature data</param>
 /// <param name="gpContext">Generic parameter context</param>
 /// <returns>A new <see cref="CallingConventionSig"/> instance or <c>null</c> if
 /// <paramref name="signature"/> is invalid.</returns>
 public static CallingConventionSig ReadSig(ISignatureReaderHelper helper, ICorLibTypes corLibTypes, byte[] signature, GenericParamContext gpContext) =>
 ReadSig(helper, corLibTypes, ByteArrayDataReaderFactory.CreateReader(signature), gpContext);
Exemple #31
0
 /// <summary>
 /// Parses a Reflection type name and creates a <see cref="ITypeDefOrRef"/>
 /// </summary>
 /// <param name="ownerModule">Module that will own the returned <see cref="ITypeDefOrRef"/> or <c>null</c></param>
 /// <param name="typeFullName">Full name of type</param>
 /// <param name="typeNameParserHelper">Helper class</param>
 /// <param name="gpContext">Generic parameter context</param>
 /// <returns>A new <see cref="ITypeDefOrRef"/> instance</returns>
 /// <exception cref="TypeNameParserException">If parsing failed</exception>
 public static ITypeDefOrRef ParseReflectionThrow(ModuleDef ownerModule, string typeFullName, IAssemblyRefFinder typeNameParserHelper, GenericParamContext gpContext)
 {
     using (var parser = new ReflectionTypeNameParser(ownerModule, typeFullName, typeNameParserHelper, gpContext))
         return(parser.Parse());
 }
Exemple #32
0
 /// <summary>
 /// Reads a <see cref="CallingConventionSig"/> signature
 /// </summary>
 /// <param name="helper">Token resolver</param>
 /// <param name="corLibTypes">A <see cref="ICorLibTypes"/> instance</param>
 /// <param name="signature">The signature reader</param>
 /// <param name="gpContext">Generic parameter context</param>
 /// <returns>A new <see cref="CallingConventionSig"/> instance or <c>null</c> if
 /// <paramref name="signature"/> is invalid.</returns>
 public static CallingConventionSig ReadSig(ISignatureReaderHelper helper, ICorLibTypes corLibTypes, DataReader signature, GenericParamContext gpContext)
 {
     try {
         var reader = new SignatureReader(helper, corLibTypes, ref signature, gpContext);
         if (reader.reader.Length == 0)
         {
             return(null);
         }
         return(reader.ReadSig());
     }
     catch {
         return(null);
     }
 }
Exemple #33
0
 /// <summary>
 /// Reads a <c>DeclSecurity</c> blob
 /// </summary>
 /// <param name="module">Module that will own the returned list</param>
 /// <param name="blob"><c>DeclSecurity</c> blob</param>
 /// <param name="gpContext">Generic parameter context</param>///
 /// <returns>A list of <see cref="SecurityAttribute"/>s</returns>
 public static IList <SecurityAttribute> Read(ModuleDef module, byte[] blob, GenericParamContext gpContext) => Read(module, ByteArrayDataReaderFactory.CreateReader(blob), gpContext);
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="readerModule">The module which contains this <c>MemberRef</c> row</param>
		/// <param name="rid">Row ID</param>
		/// <param name="gpContext">Generic parameter context</param>
		/// <exception cref="ArgumentNullException">If <paramref name="readerModule"/> is <c>null</c></exception>
		/// <exception cref="ArgumentException">If <paramref name="rid"/> is invalid</exception>
		public MemberRefMD(ModuleDefMD readerModule, uint rid, GenericParamContext gpContext) {
#if DEBUG
			if (readerModule == null)
				throw new ArgumentNullException("readerModule");
			if (readerModule.TablesStream.MemberRefTable.IsInvalidRID(rid))
				throw new BadImageFormatException(string.Format("MemberRef rid {0} does not exist", rid));
#endif
			this.origRid = rid;
			this.rid = rid;
			this.readerModule = readerModule;
			this.module = readerModule;
			uint @class, name;
			uint signature = readerModule.TablesStream.ReadMemberRefRow(origRid, out @class, out name);
			this.name = readerModule.StringsStream.ReadNoNull(name);
			this.@class = readerModule.ResolveMemberRefParent(@class, gpContext);
			this.signature = readerModule.ReadSignature(signature, gpContext);
		}
Exemple #35
0
 /// <summary>
 /// Resolves a <see cref="IHasCustomAttribute"/>
 /// </summary>
 /// <param name="codedToken">A <c>HasCustomAttribute</c> coded token</param>
 /// <param name="gpContext">Generic parameter context</param>
 /// <returns>A <see cref="IHasCustomAttribute"/> or <c>null</c> if <paramref name="codedToken"/> is invalid</returns>
 public IHasCustomAttribute ResolveHasCustomAttribute(uint codedToken, GenericParamContext gpContext)
 {
     uint token;
     if (!CodedToken.HasCustomAttribute.Decode(codedToken, out token))
         return null;
     uint rid = MDToken.ToRID(token);
     switch (MDToken.ToTable(token)) {
     case Table.Method:		return ResolveMethod(rid);
     case Table.Field:		return ResolveField(rid);
     case Table.TypeRef:		return ResolveTypeRef(rid);
     case Table.TypeDef:		return ResolveTypeDef(rid);
     case Table.Param:		return ResolveParam(rid);
     case Table.InterfaceImpl: return ResolveInterfaceImpl(rid, gpContext);
     case Table.MemberRef:	return ResolveMemberRef(rid, gpContext);
     case Table.Module:		return ResolveModule(rid);
     case Table.DeclSecurity:return ResolveDeclSecurity(rid);
     case Table.Property:	return ResolveProperty(rid);
     case Table.Event:		return ResolveEvent(rid);
     case Table.StandAloneSig: return ResolveStandAloneSig(rid, gpContext);
     case Table.ModuleRef:	return ResolveModuleRef(rid);
     case Table.TypeSpec:	return ResolveTypeSpec(rid, gpContext);
     case Table.Assembly:	return ResolveAssembly(rid);
     case Table.AssemblyRef:	return ResolveAssemblyRef(rid);
     case Table.File:		return ResolveFile(rid);
     case Table.ExportedType:return ResolveExportedType(rid);
     case Table.ManifestResource: return ResolveManifestResource(rid);
     case Table.GenericParam:return ResolveGenericParam(rid);
     case Table.MethodSpec:	return ResolveMethodSpec(rid, gpContext);
     case Table.GenericParamConstraint: return ResolveGenericParamConstraint(rid, gpContext);
     }
     return null;
 }
Exemple #36
0
 /// <summary>
 /// Resolves a <see cref="MemberRef"/>
 /// </summary>
 /// <param name="rid">The row ID</param>
 /// <param name="gpContext">Generic parameter context</param>
 /// <returns>A <see cref="MemberRef"/> instance or <c>null</c> if <paramref name="rid"/> is invalid</returns>
 public MemberRef ResolveMemberRef(uint rid, GenericParamContext gpContext)
 {
     return listMemberRefMD[rid - 1, gpContext];
 }
Exemple #37
0
 DeclSecurityReader(ModuleDef module, DataReader reader, GenericParamContext gpContext)
 {
     this.reader    = reader;
     this.module    = module;
     this.gpContext = gpContext;
 }
Exemple #38
0
 /// <summary>
 /// Resolves a <see cref="MethodSpec"/>
 /// </summary>
 /// <param name="rid">The row ID</param>
 /// <param name="gpContext">Generic parameter context</param>
 /// <returns>A <see cref="MethodSpec"/> instance or <c>null</c> if <paramref name="rid"/> is invalid</returns>
 public MethodSpec ResolveMethodSpec(uint rid, GenericParamContext gpContext)
 {
     return listMethodSpecMD[rid - 1, gpContext];
 }
Exemple #39
0
 /// <summary>
 /// Reads a <see cref="TypeSig"/> signature
 /// </summary>
 /// <param name="module">The module where the signature is located in</param>
 /// <param name="signature">The signature data</param>
 /// <param name="gpContext">Generic parameter context</param>
 /// <returns>A new <see cref="TypeSig"/> instance or <c>null</c> if
 /// <paramref name="signature"/> is invalid.</returns>
 public static TypeSig ReadTypeSig(ModuleDefMD module, byte[] signature, GenericParamContext gpContext) =>
 ReadTypeSig(module, module.CorLibTypes, ByteArrayDataReaderFactory.CreateReader(signature), gpContext);
 CustomAttributeReader(ModuleDef module, IBinaryReader reader, bool ownRerader, GenericParamContext gpContext)
 {
     this.module             = module;
     this.reader             = reader;
     this.ownReader          = ownRerader;
     this.genericArguments   = null;
     this.recursionCounter   = new RecursionCounter();
     this.verifyReadAllBytes = false;
     this.gpContext          = gpContext;
 }
Exemple #41
0
 /// <summary>
 /// Resolves a <see cref="GenericParamConstraint"/>
 /// </summary>
 /// <param name="rid">The row ID</param>
 /// <param name="gpContext">Generic parameter context</param>
 /// <returns>A <see cref="GenericParamConstraint"/> instance or <c>null</c> if <paramref name="rid"/> is invalid</returns>
 public GenericParamConstraint ResolveGenericParamConstraint(uint rid, GenericParamContext gpContext)
 {
     return listGenericParamConstraintMD[rid - 1, gpContext];
 }
Exemple #42
0
 /// <summary>
 /// Reads a <see cref="TypeSig"/> signature
 /// </summary>
 /// <param name="module">The module where the signature is located in</param>
 /// <param name="signature">The signature reader</param>
 /// <param name="gpContext">Generic parameter context</param>
 /// <returns>A new <see cref="TypeSig"/> instance or <c>null</c> if
 /// <paramref name="signature"/> is invalid.</returns>
 public static TypeSig ReadTypeSig(ModuleDefMD module, DataReader signature, GenericParamContext gpContext) =>
 ReadTypeSig(module, module.CorLibTypes, signature, gpContext);
Exemple #43
0
 /// <summary>
 /// Resolves an <see cref="InterfaceImpl"/>
 /// </summary>
 /// <param name="rid">The row ID</param>
 /// <param name="gpContext">Generic parameter context</param>
 /// <returns>A <see cref="InterfaceImpl"/> instance or <c>null</c> if <paramref name="rid"/> is invalid</returns>
 public InterfaceImpl ResolveInterfaceImpl(uint rid, GenericParamContext gpContext)
 {
     return listInterfaceImplMD[rid - 1, gpContext];
 }
Exemple #44
0
 /// <summary>
 /// Reads a <see cref="TypeSig"/> signature
 /// </summary>
 /// <param name="helper">Token resolver</param>
 /// <param name="corLibTypes">A <see cref="ICorLibTypes"/> instance</param>
 /// <param name="signature">The signature reader</param>
 /// <param name="gpContext">Generic parameter context</param>
 /// <returns>A new <see cref="TypeSig"/> instance or <c>null</c> if
 /// <paramref name="signature"/> is invalid.</returns>
 public static TypeSig ReadTypeSig(ISignatureReaderHelper helper, ICorLibTypes corLibTypes, DataReader signature, GenericParamContext gpContext) =>
 ReadTypeSig(helper, corLibTypes, signature, gpContext, out var extraData);
Exemple #45
0
 /// <summary>
 /// Resolves a <see cref="IMemberRefParent"/>
 /// </summary>
 /// <param name="codedToken">A <c>MemberRefParent</c> coded token</param>
 /// <param name="gpContext">Generic parameter context</param>
 /// <returns>A <see cref="IMemberRefParent"/> or <c>null</c> if <paramref name="codedToken"/> is invalid</returns>
 public IMemberRefParent ResolveMemberRefParent(uint codedToken, GenericParamContext gpContext)
 {
     uint token;
     if (!CodedToken.MemberRefParent.Decode(codedToken, out token))
         return null;
     uint rid = MDToken.ToRID(token);
     switch (MDToken.ToTable(token)) {
     case Table.TypeDef:		return ResolveTypeDef(rid);
     case Table.TypeRef:		return ResolveTypeRef(rid);
     case Table.ModuleRef:	return ResolveModuleRef(rid);
     case Table.Method:		return ResolveMethod(rid);
     case Table.TypeSpec:	return ResolveTypeSpec(rid, gpContext);
     }
     return null;
 }
Exemple #46
0
 /// <summary>
 /// Reads a <see cref="TypeSig"/> signature
 /// </summary>
 /// <param name="helper">Token resolver</param>
 /// <param name="corLibTypes">A <see cref="ICorLibTypes"/> instance</param>
 /// <param name="signature">The signature data</param>
 /// <param name="gpContext">Generic parameter context</param>
 /// <param name="extraData">If there's any extra data after the signature, it's saved
 /// here, else this will be <c>null</c></param>
 /// <returns>A new <see cref="TypeSig"/> instance or <c>null</c> if
 /// <paramref name="signature"/> is invalid.</returns>
 public static TypeSig ReadTypeSig(ISignatureReaderHelper helper, ICorLibTypes corLibTypes, byte[] signature, GenericParamContext gpContext, out byte[] extraData) =>
 ReadTypeSig(helper, corLibTypes, ByteArrayDataReaderFactory.CreateReader(signature), gpContext, out extraData);
Exemple #47
0
 /// <summary>
 /// Resolves a <see cref="StandAloneSig"/>
 /// </summary>
 /// <param name="rid">The row ID</param>
 /// <param name="gpContext">Generic parameter context</param>
 /// <returns>A <see cref="StandAloneSig"/> instance or <c>null</c> if <paramref name="rid"/> is invalid</returns>
 public StandAloneSig ResolveStandAloneSig(uint rid, GenericParamContext gpContext)
 {
     return listStandAloneSigMD[rid - 1, gpContext];
 }
Exemple #48
0
 /// <summary>
 /// Reads a <see cref="TypeSig"/> signature
 /// </summary>
 /// <param name="helper">Token resolver</param>
 /// <param name="corLibTypes">A <see cref="ICorLibTypes"/> instance</param>
 /// <param name="signature">The signature reader</param>
 /// <param name="gpContext">Generic parameter context</param>
 /// <param name="extraData">If there's any extra data after the signature, it's saved
 /// here, else this will be <c>null</c></param>
 /// <returns>A new <see cref="TypeSig"/> instance or <c>null</c> if
 /// <paramref name="signature"/> is invalid.</returns>
 public static TypeSig ReadTypeSig(ISignatureReaderHelper helper, ICorLibTypes corLibTypes, DataReader signature, GenericParamContext gpContext, out byte[] extraData)
 {
     try {
         var     reader = new SignatureReader(helper, corLibTypes, ref signature, gpContext);
         TypeSig ts;
         try {
             ts = reader.ReadType();
         }
         catch (IOException) {
             reader.reader.Position = 0;
             ts = null;
         }
         extraData = reader.GetExtraData();
         return(ts);
     }
     catch {
         extraData = null;
         return(null);
     }
 }
Exemple #49
0
 /// <summary>
 /// Resolves a <see cref="TypeSpec"/>
 /// </summary>
 /// <param name="rid">The row ID</param>
 /// <param name="gpContext">Generic parameter context</param>
 /// <returns>A <see cref="TypeSpec"/> instance or <c>null</c> if <paramref name="rid"/> is invalid</returns>
 public TypeSpec ResolveTypeSpec(uint rid, GenericParamContext gpContext)
 {
     return listTypeSpecMD[rid - 1, gpContext];
 }
Exemple #50
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="helper">Token resolver</param>
 /// <param name="corLibTypes">A <see cref="ICorLibTypes"/> instance</param>
 /// <param name="reader">The signature data</param>
 /// <param name="gpContext">Generic parameter context</param>
 SignatureReader(ISignatureReaderHelper helper, ICorLibTypes corLibTypes, ref DataReader reader, GenericParamContext gpContext)
 {
     this.helper      = helper;
     this.corLibTypes = corLibTypes;
     this.reader      = reader;
     this.gpContext   = gpContext;
     recursionCounter = new RecursionCounter();
 }
Exemple #51
0
 /// <summary>
 /// Reads a <see cref="MarshalType"/> from the blob
 /// </summary>
 /// <param name="table">Table of owner</param>
 /// <param name="rid">Row ID of owner</param>
 /// <param name="gpContext">Generic parameter context</param>
 /// <returns>A new <see cref="MarshalType"/> instance or <c>null</c> if there's no field
 /// marshal for this owner.</returns>
 internal MarshalType ReadMarshalType(Table table, uint rid, GenericParamContext gpContext)
 {
     var row = TablesStream.ReadFieldMarshalRow(MetaData.GetFieldMarshalRid(table, rid));
     if (row == null)
         return null;
     return MarshalBlobReader.Read(this, row.NativeType, gpContext);
 }
Exemple #52
0
 /// <summary>
 /// Reads a signature from the #Blob stream
 /// </summary>
 /// <param name="readerModule">Reader module</param>
 /// <param name="sig">#Blob stream offset of signature</param>
 /// <param name="gpContext">Generic parameter context</param>
 /// <returns>A new <see cref="CallingConventionSig"/> instance or <c>null</c> if
 /// <paramref name="sig"/> is invalid.</returns>
 public static CallingConventionSig ReadSig(ModuleDefMD readerModule, uint sig, GenericParamContext gpContext)
 {
     try {
         var reader = new SignatureReader(readerModule, sig, gpContext);
         if (reader.reader.Length == 0)
         {
             return(null);
         }
         var csig = reader.ReadSig();
         if (!(csig is null))
         {
             csig.ExtraData = reader.GetExtraData();
         }
         return(csig);
     }
     catch {
         return(null);
     }
 }
Exemple #53
0
        /// <summary>
        /// Reads a CIL method body
        /// </summary>
        /// <param name="parameters">Method parameters</param>
        /// <param name="rva">RVA</param>
        /// <param name="gpContext">Generic parameter context</param>
        /// <returns>A new <see cref="CilBody"/> instance. It's empty if RVA is invalid (eg. 0 or
        /// it doesn't point to a CIL method body)</returns>
        public CilBody ReadCilBody(IList<Parameter> parameters, RVA rva, GenericParamContext gpContext)
        {
            if (rva == 0)
                return new CilBody();

            // Create a full stream so position will be the real position in the file. This
            // is important when reading exception handlers since those must be 4-byte aligned.
            // If we create a partial stream starting from rva, then position will be 0 and always
            // 4-byte aligned. All fat method bodies should be 4-byte aligned, but the CLR doesn't
            // seem to verify it. We must parse the method exactly the way the CLR parses it.
            using (var reader = metaData.PEImage.CreateFullStream()) {
                reader.Position = (long)metaData.PEImage.ToFileOffset(rva);
                return MethodBodyReader.CreateCilBody(this, reader, parameters, gpContext);
            }
        }
Exemple #54
0
 /// <inheritdoc/>
 protected override MarshalType GetMarshalType_NoLock()
 {
     return(readerModule.ReadMarshalType(Table.Param, origRid, GenericParamContext.Create(declaringMethod)));
 }
Exemple #55
0
 /// <summary>
 /// Reads a signature from the #Blob stream
 /// </summary>
 /// <param name="sig">#Blob stream offset of signature</param>
 /// <param name="gpContext">Generic parameter context</param>
 /// <returns>A new <see cref="CallingConventionSig"/> instance or <c>null</c> if
 /// <paramref name="sig"/> is invalid.</returns>
 public CallingConventionSig ReadSignature(uint sig, GenericParamContext gpContext)
 {
     return SignatureReader.ReadSig(this, sig, gpContext);
 }
Exemple #56
0
 /// <summary>
 /// Parses a Reflection type name and creates a <see cref="TypeSig"/>
 /// </summary>
 /// <param name="ownerModule">Module that will own the returned <see cref="TypeSig"/> or <c>null</c></param>
 /// <param name="typeFullName">Full name of type</param>
 /// <param name="typeNameParserHelper">Helper class</param>
 /// <param name="gpContext">Generic parameter context</param>
 /// <returns>A new <see cref="TypeSig"/> instance or <c>null</c> if parsing failed</returns>
 public static TypeSig ParseAsTypeSigReflection(ModuleDef ownerModule, string typeFullName, IAssemblyRefFinder typeNameParserHelper, GenericParamContext gpContext)
 {
     try {
         return(ParseAsTypeSigReflectionThrow(ownerModule, typeFullName, typeNameParserHelper, gpContext));
     }
     catch (TypeNameParserException) {
         return(null);
     }
 }
Exemple #57
0
 /// <summary>
 /// Reads a type signature from the #Blob stream
 /// </summary>
 /// <param name="sig">#Blob stream offset of signature</param>
 /// <param name="extraData">If there's any extra data after the signature, it's saved
 /// here, else this will be <c>null</c></param>
 /// <param name="gpContext">Generic parameter context</param>
 /// <returns>A new <see cref="TypeSig"/> instance or <c>null</c> if
 /// <paramref name="sig"/> is invalid.</returns>
 public TypeSig ReadTypeSignature(uint sig, GenericParamContext gpContext, out byte[] extraData)
 {
     return SignatureReader.ReadTypeSig(this, sig, gpContext, out extraData);
 }
Exemple #58
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="ownerModule">Module that will own the returned <see cref="IType"/> or <c>null</c></param>
 /// <param name="typeFullName">Full name of type</param>
 /// <param name="typeNameParserHelper">Helper class</param>
 /// <param name="gpContext">Generic parameter context</param>
 protected TypeNameParser(ModuleDef ownerModule, string typeFullName, IAssemblyRefFinder typeNameParserHelper, GenericParamContext gpContext)
 {
     this.ownerModule          = ownerModule;
     this.reader               = new StringReader(typeFullName ?? string.Empty);
     this.typeNameParserHelper = typeNameParserHelper;
     this.gpContext            = gpContext;
 }
 public ITypeDefOrRef ResolveTypeDefOrRef(uint codedToken, GenericParamContext gpContext)
 {
     uint token;
     if (!CodedToken.TypeDefOrRef.Decode(codedToken, out token))
         return null;
     uint rid = MDToken.ToRID(token);
     switch (MDToken.ToTable(token)) {
     case Table.TypeDef:		return new TypeDefUser(UTF8String.Empty) { Rid = rid };
     case Table.TypeRef:		return new TypeRefUser(null, UTF8String.Empty) { Rid = rid };
     case Table.TypeSpec:	return new TypeSpecUser() { Rid = rid };
     }
     return null;
 }
Exemple #60
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="ownerModule">Module that will own the returned <see cref="IType"/> or <c>null</c></param>
 /// <param name="typeFullName">Full name of type</param>
 /// <param name="typeNameParserHelper">Helper class</param>
 /// <param name="gpContext">Generic parameter context</param>
 public ReflectionTypeNameParser(ModuleDef ownerModule, string typeFullName, IAssemblyRefFinder typeNameParserHelper, GenericParamContext gpContext)
     : base(ownerModule, typeFullName, typeNameParserHelper, gpContext)
 {
 }