Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CilGenericType"/> class.
        /// </summary>
        /// <param name="typeModule">The type module.</param>
        /// <param name="token">The token.</param>
        /// <param name="baseGenericType">Type of the base generic.</param>
        /// <param name="genericTypeInstanceSignature">The generic type instance signature.</param>
        public CilGenericType(ITypeModule typeModule, Token token, RuntimeType baseGenericType, GenericInstSigType genericTypeInstanceSignature)
            : base(baseGenericType.Module, token, baseGenericType.BaseType)
        {
            Debug.Assert(baseGenericType is CilRuntimeType);

            this.signature = genericTypeInstanceSignature;
            this.baseGenericType = baseGenericType as CilRuntimeType;
            this.InstantiationModule = typeModule;
            base.Attributes = baseGenericType.Attributes;
            base.Namespace = baseGenericType.Namespace;

            if (this.baseGenericType.IsNested)
            {
                // TODO: find generic type

                ;
            }

            // TODO: if this is a nested types, add enclosing type(s) into genericArguments first
            this.genericArguments = signature.GenericArguments;

            base.Name = GetName(typeModule);

            ResolveMethods();
            ResolveFields();

            this.containsOpenGenericArguments = CheckContainsOpenGenericParameters();
        }
Exemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RuntimeAttribute"/> class.
 /// </summary>
 /// <param name="typeModule">The type module.</param>
 /// <param name="ctor">The ctor.</param>
 /// <param name="ctorMethod">The ctor method.</param>
 /// <param name="blobIndex">Index of the blob.</param>
 public RuntimeAttribute(ITypeModule typeModule, Token ctor, RuntimeMethod ctorMethod, HeapIndexToken blobIndex)
 {
     this.typeModule = typeModule;
     this.ctorMethod = ctorMethod;
     this.ctor = ctor;
     this.blobIndex = blobIndex;
 }
Exemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CilRuntimeField"/> class.
 /// </summary>
 /// <param name="module">The module.</param>
 /// <param name="name">The name.</param>
 /// <param name="signature">The signature.</param>
 /// <param name="token">The token.</param>
 /// <param name="offset">The offset.</param>
 /// <param name="rva">The rva.</param>
 /// <param name="declaringType">Type of the declaring.</param>
 /// <param name="attributes">The attributes.</param>
 public CilRuntimeField(ITypeModule module, string name, FieldSignature signature, Token token, uint offset, uint rva, RuntimeType declaringType, FieldAttributes attributes)
     : base(module, token, declaringType)
 {
     this.Name = name;
     this.Signature = signature;
     base.Attributes = attributes;
     base.RVA = rva;
 }
Exemplo n.º 4
0
 public VerificationEntry(string assembly, VerificationType type, string section, string error, string description, Token token)
 {
     this.Assembly = assembly;
     this.Type = type;
     this.Section = section;
     this.Rule = error;
     this.Description = description;
     this.Location = token;
 }
Exemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CilRuntimeMethod"/> class.
        /// </summary>
        /// <param name="module">The module.</param>
        /// <param name="name">The name.</param>
        /// <param name="signature">The signature.</param>
        /// <param name="token">The token.</param>
        /// <param name="declaringType">Type of the declaring.</param>
        /// <param name="methodAttributes">The method attributes.</param>
        /// <param name="methodImplAttributes">The method impl attributes.</param>
        /// <param name="rva">The rva.</param>
        public CilRuntimeMethod(ITypeModule module, string name, MethodSignature signature, Token token, RuntimeType declaringType, MethodAttributes methodAttributes, MethodImplAttributes methodImplAttributes, uint rva)
            : base(module, token, declaringType)
        {
            base.Attributes = methodAttributes;
            base.ImplAttributes = methodImplAttributes;
            base.Rva = rva;
            this.Name = name;
            this.Signature = signature;

            this.Parameters = new List<RuntimeParameter>();
        }
Exemplo n.º 6
0
        protected override void Run()
        {
            int rows = metadata.GetRowCount(TableType.Assembly);

            if (rows == 0)
                return;

            // 1. The Assembly table shall contain zero or one row
            if (rows > 1)
            {
                AddSpecificationError("22.2-1", "The Assembly table shall contain zero or one row", "Multiple rows found");
            }

            Token token = new Token(TableType.Assembly, 1);
            AssemblyRow row = metadata.ReadAssemblyRow(token);

            // 2. HashAlgId shall be one of the specified values
            // Note: Microsoft treats this as a WARNING rather than an error
            if (!IsValidHashAlgID((int)row.HashAlgId))
            {
                AddSpecificationError("22.2-2", "HashAlgId shall be one of the specified values", "Invalid Hash Algorithm ID", token);
            }

            // 4. Flags shall have only those values set that are specified
            if (!IsAssemblyFlags((int)row.Flags))
            {
                AddSpecificationError("22.2-4", "Flags shall have only those values set that are specified", "Invalid Hash Algorithm ID", token);
            }

            // 6. Name shall index a non-empty string in the String heap
            switch (CheckName(row.Name))
            {
                case 0: break;
                case 1: AddSpecificationError("22.2-6", "Name shall index a non-empty string, in the String heap", "Empty name", token); break;
                case 2: AddSpecificationError("22.2-6", "Name shall index a non-empty string, in the String heap", "Invalid index", token); break;
                case 3: AddSpecificationError("22.2-6", "Name shall index a non-empty string, in the String heap", "Empty name", token); break;
            }

            // 9. If Culture is non-null, it shall index a single string from the list specified
            switch (CheckCulture(row.Culture))
            {
                case 0: break;
                case 1: AddSpecificationError("22.2-9", "If Culture is non-null, it shall index a single string from the list specified", "Invalid or Missing Culture", token); break;
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CilRuntimeType"/> class.
        /// </summary>
        /// <param name="module">The module.</param>
        /// <param name="name">The name.</param>
        /// <param name="typeNamespace">The type namespace.</param>
        /// <param name="packing">The packing.</param>
        /// <param name="size">The size.</param>
        /// <param name="token">The token.</param>
        /// <param name="baseType">Type of the base.</param>
        /// <param name="enclosingType">Type of the enclosing.</param>
        /// <param name="attributes">The attributes.</param>
        /// <param name="baseToken">The base token.</param>
        public CilRuntimeType(ITypeModule module, string name, string typeNamespace, int packing, int size, Token token, RuntimeType baseType, RuntimeType enclosingType, TypeAttributes attributes, Token baseToken)
            : base(module, token, baseType)
        {
            this.baseTypeToken = baseToken;
            this.enclosingType = enclosingType;

            base.Attributes = attributes;
            base.Pack = packing;
            base.LayoutSize = size;
            base.Name = name;
            base.Namespace = typeNamespace;

            if (IsNested)
            {
                Debug.Assert(enclosingType != null);
                this.Namespace = enclosingType.Namespace + "." + enclosingType.Name;
            }
        }
Exemplo n.º 8
0
        protected void UpdateTree()
        {
            treeView.BeginUpdate();
            treeView.Nodes.Clear();

            //Cycle through all metadata tables
            foreach (TableType table in Enum.GetValues(typeof(TableType)))
            {
                if (table == TableType.Module)
                    continue;

                int count = metadataModule.Metadata.GetRowCount(table);

                if (count == 0)
                    continue;

                TreeNode tableNode = new TreeNode("[" + table.FormatToString() + "] " + table.ToString() + " (" + count.ToString() + ")");
                treeView.Nodes.Add(tableNode);

                //Cycle through all metadata rows
                for (int rowid = 1; rowid <= count; rowid++)
                {
                    Token token = new Token(table, rowid);

                    TableRow row = Resolver.GetTableRow(metadataModule, token);

                    if (row == null)
                        continue;

                    TreeNode rowNode = new TreeNode(token.FormatToString() + " - " + row.Name);
                    tableNode.Nodes.Add(rowNode);

                    foreach (KeyValuePair<string, string> data in row.GetValues())
                    {
                        TreeNode rowValueNode = new TreeNode(data.Key + ": " + data.Value);
                        rowNode.Nodes.Add(rowValueNode);
                    }
                }
            }

            treeView.EndUpdate();
        }
Exemplo n.º 9
0
        /// <summary>
        /// Runs the specified compiler.
        /// </summary>
        void IMethodCompilerStage.Run()
        {
            // Handler Code
            foreach (ExceptionHandlingClause clause in methodCompiler.ExceptionClauseHeader.Clauses)
            {
                if (clause.ExceptionHandler == ExceptionHandlerType.Exception)
                {
                    var typeToken = new Token(clause.ClassToken);

                    RuntimeType type = methodCompiler.Method.Module.GetType(typeToken);

                    var block = FindBlock(clause.HandlerOffset);

                    var context = new Context(instructionSet, block).InsertBefore();

                    SigType sigType = new ClassSigType(typeToken);
                    Operand exceptionObject = methodCompiler.CreateTemporary(sigType);

                    context.SetInstruction(IR.Instruction.ExceptionPrologueInstruction, exceptionObject);
                }
            }
        }
Exemplo n.º 10
0
        public static TableRow GetTableRow(IMetadataProvider metadata, Token token)
        {
            switch (token.Table)
            {
                case TableType.File: return new FileRowExt(metadata, metadata.ReadFileRow(token));
                case TableType.TypeDef: return new TypeDefRowExt(metadata, metadata.ReadTypeDefRow(token));
                case TableType.TypeSpec: return new TypeSpecRowExt(metadata, metadata.ReadTypeSpecRow(token));
                case TableType.TypeRef: return new TypeRefRowExt(metadata, metadata.ReadTypeRefRow(token));
                case TableType.Field: return new FieldRowExt(metadata, metadata.ReadFieldRow(token));
                case TableType.MethodDef: return new MethodDefRowExt(metadata, metadata.ReadMethodDefRow(token));
                case TableType.ImplMap: return new ImplMapRowExt(metadata, metadata.ReadImplMapRow(token));
                case TableType.MemberRef: return new MemberRefRowExt(metadata, metadata.ReadMemberRefRow(token));
                case TableType.InterfaceImpl: return new InterfaceImplRowExt(metadata, metadata.ReadInterfaceImplRow(token));
                case TableType.CustomAttribute: return new CustomAttributeRowExt(metadata, metadata.ReadCustomAttributeRow(token));
                case TableType.Assembly: return new AssemblyRowExt(metadata, metadata.ReadAssemblyRow(token));
                case TableType.AssemblyRef: return new AssemblyRefRowExt(metadata, metadata.ReadAssemblyRefRow(token));
                case TableType.GenericParam: return new GenericParamRowExt(metadata, metadata.ReadGenericParamRow(token));
                case TableType.Param: return new ParamRowExt(metadata, metadata.ReadParamRow(token));

                default: return null;
            }
        }
Exemplo n.º 11
0
 public static TableRow GetTableRow(IMetadataModule metadataModule, Token token)
 {
     switch (token.Table)
     {
         case TableType.File: return new FileRowExt(metadataModule, metadataModule.Metadata.ReadFileRow(token));
         case TableType.TypeDef: return new TypeDefRowExt(metadataModule, metadataModule.Metadata.ReadTypeDefRow(token));
         case TableType.TypeSpec: return new TypeSpecRowExt(metadataModule, metadataModule.Metadata.ReadTypeSpecRow(token));
         case TableType.TypeRef: return new TypeRefRowExt(metadataModule, metadataModule.Metadata.ReadTypeRefRow(token));
         case TableType.Field: return new FieldRowExt(metadataModule, metadataModule.Metadata.ReadFieldRow(token));
         case TableType.MethodDef: return new MethodDefRowExt(metadataModule, metadataModule.Metadata.ReadMethodDefRow(token));
         case TableType.ImplMap: return new ImplMapRowExt(metadataModule, metadataModule.Metadata.ReadImplMapRow(token));
         case TableType.MemberRef: return new MemberRefRowExt(metadataModule, metadataModule.Metadata.ReadMemberRefRow(token));
         case TableType.InterfaceImpl: return new InterfaceImplRowExt(metadataModule, metadataModule.Metadata.ReadInterfaceImplRow(token));
         case TableType.CustomAttribute: return new CustomAttributeRowExt(metadataModule, metadataModule.Metadata.ReadCustomAttributeRow(token));
         case TableType.Assembly: return new AssemblyRowExt(metadataModule, metadataModule.Metadata.ReadAssemblyRow(token));
         case TableType.AssemblyRef: return new AssemblyRefRowExt(metadataModule, metadataModule.Metadata.ReadAssemblyRefRow(token));
         case TableType.GenericParam: return new GenericParamRowExt(metadataModule, metadataModule.Metadata.ReadGenericParamRow(token));
         case TableType.Param: return new ParamRowExt(metadataModule, metadataModule.Metadata.ReadParamRow(token));
         case TableType.StandAloneSig: return new StandAloneSigExt(metadataModule, metadataModule.Metadata.ReadStandAloneSigRow(token));
         case TableType.MethodSpec: return new MethodSpecExt(metadataModule, metadataModule.Metadata.ReadMethodSpecRow(token));
         case TableType.NestedClass: return new NestedClassExt(metadataModule, metadataModule.Metadata.ReadNestedClassRow(token));
         default: return null;
     }
 }
Exemplo n.º 12
0
        /// <summary>
        /// Reads the specified token.
        /// </summary>
        /// <param name="token">The token.</param>
        /// <returns></returns>
        public PropertyRow ReadPropertyRow(Token token)
        {
            if (token.Table != TableType.Property)
                throw new ArgumentException("Invalid token type for PropertyRow.", @"token");

            using (var reader = CreateReaderForToken(token))
            {
                return new PropertyRow(
                    (PropertyAttributes)reader.ReadUInt16(),
                    ReadHeapToken(reader, IndexType.StringHeap),
                    ReadHeapToken(reader, IndexType.BlobHeap)
                );
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Reads the specified token.
        /// </summary>
        /// <param name="token">The token.</param>
        /// <returns></returns>
        public PropertyMapRow ReadPropertyMapRow(Token token)
        {
            if (token.Table != TableType.PropertyMap)
                throw new ArgumentException("Invalid token type for PropertyMapRow.", @"token");

            using (var reader = CreateReaderForToken(token))
            {
                return new PropertyMapRow(
                    ReadIndexValue(reader, TableType.TypeDef),
                    ReadIndexValue(reader, TableType.Property)
                );
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Reads the specified token.
        /// </summary>
        /// <param name="token">The token.</param>
        /// <returns></returns>
        public ParamRow ReadParamRow(Token token)
        {
            if (token.Table != TableType.Param)
                throw new ArgumentException("Invalid token type for ParamRow.", @"token");

            using (var reader = CreateReaderForToken(token))
            {
                return new ParamRow(
                    (ParameterAttributes)reader.ReadUInt16(),
                    reader.ReadInt16(),
                    ReadHeapToken(reader, IndexType.StringHeap)
                );
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// Reads the specified token.
        /// </summary>
        /// <param name="token">The token.</param>
        /// <returns></returns>
        public NestedClassRow ReadNestedClassRow(Token token)
        {
            if (token.Table != TableType.NestedClass)
                throw new ArgumentException("Invalid token type for NestedClassRow.", @"token");

            using (var reader = CreateReaderForToken(token))
            {
                return new NestedClassRow(
                    ReadIndexValue(reader, TableType.TypeDef),
                    ReadIndexValue(reader, TableType.TypeDef)
                );
            }
        }
Exemplo n.º 16
0
 /// <summary>
 /// Retrieves the runtime type for a given metadata token.
 /// </summary>
 /// <param name="token">The token of the type to load. This can represent a typeref, typedef or typespec token.</param>
 /// <returns>The runtime type of the specified token.</returns>
 RuntimeType ITypeModule.GetType(Token token)
 {
     return null;
 }
Exemplo n.º 17
0
 /// <summary>
 /// Retrieves the method definition identified by the given token in the scope.
 /// </summary>
 /// <param name="token">The token of the method to retrieve.</param>
 /// <returns></returns>
 RuntimeMethod ITypeModule.GetMethod(Token token)
 {
     foreach (var method in methods)
         if (method.Token == token)
             return method;
     return null;
 }
Exemplo n.º 18
0
 /// <summary>
 /// Gets the name of the external.
 /// </summary>
 /// <param name="token">The token.</param>
 /// <returns></returns>
 string ITypeModule.GetExternalName(Token token)
 {
     return null;
 }
Exemplo n.º 19
0
        /// <summary>
        /// Reads the specified token.
        /// </summary>
        /// <param name="token">The token.</param>
        /// <returns></returns>
        public TypeRefRow ReadTypeRefRow(Token token)
        {
            if (token.Table != TableType.TypeRef)
                throw new ArgumentException("Invalid token type for TypeRefRow.", @"token");

            using (var reader = CreateReaderForToken(token))
            {
                return new TypeRefRow(
                    ReadMetadataToken(reader, IndexType.ResolutionScope),
                    ReadHeapToken(reader, IndexType.StringHeap),
                    ReadHeapToken(reader, IndexType.StringHeap)
                );
            }
        }
Exemplo n.º 20
0
        /// <summary>
        /// Reads the specified token.
        /// </summary>
        /// <param name="token">The token.</param>
        /// <returns></returns>
        public StandAloneSigRow ReadStandAloneSigRow(Token token)
        {
            if (token.Table != TableType.StandAloneSig)
                throw new ArgumentException("Invalid token type for StandAloneSigRow.", @"token");

            using (var reader = CreateReaderForToken(token))
            {
                return new StandAloneSigRow(
                    ReadHeapToken(reader, IndexType.BlobHeap)
                );
            }
        }
Exemplo n.º 21
0
        /// <summary>
        /// Reads the specified token.
        /// </summary>
        /// <param name="token">The token.</param>
        /// <returns></returns>
        public TypeDefRow ReadTypeDefRow(Token token)
        {
            if (token.Table != TableType.TypeDef)
                throw new ArgumentException("Invalid token type for TypeDefRow.", @"token");

            using (var reader = CreateReaderForToken(token))
            {
                return new TypeDefRow(
                    (TypeAttributes)reader.ReadUInt32(),
                    ReadHeapToken(reader, IndexType.StringHeap),
                    ReadHeapToken(reader, IndexType.StringHeap),
                    ReadMetadataToken(reader, IndexType.TypeDefOrRef),
                    ReadIndexValue(reader, TableType.Field),
                    ReadIndexValue(reader, TableType.MethodDef)
                );
            }
        }
Exemplo n.º 22
0
        /// <summary>
        /// Reads the specified token.
        /// </summary>
        /// <param name="token">The token.</param>
        /// <returns></returns>
        public MethodDefRow ReadMethodDefRow(Token token)
        {
            if (token.Table != TableType.MethodDef)
                throw new ArgumentException("Invalid token type for MethodDefRow.", @"token");

            using (var reader = CreateReaderForToken(token))
            {
                return new MethodDefRow(
                    reader.ReadUInt32(),
                    (MethodImplAttributes)reader.ReadUInt16(),
                    (MethodAttributes)reader.ReadUInt16(),
                    ReadHeapToken(reader, IndexType.StringHeap),
                    ReadHeapToken(reader, IndexType.BlobHeap),
                    ReadIndexValue(reader, TableType.Param)
                );
            }
        }
Exemplo n.º 23
0
        /// <summary>
        /// Reads the specified token.
        /// </summary>
        /// <param name="token">The token.</param>
        /// <returns></returns>
        public TypeSpecRow ReadTypeSpecRow(Token token)
        {
            if (token.Table != TableType.TypeSpec)
                throw new ArgumentException("Invalid token type for TypeSpecRow.", @"token");

            using (var reader = CreateReaderForToken(token))
            {
                return new TypeSpecRow(
                    ReadHeapToken(reader, IndexType.BlobHeap)
                );
            }
        }
Exemplo n.º 24
0
        /// <summary>
        /// Reads the specified token.
        /// </summary>
        /// <param name="token">The token.</param>
        /// <returns></returns>
        public MethodImplRow ReadMethodImplRow(Token token)
        {
            if (token.Table != TableType.MethodImpl)
                throw new ArgumentException("Invalid token type for MethodImplRow.", @"token");

            using (var reader = CreateReaderForToken(token))
            {
                return new MethodImplRow(
                    ReadIndexValue(reader, TableType.TypeDef),
                    ReadMetadataToken(reader, IndexType.MethodDefOrRef),
                    ReadMetadataToken(reader, IndexType.MethodDefOrRef)
                );
            }
        }
Exemplo n.º 25
0
 /// <summary>
 /// Retrieves the field definition identified by the given token in the scope.
 /// </summary>
 /// <param name="token">The token of the field to retrieve.</param>
 /// <returns></returns>
 RuntimeField ITypeModule.GetField(Token token)
 {
     return null;
 }
Exemplo n.º 26
0
        /// <summary>
        /// Reads the specified token.
        /// </summary>
        /// <param name="token">The token.</param>
        /// <returns></returns>
        public MethodSemanticsRow ReadMethodSemanticsRow(Token token)
        {
            using (var reader = CreateReaderForToken(token))
            {
                if (token.Table != TableType.MethodSemantics)
                    throw new ArgumentException("Invalid token type for MethodSemanticsRow.", @"token");

                return new MethodSemanticsRow(
                    (MethodSemanticsAttributes)reader.ReadInt16(),
                    ReadIndexValue(reader, TableType.MethodDef),
                    ReadMetadataToken(reader, IndexType.HasSemantics)
                );
            }
        }
Exemplo n.º 27
0
 /// <summary>
 /// Gets the method.
 /// </summary>
 /// <param name="token">The token.</param>
 /// <param name="callingType">Type of the calling.</param>
 /// <returns></returns>
 RuntimeMethod ITypeModule.GetMethod(Token token, RuntimeType callingType)
 {
     return null;
 }
Exemplo n.º 28
0
        /// <summary>
        /// Reads the specified token.
        /// </summary>
        /// <param name="token">The token.</param>
        /// <returns></returns>
        public MethodSpecRow ReadMethodSpecRow(Token token)
        {
            if (token.Table != TableType.MethodSpec)
                throw new ArgumentException("Invalid token type for MethodSpecRow.", @"token");

            using (var reader = CreateReaderForToken(token))
            {
                return new MethodSpecRow(
                    ReadMetadataToken(reader, IndexType.MethodDefOrRef),
                    ReadHeapToken(reader, IndexType.BlobHeap)
                );
            }
        }
Exemplo n.º 29
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RuntimeMethod"/> class.
 /// </summary>
 /// <param name="token">The token.</param>
 /// <param name="declaringType">The type, which declared this method.</param>
 public RuntimeMethod(ITypeModule module, Token token, RuntimeType declaringType)
     : base(module, token, declaringType)
 {
     this.genericParameters = new List<GenericParameter>();
 }
Exemplo n.º 30
0
        /// <summary>
        /// Reads the specified token.
        /// </summary>
        /// <param name="token">The token.</param>
        /// <returns></returns>
        public ModuleRow ReadModuleRow(Token token)
        {
            if (token.Table != TableType.Module)
                throw new ArgumentException("Invalid token type for ModuleRow.", @"token");

            using (var reader = CreateReaderForToken(token))
            {
                return new ModuleRow(
                     reader.ReadUInt16(),
                     ReadHeapToken(reader, IndexType.StringHeap),
                     ReadHeapToken(reader, IndexType.GuidHeap),
                     ReadHeapToken(reader, IndexType.GuidHeap),
                     ReadHeapToken(reader, IndexType.GuidHeap)
                 );
            }
        }