コード例 #1
0
        public AssemblyLoader()
        {
            _signatureResolver = new SignatureResolver(this);

            _assemblyTable = new AssemblyTable(this);

            Const             = new ConstantTable(this);
            Files             = new FileTable(this);
            ManifestResources = new ManifestResourceTable(this);

            Modules = new ModuleTable(this);

            ModuleRefs   = new ModuleRefTable(this);
            AssemblyRefs = new AssemblyRefTable(this);

            TypeRefs    = new TypeRefTable(this);
            MemberRefs  = new MemberRefTable(this);
            _typeSpec   = new TypeSpecTable(this);
            _methodSpec = new MethodSpecTable(this);

            Parameters        = new ParamTable(this);
            Fields            = new FieldTable(this);
            Properties        = new PropertyTable(this);
            Events            = new EventTable(this);
            GenericParameters = new GenericParamTable(this);

            Methods = new MethodTable(this);
            Types   = new TypeTable(this);
        }
コード例 #2
0
        private bool IsWindowsAttributeUsageAttribute(EntityHandle targetType, CustomAttributeHandle attributeHandle)
        {
            // Check for Windows.Foundation.Metadata.AttributeUsageAttribute.
            // WinMD rules:
            //   - The attribute is only applicable on TypeDefs.
            //   - Constructor must be a MemberRef with TypeRef.

            if (targetType.Kind != HandleKind.TypeDefinition)
            {
                return(false);
            }

            var attributeCtor = CustomAttributeTable.GetConstructor(attributeHandle);

            if (attributeCtor.Kind != HandleKind.MemberReference)
            {
                return(false);
            }

            var attributeType = MemberRefTable.GetClass((MemberReferenceHandle)attributeCtor);

            if (attributeType.Kind != HandleKind.TypeReference)
            {
                return(false);
            }

            var attributeTypeRef = (TypeReferenceHandle)attributeType;

            return(StringStream.EqualsRaw(TypeRefTable.GetName(attributeTypeRef), "AttributeUsageAttribute") &&
                   StringStream.EqualsRaw(TypeRefTable.GetNamespace(attributeTypeRef), "Windows.Foundation.Metadata"));
        }
コード例 #3
0
ファイル: IndexManager.cs プロジェクト: GeGuNa/mona-os
        public string GetName(MemberRefTable m)
        {
            string n = this.GetStringsString(m.Name);

            if (m.ParentTable == null)
            {
                return(n);
            }
            return(this.GetName(m.ParentTable as TypeRefTable) + "::" + n);
        }
コード例 #4
0
        void EncodeMemberRefTable(MemberRefTable table)
        {
            int index = 0;

            foreach (MemberRefRow row in table.Rows)
            {
                this.asm.ALIGN(Assembly.OBJECT_ALIGNMENT);
                this.asm.LABEL(moduleName + " MemberRefRow#" + index);
                this.asm.AddObjectFields(typeof(SharpOS.AOT.Metadata.MemberRefRow).ToString());
                this.asm.DATA(row.Class.ToUInt());
                this.asm.DATA(row.Name);
                this.asm.DATA(row.Signature);
                ++index;
            }

            this.MetadataArray("MemberRef", table);
        }
コード例 #5
0
        /// <summary>
        /// We want to know if a given method implements a redirected interface.
        /// For example, if we are given the method RemoveAt on a class "A"
        /// which implements the IVector interface (which is redirected
        /// to IList in .NET) then this method would return true. The most
        /// likely reason why we would want to know this is that we wish to hide
        /// (mark private) all methods which implement methods on a redirected
        /// interface.
        /// </summary>
        /// <param name="memberRef">The declaration token for the method</param>
        /// <param name="isIDisposable">
        /// Returns true if the redirected interface is <see cref="IDisposable"/>.
        /// </param>
        /// <returns>True if the method implements a method on a redirected interface.
        /// False otherwise.</returns>
        private bool ImplementsRedirectedInterface(MemberReferenceHandle memberRef, out bool isIDisposable)
        {
            isIDisposable = false;

            EntityHandle parent = MemberRefTable.GetClass(memberRef);

            TypeReferenceHandle typeRef;

            if (parent.Kind == HandleKind.TypeReference)
            {
                typeRef = (TypeReferenceHandle)parent;
            }
            else if (parent.Kind == HandleKind.TypeSpecification)
            {
                BlobHandle blob = TypeSpecTable.GetSignature((TypeSpecificationHandle)parent);
                BlobReader sig  = new BlobReader(BlobStream.GetMemoryBlock(blob));

                if (sig.Length < 2 ||
                    sig.ReadByte() != (byte)CorElementType.ELEMENT_TYPE_GENERICINST ||
                    sig.ReadByte() != (byte)CorElementType.ELEMENT_TYPE_CLASS)
                {
                    return(false);
                }

                EntityHandle token = sig.ReadTypeHandle();
                if (token.Kind != HandleKind.TypeReference)
                {
                    return(false);
                }

                typeRef = (TypeReferenceHandle)token;
            }
            else
            {
                return(false);
            }

            return(GetProjectionIndexForTypeReference(typeRef, out isIDisposable) >= 0);
        }
コード例 #6
0
        /// <summary>
        /// Returns the type definition or reference handle of the attribute type.
        /// </summary>
        /// <returns><see cref="TypeDefinitionHandle"/> or <see cref="TypeReferenceHandle"/> or nil token if the metadata is invalid and the type can't be determined.</returns>
        private EntityHandle GetAttributeTypeRaw(CustomAttributeHandle handle)
        {
            var ctor = CustomAttributeTable.GetConstructor(handle);

            if (ctor.Kind == HandleKind.MethodDefinition)
            {
                return(GetDeclaringType((MethodDefinitionHandle)ctor));
            }

            if (ctor.Kind == HandleKind.MemberReference)
            {
                // In general the parent can be MethodDef, ModuleRef, TypeDef, TypeRef, or TypeSpec.
                // For attributes only TypeDef and TypeRef are applicable.
                EntityHandle typeDefOrRef = MemberRefTable.GetClass((MemberReferenceHandle)ctor);
                HandleKind   handleType   = typeDefOrRef.Kind;

                if (handleType == HandleKind.TypeReference || handleType == HandleKind.TypeDefinition)
                {
                    return(typeDefOrRef);
                }
            }

            return(default(EntityHandle));
        }
コード例 #7
0
 public virtual void VisitMemberRefTable(MemberRefTable table)
 {
 }
コード例 #8
0
ファイル: MetadataTables.cs プロジェクト: modulexcite/IL2JS
        public void Read(ReaderContext ctxt)
        {
            var reader = ctxt.GetTablesReader();

            var actualReserved0 = reader.ReadUInt32();
            if (actualReserved0 != reserved0)
                throw new PEException("invalid MetadataTable header");
            var actualMajorVersion = reader.ReadByte();
            if (actualMajorVersion != majorVersion)
                throw new PEException("invalid MetadataTable header");
            var actualMinorVersion = reader.ReadByte();
            if (actualMinorVersion != minorVersion)
                throw new PEException("invalid MetadataTable header");
            var heapSizes = reader.ReadByte();
            IsStringStreamBig = (heapSizes & 0x01) != 0;
            IsGuidStreamBig = (heapSizes & 0x02) != 0;
            IsBlobStreamBig = (heapSizes & 0x04) != 0;
            Reserved1 = reader.ReadByte();

            var valid = new IntSet64(reader.ReadUInt64());
            var sorted = new IntSet64(reader.ReadUInt64());

            for (var i = 0; i < 64; i++)
            {
                var numRows = 0;
                if (valid[i])
                    numRows = (int)reader.ReadUInt32();

                switch ((TableTag)i)
                {
                case TableTag.Module:
                    ModuleTable = new ModuleTable(numRows);
                    break;
                case TableTag.Assembly:
                    AssemblyTable = new AssemblyTable(numRows);
                    break;
                case TableTag.AssemblyOS:
                    AssemblyOSTable = new AssemblyOSTable(numRows);
                    break;
                case TableTag.AssemblyProcessor:
                    AssemblyProcessorTable = new AssemblyProcessorTable(numRows);
                    break;
                case TableTag.AssemblyRef:
                    AssemblyRefTable = new AssemblyRefTable(numRows);
                    break;
                case TableTag.AssemblyRefOS:
                    AssemblyRefOSTable = new AssemblyRefOSTable(numRows);
                    break;
                case TableTag.AssemblyRefProcessor:
                    AssemblyRefProcessorTable = new AssemblyRefProcessorTable(numRows);
                    break;
                case TableTag.ClassLayout:
                    ClassLayoutTable = new ClassLayoutTable(numRows);
                    break;
                case TableTag.Constant:
                    ConstantTable = new ConstantTable(numRows);
                    break;
                case TableTag.CustomAttribute:
                    CustomAttributeTable = new CustomAttributeTable(numRows);
                    break;
                case TableTag.DeclSecurity:
                    DeclSecurityTable = new DeclSecurityTable(numRows);
                    break;
                case TableTag.EventMap:
                    EventMapTable = new EventMapTable(numRows);
                    break;
                case TableTag.Event:
                    EventTable = new EventTable(numRows);
                    break;
                case TableTag.ExportedType:
                    ExportedTypeTable = new ExportedTypeTable(numRows);
                    break;
                case TableTag.Field:
                    FieldTable = new FieldTable(numRows);
                    break;
                case TableTag.FieldLayout:
                    FieldLayoutTable = new FieldLayoutTable(numRows);
                    break;
                case TableTag.FieldMarshal:
                    FieldMarshalTable = new FieldMarshalTable(numRows);
                    break;
                case TableTag.FieldRVA:
                    FieldRVATable = new FieldRVATable(numRows);
                    break;
                case TableTag.File:
                    FileTable = new FileTable(numRows);
                    break;
                case TableTag.GenericParam:
                    GenericParamTable = new GenericParamTable(numRows);
                    break;
                case TableTag.GenericParamConstraint:
                    GenericParamConstraintTable = new GenericParamConstraintTable(numRows);
                    break;
                case TableTag.ImplMap:
                    ImplMapTable = new ImplMapTable(numRows);
                    break;
                case TableTag.InterfaceImpl:
                    InterfaceImplTable = new InterfaceImplTable(numRows);
                    break;
                case TableTag.ManifestResource:
                    ManifestResourceTable = new ManifestResourceTable(numRows);
                    break;
                case TableTag.MemberRef:
                    MemberRefTable = new MemberRefTable(numRows);
                    break;
                case TableTag.MethodDef:
                    MethodDefTable = new MethodDefTable(numRows);
                    break;
                case TableTag.MethodImpl:
                    MethodImplTable = new MethodImplTable(numRows);
                    break;
                case TableTag.MethodSemantics:
                    MethodSemanticsTable = new MethodSemanticsTable(numRows);
                    break;
                case TableTag.MethodSpec:
                    MethodSpecTable = new MethodSpecTable(numRows);
                    break;
                case TableTag.ModuleRef:
                    ModuleRefTable = new ModuleRefTable(numRows);
                    break;
                case TableTag.NestedClass:
                    NestedClassTable = new NestedClassTable(numRows);
                    break;
                case TableTag.Param:
                    ParamTable = new ParamTable(numRows);
                    break;
                case TableTag.Property:
                    PropertyTable = new PropertyTable(numRows);
                    break;
                case TableTag.PropertyMap:
                    PropertyMapTable = new PropertyMapTable(numRows);
                    break;
                case TableTag.StandAloneSig:
                    StandAloneSigTable = new StandAloneSigTable(numRows);
                    break;
                case TableTag.TypeDef:
                    TypeDefTable = new TypeDefTable(numRows);
                    break;
                case TableTag.TypeRef:
                    TypeRefTable = new TypeRefTable(numRows);
                    break;
                case TableTag.TypeSpec:
                    TypeSpecTable = new TypeSpecTable(numRows);
                    break;
                default:
                    // Ignore
                    break;
                }
            }

            DetermineIndexCodingSizes();

            for (var i = 0; i < 64; i++)
            {
                if (valid[i])
                {
                    switch ((TableTag)i)
                    {
                    case TableTag.Module:
                        ModuleTable.Read(ctxt, reader);
                        break;
                    case TableTag.Assembly:
                        AssemblyTable.Read(ctxt, reader);
                        break;
                    case TableTag.AssemblyOS:
                        AssemblyOSTable.Read(ctxt, reader);
                        break;
                    case TableTag.AssemblyProcessor:
                        AssemblyProcessorTable.Read(ctxt, reader);
                        break;
                    case TableTag.AssemblyRef:
                        AssemblyRefTable.Read(ctxt, reader);
                        break;
                    case TableTag.AssemblyRefOS:
                        AssemblyRefOSTable.Read(ctxt, reader);
                        break;
                    case TableTag.AssemblyRefProcessor:
                        AssemblyRefProcessorTable.Read(ctxt, reader);
                        break;
                    case TableTag.ClassLayout:
                        ClassLayoutTable.Read(ctxt, reader);
                        break;
                    case TableTag.Constant:
                        ConstantTable.Read(ctxt, reader);
                        break;
                    case TableTag.CustomAttribute:
                        CustomAttributeTable.Read(ctxt, reader);
                        break;
                    case TableTag.DeclSecurity:
                        DeclSecurityTable.Read(ctxt, reader);
                        break;
                    case TableTag.EventMap:
                        EventMapTable.Read(ctxt, reader);
                        break;
                    case TableTag.Event:
                        EventTable.Read(ctxt, reader);
                        break;
                    case TableTag.ExportedType:
                        ExportedTypeTable.Read(ctxt, reader);
                        break;
                    case TableTag.Field:
                        FieldTable.Read(ctxt, reader);
                        break;
                    case TableTag.FieldLayout:
                        FieldLayoutTable.Read(ctxt, reader);
                        break;
                    case TableTag.FieldMarshal:
                        FieldMarshalTable.Read(ctxt, reader);
                        break;
                    case TableTag.FieldRVA:
                        FieldRVATable.Read(ctxt, reader);
                        break;
                    case TableTag.File:
                        FileTable.Read(ctxt, reader);
                        break;
                    case TableTag.GenericParam:
                        GenericParamTable.Read(ctxt, reader);
                        break;
                    case TableTag.GenericParamConstraint:
                        GenericParamConstraintTable.Read(ctxt, reader);
                        break;
                    case TableTag.ImplMap:
                        ImplMapTable.Read(ctxt, reader);
                        break;
                    case TableTag.InterfaceImpl:
                        InterfaceImplTable.Read(ctxt, reader);
                        break;
                    case TableTag.ManifestResource:
                        ManifestResourceTable.Read(ctxt, reader);
                        break;
                    case TableTag.MemberRef:
                        MemberRefTable.Read(ctxt, reader);
                        break;
                    case TableTag.MethodDef:
                        MethodDefTable.Read(ctxt, reader);
                        break;
                    case TableTag.MethodImpl:
                        MethodImplTable.Read(ctxt, reader);
                        break;
                    case TableTag.MethodSemantics:
                        MethodSemanticsTable.Read(ctxt, reader);
                        break;
                    case TableTag.MethodSpec:
                        MethodSpecTable.Read(ctxt, reader);
                        break;
                    case TableTag.ModuleRef:
                        ModuleRefTable.Read(ctxt, reader);
                        break;
                    case TableTag.NestedClass:
                        NestedClassTable.Read(ctxt, reader);
                        break;
                    case TableTag.Param:
                        ParamTable.Read(ctxt, reader);
                        break;
                    case TableTag.Property:
                        PropertyTable.Read(ctxt, reader);
                        break;
                    case TableTag.PropertyMap:
                        PropertyMapTable.Read(ctxt, reader);
                        break;
                    case TableTag.StandAloneSig:
                        StandAloneSigTable.Read(ctxt, reader);
                        break;
                    case TableTag.TypeDef:
                        TypeDefTable.Read(ctxt, reader);
                        break;
                    case TableTag.TypeRef:
                        TypeRefTable.Read(ctxt, reader);
                        break;
                    case TableTag.TypeSpec:
                        TypeSpecTable.Read(ctxt, reader);
                        break;
                    default:
                        throw new PEException("unexpected table tag in MetadataTable body");
                    }
                }
            }

            ModuleTable.ResolveIndexes(ctxt);
            TypeRefTable.ResolveIndexes(ctxt);
            TypeDefTable.ResolveIndexes(ctxt);
            FieldTable.ResolveIndexes(ctxt);
            MethodDefTable.ResolveIndexes(ctxt);
            ParamTable.ResolveIndexes(ctxt);
            InterfaceImplTable.ResolveIndexes(ctxt);
            MemberRefTable.ResolveIndexes(ctxt);
            ConstantTable.ResolveIndexes(ctxt);
            CustomAttributeTable.ResolveIndexes(ctxt);
            FieldMarshalTable.ResolveIndexes(ctxt);
            DeclSecurityTable.ResolveIndexes(ctxt);
            ClassLayoutTable.ResolveIndexes(ctxt);
            FieldLayoutTable.ResolveIndexes(ctxt);
            StandAloneSigTable.ResolveIndexes(ctxt);
            EventMapTable.ResolveIndexes(ctxt);
            EventTable.ResolveIndexes(ctxt);
            PropertyMapTable.ResolveIndexes(ctxt);
            PropertyTable.ResolveIndexes(ctxt);
            MethodSemanticsTable.ResolveIndexes(ctxt);
            MethodImplTable.ResolveIndexes(ctxt);
            ModuleRefTable.ResolveIndexes(ctxt);
            TypeSpecTable.ResolveIndexes(ctxt);
            ImplMapTable.ResolveIndexes(ctxt);
            FieldRVATable.ResolveIndexes(ctxt);
            AssemblyTable.ResolveIndexes(ctxt);
            AssemblyProcessorTable.ResolveIndexes(ctxt);
            AssemblyOSTable.ResolveIndexes(ctxt);
            AssemblyRefTable.ResolveIndexes(ctxt);
            AssemblyRefProcessorTable.ResolveIndexes(ctxt);
            AssemblyRefOSTable.ResolveIndexes(ctxt);
            FileTable.ResolveIndexes(ctxt);
            ExportedTypeTable.ResolveIndexes(ctxt);
            ManifestResourceTable.ResolveIndexes(ctxt);
            NestedClassTable.ResolveIndexes(ctxt);
            GenericParamTable.ResolveIndexes(ctxt);
            MethodSpecTable.ResolveIndexes(ctxt);
            GenericParamConstraintTable.ResolveIndexes(ctxt);
        }
コード例 #9
0
 public virtual void VisitMemberRefTable(MemberRefTable table)
 {
 }
コード例 #10
0
 /// <summary>
 /// コンストラクタです。
 /// </summary>
 public MethodData(PEData data, MemberRefTable m)
 {
     MethodData.Initialize();
     this.Parse(data, m);
 }
コード例 #11
0
ファイル: IndexManager.cs プロジェクト: GeGuNa/mona-os
        public void MakeTree(PEData data)
        {
            ArrayList listType = this.Tables[(int)MetadataTables.TypeDef];
            int       len      = listType.Count;

            for (int i = 0; i < len; i++)
            {
                this.MakeTree(listType[i] as TypeDefTable, i + 1 < len ? listType[i + 1] as TypeDefTable : null);
            }
            foreach (object obj in this.Tables[(int)MetadataTables.AssemblyRef])
            {
                (obj as TableBase).Children = new ArrayList[]
                {
                    new ArrayList()
                }
                ;
            }
            foreach (object obj in this.Tables[(int)MetadataTables.TypeRef])
            {
                (obj as TableBase).Children = new ArrayList[]
                {
                    new ArrayList(), new ArrayList(), new ArrayList()
                }
                ;
            }
            foreach (object obj in this.Tables[(int)MetadataTables.TypeRef])
            {
                TypeRefTable t = obj as TypeRefTable;
                if (t.ResolutionScope == 0)
                {
                    continue;
                }
                t.ParentTable = this.GetTable(this.GetToken(CodedIndices.ResolutionScope, t.ResolutionScope));
                t.ParentTable.Children[(int)Children.RefNested].Add(t);
            }
            foreach (object obj in this.Tables[(int)MetadataTables.MethodDef])
            {
                MethodDefTable m = obj as MethodDefTable;
                m.Tag = new MethodData(data, m);
            }
            foreach (object obj in this.Tables[(int)MetadataTables.MemberRef])
            {
                MemberRefTable m  = obj as MemberRefTable;
                MethodData     md = new MethodData(data, m);
                m.Tag = md;
                if (m.Class == 0)
                {
                    continue;
                }
                m.ParentTable = this.GetTable(this.GetToken(CodedIndices.MemberRefParent, m.Class));
                if (md.IsField)
                {
                    m.ParentTable.Children[(int)Children.RefField].Add(m);
                }
                else
                {
                    m.ParentTable.Children[(int)Children.RefMethod].Add(m);
                }
            }
            foreach (object obj in this.Tables[(int)MetadataTables.ImplMap])
            {
                ImplMapTable   im = obj as ImplMapTable;
                MethodDefTable m  = this.GetTable(this.GetToken(CodedIndices.MemberForwarded, im.MemberForwarded)) as MethodDefTable;
                if (m != null)
                {
                    (m.Tag as MethodData).ImplMap = im;
                }
            }
            foreach (object obj in this.Tables[(int)MetadataTables.NestedClass])
            {
                NestedClassTable nc  = obj as NestedClassTable;
                TypeDefTable     nst = listType[nc.NestedClass - 1] as TypeDefTable;
                TypeDefTable     enc = listType[nc.EnclosingClass - 1] as TypeDefTable;
                nst.ParentTable = enc;
                enc.Children[(int)Children.DefNested].Add(nst);
            }
        }
コード例 #12
0
        public void Read(ReaderContext ctxt)
        {
            var reader = ctxt.GetTablesReader();

            var actualReserved0 = reader.ReadUInt32();

            if (actualReserved0 != reserved0)
            {
                throw new PEException("invalid MetadataTable header");
            }
            var actualMajorVersion = reader.ReadByte();

            if (actualMajorVersion != majorVersion)
            {
                throw new PEException("invalid MetadataTable header");
            }
            var actualMinorVersion = reader.ReadByte();

            if (actualMinorVersion != minorVersion)
            {
                throw new PEException("invalid MetadataTable header");
            }
            var heapSizes = reader.ReadByte();

            IsStringStreamBig = (heapSizes & 0x01) != 0;
            IsGuidStreamBig   = (heapSizes & 0x02) != 0;
            IsBlobStreamBig   = (heapSizes & 0x04) != 0;
            Reserved1         = reader.ReadByte();

            var valid  = new IntSet64(reader.ReadUInt64());
            var sorted = new IntSet64(reader.ReadUInt64());

            for (var i = 0; i < 64; i++)
            {
                var numRows = 0;
                if (valid[i])
                {
                    numRows = (int)reader.ReadUInt32();
                }

                switch ((TableTag)i)
                {
                case TableTag.Module:
                    ModuleTable = new ModuleTable(numRows);
                    break;

                case TableTag.Assembly:
                    AssemblyTable = new AssemblyTable(numRows);
                    break;

                case TableTag.AssemblyOS:
                    AssemblyOSTable = new AssemblyOSTable(numRows);
                    break;

                case TableTag.AssemblyProcessor:
                    AssemblyProcessorTable = new AssemblyProcessorTable(numRows);
                    break;

                case TableTag.AssemblyRef:
                    AssemblyRefTable = new AssemblyRefTable(numRows);
                    break;

                case TableTag.AssemblyRefOS:
                    AssemblyRefOSTable = new AssemblyRefOSTable(numRows);
                    break;

                case TableTag.AssemblyRefProcessor:
                    AssemblyRefProcessorTable = new AssemblyRefProcessorTable(numRows);
                    break;

                case TableTag.ClassLayout:
                    ClassLayoutTable = new ClassLayoutTable(numRows);
                    break;

                case TableTag.Constant:
                    ConstantTable = new ConstantTable(numRows);
                    break;

                case TableTag.CustomAttribute:
                    CustomAttributeTable = new CustomAttributeTable(numRows);
                    break;

                case TableTag.DeclSecurity:
                    DeclSecurityTable = new DeclSecurityTable(numRows);
                    break;

                case TableTag.EventMap:
                    EventMapTable = new EventMapTable(numRows);
                    break;

                case TableTag.Event:
                    EventTable = new EventTable(numRows);
                    break;

                case TableTag.ExportedType:
                    ExportedTypeTable = new ExportedTypeTable(numRows);
                    break;

                case TableTag.Field:
                    FieldTable = new FieldTable(numRows);
                    break;

                case TableTag.FieldLayout:
                    FieldLayoutTable = new FieldLayoutTable(numRows);
                    break;

                case TableTag.FieldMarshal:
                    FieldMarshalTable = new FieldMarshalTable(numRows);
                    break;

                case TableTag.FieldRVA:
                    FieldRVATable = new FieldRVATable(numRows);
                    break;

                case TableTag.File:
                    FileTable = new FileTable(numRows);
                    break;

                case TableTag.GenericParam:
                    GenericParamTable = new GenericParamTable(numRows);
                    break;

                case TableTag.GenericParamConstraint:
                    GenericParamConstraintTable = new GenericParamConstraintTable(numRows);
                    break;

                case TableTag.ImplMap:
                    ImplMapTable = new ImplMapTable(numRows);
                    break;

                case TableTag.InterfaceImpl:
                    InterfaceImplTable = new InterfaceImplTable(numRows);
                    break;

                case TableTag.ManifestResource:
                    ManifestResourceTable = new ManifestResourceTable(numRows);
                    break;

                case TableTag.MemberRef:
                    MemberRefTable = new MemberRefTable(numRows);
                    break;

                case TableTag.MethodDef:
                    MethodDefTable = new MethodDefTable(numRows);
                    break;

                case TableTag.MethodImpl:
                    MethodImplTable = new MethodImplTable(numRows);
                    break;

                case TableTag.MethodSemantics:
                    MethodSemanticsTable = new MethodSemanticsTable(numRows);
                    break;

                case TableTag.MethodSpec:
                    MethodSpecTable = new MethodSpecTable(numRows);
                    break;

                case TableTag.ModuleRef:
                    ModuleRefTable = new ModuleRefTable(numRows);
                    break;

                case TableTag.NestedClass:
                    NestedClassTable = new NestedClassTable(numRows);
                    break;

                case TableTag.Param:
                    ParamTable = new ParamTable(numRows);
                    break;

                case TableTag.Property:
                    PropertyTable = new PropertyTable(numRows);
                    break;

                case TableTag.PropertyMap:
                    PropertyMapTable = new PropertyMapTable(numRows);
                    break;

                case TableTag.StandAloneSig:
                    StandAloneSigTable = new StandAloneSigTable(numRows);
                    break;

                case TableTag.TypeDef:
                    TypeDefTable = new TypeDefTable(numRows);
                    break;

                case TableTag.TypeRef:
                    TypeRefTable = new TypeRefTable(numRows);
                    break;

                case TableTag.TypeSpec:
                    TypeSpecTable = new TypeSpecTable(numRows);
                    break;

                default:
                    // Ignore
                    break;
                }
            }

            DetermineIndexCodingSizes();

            for (var i = 0; i < 64; i++)
            {
                if (valid[i])
                {
                    switch ((TableTag)i)
                    {
                    case TableTag.Module:
                        ModuleTable.Read(ctxt, reader);
                        break;

                    case TableTag.Assembly:
                        AssemblyTable.Read(ctxt, reader);
                        break;

                    case TableTag.AssemblyOS:
                        AssemblyOSTable.Read(ctxt, reader);
                        break;

                    case TableTag.AssemblyProcessor:
                        AssemblyProcessorTable.Read(ctxt, reader);
                        break;

                    case TableTag.AssemblyRef:
                        AssemblyRefTable.Read(ctxt, reader);
                        break;

                    case TableTag.AssemblyRefOS:
                        AssemblyRefOSTable.Read(ctxt, reader);
                        break;

                    case TableTag.AssemblyRefProcessor:
                        AssemblyRefProcessorTable.Read(ctxt, reader);
                        break;

                    case TableTag.ClassLayout:
                        ClassLayoutTable.Read(ctxt, reader);
                        break;

                    case TableTag.Constant:
                        ConstantTable.Read(ctxt, reader);
                        break;

                    case TableTag.CustomAttribute:
                        CustomAttributeTable.Read(ctxt, reader);
                        break;

                    case TableTag.DeclSecurity:
                        DeclSecurityTable.Read(ctxt, reader);
                        break;

                    case TableTag.EventMap:
                        EventMapTable.Read(ctxt, reader);
                        break;

                    case TableTag.Event:
                        EventTable.Read(ctxt, reader);
                        break;

                    case TableTag.ExportedType:
                        ExportedTypeTable.Read(ctxt, reader);
                        break;

                    case TableTag.Field:
                        FieldTable.Read(ctxt, reader);
                        break;

                    case TableTag.FieldLayout:
                        FieldLayoutTable.Read(ctxt, reader);
                        break;

                    case TableTag.FieldMarshal:
                        FieldMarshalTable.Read(ctxt, reader);
                        break;

                    case TableTag.FieldRVA:
                        FieldRVATable.Read(ctxt, reader);
                        break;

                    case TableTag.File:
                        FileTable.Read(ctxt, reader);
                        break;

                    case TableTag.GenericParam:
                        GenericParamTable.Read(ctxt, reader);
                        break;

                    case TableTag.GenericParamConstraint:
                        GenericParamConstraintTable.Read(ctxt, reader);
                        break;

                    case TableTag.ImplMap:
                        ImplMapTable.Read(ctxt, reader);
                        break;

                    case TableTag.InterfaceImpl:
                        InterfaceImplTable.Read(ctxt, reader);
                        break;

                    case TableTag.ManifestResource:
                        ManifestResourceTable.Read(ctxt, reader);
                        break;

                    case TableTag.MemberRef:
                        MemberRefTable.Read(ctxt, reader);
                        break;

                    case TableTag.MethodDef:
                        MethodDefTable.Read(ctxt, reader);
                        break;

                    case TableTag.MethodImpl:
                        MethodImplTable.Read(ctxt, reader);
                        break;

                    case TableTag.MethodSemantics:
                        MethodSemanticsTable.Read(ctxt, reader);
                        break;

                    case TableTag.MethodSpec:
                        MethodSpecTable.Read(ctxt, reader);
                        break;

                    case TableTag.ModuleRef:
                        ModuleRefTable.Read(ctxt, reader);
                        break;

                    case TableTag.NestedClass:
                        NestedClassTable.Read(ctxt, reader);
                        break;

                    case TableTag.Param:
                        ParamTable.Read(ctxt, reader);
                        break;

                    case TableTag.Property:
                        PropertyTable.Read(ctxt, reader);
                        break;

                    case TableTag.PropertyMap:
                        PropertyMapTable.Read(ctxt, reader);
                        break;

                    case TableTag.StandAloneSig:
                        StandAloneSigTable.Read(ctxt, reader);
                        break;

                    case TableTag.TypeDef:
                        TypeDefTable.Read(ctxt, reader);
                        break;

                    case TableTag.TypeRef:
                        TypeRefTable.Read(ctxt, reader);
                        break;

                    case TableTag.TypeSpec:
                        TypeSpecTable.Read(ctxt, reader);
                        break;

                    default:
                        throw new PEException("unexpected table tag in MetadataTable body");
                    }
                }
            }

            ModuleTable.ResolveIndexes(ctxt);
            TypeRefTable.ResolveIndexes(ctxt);
            TypeDefTable.ResolveIndexes(ctxt);
            FieldTable.ResolveIndexes(ctxt);
            MethodDefTable.ResolveIndexes(ctxt);
            ParamTable.ResolveIndexes(ctxt);
            InterfaceImplTable.ResolveIndexes(ctxt);
            MemberRefTable.ResolveIndexes(ctxt);
            ConstantTable.ResolveIndexes(ctxt);
            CustomAttributeTable.ResolveIndexes(ctxt);
            FieldMarshalTable.ResolveIndexes(ctxt);
            DeclSecurityTable.ResolveIndexes(ctxt);
            ClassLayoutTable.ResolveIndexes(ctxt);
            FieldLayoutTable.ResolveIndexes(ctxt);
            StandAloneSigTable.ResolveIndexes(ctxt);
            EventMapTable.ResolveIndexes(ctxt);
            EventTable.ResolveIndexes(ctxt);
            PropertyMapTable.ResolveIndexes(ctxt);
            PropertyTable.ResolveIndexes(ctxt);
            MethodSemanticsTable.ResolveIndexes(ctxt);
            MethodImplTable.ResolveIndexes(ctxt);
            ModuleRefTable.ResolveIndexes(ctxt);
            TypeSpecTable.ResolveIndexes(ctxt);
            ImplMapTable.ResolveIndexes(ctxt);
            FieldRVATable.ResolveIndexes(ctxt);
            AssemblyTable.ResolveIndexes(ctxt);
            AssemblyProcessorTable.ResolveIndexes(ctxt);
            AssemblyOSTable.ResolveIndexes(ctxt);
            AssemblyRefTable.ResolveIndexes(ctxt);
            AssemblyRefProcessorTable.ResolveIndexes(ctxt);
            AssemblyRefOSTable.ResolveIndexes(ctxt);
            FileTable.ResolveIndexes(ctxt);
            ExportedTypeTable.ResolveIndexes(ctxt);
            ManifestResourceTable.ResolveIndexes(ctxt);
            NestedClassTable.ResolveIndexes(ctxt);
            GenericParamTable.ResolveIndexes(ctxt);
            MethodSpecTable.ResolveIndexes(ctxt);
            GenericParamConstraintTable.ResolveIndexes(ctxt);
        }