Ejemplo n.º 1
0
        private void ReadTableHeap()
        {
            TableHeap tableHeap = image.TableHeap;

            base.MoveTo(table_heap_offset + image.MetadataSection.PointerToRawData);
            base.Advance(6);
            byte sizes = ReadByte();

            base.Advance(1);
            tableHeap.Valid  = ReadInt64();
            tableHeap.Sorted = ReadInt64();
            if (image.PdbHeap != null)
            {
                for (int i = 0; i < 58; i++)
                {
                    if (image.PdbHeap.HasTable((Table)i))
                    {
                        tableHeap.Tables[i].Length = image.PdbHeap.TypeSystemTableRows[i];
                    }
                }
            }
            for (int j = 0; j < 58; j++)
            {
                if (tableHeap.HasTable((Table)j))
                {
                    tableHeap.Tables[j].Length = ReadUInt32();
                }
            }
            SetIndexSize(image.StringHeap, sizes, 1);
            SetIndexSize(image.GuidHeap, sizes, 2);
            SetIndexSize(image.BlobHeap, sizes, 4);
            ComputeTableInformations();
        }
Ejemplo n.º 2
0
        private void ReadTableHeap()
        {
            TableHeap tableHeap        = this.image.TableHeap;
            uint      pointerToRawData = tableHeap.Section.PointerToRawData;

            this.MoveTo((uint)(tableHeap.Offset + pointerToRawData));
            base.Advance(6);
            byte sizes = this.ReadByte();

            base.Advance(1);
            tableHeap.Valid  = this.ReadInt64();
            tableHeap.Sorted = this.ReadInt64();
            for (int i = 0; i < 0x2d; i++)
            {
                if (tableHeap.HasTable((Table)((byte)i)))
                {
                    tableHeap.Tables[i].Length = this.ReadUInt32();
                }
            }
            SetIndexSize(this.image.StringHeap, sizes, 1);
            SetIndexSize(this.image.GuidHeap, sizes, 2);
            SetIndexSize(this.image.BlobHeap, sizes, 4);
            this.ComputeTableInformations();
        }
Ejemplo n.º 3
0
        private void ComputeTableInformations()
        {
            uint      num       = ((uint)this.BaseStream.Position) - this.image.MetadataSection.PointerToRawData;
            int       indexSize = this.image.StringHeap.IndexSize;
            int       num3      = (this.image.BlobHeap != null) ? this.image.BlobHeap.IndexSize : 2;
            TableHeap tableHeap = this.image.TableHeap;

            TableInformation[] tables = tableHeap.Tables;
            for (int i = 0; i < 0x2d; i++)
            {
                Table table = (Table)((byte)i);
                if (tableHeap.HasTable(table))
                {
                    int tableIndexSize;
                    switch (table)
                    {
                    case Table.Module:
                        tableIndexSize = (2 + indexSize) + (this.image.GuidHeap.IndexSize * 3);
                        break;

                    case Table.TypeRef:
                        tableIndexSize = this.GetCodedIndexSize(CodedIndex.ResolutionScope) + (indexSize * 2);
                        break;

                    case Table.TypeDef:
                        tableIndexSize = (((4 + (indexSize * 2)) + this.GetCodedIndexSize(CodedIndex.TypeDefOrRef)) + this.GetTableIndexSize(Table.Field)) + this.GetTableIndexSize(Table.Method);
                        break;

                    case Table.FieldPtr:
                        tableIndexSize = this.GetTableIndexSize(Table.Field);
                        break;

                    case Table.Field:
                        tableIndexSize = (2 + indexSize) + num3;
                        break;

                    case Table.MethodPtr:
                        tableIndexSize = this.GetTableIndexSize(Table.Method);
                        break;

                    case Table.Method:
                        tableIndexSize = ((8 + indexSize) + num3) + this.GetTableIndexSize(Table.Param);
                        break;

                    case Table.ParamPtr:
                        tableIndexSize = this.GetTableIndexSize(Table.Param);
                        break;

                    case Table.Param:
                        tableIndexSize = 4 + indexSize;
                        break;

                    case Table.InterfaceImpl:
                        tableIndexSize = this.GetTableIndexSize(Table.TypeDef) + this.GetCodedIndexSize(CodedIndex.TypeDefOrRef);
                        break;

                    case Table.MemberRef:
                        tableIndexSize = (this.GetCodedIndexSize(CodedIndex.MemberRefParent) + indexSize) + num3;
                        break;

                    case Table.Constant:
                        tableIndexSize = (2 + this.GetCodedIndexSize(CodedIndex.HasConstant)) + num3;
                        break;

                    case Table.CustomAttribute:
                        tableIndexSize = (this.GetCodedIndexSize(CodedIndex.HasCustomAttribute) + this.GetCodedIndexSize(CodedIndex.CustomAttributeType)) + num3;
                        break;

                    case Table.FieldMarshal:
                        tableIndexSize = this.GetCodedIndexSize(CodedIndex.HasFieldMarshal) + num3;
                        break;

                    case Table.DeclSecurity:
                        tableIndexSize = (2 + this.GetCodedIndexSize(CodedIndex.HasDeclSecurity)) + num3;
                        break;

                    case Table.ClassLayout:
                        tableIndexSize = 6 + this.GetTableIndexSize(Table.TypeDef);
                        break;

                    case Table.FieldLayout:
                        tableIndexSize = 4 + this.GetTableIndexSize(Table.Field);
                        break;

                    case Table.StandAloneSig:
                        tableIndexSize = num3;
                        break;

                    case Table.EventMap:
                        tableIndexSize = this.GetTableIndexSize(Table.TypeDef) + this.GetTableIndexSize(Table.Event);
                        break;

                    case Table.EventPtr:
                        tableIndexSize = this.GetTableIndexSize(Table.Event);
                        break;

                    case Table.Event:
                        tableIndexSize = (2 + indexSize) + this.GetCodedIndexSize(CodedIndex.TypeDefOrRef);
                        break;

                    case Table.PropertyMap:
                        tableIndexSize = this.GetTableIndexSize(Table.TypeDef) + this.GetTableIndexSize(Table.Property);
                        break;

                    case Table.PropertyPtr:
                        tableIndexSize = this.GetTableIndexSize(Table.Property);
                        break;

                    case Table.Property:
                        tableIndexSize = (2 + indexSize) + num3;
                        break;

                    case Table.MethodSemantics:
                        tableIndexSize = (2 + this.GetTableIndexSize(Table.Method)) + this.GetCodedIndexSize(CodedIndex.HasSemantics);
                        break;

                    case Table.MethodImpl:
                        tableIndexSize = (this.GetTableIndexSize(Table.TypeDef) + this.GetCodedIndexSize(CodedIndex.MethodDefOrRef)) + this.GetCodedIndexSize(CodedIndex.MethodDefOrRef);
                        break;

                    case Table.ModuleRef:
                        tableIndexSize = indexSize;
                        break;

                    case Table.TypeSpec:
                        tableIndexSize = num3;
                        break;

                    case Table.ImplMap:
                        tableIndexSize = ((2 + this.GetCodedIndexSize(CodedIndex.MemberForwarded)) + indexSize) + this.GetTableIndexSize(Table.ModuleRef);
                        break;

                    case Table.FieldRVA:
                        tableIndexSize = 4 + this.GetTableIndexSize(Table.Field);
                        break;

                    case Table.EncLog:
                        tableIndexSize = 8;
                        break;

                    case Table.EncMap:
                        tableIndexSize = 4;
                        break;

                    case Table.Assembly:
                        tableIndexSize = (0x10 + num3) + (indexSize * 2);
                        break;

                    case Table.AssemblyProcessor:
                        tableIndexSize = 4;
                        break;

                    case Table.AssemblyOS:
                        tableIndexSize = 12;
                        break;

                    case Table.AssemblyRef:
                        tableIndexSize = (12 + (num3 * 2)) + (indexSize * 2);
                        break;

                    case Table.AssemblyRefProcessor:
                        tableIndexSize = 4 + this.GetTableIndexSize(Table.AssemblyRef);
                        break;

                    case Table.AssemblyRefOS:
                        tableIndexSize = 12 + this.GetTableIndexSize(Table.AssemblyRef);
                        break;

                    case Table.File:
                        tableIndexSize = (4 + indexSize) + num3;
                        break;

                    case Table.ExportedType:
                        tableIndexSize = (8 + (indexSize * 2)) + this.GetCodedIndexSize(CodedIndex.Implementation);
                        break;

                    case Table.ManifestResource:
                        tableIndexSize = (8 + indexSize) + this.GetCodedIndexSize(CodedIndex.Implementation);
                        break;

                    case Table.NestedClass:
                        tableIndexSize = this.GetTableIndexSize(Table.TypeDef) + this.GetTableIndexSize(Table.TypeDef);
                        break;

                    case Table.GenericParam:
                        tableIndexSize = (4 + this.GetCodedIndexSize(CodedIndex.TypeOrMethodDef)) + indexSize;
                        break;

                    case Table.MethodSpec:
                        tableIndexSize = this.GetCodedIndexSize(CodedIndex.MethodDefOrRef) + num3;
                        break;

                    case Table.GenericParamConstraint:
                        tableIndexSize = this.GetTableIndexSize(Table.GenericParam) + this.GetCodedIndexSize(CodedIndex.TypeDefOrRef);
                        break;

                    default:
                        throw new NotSupportedException();
                    }
                    tables[i].RowSize = (uint)tableIndexSize;
                    tables[i].Offset  = num;
                    num += (uint)(tableIndexSize * tables[i].Length);
                }
            }
        }
Ejemplo n.º 4
0
        private void ComputeTableInformations()
        {
            int       indexSize;
            uint      position  = (uint)this.BaseStream.Position - this.image.MetadataSection.PointerToRawData;
            int       num       = this.image.StringHeap.IndexSize;
            int       num1      = (this.image.BlobHeap != null ? this.image.BlobHeap.IndexSize : 2);
            TableHeap tableHeap = this.image.TableHeap;

            TableInformation[] tables = tableHeap.Tables;
            for (int i = 0; i < 45; i++)
            {
                Table table = (Table)((byte)i);
                if (tableHeap.HasTable(table))
                {
                    switch (table)
                    {
                    case Table.Module:
                    {
                        indexSize = 2 + num + this.image.GuidHeap.IndexSize * 3;
                        break;
                    }

                    case Table.TypeRef:
                    {
                        indexSize = this.GetCodedIndexSize(CodedIndex.ResolutionScope) + num * 2;
                        break;
                    }

                    case Table.TypeDef:
                    {
                        indexSize = 4 + num * 2 + this.GetCodedIndexSize(CodedIndex.TypeDefOrRef) + this.GetTableIndexSize(Table.Field) + this.GetTableIndexSize(Table.Method);
                        break;
                    }

                    case Table.FieldPtr:
                    {
                        indexSize = this.GetTableIndexSize(Table.Field);
                        break;
                    }

                    case Table.Field:
                    {
                        indexSize = 2 + num + num1;
                        break;
                    }

                    case Table.MethodPtr:
                    {
                        indexSize = this.GetTableIndexSize(Table.Method);
                        break;
                    }

                    case Table.Method:
                    {
                        indexSize = 8 + num + num1 + this.GetTableIndexSize(Table.Param);
                        break;
                    }

                    case Table.ParamPtr:
                    {
                        indexSize = this.GetTableIndexSize(Table.Param);
                        break;
                    }

                    case Table.Param:
                    {
                        indexSize = 4 + num;
                        break;
                    }

                    case Table.InterfaceImpl:
                    {
                        indexSize = this.GetTableIndexSize(Table.TypeDef) + this.GetCodedIndexSize(CodedIndex.TypeDefOrRef);
                        break;
                    }

                    case Table.MemberRef:
                    {
                        indexSize = this.GetCodedIndexSize(CodedIndex.MemberRefParent) + num + num1;
                        break;
                    }

                    case Table.Constant:
                    {
                        indexSize = 2 + this.GetCodedIndexSize(CodedIndex.HasConstant) + num1;
                        break;
                    }

                    case Table.CustomAttribute:
                    {
                        indexSize = this.GetCodedIndexSize(CodedIndex.HasCustomAttribute) + this.GetCodedIndexSize(CodedIndex.CustomAttributeType) + num1;
                        break;
                    }

                    case Table.FieldMarshal:
                    {
                        indexSize = this.GetCodedIndexSize(CodedIndex.HasFieldMarshal) + num1;
                        break;
                    }

                    case Table.DeclSecurity:
                    {
                        indexSize = 2 + this.GetCodedIndexSize(CodedIndex.HasDeclSecurity) + num1;
                        break;
                    }

                    case Table.ClassLayout:
                    {
                        indexSize = 6 + this.GetTableIndexSize(Table.TypeDef);
                        break;
                    }

                    case Table.FieldLayout:
                    {
                        indexSize = 4 + this.GetTableIndexSize(Table.Field);
                        break;
                    }

                    case Table.StandAloneSig:
                    {
                        indexSize = num1;
                        break;
                    }

                    case Table.EventMap:
                    {
                        indexSize = this.GetTableIndexSize(Table.TypeDef) + this.GetTableIndexSize(Table.Event);
                        break;
                    }

                    case Table.EventPtr:
                    {
                        indexSize = this.GetTableIndexSize(Table.Event);
                        break;
                    }

                    case Table.Event:
                    {
                        indexSize = 2 + num + this.GetCodedIndexSize(CodedIndex.TypeDefOrRef);
                        break;
                    }

                    case Table.PropertyMap:
                    {
                        indexSize = this.GetTableIndexSize(Table.TypeDef) + this.GetTableIndexSize(Table.Property);
                        break;
                    }

                    case Table.PropertyPtr:
                    {
                        indexSize = this.GetTableIndexSize(Table.Property);
                        break;
                    }

                    case Table.Property:
                    {
                        indexSize = 2 + num + num1;
                        break;
                    }

                    case Table.MethodSemantics:
                    {
                        indexSize = 2 + this.GetTableIndexSize(Table.Method) + this.GetCodedIndexSize(CodedIndex.HasSemantics);
                        break;
                    }

                    case Table.MethodImpl:
                    {
                        indexSize = this.GetTableIndexSize(Table.TypeDef) + this.GetCodedIndexSize(CodedIndex.MethodDefOrRef) + this.GetCodedIndexSize(CodedIndex.MethodDefOrRef);
                        break;
                    }

                    case Table.ModuleRef:
                    {
                        indexSize = num;
                        break;
                    }

                    case Table.TypeSpec:
                    {
                        indexSize = num1;
                        break;
                    }

                    case Table.ImplMap:
                    {
                        indexSize = 2 + this.GetCodedIndexSize(CodedIndex.MemberForwarded) + num + this.GetTableIndexSize(Table.ModuleRef);
                        break;
                    }

                    case Table.FieldRVA:
                    {
                        indexSize = 4 + this.GetTableIndexSize(Table.Field);
                        break;
                    }

                    case Table.EncLog:
                    {
                        indexSize = 8;
                        break;
                    }

                    case Table.EncMap:
                    {
                        indexSize = 4;
                        break;
                    }

                    case Table.Assembly:
                    {
                        indexSize = 16 + num1 + num * 2;
                        break;
                    }

                    case Table.AssemblyProcessor:
                    {
                        indexSize = 4;
                        break;
                    }

                    case Table.AssemblyOS:
                    {
                        indexSize = 12;
                        break;
                    }

                    case Table.AssemblyRef:
                    {
                        indexSize = 12 + num1 * 2 + num * 2;
                        break;
                    }

                    case Table.AssemblyRefProcessor:
                    {
                        indexSize = 4 + this.GetTableIndexSize(Table.AssemblyRef);
                        break;
                    }

                    case Table.AssemblyRefOS:
                    {
                        indexSize = 12 + this.GetTableIndexSize(Table.AssemblyRef);
                        break;
                    }

                    case Table.File:
                    {
                        indexSize = 4 + num + num1;
                        break;
                    }

                    case Table.ExportedType:
                    {
                        indexSize = 8 + num * 2 + this.GetCodedIndexSize(CodedIndex.Implementation);
                        break;
                    }

                    case Table.ManifestResource:
                    {
                        indexSize = 8 + num + this.GetCodedIndexSize(CodedIndex.Implementation);
                        break;
                    }

                    case Table.NestedClass:
                    {
                        indexSize = this.GetTableIndexSize(Table.TypeDef) + this.GetTableIndexSize(Table.TypeDef);
                        break;
                    }

                    case Table.GenericParam:
                    {
                        indexSize = 4 + this.GetCodedIndexSize(CodedIndex.TypeOrMethodDef) + num;
                        break;
                    }

                    case Table.MethodSpec:
                    {
                        indexSize = this.GetCodedIndexSize(CodedIndex.MethodDefOrRef) + num1;
                        break;
                    }

                    case Table.GenericParamConstraint:
                    {
                        indexSize = this.GetTableIndexSize(Table.GenericParam) + this.GetCodedIndexSize(CodedIndex.TypeDefOrRef);
                        break;
                    }

                    default:
                    {
                        throw new NotSupportedException();
                    }
                    }
                    tables[i].RowSize = (uint)indexSize;
                    tables[i].Offset  = position;
                    position          = position + indexSize * tables[i].Length;
                }
            }
        }
Ejemplo n.º 5
0
        private void ComputeTableInformations()
        {
            uint      num       = (uint)((int)BaseStream.Position - (int)table_heap_offset - (int)image.MetadataSection.PointerToRawData);
            int       indexSize = image.StringHeap.IndexSize;
            int       num2      = (image.GuidHeap != null) ? image.GuidHeap.IndexSize : 2;
            int       num3      = (image.BlobHeap != null) ? image.BlobHeap.IndexSize : 2;
            TableHeap tableHeap = image.TableHeap;

            TableInformation[] tables = tableHeap.Tables;
            for (int i = 0; i < 58; i++)
            {
                Table table = (Table)i;
                if (tableHeap.HasTable(table))
                {
                    int num4;
                    switch (table)
                    {
                    case Table.Module:
                        num4 = 2 + indexSize + num2 * 3;
                        break;

                    case Table.TypeRef:
                        num4 = GetCodedIndexSize(CodedIndex.ResolutionScope) + indexSize * 2;
                        break;

                    case Table.TypeDef:
                        num4 = 4 + indexSize * 2 + GetCodedIndexSize(CodedIndex.TypeDefOrRef) + GetTableIndexSize(Table.Field) + GetTableIndexSize(Table.Method);
                        break;

                    case Table.FieldPtr:
                        num4 = GetTableIndexSize(Table.Field);
                        break;

                    case Table.Field:
                        num4 = 2 + indexSize + num3;
                        break;

                    case Table.MethodPtr:
                        num4 = GetTableIndexSize(Table.Method);
                        break;

                    case Table.Method:
                        num4 = 8 + indexSize + num3 + GetTableIndexSize(Table.Param);
                        break;

                    case Table.ParamPtr:
                        num4 = GetTableIndexSize(Table.Param);
                        break;

                    case Table.Param:
                        num4 = 4 + indexSize;
                        break;

                    case Table.InterfaceImpl:
                        num4 = GetTableIndexSize(Table.TypeDef) + GetCodedIndexSize(CodedIndex.TypeDefOrRef);
                        break;

                    case Table.MemberRef:
                        num4 = GetCodedIndexSize(CodedIndex.MemberRefParent) + indexSize + num3;
                        break;

                    case Table.Constant:
                        num4 = 2 + GetCodedIndexSize(CodedIndex.HasConstant) + num3;
                        break;

                    case Table.CustomAttribute:
                        num4 = GetCodedIndexSize(CodedIndex.HasCustomAttribute) + GetCodedIndexSize(CodedIndex.CustomAttributeType) + num3;
                        break;

                    case Table.FieldMarshal:
                        num4 = GetCodedIndexSize(CodedIndex.HasFieldMarshal) + num3;
                        break;

                    case Table.DeclSecurity:
                        num4 = 2 + GetCodedIndexSize(CodedIndex.HasDeclSecurity) + num3;
                        break;

                    case Table.ClassLayout:
                        num4 = 6 + GetTableIndexSize(Table.TypeDef);
                        break;

                    case Table.FieldLayout:
                        num4 = 4 + GetTableIndexSize(Table.Field);
                        break;

                    case Table.StandAloneSig:
                        num4 = num3;
                        break;

                    case Table.EventMap:
                        num4 = GetTableIndexSize(Table.TypeDef) + GetTableIndexSize(Table.Event);
                        break;

                    case Table.EventPtr:
                        num4 = GetTableIndexSize(Table.Event);
                        break;

                    case Table.Event:
                        num4 = 2 + indexSize + GetCodedIndexSize(CodedIndex.TypeDefOrRef);
                        break;

                    case Table.PropertyMap:
                        num4 = GetTableIndexSize(Table.TypeDef) + GetTableIndexSize(Table.Property);
                        break;

                    case Table.PropertyPtr:
                        num4 = GetTableIndexSize(Table.Property);
                        break;

                    case Table.Property:
                        num4 = 2 + indexSize + num3;
                        break;

                    case Table.MethodSemantics:
                        num4 = 2 + GetTableIndexSize(Table.Method) + GetCodedIndexSize(CodedIndex.HasSemantics);
                        break;

                    case Table.MethodImpl:
                        num4 = GetTableIndexSize(Table.TypeDef) + GetCodedIndexSize(CodedIndex.MethodDefOrRef) + GetCodedIndexSize(CodedIndex.MethodDefOrRef);
                        break;

                    case Table.ModuleRef:
                        num4 = indexSize;
                        break;

                    case Table.TypeSpec:
                        num4 = num3;
                        break;

                    case Table.ImplMap:
                        num4 = 2 + GetCodedIndexSize(CodedIndex.MemberForwarded) + indexSize + GetTableIndexSize(Table.ModuleRef);
                        break;

                    case Table.FieldRVA:
                        num4 = 4 + GetTableIndexSize(Table.Field);
                        break;

                    case Table.EncLog:
                        num4 = 8;
                        break;

                    case Table.EncMap:
                        num4 = 4;
                        break;

                    case Table.Assembly:
                        num4 = 16 + num3 + indexSize * 2;
                        break;

                    case Table.AssemblyProcessor:
                        num4 = 4;
                        break;

                    case Table.AssemblyOS:
                        num4 = 12;
                        break;

                    case Table.AssemblyRef:
                        num4 = 12 + num3 * 2 + indexSize * 2;
                        break;

                    case Table.AssemblyRefProcessor:
                        num4 = 4 + GetTableIndexSize(Table.AssemblyRef);
                        break;

                    case Table.AssemblyRefOS:
                        num4 = 12 + GetTableIndexSize(Table.AssemblyRef);
                        break;

                    case Table.File:
                        num4 = 4 + indexSize + num3;
                        break;

                    case Table.ExportedType:
                        num4 = 8 + indexSize * 2 + GetCodedIndexSize(CodedIndex.Implementation);
                        break;

                    case Table.ManifestResource:
                        num4 = 8 + indexSize + GetCodedIndexSize(CodedIndex.Implementation);
                        break;

                    case Table.NestedClass:
                        num4 = GetTableIndexSize(Table.TypeDef) + GetTableIndexSize(Table.TypeDef);
                        break;

                    case Table.GenericParam:
                        num4 = 4 + GetCodedIndexSize(CodedIndex.TypeOrMethodDef) + indexSize;
                        break;

                    case Table.MethodSpec:
                        num4 = GetCodedIndexSize(CodedIndex.MethodDefOrRef) + num3;
                        break;

                    case Table.GenericParamConstraint:
                        num4 = GetTableIndexSize(Table.GenericParam) + GetCodedIndexSize(CodedIndex.TypeDefOrRef);
                        break;

                    case Table.Document:
                        num4 = num3 + num2 + num3 + num2;
                        break;

                    case Table.MethodDebugInformation:
                        num4 = GetTableIndexSize(Table.Document) + num3;
                        break;

                    case Table.LocalScope:
                        num4 = GetTableIndexSize(Table.Method) + GetTableIndexSize(Table.ImportScope) + GetTableIndexSize(Table.LocalVariable) + GetTableIndexSize(Table.LocalConstant) + 8;
                        break;

                    case Table.LocalVariable:
                        num4 = 4 + indexSize;
                        break;

                    case Table.LocalConstant:
                        num4 = indexSize + num3;
                        break;

                    case Table.ImportScope:
                        num4 = GetTableIndexSize(Table.ImportScope) + num3;
                        break;

                    case Table.StateMachineMethod:
                        num4 = GetTableIndexSize(Table.Method) + GetTableIndexSize(Table.Method);
                        break;

                    case Table.CustomDebugInformation:
                        num4 = GetCodedIndexSize(CodedIndex.HasCustomDebugInformation) + num2 + num3;
                        break;

                    default:
                        throw new NotSupportedException();
                    }
                    tables[i].RowSize = (uint)num4;
                    tables[i].Offset  = num;
                    num = (uint)((int)num + num4 * (int)tables[i].Length);
                }
            }
        }