public override bool View(ViewModels.TabPageModel tabPage) { tabPage.Title = Text.ToString(); tabPage.SupportsLanguageSwitching = false; var view = Helpers.PrepareDataGrid(tabPage, this); var metadata = module.Metadata; var list = new List <TypeDefEntry>(); TypeDefEntry scrollTargetEntry = default; foreach (var row in metadata.TypeDefinitions) { TypeDefEntry entry = new TypeDefEntry(module, row); if (entry.RID == this.scrollTarget) { scrollTargetEntry = entry; } list.Add(entry); } view.ItemsSource = list; tabPage.Content = view; if (scrollTargetEntry.RID > 0) { ScrollItemIntoView(view, scrollTargetEntry); } return(true); }
void LoadTypes() { var typeDefEntries = (TypeDefEntry[])tableStream.Tables[(int)TableKind.TypeDef]; if (typeDefEntries == null || typeDefEntries.Length == 0) { this.module.Types = null; return; } bool isFirstTypeModuleStub; if (typeDefEntries[0].Extends.Index == 0 && (typeDefEntries[0].TypeDefinition.Attributes & TypeAttributes.Interface) == 0) { isFirstTypeModuleStub = true; } else { isFirstTypeModuleStub = false; } { int typeCount = isFirstTypeModuleStub ? typeDefEntries.Length - 1 : typeDefEntries.Length; if (this.module.Types == null || this.module.Types.Length != typeCount) { this.module.Types = new TypeDefinition[typeCount]; } } var fieldEntries = (FieldEntry[])this.tableStream.Tables[(int)TableKind.Field]; var methodDefEntries = (MethodDefEntry[])this.tableStream.Tables[(int)TableKind.MethodDef]; var paramDefEntries = (ParamEntry[])this.tableStream.Tables[(int)TableKind.Param]; for (int iType = isFirstTypeModuleStub ? 1 : 0; iType < typeDefEntries.Length; iType++) { TypeDefEntry typeDef = typeDefEntries[iType]; int typeIndex = isFirstTypeModuleStub ? iType - 1 : iType; TypeDefinition type = typeDef.TypeDefinition; type.BaseType = GetTypeReference(typeDef.Extends); uint fieldIndex = typeDef.FieldList - 1; uint methodIndex = typeDef.MethodList - 1; uint nextFieldIndex; uint nextMethodIndex; if (iType < typeDefEntries.Length - 1) { var nextTypeDef = typeDefEntries[iType + 1]; nextFieldIndex = nextTypeDef.FieldList - 1; nextMethodIndex = nextTypeDef.MethodList - 1; } else { nextFieldIndex = (uint)fieldEntries.Length; nextMethodIndex = (uint)methodDefEntries.Length; } type.Fields = nextFieldIndex - fieldIndex == 0 ? EmptyFields : new FieldDefinition[nextFieldIndex - fieldIndex]; for (int iField = 0; iField < type.Fields.Length; iField++) { type.Fields[iField] = fieldEntries[fieldIndex + iField].FieldDefinition; } type.Methods = nextMethodIndex - methodIndex == 0 ? EmptyMethods : new MethodDefinition[nextMethodIndex - methodIndex]; for (int iMethod = 0; iMethod < type.Methods.Length; iMethod++) { var methodDef = methodDefEntries[methodIndex + iMethod]; var method = methodDef.MethodDefinition; uint paramIndex = methodDef.ParamList - 1; uint nextParamIndex; if (methodIndex + iMethod < methodDefEntries.Length - 1) { var nextMethodDef = methodDefEntries[methodIndex + iMethod + 1]; nextParamIndex = nextMethodDef.ParamList - 1; } else { nextParamIndex = (uint)paramDefEntries.Length; } method.Parameters = nextParamIndex - paramIndex == 0 ? EmptyParameters : new ParameterDefinition[nextParamIndex - paramIndex]; for (int iParam = 0; iParam < method.Parameters.Length; iParam++) { method.Parameters[iParam] = paramDefEntries[paramIndex + iParam].ParameterDefinition; } type.Methods[iMethod] = method; } this.module.Types[typeIndex] = type; } var propertyEntries = (PropertyEntry[])tableStream.Tables[(int)TableKind.Property]; var propertyMapEntries = (PropertyMapEntry[])tableStream.Tables[(int)TableKind.PropertyMap]; if (propertyMapEntries != null) { for (int propertyMapIndex = 0; propertyMapIndex < propertyMapEntries.Length; propertyMapIndex++) { uint propertyEntryIndex = propertyMapEntries[propertyMapIndex].PropertyList - 1; uint nextPropertyEntryIndex = propertyMapIndex < propertyMapEntries.Length - 1 ? propertyMapEntries[propertyMapIndex + 1].PropertyList - 1 : (uint)propertyEntries.Length; PropertyDefinition[] properties = nextPropertyEntryIndex == propertyEntryIndex + 1 ? EmptyProperties : new PropertyDefinition[nextPropertyEntryIndex - propertyEntryIndex - 1]; for (int iProperty = 0; iProperty < properties.Length; iProperty++) { properties[iProperty] = propertyEntries[propertyEntryIndex + iProperty].PropertyDefinition; } uint typeDefIndex = propertyMapEntries[propertyMapIndex].Parent - 1; typeDefEntries[typeDefIndex].TypeDefinition.Properties = properties; } } }
private void ReadAndInitializeRowCounts(BinaryStreamReader reader, ulong validMask) { var tables = new Array[45]; if ((validMask & ((ulong)1 << (int)TableKind.Module)) != 0) { uint rowCount = reader.ReadUInt32(); var table = new ModuleEntry[rowCount]; tables[(int)TableKind.Module] = table; } if ((validMask & ((ulong)1 << (int)TableKind.TypeRef)) != 0) { uint rowCount = reader.ReadUInt32(); var table = new TypeRefEntry[rowCount]; tables[(int)TableKind.TypeRef] = table; } if ((validMask & ((ulong)1 << (int)TableKind.TypeDef)) != 0) { uint rowCount = reader.ReadUInt32(); var table = new TypeDefEntry[rowCount]; tables[(int)TableKind.TypeDef] = table; } if ((validMask & ((ulong)1 << 0x03)) != 0) throw new BadImageFormatException("Non-standard metadata table 0x"+validMask.ToString("X2")+"."); if ((validMask & ((ulong)1 << (int)TableKind.Field)) != 0) { uint rowCount = reader.ReadUInt32(); var table = new FieldEntry[rowCount]; tables[(int)TableKind.Field] = table; } if ((validMask & ((ulong)1 << 0x05)) != 0) throw new BadImageFormatException("Non-standard metadata table 0x"+validMask.ToString("X2")+"."); if ((validMask & ((ulong)1 << (int)TableKind.MethodDef)) != 0) { uint rowCount = reader.ReadUInt32(); var table = new MethodDefEntry[rowCount]; tables[(int)TableKind.MethodDef] = table; } if ((validMask & ((ulong)1 << 0x07)) != 0) throw new BadImageFormatException("Non-standard metadata table 0x"+validMask.ToString("X2")+"."); if ((validMask & ((ulong)1 << (int)TableKind.Param)) != 0) { uint rowCount = reader.ReadUInt32(); var table = new ParamEntry[rowCount]; tables[(int)TableKind.Param] = table; } if ((validMask & ((ulong)1 << (int)TableKind.InterfaceImpl)) != 0) { uint rowCount = reader.ReadUInt32(); var table = new InterfaceImplEntry[rowCount]; tables[(int)TableKind.InterfaceImpl] = table; } if ((validMask & ((ulong)1 << (int)TableKind.MemberRef)) != 0) { uint rowCount = reader.ReadUInt32(); var table = new MemberRefEntry[rowCount]; tables[(int)TableKind.MemberRef] = table; } if ((validMask & ((ulong)1 << (int)TableKind.Constant)) != 0) { uint rowCount = reader.ReadUInt32(); var table = new ConstantEntry[rowCount]; tables[(int)TableKind.Constant] = table; } if ((validMask & ((ulong)1 << (int)TableKind.CustomAttribute)) != 0) { uint rowCount = reader.ReadUInt32(); var table = new CustomAttributeEntry[rowCount]; tables[(int)TableKind.CustomAttribute] = table; } if ((validMask & ((ulong)1 << (int)TableKind.FieldMarshal)) != 0) { uint rowCount = reader.ReadUInt32(); var table = new FieldMarshalEntry[rowCount]; tables[(int)TableKind.FieldMarshal] = table; } if ((validMask & ((ulong)1 << (int)TableKind.DeclSecurity)) != 0) { uint rowCount = reader.ReadUInt32(); var table = new DeclSecurityEntry[rowCount]; tables[(int)TableKind.DeclSecurity] = table; } if ((validMask & ((ulong)1 << (int)TableKind.ClassLayout)) != 0) { uint rowCount = reader.ReadUInt32(); var table = new ClassLayoutEntry[rowCount]; tables[(int)TableKind.ClassLayout] = table; } if ((validMask & ((ulong)1 << (int)TableKind.FieldLayout)) != 0) { uint rowCount = reader.ReadUInt32(); var table = new FieldLayoutEntry[rowCount]; tables[(int)TableKind.FieldLayout] = table; } if ((validMask & ((ulong)1 << (int)TableKind.StandAloneSig)) != 0) { uint rowCount = reader.ReadUInt32(); var table = new StandAloneSigEntry[rowCount]; tables[(int)TableKind.StandAloneSig] = table; } if ((validMask & ((ulong)1 << (int)TableKind.EventMap)) != 0) { uint rowCount = reader.ReadUInt32(); var table = new EventMapEntry[rowCount]; tables[(int)TableKind.EventMap] = table; } if ((validMask & ((ulong)1 << 0x13)) != 0) throw new BadImageFormatException("Non-standard metadata table 0x"+validMask.ToString("X2")+"."); if ((validMask & ((ulong)1 << (int)TableKind.Event)) != 0) { uint rowCount = reader.ReadUInt32(); var table = new EventEntry[rowCount]; tables[(int)TableKind.Event] = table; } if ((validMask & ((ulong)1 << (int)TableKind.PropertyMap)) != 0) { uint rowCount = reader.ReadUInt32(); var table = new PropertyMapEntry[rowCount]; tables[(int)TableKind.PropertyMap] = table; } if ((validMask & ((ulong)1 << 0x16)) != 0) throw new BadImageFormatException("Non-standard metadata table 0x"+validMask.ToString("X2")+"."); if ((validMask & ((ulong)1 << (int)TableKind.Property)) != 0) { uint rowCount = reader.ReadUInt32(); var table = new PropertyEntry[rowCount]; tables[(int)TableKind.Property] = table; } if ((validMask & ((ulong)1 << (int)TableKind.MethodSemantics)) != 0) { uint rowCount = reader.ReadUInt32(); var table = new MethodSemanticsEntry[rowCount]; tables[(int)TableKind.MethodSemantics] = table; } if ((validMask & ((ulong)1 << (int)TableKind.MethodImpl)) != 0) { uint rowCount = reader.ReadUInt32(); var table = new MethodImplEntry[rowCount]; tables[(int)TableKind.MethodImpl] = table; } if ((validMask & ((ulong)1 << (int)TableKind.ModuleRef)) != 0) { uint rowCount = reader.ReadUInt32(); var table = new ModuleRefEntry[rowCount]; tables[(int)TableKind.ModuleRef] = table; } if ((validMask & ((ulong)1 << (int)TableKind.TypeSpec)) != 0) { uint rowCount = reader.ReadUInt32(); var table = new TypeSpecEntry[rowCount]; tables[(int)TableKind.TypeSpec] = table; } if ((validMask & ((ulong)1 << (int)TableKind.ImplMap)) != 0) { uint rowCount = reader.ReadUInt32(); var table = new ImplMapEntry[rowCount]; tables[(int)TableKind.ImplMap] = table; } if ((validMask & ((ulong)1 << (int)TableKind.FieldRVA)) != 0) { uint rowCount = reader.ReadUInt32(); var table = new FieldRVAEntry[rowCount]; tables[(int)TableKind.FieldRVA] = table; } if ((validMask & ((ulong)1 << 0x1E)) != 0) throw new BadImageFormatException("Non-standard metadata table 0x"+validMask.ToString("X2")+"."); if ((validMask & ((ulong)1 << 0x1F)) != 0) throw new BadImageFormatException("Non-standard metadata table 0x"+validMask.ToString("X2")+"."); if ((validMask & ((ulong)1 << (int)TableKind.Assembly)) != 0) { uint rowCount = reader.ReadUInt32(); var table = new AssemblyEntry[rowCount]; tables[(int)TableKind.Assembly] = table; } if ((validMask & ((ulong)1 << (int)TableKind.AssemblyProcessor)) != 0) { uint rowCount = reader.ReadUInt32(); var table = new AssemblyProcessorEntry[rowCount]; tables[(int)TableKind.AssemblyProcessor] = table; } if ((validMask & ((ulong)1 << (int)TableKind.AssemblyOS)) != 0) { uint rowCount = reader.ReadUInt32(); var table = new AssemblyOSEntry[rowCount]; tables[(int)TableKind.AssemblyOS] = table; } if ((validMask & ((ulong)1 << (int)TableKind.AssemblyRef)) != 0) { uint rowCount = reader.ReadUInt32(); var table = new AssemblyRefEntry[rowCount]; tables[(int)TableKind.AssemblyRef] = table; } if ((validMask & ((ulong)1 << (int)TableKind.AssemblyRefProcessor)) != 0) { uint rowCount = reader.ReadUInt32(); var table = new AssemblyRefProcessorEntry[rowCount]; tables[(int)TableKind.AssemblyRefProcessor] = table; } if ((validMask & ((ulong)1 << (int)TableKind.AssemblyRefOS)) != 0) { uint rowCount = reader.ReadUInt32(); var table = new AssemblyRefOSEntry[rowCount]; tables[(int)TableKind.AssemblyRefOS] = table; } if ((validMask & ((ulong)1 << (int)TableKind.File)) != 0) { uint rowCount = reader.ReadUInt32(); var table = new FileEntry[rowCount]; tables[(int)TableKind.File] = table; } if ((validMask & ((ulong)1 << (int)TableKind.ExportedType)) != 0) { uint rowCount = reader.ReadUInt32(); var table = new ExportedTypeEntry[rowCount]; tables[(int)TableKind.ExportedType] = table; } if ((validMask & ((ulong)1 << (int)TableKind.ManifestResource)) != 0) { uint rowCount = reader.ReadUInt32(); var table = new ManifestResourceEntry[rowCount]; tables[(int)TableKind.ManifestResource] = table; } if ((validMask & ((ulong)1 << (int)TableKind.NestedClass)) != 0) { uint rowCount = reader.ReadUInt32(); var table = new NestedClassEntry[rowCount]; tables[(int)TableKind.NestedClass] = table; } if ((validMask & ((ulong)1 << (int)TableKind.GenericParam)) != 0) { uint rowCount = reader.ReadUInt32(); var table = new GenericParamEntry[rowCount]; tables[(int)TableKind.GenericParam] = table; } if ((validMask & ((ulong)1 << (int)TableKind.MethodSpec)) != 0) { uint rowCount = reader.ReadUInt32(); var table = new MethodSpecEntry[rowCount]; tables[(int)TableKind.MethodSpec] = table; } if ((validMask & ((ulong)1 << (int)TableKind.GenericParamConstraint)) != 0) { uint rowCount = reader.ReadUInt32(); var table = new GenericParamConstraintEntry[rowCount]; tables[(int)TableKind.GenericParamConstraint] = table; } ulong trailingZeroesMask = ulong.MaxValue << 45; if ((validMask & trailingZeroesMask) != 0) throw new BadImageFormatException("Non-standard metadata table bits."); this.Tables = tables; }