protected override void ParseSignature(SignatureReader reader) { this.ParseModifier(reader); this.customMods = CustomMod.ParseCustomMods(reader); this.type = SigType.ParseTypeSignature(reader); }
/// <summary> /// Loads the signature. /// </summary> /// <param name="provider">The provider.</param> /// <param name="token">The token.</param> public Signature(IMetadataProvider provider, TokenTypes token) { SignatureReader reader = new SignatureReader(provider.ReadBlob(token)); this.ParseSignature(reader); Debug.Assert(reader.Index == reader.Length, @"Signature parser didn't complete."); this.token = token; }
/// <summary> /// FieldSignature signature is indexed by the Field.Signature column /// </summary> /// <param name="reader">The reader.</param> protected override void ParseSignature(SignatureReader reader) { if (Field != reader.ReadByte()) { throw new InvalidOperationException(@"Invalid method definition signature."); } base.ParseSignature(reader); }
/// <summary> /// Parses the signature. /// </summary> /// <param name="reader">The reader.</param> protected override void ParseSignature(SignatureReader reader) { if (reader.ReadByte() != 0x0A) throw new InvalidOperationException(@"Invalid signature."); int genArgCount = reader.ReadCompressedInt32(); Types = new SigType[genArgCount]; for (int i = 0; i < genArgCount; i++) Types[i] = SigType.ParseTypeSignature(reader); }
public TypeSig ReadTypeSignature(IMetaDataImport mdi, byte[] data) { return(SignatureReader.ReadTypeSig(new SignatureReaderHelper(mdi), corLibTypes, data)); }
/// <summary> /// Initializes a new instance of the <see cref="MethodSignature"/> class. /// </summary> /// <param name="reader">The reader.</param> public MethodSignature(SignatureReader reader) : base(reader) { }
/// <summary> /// Initializes a new instance of the <see cref="TypeSpecSignature"/> class. /// </summary> /// <param name="reader">The reader.</param> public TypeSpecSignature(SignatureReader reader) : base(reader) { }
/// <summary> /// Parses the type signature. /// </summary> /// <param name="reader">The reader.</param> /// <returns></returns> public static SigType ParseTypeSignature(SignatureReader reader) { CilElementType type = (CilElementType)reader.ReadByte(); switch (type) { case CilElementType.Void: return(BuiltInSigType.Void); case CilElementType.Boolean: return(BuiltInSigType.Boolean); case CilElementType.Char: return(BuiltInSigType.Char); case CilElementType.I1: return(BuiltInSigType.SByte); case CilElementType.U1: return(BuiltInSigType.Byte); case CilElementType.I2: return(BuiltInSigType.Int16); case CilElementType.U2: return(BuiltInSigType.UInt16); case CilElementType.I4: return(BuiltInSigType.Int32); case CilElementType.U4: return(BuiltInSigType.UInt32); case CilElementType.I8: return(BuiltInSigType.Int64); case CilElementType.U8: return(BuiltInSigType.UInt64); case CilElementType.R4: return(BuiltInSigType.Single); case CilElementType.R8: return(BuiltInSigType.Double); case CilElementType.String: return(BuiltInSigType.String); case CilElementType.Object: return(BuiltInSigType.Object); case CilElementType.I: return(BuiltInSigType.IntPtr); case CilElementType.U: return(BuiltInSigType.UIntPtr); case CilElementType.TypedByRef: return(BuiltInSigType.TypedByRef); case CilElementType.Array: return(ParseArraySignature(reader)); case CilElementType.Class: return(ParseClassSignature(reader)); case CilElementType.FunctionPtr: return(ParseFunctionPointer(reader)); case CilElementType.GenericInst: return(ParseGenericInstance(reader)); case CilElementType.MVar: return(ParseMVar(reader)); case CilElementType.Ptr: return(ParsePointer(reader)); case CilElementType.SZArray: return(ParseSZArraySignature(reader)); case CilElementType.ValueType: return(ParseValueType(reader)); case CilElementType.Var: return(ParseVar(reader)); case CilElementType.ByRef: return(ParseReference(reader)); default: throw new NotSupportedException(@"Unsupported CIL element type: " + type); } }
/// <summary> /// Initializes a new instance of the <see cref="LocalVariableSignature"/> class. /// </summary> /// <param name="reader">The reader.</param> public LocalVariableSignature(SignatureReader reader) : base(reader) { }
public override void Read(SignatureReader rdr) { Element = rdr.ReadElementType(); }
/// <summary> /// Parses the reference. /// </summary> /// <param name="reader">The reader.</param> /// <returns></returns> private static SigType ParseReference(SignatureReader reader) { SigType type = ParseTypeSignature(reader); return(new RefSigType(type)); }
/// <summary> /// Parses the var. /// </summary> /// <param name="reader">The reader.</param> /// <returns></returns> private static SigType ParseVar(SignatureReader reader) { int typeVariableIndex = reader.ReadCompressedInt32(); return new VarSigType(typeVariableIndex); }
/// <summary> /// Parses the custom mods. /// </summary> /// <param name="reader">The reader.</param> /// <returns></returns> public static CustomMod[] ParseCustomMods(SignatureReader reader) { List<CustomMod> mods = new List<CustomMod>(); while (reader.Index != reader.Length) { CilElementType type = (CilElementType)reader.PeekByte(); if (type != CilElementType.Optional && type != CilElementType.Required) break; reader.SkipByte(); Token modType = reader.ReadEncodedTypeDefOrRef(); mods.Add(new CustomMod((CustomModType)(type - CilElementType.Required + 1), modType)); } return mods.ToArray(); }
/// <summary> /// Parses the SZ array signature. /// </summary> /// <param name="reader">The reader.</param> /// <returns></returns> private static SigType ParseSZArraySignature(SignatureReader reader) { CustomMod[] customMods = CustomMod.ParseCustomMods(reader); SigType elementType = ParseTypeSignature(reader); return new SZArraySigType(customMods, elementType); }
/// <summary> /// Parses the type of the value. /// </summary> /// <param name="reader">The reader.</param> /// <returns></returns> private static TypeSigType ParseValueType(SignatureReader reader) { Token token = reader.ReadEncodedTypeDefOrRef(); return new ValueTypeSigType(token); }
/// <summary> /// Parses the reference. /// </summary> /// <param name="reader">The reader.</param> /// <returns></returns> private static SigType ParseReference(SignatureReader reader) { SigType type = ParseTypeSignature(reader); return new RefSigType(type); }
/// <summary> /// Parses the pointer. /// </summary> /// <param name="reader">The reader.</param> /// <returns></returns> private static SigType ParsePointer(SignatureReader reader) { CustomMod[] mods = CustomMod.ParseCustomMods(reader); SigType type = ParseTypeSignature(reader); return new PtrSigType(type, mods); }
/// <summary> /// Parses the MVar. /// </summary> /// <param name="reader">The reader.</param> /// <returns></returns> private static SigType ParseMVar(SignatureReader reader) { int methodVariableIndex = reader.ReadCompressedInt32(); return new MVarSigType(methodVariableIndex); }
/// <summary> /// Initializes a new instance of the <see cref="TypeSpecSignature"/> class. /// </summary> /// <param name="reader">The reader.</param> public TypeSpecSignature(SignatureReader reader) : base(reader) { }
public override void Read(SignatureReader rdr) { Element = rdr.ReadElementType(); tkn = rdr.ReadTypeDefOrRefEncoded(); }
/// <summary> /// Parses the generic instance. /// </summary> /// <param name="reader">The reader.</param> /// <returns></returns> private static SigType ParseGenericInstance(SignatureReader reader) { TypeSigType originalType; CilElementType type = (CilElementType)reader.ReadByte(); switch (type) { case CilElementType.Class: originalType = ParseClassSignature(reader); break; case CilElementType.ValueType: originalType = ParseValueType(reader); break; default: throw new InvalidOperationException(@"Invalid signature type."); } int genArgCount = reader.ReadCompressedInt32(); SigType[] genArgs = new SigType[genArgCount]; for (int i = 0; i < genArgCount; i++) { genArgs[i] = ParseTypeSignature(reader); } return new GenericInstSigType(originalType, genArgs); }
public SecurityDeclarationReader(MetadataRoot root, ReflectionReader reader) { sr = new SignatureReader(root, reader); }
/// <summary> /// Loads the signature. /// </summary> /// <param name="reader">The reader.</param> public FieldSignature(SignatureReader reader) : base(reader) { }
public override void Read(SignatureReader rdr) { Element = rdr.ReadElementType(); num = rdr.ReadCompressedInt(); }
/// <summary> /// Parses the function pointer. /// </summary> /// <param name="reader">The reader.</param> /// <returns></returns> private static SigType ParseFunctionPointer(SignatureReader reader) { HeapIndexToken token = reader.ReadEncodedToken(); return(new FnptrSigType(token)); }
/// <summary> /// Parses the array signature. /// </summary> /// <param name="reader">The reader.</param> /// <returns></returns> private static SigType ParseArraySignature(SignatureReader reader) { SigType elementType = ParseTypeSignature(reader); int rank, count; int[] sizes, lowerBounds; rank = reader.ReadCompressedInt32(); count = reader.ReadCompressedInt32(); sizes = new int[count]; for (int i = 0; i < count; i++) sizes[i] = reader.ReadCompressedInt32(); count = reader.ReadCompressedInt32(); lowerBounds = new int[count]; for (int i = 0; i < count; i++) lowerBounds[i] = reader.ReadCompressedInt32(); return new ArraySigType(elementType, rank, sizes, lowerBounds); }
public TypeSig ReadTypeSignature(byte[] data) { return(SignatureReader.ReadTypeSig(SignatureReaderHelper.Instance, corLibTypes, data)); }
private void ParseModifier(SignatureReader reader) { CilElementType value = (CilElementType)reader.PeekByte(); if (value == CilElementType.Pinned) { this.modifier = value; reader.SkipByte(); } }
/// <summary> /// PropertySignature signature is indexed by the Property.Type column /// </summary> /// <param name="reader">The reader.</param> protected override void ParseSignature(SignatureReader reader) { throw new Exception("The method or operation is not implemented."); }
public static Signature FromMemberRefSignatureToken(IMetadataProvider provider, HeapIndexToken token, SigType[] genericArguments) { SignatureReader reader = new SignatureReader(provider.ReadBlob(token)); if (reader[0] == 0x06) { return new FieldSignature(reader, genericArguments); } else { return new MethodSignature(reader, genericArguments); } }
/// <summary> /// Initializes a new instance of the <see cref="MethodReferenceSignature"/> class. /// </summary> /// <param name="reader">The reader.</param> public MethodReferenceSignature(SignatureReader reader) : base(reader) { }
/// <summary> /// Loads the signature. /// </summary> /// <param name="reader">The reader.</param> public FieldSignature(SignatureReader reader) : base(reader) { }
/// <summary> /// Parses the signature. /// </summary> /// <param name="reader">The reader.</param> protected override void ParseSignature(SignatureReader reader) { type = SigType.ParseTypeSignature(reader); }
/// <summary> /// Parses the signature. /// </summary> /// <param name="reader">The reader.</param> protected abstract void ParseSignature(SignatureReader reader);
public CallingConventionSig ReadSignature(IMetaDataImport mdi, byte[] data) { return(SignatureReader.ReadSig(new SignatureReaderHelper(mdi), corLibTypes, data)); }
public override void Read(SignatureReader rdr) { Element = rdr.ReadElementType(); mtd = new MethodSig(); mtd.Read(rdr); }
/// <summary> /// Parses the signature. /// </summary> /// <param name="reader">The reader.</param> protected override void ParseSignature(SignatureReader reader) { type = SigType.ParseTypeSignature(reader); }
/// <summary> /// Parses the function pointer. /// </summary> /// <param name="reader">The reader.</param> /// <returns></returns> private static SigType ParseFunctionPointer(SignatureReader reader) { HeapIndexToken token = reader.ReadEncodedToken(); return new FnptrSigType(token); }
/// <summary> /// Loads the signature. /// </summary> /// <param name="reader">The reader.</param> /// <param name="genericArguments">The generic arguments.</param> public FieldSignature(SignatureReader reader, SigType[] genericArguments) : base(reader) { ApplyGenericArguments(genericArguments); }
/// <summary> /// Initializes a new instance of the <see cref="StandAloneMethodSignature"/> class. /// </summary> /// <param name="reader">The reader.</param> public StandAloneMethodSignature(SignatureReader reader) : base(reader) { }
/// <summary> /// Loads the signature. /// </summary> /// <param name="reader">The reader.</param> public Signature(SignatureReader reader) { ParseSignature(reader); }
/// <summary> /// Asynchronously generates bindings for the API described by the given <see cref="IGeneratorSettings"/> /// object. /// /// Broadly, this takes the following steps: /// 1) Load the base API. /// 2) Bake overrides into the API /// 3) Bake Documentation into the API /// 4) Create mappings between OpenGL types and C# types /// 5) Apply the mappings to the API /// 6) Bake convenience overloads into the API (adding unsafe, etc) /// 7) Write the bindings to the files. /// /// </summary> /// <param name="generatorSettings">The settings describing the API.</param> /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns> private static async Task GenerateBindingsAsync([NotNull] IGeneratorSettings generatorSettings) { var signaturePath = Path.Combine(Arguments.InputPath, generatorSettings.SpecificationFile); if (!_cachedProfiles.TryGetValue(signaturePath, out var profiles)) { profiles = SignatureReader.GetAvailableProfiles(signaturePath).ToList(); _cachedProfiles.TryAdd(signaturePath, profiles); } var profileOverrides = OverrideReader .GetProfileOverrides(generatorSettings.OverrideFiles.ToArray()) .ToList(); var baker = new ProfileBaker(profiles, profileOverrides); var bakedProfile = baker.BakeProfile ( generatorSettings.ProfileName, generatorSettings.Versions, generatorSettings.BaseProfileName ); var documentationPath = Path.Combine ( Arguments.DocumentationPath, generatorSettings.SpecificationDocumentationPath ); var docs = DocumentationReader.ReadProfileDocumentation(documentationPath); var bakedDocs = new DocumentationBaker(bakedProfile).BakeDocumentation(docs); var languageTypemapPath = Path.Combine(Arguments.InputPath, generatorSettings.LanguageTypemap); if (!_cachedTypemaps.TryGetValue(languageTypemapPath, out var languageTypemap)) { using (var fs = File.OpenRead(languageTypemapPath)) { languageTypemap = new TypemapReader().ReadTypemap(fs); _cachedTypemaps.TryAdd(languageTypemapPath, languageTypemap); } } var apiTypemapPath = Path.Combine(Arguments.InputPath, generatorSettings.APITypemap); if (!_cachedTypemaps.TryGetValue(apiTypemapPath, out var apiTypemap)) { using (var fs = File.OpenRead(apiTypemapPath)) { apiTypemap = new TypemapReader().ReadTypemap(fs); _cachedTypemaps.TryAdd(apiTypemapPath, apiTypemap); } } var bakedMap = TypemapBaker.BakeTypemaps(apiTypemap, languageTypemap); var mapper = new ProfileMapper(bakedMap); var mappedProfile = mapper.Map(bakedProfile); var overloadedProfile = OverloadBaker.BakeOverloads(mappedProfile); var bindingsWriter = new BindingWriter(generatorSettings, overloadedProfile, bakedDocs); await bindingsWriter.WriteBindingsAsync(); }
/// <summary> /// Froms the member ref signature token. /// </summary> /// <param name="provider">The provider.</param> /// <param name="token">The token.</param> /// <returns></returns> public static Signature FromMemberRefSignatureToken(IMetadataProvider provider, TokenTypes token) { SignatureReader reader = new SignatureReader(provider.ReadBlob(token)); if (reader[0] == 0x06) { return new FieldSignature(reader); } else { return new MethodSignature(reader); } }
/// <summary> /// PropertySignature signature is indexed by the Property.Type column /// </summary> /// <param name="reader">The reader.</param> protected override void ParseSignature(SignatureReader reader) { throw new Exception("The method or operation is not implemented."); }
void ReadRvaData(MetadataTable tbl, MetadataReader mdRdr, List <Rva> rvas, MetadataRowCollection rows) { List <Rva> sorted = new List <Rva>(rvas); sorted.Sort(); for (int i = 0; i < rvas.Count; i++) { Rva rva = rvas[i]; MetadataRow r = rows[i + 1]; byte[] dat = null; VirtualReader rdr = new VirtualReader(mdRdr.BaseStream.File.SectionHeaders.GetVirtualStream()); if (tbl.Type == TableType.FieldRVA) { MetadataRoot root = tbl.Heap.Stream.Root; rdr.SetPosition(rva); MetadataRow fd = (r["Field"] as TableToken).ResolveRow(); FieldSig sig = new FieldSig(); SignatureReader sigRdr = new SignatureReader(new MetadataReader(root[MetadataStreamType.Blob])); sigRdr.BaseStream.Position = (fd["Signature"] as BlobToken).Token.Index; sig.Read(sigRdr); int c = 0; switch (sig.Type.Element) { case ElementType.Boolean: case ElementType.UInt8: case ElementType.Int8: c = 1; break; case ElementType.UInt16: case ElementType.Int16: case ElementType.Char: c = 2; break; case ElementType.UInt32: case ElementType.Int32: case ElementType.Single: c = 4; break; case ElementType.UInt64: case ElementType.Int64: case ElementType.Double: c = 8; break; case ElementType.ValueType: TableToken vt = (sig.Type as VALUETYPE).Type; foreach (MetadataRow cl in tbl.Heap[TableType.ClassLayout]) { if (cl["Parent"] == vt) { c = (int)cl["ClassSize"]; break; } } break; default: throw new InvalidOperationException("ReadRvaData"); } dat = rdr.ReadBytes(c); } else if (tbl.Type == TableType.MethodDef && rva != 0) { //MethodBody bdy; //if (((MethodImplAttributes)r["ImplFlags"] & MethodImplAttributes.Native) == MethodImplAttributes.Native) //{ // bdy = new NativeMethodBody(r); //} //else //{ // bdy = new ManagedMethodBody(r); //} //rdr.SetPosition(rva); //bdy.Load(rdr); //rdr.SetPosition(rva); //dat = rdr.ReadBytes((int)bdy.Size); int idx; Rva next; if ((idx = sorted.IndexOf(rva)) == sorted.Count - 1) { CLRDirectory root = tbl.Heap.Stream.Root.Directory; Rva now; next = uint.MaxValue; rdr.SetPosition(root.Location.Address); rdr.BaseStream.Seek(0x8, System.IO.SeekOrigin.Current); if ((now = rdr.ReadRva()) < next && now != 0 && now > rva) { next = now; } rdr.BaseStream.Seek(0xC, System.IO.SeekOrigin.Current); if ((now = rdr.ReadRva()) < next && now != 0 && now > rva) { next = now; } rdr.BaseStream.Seek(0x4, System.IO.SeekOrigin.Current); if ((now = rdr.ReadRva()) < next && now != 0 && now > rva) { next = now; } rdr.BaseStream.Seek(0x4, System.IO.SeekOrigin.Current); if ((now = rdr.ReadRva()) < next && now != 0 && now > rva) { next = now; } rdr.BaseStream.Seek(0x4, System.IO.SeekOrigin.Current); if ((now = rdr.ReadRva()) < next && now != 0 && now > rva) { next = now; } rdr.BaseStream.Seek(0x4, System.IO.SeekOrigin.Current); if ((now = rdr.ReadRva()) < next && now != 0 && now > rva) { next = now; } rdr.BaseStream.Seek(0x4, System.IO.SeekOrigin.Current); if ((now = rdr.ReadRva()) < next && now != 0 && now > rva) { next = now; } } else { next = sorted[idx + 1]; } rdr.SetPosition(rva); dat = rdr.ReadBytes((int)(next - rva)); } if (!tbl.Heap.Stream.Root.Directory.Datas.ContainsAddress(rva) && dat != null) { tbl.Heap.Stream.Root.Directory.Datas.Add(new CLRData() { Address = rva, Data = dat }); } } }
/// <summary> /// Loads the signature. /// </summary> /// <param name="reader">The reader.</param> /// <param name="genericArguments">The generic arguments.</param> public FieldSignature(SignatureReader reader, SigType[] genericArguments) : base(reader) { ApplyGenericArguments(genericArguments); }
/// <summary> /// Parses the var. /// </summary> /// <param name="reader">The reader.</param> /// <returns></returns> private static SigType ParseVar(SignatureReader reader) { int typeVariableIndex = reader.ReadCompressedInt32(); return(new VarSigType(typeVariableIndex)); }
/// <summary> /// Parses the signature. /// </summary> /// <param name="reader">The reader.</param> protected abstract void ParseSignature(SignatureReader reader);
/// <summary> /// Parses the MVar. /// </summary> /// <param name="reader">The reader.</param> /// <returns></returns> private static SigType ParseMVar(SignatureReader reader) { int methodVariableIndex = reader.ReadCompressedInt32(); return(new MVarSigType(methodVariableIndex)); }
/// <summary> /// Loads the signature. /// </summary> /// <param name="reader">The reader.</param> public Signature(SignatureReader reader) { ParseSignature(reader); }
/// <summary> /// Parses the class signature. /// </summary> /// <param name="reader">The reader.</param> /// <returns></returns> private static TypeSigType ParseClassSignature(SignatureReader reader) { Token token = reader.ReadEncodedTypeDefOrRef(); return(new ClassSigType(token)); }
/// <summary> /// Initializes a new instance of the <see cref="VariableSignature"/> class. /// </summary> /// <param name="reader">The reader.</param> public VariableSignature(SignatureReader reader) : base(reader) { }
/// <summary> /// Initializes a new instance of the <see cref="MethodReferenceSignature"/> class. /// </summary> /// <param name="reader">The reader.</param> public MethodReferenceSignature(SignatureReader reader) : base(reader) { }
protected override void ParseSignature(SignatureReader reader) { ParseModifier(reader); CustomMods = CustomMod.ParseCustomMods(reader); Type = SigType.ParseTypeSignature(reader); }
/// <summary> /// Parses the signature. /// </summary> /// <param name="reader">The reader.</param> protected override void ParseSignature(SignatureReader reader) { // Check signature identifier if (reader.ReadByte() != 0x07) throw new ArgumentException(@"Token doesn't represent a local variable signature.", @"token"); // Retrieve the number of locals int count = reader.ReadCompressedInt32(); if (count != 0) { this.locals = new VariableSignature[count]; for (int i = 0; i < count; i++) { locals[i] = new VariableSignature(reader); } } }
/// <summary> /// Parses the signature. /// </summary> /// <param name="reader">The reader.</param> protected override sealed void ParseSignature(SignatureReader reader) { byte value = reader.ReadByte(); // Check for instance signature if (HAS_THIS == (value & HAS_THIS)) { hasThis = true; } if (HAS_EXPLICIT_THIS == (value & HAS_EXPLICIT_THIS)) { hasExplicitThis = true; } if (GENERIC == (value & GENERIC)) { callingConvention = CallingConvention.Generic; genericParameterCount = reader.ReadCompressedInt32(); } else if (VARARG == (value & VARARG)) { callingConvention = CallingConvention.Vararg; } else if ((value & 0x1F) != 0x00) { throw new InvalidOperationException(@"Invalid method definition signature."); } // Number of parameters int paramCount = reader.ReadCompressedInt32(); parameters = new SigType[paramCount]; // Read the return type returnType = SigType.ParseTypeSignature(reader); // Read all parameters for (int i = 0; i < paramCount; i++) parameters[i] = SigType.ParseTypeSignature(reader); }
/// <summary> /// Initializes a new instance of the <see cref="StandaloneMethodSignature"/> class. /// </summary> /// <param name="reader">The reader.</param> public StandaloneMethodSignature(SignatureReader reader) : base(reader) { }
/// <summary> /// Initializes a new instance of the <see cref="MethodSignature"/> class. /// </summary> /// <param name="reader">The reader.</param> public MethodSignature(SignatureReader reader) : base(reader) { }