Esempio n. 1
0
        protected string FormatToString(Token token)
        {
            if (!showTokenValues.Checked)
                return string.Empty;

            return "[" + TokenToString(token) + "] ";
        }
Esempio n. 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GenericParamRow"/> struct.
 /// </summary>
 /// <param name="number">The number.</param>
 /// <param name="flags">The flags.</param>
 /// <param name="owner">The owner table idx.</param>
 /// <param name="nameStringIdx">The name string idx.</param>
 public GenericParamRow(ushort number, GenericParameterAttributes flags, Token owner, HeapIndexToken nameStringIdx)
 {
     this.number = number;
     this.flags = flags;
     this.owner = owner;
     this.nameStringIdx = nameStringIdx;
 }
Esempio n. 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CilGenericType"/> class.
        /// </summary>
        /// <param name="module">The module.</param>
        /// <param name="baseGenericType">Type of the base generic.</param>
        /// <param name="genericTypeInstanceSignature">The generic type instance signature.</param>
        /// <param name="token">The token.</param>
        /// <param name="typeModule">The type module.</param>
        public CilGenericType(ITypeModule module, RuntimeType baseGenericType, GenericInstSigType genericTypeInstanceSignature, Token token, ITypeModule typeModule)
            : base(module, token, baseGenericType.BaseType)
        {
            Debug.Assert(baseGenericType is CilRuntimeType);

            this.signature = genericTypeInstanceSignature;
            this.baseGenericType = baseGenericType as CilRuntimeType;
            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();
        }
Esempio n. 4
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;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="MethodSemanticsRow"/> struct.
        /// </summary>
        /// <param name="semantics">The semantics.</param>
        /// <param name="method">The method.</param>
        /// <param name="association">The association.</param>
        public MethodSemanticsRow(MethodSemanticsAttributes semantics, Token method,
									Token association)
        {
            _semantics = semantics;
            _method = method;
            _association = association;
        }
Esempio n. 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ImplMapRow"/> struct.
        /// </summary>
        /// <param name="mappingFlags">The mapping flags.</param>
        /// <param name="memberForwardedTableIdx">The member forwarded table idx.</param>
        /// <param name="importNameStringIdx">The import name string idx.</param>
        /// <param name="importScopeTableIdx">The import scope table idx.</param>
        public ImplMapRow(PInvokeAttributes mappingFlags, Token memberForwardedTableIdx,
			HeapIndexToken importNameStringIdx, Token importScopeTableIdx)
        {
            _mappingFlags = mappingFlags;
            _memberForwardedTableIdx = memberForwardedTableIdx;
            _importNameStringIdx = importNameStringIdx;
            _importScopeTableIdx = importScopeTableIdx;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ManifestResourceRow"/> struct.
        /// </summary>
        /// <param name="offset">The offset.</param>
        /// <param name="flags">The flags.</param>
        /// <param name="nameStringIndex">Index of the name string.</param>
        /// <param name="implementation">The implementation table idx.</param>
        public ManifestResourceRow(uint offset, ManifestResourceAttributes flags, HeapIndexToken nameStringIndex,
			Token implementation)
        {
            _offset = offset;
            _flags = flags;
            _nameStringIdx = nameStringIndex;
            _implementation = implementation;
        }
Esempio n. 8
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;
 }
Esempio n. 9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ExportedTypeRow"/> struct.
        /// </summary>
        /// <param name="flags">The flags.</param>
        /// <param name="typeDef">The type def.</param>
        /// <param name="typeName">Name of the type.</param>
        /// <param name="typeNamespace">The type namespace.</param>
        /// <param name="implementation">The implementation.</param>
        public ExportedTypeRow(TypeAttributes flags, HeapIndexToken typeDef, HeapIndexToken typeName,
								HeapIndexToken typeNamespace, Token implementation)
        {
            this.flags = flags;
            this.typeDef = typeDef;
            this.typeName = typeName;
            this.typeNamespace = typeNamespace;
            this.implementation = implementation;
        }
Esempio n. 10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MethodDefRow"/> struct.
        /// </summary>
        /// <param name="rva">The rva.</param>
        /// <param name="implFlags">The impl flags.</param>
        /// <param name="flags">The flags.</param>
        /// <param name="nameStringIdx">The name string idx.</param>
        /// <param name="signatureBlobIdx">The signature BLOB idx.</param>
        /// <param name="paramList">The param list.</param>
        public MethodDefRow(uint rva, MethodImplAttributes implFlags, MethodAttributes flags, HeapIndexToken nameStringIdx,
								HeapIndexToken signatureBlobIdx, Token paramList)
        {
            this._rva = rva;
            this._implFlags = implFlags;
            this._flags = flags;
            this._nameStringIdx = nameStringIdx;
            this._signatureBlobIdx = signatureBlobIdx;
            this._paramList = paramList;
        }
Esempio n. 11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TypeDefRow"/> struct.
        /// </summary>
        /// <param name="flags">The flags.</param>
        /// <param name="typeNameIdx">The type name idx.</param>
        /// <param name="typeNamespaceIdx">The type namespace idx.</param>
        /// <param name="extends">The extends.</param>
        /// <param name="fieldList">The field list.</param>
        /// <param name="methodList">The method list.</param>
        public TypeDefRow(TypeAttributes flags, HeapIndexToken typeNameIdx, HeapIndexToken typeNamespaceIdx,
							Token extends, Token fieldList, Token methodList)
        {
            this.flags = flags;
            this.typeNameIdx = typeNameIdx;
            this.typeNamespaceIdx = typeNamespaceIdx;
            this.extends = extends;
            this.fieldList = fieldList;
            this.methodList = methodList;
        }
Esempio n. 12
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>();
        }
Esempio n. 13
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;
            }
        }
Esempio n. 14
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.Metadata, 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();
        }
Esempio n. 15
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;
            }
        }
Esempio n. 16
0
        /// <summary>
        /// Reads the specified token.
        /// </summary>
        /// <param name="token">The token.</param>
        /// <returns></returns>
        public MethodSemanticsRow ReadMethodSemanticsRow(Token token)
        {
            using (BinaryReader 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)
                );
            }
        }
Esempio n. 17
0
        /// <summary>
        /// Reads the specified token.
        /// </summary>
        /// <param name="token">The token.</param>
        /// <returns></returns>
        public ManifestResourceRow ReadManifestResourceRow(Token token)
        {
            if (token.Table != TableType.ManifestResource)
                throw new ArgumentException("Invalid token type for ManifestResourceRow.", @"token");

            using (BinaryReader reader = CreateReaderForToken(token))
            {
                return new ManifestResourceRow(
                    reader.ReadUInt32(),
                    (ManifestResourceAttributes)reader.ReadUInt32(),
                    ReadHeapToken(reader, IndexType.StringHeap),
                    ReadMetadataToken(reader, IndexType.Implementation)
                );
            }
        }
Esempio n. 18
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 (BinaryReader reader = CreateReaderForToken(token))
            {
                return new TypeSpecRow(
                    ReadHeapToken(reader, IndexType.BlobHeap)
                );
            }
        }
Esempio n. 19
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 (BinaryReader 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)
                );
            }
        }
Esempio n. 20
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 (BinaryReader 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)
                );
            }
        }
Esempio n. 21
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 (BinaryReader reader = CreateReaderForToken(token))
            {
                return new TypeRefRow(
                    ReadMetadataToken(reader, IndexType.ResolutionScope),
                    ReadHeapToken(reader, IndexType.StringHeap),
                    ReadHeapToken(reader, IndexType.StringHeap)
                );
            }
        }
Esempio n. 22
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 (BinaryReader reader = CreateReaderForToken(token))
            {
                return new PropertyRow(
                    (PropertyAttributes)reader.ReadUInt16(),
                    ReadHeapToken(reader, IndexType.StringHeap),
                    ReadHeapToken(reader, IndexType.BlobHeap)
                );
            }
        }
Esempio n. 23
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 (BinaryReader reader = CreateReaderForToken(token))
            {
                return new StandAloneSigRow(
                    ReadHeapToken(reader, IndexType.BlobHeap)
                );
            }
        }
Esempio n. 24
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 (BinaryReader reader = CreateReaderForToken(token))
            {
                return new PropertyMapRow(
                    ReadIndexValue(reader, TableType.TypeDef),
                    ReadIndexValue(reader, TableType.Property)
                );
            }
        }
Esempio n. 25
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 (BinaryReader reader = CreateReaderForToken(token))
            {
                return new NestedClassRow(
                    ReadIndexValue(reader, TableType.TypeDef),
                    ReadIndexValue(reader, TableType.TypeDef)
                );
            }
        }
Esempio n. 26
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 (BinaryReader reader = CreateReaderForToken(token))
            {
                return new ModuleRow(
                     reader.ReadUInt16(),
                     ReadHeapToken(reader, IndexType.StringHeap),
                     ReadHeapToken(reader, IndexType.GuidHeap),
                     ReadHeapToken(reader, IndexType.GuidHeap),
                     ReadHeapToken(reader, IndexType.GuidHeap)
                 );
            }
        }
Esempio n. 27
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 (BinaryReader reader = CreateReaderForToken(token))
            {
                return new MethodImplRow(
                    ReadIndexValue(reader, TableType.TypeDef),
                    ReadMetadataToken(reader, IndexType.MethodDefOrRef),
                    ReadMetadataToken(reader, IndexType.MethodDefOrRef)
                );
            }
        }
Esempio n. 28
0
 protected KeyValuePair<string, string> Value(string name, Token token)
 {
     return Value(name, token.FormatToString());
 }
Esempio n. 29
0
        private RuntimeMethod FindMethodByToken(RuntimeType type, Token methodToken)
        {
            foreach (RuntimeMethod method in type.Methods)
            {
                if (method.Token == methodToken)
                {
                    return method;
                }
            }

            throw new InvalidOperationException(@"Failed to find explicit interface method implementation.");
        }
Esempio n. 30
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 (BinaryReader reader = CreateReaderForToken(token))
            {
                return new MethodSpecRow(
                    ReadMetadataToken(reader, IndexType.MethodDefOrRef),
                    ReadHeapToken(reader, IndexType.BlobHeap)
                );
            }
        }