Exemple #1
0
        public static MemberRange <T> CreateRange <T>(MetaDataMember member, int mdrowIndex, MetaDataTable targetTable) where T : MetaDataMember
        {
            MemberRange <T> range = new MemberRange <T>();

            range.Start       = Convert.ToInt32(member.MetaDataRow.Parts[mdrowIndex]) - 1;
            range.TargetTable = targetTable;

            MetaDataTable currentTable = member.NETHeader.TablesHeap.GetTable(member.Table, false);
            int           memberIndex  = (int)(member.metadatatoken | (0xFF << 24)) - (0xFF << 24);

            if (currentTable != null)
            {
                if (memberIndex == currentTable.AmountOfRows)
                {
                    range.Length = targetTable.AmountOfRows - range.Start;
                }
                else
                {
                    int nextIndex = Convert.ToInt32(currentTable.Members[memberIndex].MetaDataRow.parts[mdrowIndex]) - 1;
                    range.Length = nextIndex - range.Start;
                }
            }
            if (range.Length > targetTable.AmountOfRows - range.Start)
            {
                range.Length = 0;
            }

            return(range);
        }
Exemple #2
0
        public void AddTable(MetaDataTableType type)
        {
            MetaDataTable table = new MetaDataTable(this, true);

            table._type        = type;
            _tables[(int)type] = table;
            MaskValid         |= ((ulong)1 << (int)type);
        }
Exemple #3
0
        public uint GetCodedIndex(MetaDataMember member)
        {
            if (member == null)
            {
                return(0);
            }

            MetaDataTable table = tables.FirstOrDefault(t => t != null && t.Type == member.Table);

            if (table == null)
            {
                throw new ArgumentException("Member does not belong to the metadata table group.");
            }

            uint rowIndex   = ((uint)(member.metadatatoken - ((uint)table.Type << 24)));
            uint tableIndex = (uint)Array.IndexOf(tables, table);

            return((rowIndex << bits) | tableIndex);
        }
        internal MetaDataTable CreateTable(MetaDataTableType type, int rowAmount, long rowAmountOffset)
        {
            //customattribute[permission]?

            MetaDataTable table = new MetaDataTable(tableheap);
            table.Type = type;
            table.rowAmount = rowAmount;
            table.rowAmountOffset = rowAmountOffset;
            switch (type)
            {
                case MetaDataTableType.Assembly:
                    HasCustomAttribute[14] = table;
                    HasDeclSecurity[2] = table;
                    break;
                case MetaDataTableType.AssemblyRef:
                    HasCustomAttribute[15] = table;
                    Implementation[1] = table;
                    ResolutionScope[2] = table;
                    break;
                case MetaDataTableType.Event:
                    HasCustomAttribute[10] = table;
                    HasSemantics[0] = table;
                    break;
                case MetaDataTableType.ExportedType:
                    HasCustomAttribute[17] = table;
                    Implementation[2] = table;
                    break;
                case MetaDataTableType.Field:
                    HasConstant[0] = table;
                    HasCustomAttribute[1] = table;
                    HasFieldMarshall[0] = table;
                    MemberForwarded[0] = table;
                    break;
                case MetaDataTableType.File:
                    HasCustomAttribute[16] = table;
                    Implementation[0] = table;
                    break;
                case MetaDataTableType.GenericParam:
                    HasCustomAttribute[19] = table;
                    break;
                case MetaDataTableType.GenericParamConstraint:
                    HasCustomAttribute[20] = table;
                    break;
                case MetaDataTableType.InterfaceImpl:
                    HasCustomAttribute[5] = table;
                    break;
                case MetaDataTableType.ManifestResource:
                    HasCustomAttribute[18] = table;
                    break;
                case MetaDataTableType.MemberRef:
                    HasCustomAttribute[6] = table;
                    MethodDefOrRef[1] = table;
                    CustomAttributeType[3] = table;
                    break;
                case MetaDataTableType.Method:
                    HasCustomAttribute[0] = table;
                    HasDeclSecurity[1] = table;
                    MemberRefParent[3] = table;
                    MethodDefOrRef[0] = table;
                    MemberForwarded[1] = table;
                    CustomAttributeType[2] = table;
                    TypeOrMethod[1] = table;
                    break;
                case MetaDataTableType.MethodSpec:
                    HasCustomAttribute[21] = table;
                    break;
                case MetaDataTableType.Module:
                    HasCustomAttribute[7] = table;
                    ResolutionScope[0] = table;
                    break;
                case MetaDataTableType.ModuleRef:
                    HasCustomAttribute[12] = table;
                    MemberRefParent[2] = table;
                    ResolutionScope[1] = table;
                    break;
                case MetaDataTableType.Param:
                    HasConstant[1] = table;
                    HasCustomAttribute[4] = table;
                    HasFieldMarshall[1] = table;
                    break;
                case MetaDataTableType.Property:
                    HasConstant[2] = table;
                    HasCustomAttribute[9] = table;
                    HasSemantics[1] = table;
                    break;
                case MetaDataTableType.StandAloneSig:
                    HasCustomAttribute[11] = table;
                    break;
                case MetaDataTableType.TypeDef:
                    TypeDefOrRef[0] = table;
                    HasCustomAttribute[3] = table;
                    HasDeclSecurity[0] = table;
                    MemberRefParent[0] = table;
                    TypeOrMethod[0] = table;
                    break;
                case MetaDataTableType.TypeRef:
                    TypeDefOrRef[1] = table;
                    HasCustomAttribute[2] = table;
                    MemberRefParent[1] = table;
                    ResolutionScope[3] = table;
                    break;
                case MetaDataTableType.TypeSpec:
                    TypeDefOrRef[2] = table;
                    HasCustomAttribute[13] = table;
                    MemberRefParent[4] = table;
                    break;
            }
            return table;
        }
 public MemberCollection(MetaDataTable table)
 {
     _table         = table;
     _internalArray = new MetaDataMember[table.AmountOfRows];
 }
Exemple #6
0
        private bool GetRowAndType(BinaryReader reader, MetaDataTable table, out MetaDataRow row, out Type type)
        {
            type = null;
            row = default(MetaDataRow);

            switch (table.Type)
            {
                case MetaDataTableType.Module:
                    row = ReadRow(reader, GetModuleSignature()); type = typeof(ModuleDefinition); break;
                case MetaDataTableType.TypeRef:
                    row = ReadRow(reader, GetTypeRefSignature()); type = typeof(TypeReference); break;
                case MetaDataTableType.TypeDef:
                    row = ReadRow(reader, GetTypeDefSignature()); type = typeof(TypeDefinition); break;
                case MetaDataTableType.FieldPtr:
                    row = ReadRow(reader, GetFieldPtrSignature()); type = typeof(FieldPtr); break;
                case MetaDataTableType.Field:
                    row = ReadRow(reader, GetFieldDefSignature()); type = typeof(FieldDefinition); break;
                case MetaDataTableType.MethodPtr:
                    row = ReadRow(reader, GetMethodPtrSignature()); type = typeof(MethodPtr); break;
                case MetaDataTableType.Method:
                    row = ReadRow(reader, GetMethodDefSignature()); type = typeof(MethodDefinition); break;
                case MetaDataTableType.ParamPtr:
                    row = ReadRow(reader, GetParamPtrSignature()); type = typeof(ParamPtr); break;
                case MetaDataTableType.Param:
                    row = ReadRow(reader, GetParamDefSignature()); type = typeof(ParameterDefinition); break;
                case MetaDataTableType.InterfaceImpl:
                    row = ReadRow(reader, GetInterfaceImplSignature()); type = typeof(InterfaceImplementation); break;
                case MetaDataTableType.MemberRef:
                    row = ReadRow(reader, GetMemberRefSignature());
                    tablesHeap._netheader.BlobHeap._mainStream.Seek(Convert.ToUInt32(row._parts[2]), SeekOrigin.Begin);
                    tablesHeap._netheader.BlobHeap._binReader.ReadByte();
                    byte sigtype = tablesHeap._netheader.BlobHeap._binReader.ReadByte();

                    if (sigtype == 0x6)
                        type = typeof(FieldReference);
                    else
                        type = typeof(MethodReference);

                    break;
                case MetaDataTableType.Constant:
                    row = ReadRow(reader, GetConstantSignature()); type = typeof(Constant); break;
                case MetaDataTableType.CustomAttribute:
                    row = ReadRow(reader, GetCustomAttributeSignature()); type = typeof(CustomAttribute); break;
                case MetaDataTableType.FieldMarshal:
                    row = ReadRow(reader, GetFieldMarshalSignature()); type = typeof(FieldMarshal); break;
                case MetaDataTableType.DeclSecurity:
                    row = ReadRow(reader, GetSecurityDeclSignature()); type = typeof(SecurityDeclaration); break;
                case MetaDataTableType.ClassLayout:
                    row = ReadRow(reader, GetClassLayoutSignature()); type = typeof(ClassLayout); break;
                case MetaDataTableType.FieldLayout:
                    row = ReadRow(reader, GetFieldLayoutSignature()); type = typeof(FieldLayout); break;
                case MetaDataTableType.StandAloneSig:
                    row = ReadRow(reader, GetStandAloneSigSignature()); type = typeof(StandAloneSignature); break;
                case MetaDataTableType.EventMap:
                    row = ReadRow(reader, GetEventMapSignature()); type = typeof(EventMap); break;
                case MetaDataTableType.Event:
                    row = ReadRow(reader, GetEventDefSignature()); type = typeof(EventDefinition); break;
                case MetaDataTableType.PropertyMap:
                    row = ReadRow(reader, GetPropertyMapSignature()); type = typeof(PropertyMap); break;
                case MetaDataTableType.PropertyPtr:
                    row = ReadRow(reader, GetPropertyPtrSignature()); type = typeof(PropertyPtr); break;
                case MetaDataTableType.Property:
                    row = ReadRow(reader, GetPropertyDefSignature()); type = typeof(PropertyDefinition); break;
                case MetaDataTableType.MethodSemantics:
                    row = ReadRow(reader, GetMethodSemanticsSignature()); type = typeof(MethodSemantics); break;
                case MetaDataTableType.MethodImpl:
                    row = ReadRow(reader, GetMethodImplSignature()); type = typeof(MethodImplementation); break;
                case MetaDataTableType.ModuleRef:
                    row = ReadRow(reader, GetModuleRefSignature()); type = typeof(ModuleReference); break;
                case MetaDataTableType.TypeSpec:
                    row = ReadRow(reader, GetTypeSpecSignature()); type = typeof(TypeSpecification); break;
                case MetaDataTableType.MethodSpec:
                    row = ReadRow(reader, GetMethodSpecSignature()); type = typeof(MethodSpecification); break;
                case MetaDataTableType.ImplMap:
                    row = ReadRow(reader, GetPInvokeImplSignature()); type = typeof(PInvokeImplementation); break;
                case MetaDataTableType.FieldRVA:
                    row = ReadRow(reader, GetFieldRVASignature()); type = typeof(FieldRVA); break;
                case MetaDataTableType.Assembly:
                    row = ReadRow(reader, GetAssemblyDefSignature()); type = typeof(AssemblyDefinition); break;
                case MetaDataTableType.AssemblyProcessor:
                    row = ReadRow(reader, GetAssemblyProcSignature()); type = typeof(AssemblyProcessor); break;
                case MetaDataTableType.AssemblyOS:
                    row = ReadRow(reader, GetAssemblyOSSignature()); type = typeof(AssemblyOS); break;
                case MetaDataTableType.AssemblyRef:
                    row = ReadRow(reader, GetAssemblyRefSignature()); type = typeof(AssemblyReference); break;
                case MetaDataTableType.AssemblyRefProcessor:
                    row = ReadRow(reader, GetAssemblyRefProcSignature()); type = typeof(AssemblyRefProcessor); break;
                case MetaDataTableType.AssemblyRefOS:
                    row = ReadRow(reader, GetAssemblyRefOSSignature()); type = typeof(AssemblyRefOS); break;
                case MetaDataTableType.File:
                    row = ReadRow(reader, GetFileReferenceSignature()); type = typeof(File); break;
                case MetaDataTableType.ExportedType:
                    row = ReadRow(reader, GetExportedTypeSignature()); type = typeof(ExportedType); break;
                case MetaDataTableType.ManifestResource:
                    row = ReadRow(reader, GetManifestResSignature()); type = typeof(ManifestResource); break;
                case MetaDataTableType.NestedClass:
                    row = ReadRow(reader, GetNestedClassSignature()); type = typeof(NestedClass); break;
                case MetaDataTableType.EncLog:
                    row = ReadRow(reader, GetEnCLogSignature()); type = typeof(EnCLog); break;
                case MetaDataTableType.EncMap:
                    row = ReadRow(reader, GetEnCMapSignature()); type = typeof(EnCMap); break;
                case MetaDataTableType.GenericParam:
                    row = ReadRow(reader, GetGenericParamSignature()); type = typeof(GenericParameter); break;
                case MetaDataTableType.GenericParamConstraint:
                    row = ReadRow(reader, GetGenericParamConstraintSignature()); type = typeof(GenericParamConstraint); break;

            }

            return type != null;
        }
Exemple #7
0
 internal MetaDataMember ReadMember(MetaDataTable table, int index)
 {
     using (MemoryStream stream = new MemoryStream(tablesHeap.Contents))
     {
         using (BinaryReader reader = new BinaryReader(stream))
         {
             stream.Position = table.TableOffset - tablesHeap.StreamOffset;
             stream.Position += (table.CalculateRowSize() * (index - 1));
             Type type;
             MetaDataRow row;
             if (GetRowAndType(reader, table, out row, out type))
             {
                 return CreateMember(type, row, table.Type, index);
             }
         }
     }
     return null;
 }
Exemple #8
0
 public void AddTable(MetaDataTableType type)
 {
     MetaDataTable table = new MetaDataTable(this, true);
     table._type = type;
     _tables[(int)type] = table;
     MaskValid |= ((ulong)1 << (int)type);
 }