/// <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 not null) { csig.ExtraData = reader.GetExtraData(); } return(csig); } catch { return(null); } }
/// <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); } }
/// <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(); }
/// <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);
/// <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);
/// <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);
/// <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);
/// <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);
/// <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); } }
/// <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);
DeclSecurityReader(ModuleDef module, DataReader reader, GenericParamContext gpContext) { this.reader = reader; this.module = module; this.gpContext = gpContext; }
/// <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()); }
/// <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> /// 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);