Jump to content
Setting up an AI agent? ReverseEngineering.wiki skill (works from the command line, no configuration): https://reverseengineering.wiki/skill/rewiki/SKILL.md · setup for every client, including MCP: https://reverseengineering.wiki/llms.txt · REWiki:Connect

Format:.NET metadata (ECMA-335)/Tables

From ReverseEngineering.wiki

Every metadata table of ECMA-335 (ids 0x00-0x2C) and of Portable PDB (0x30-0x37) with its columns in file order, and the 14 coded-index kinds with their tag bits and target tables: what a reader needs to compute row sizes and decode rows of the #~ stream.

Tables

Column types: u8/u16/u32 fixed; #Strings, #GUID, #Blob = heap index (2 or 4 bytes by HeapSizes); "X index" = row number in table X (2 bytes up to 0xFFFF rows, else 4); "(coded)" = coded index (see below). Row numbers start at 1; 0 means null. The token of a row is the table id in the top byte and the row number below it. Ptr tables (0x03, 0x05, 0x07, 0x13, 0x16) and ENCLog/ENCMap appear only in uncompressed #- metadata. In tables-stream version 1.1 (pre-2.0 betas) GenericParam has an extra Kind column (TypeDefOrRef); every file observed had version 2.0, or 1.0 for .NET 1.x assemblies.

Id Table Token Columns
0x00 Module 0x00xxxxxx Generation (u16), Name (#Strings), Mvid (#GUID), EncId (#GUID), EncBaseId (#GUID)
0x01 TypeRef 0x01xxxxxx ResolutionScope (ResolutionScope (coded)), Name (#Strings), Namespace (#Strings)
0x02 TypeDef 0x02xxxxxx Flags (u32), Name (#Strings), Namespace (#Strings), Extends (TypeDefOrRef (coded)), FieldList (Field index), MethodList (MethodDef index)
0x03 FieldPtr 0x03xxxxxx Field (Field index)
0x04 Field 0x04xxxxxx Flags (u16), Name (#Strings), Signature (#Blob)
0x05 MethodPtr 0x05xxxxxx Method (MethodDef index)
0x06 MethodDef 0x06xxxxxx RVA (u32), ImplFlags (u16), Flags (u16), Name (#Strings), Signature (#Blob), ParamList (Param index)
0x07 ParamPtr 0x07xxxxxx Param (Param index)
0x08 Param 0x08xxxxxx Flags (u16), Sequence (u16), Name (#Strings)
0x09 InterfaceImpl 0x09xxxxxx Class (TypeDef index), Interface (TypeDefOrRef (coded))
0x0A MemberRef 0x0Axxxxxx Class (MemberRefParent (coded)), Name (#Strings), Signature (#Blob)
0x0B Constant 0x0Bxxxxxx Type (u8), Padding (u8), Parent (HasConstant (coded)), Value (#Blob)
0x0C CustomAttribute 0x0Cxxxxxx Parent (HasCustomAttribute (coded)), Type (CustomAttributeType (coded)), Value (#Blob)
0x0D FieldMarshal 0x0Dxxxxxx Parent (HasFieldMarshal (coded)), NativeType (#Blob)
0x0E DeclSecurity 0x0Exxxxxx Action (u16), Parent (HasDeclSecurity (coded)), PermissionSet (#Blob)
0x0F ClassLayout 0x0Fxxxxxx PackingSize (u16), ClassSize (u32), Parent (TypeDef index)
0x10 FieldLayout 0x10xxxxxx Offset (u32), Field (Field index)
0x11 StandAloneSig 0x11xxxxxx Signature (#Blob)
0x12 EventMap 0x12xxxxxx Parent (TypeDef index), EventList (Event index)
0x13 EventPtr 0x13xxxxxx Event (Event index)
0x14 Event 0x14xxxxxx EventFlags (u16), Name (#Strings), EventType (TypeDefOrRef (coded))
0x15 PropertyMap 0x15xxxxxx Parent (TypeDef index), PropertyList (Property index)
0x16 PropertyPtr 0x16xxxxxx Property (Property index)
0x17 Property 0x17xxxxxx Flags (u16), Name (#Strings), Type (#Blob)
0x18 MethodSemantics 0x18xxxxxx Semantics (u16), Method (MethodDef index), Association (HasSemantics (coded))
0x19 MethodImpl 0x19xxxxxx Class (TypeDef index), MethodBody (MethodDefOrRef (coded)), MethodDeclaration (MethodDefOrRef (coded))
0x1A ModuleRef 0x1Axxxxxx Name (#Strings)
0x1B TypeSpec 0x1Bxxxxxx Signature (#Blob)
0x1C ImplMap 0x1Cxxxxxx MappingFlags (u16), MemberForwarded (MemberForwarded (coded)), ImportName (#Strings), ImportScope (ModuleRef index)
0x1D FieldRVA 0x1Dxxxxxx RVA (u32), Field (Field index)
0x1E ENCLog 0x1Exxxxxx Token (u32), FuncCode (u32)
0x1F ENCMap 0x1Fxxxxxx Token (u32)
0x20 Assembly 0x20xxxxxx HashAlgId (u32), MajorVersion (u16), MinorVersion (u16), BuildNumber (u16), RevisionNumber (u16), Flags (u32), PublicKey (#Blob), Name (#Strings), Culture (#Strings)
0x21 AssemblyProcessor 0x21xxxxxx Processor (u32)
0x22 AssemblyOS 0x22xxxxxx OSPlatformId (u32), OSMajorVersion (u32), OSMinorVersion (u32)
0x23 AssemblyRef 0x23xxxxxx MajorVersion (u16), MinorVersion (u16), BuildNumber (u16), RevisionNumber (u16), Flags (u32), PublicKeyOrToken (#Blob), Name (#Strings), Culture (#Strings), HashValue (#Blob)
0x24 AssemblyRefProcessor 0x24xxxxxx Processor (u32), AssemblyRef (AssemblyRef index)
0x25 AssemblyRefOS 0x25xxxxxx OSPlatformId (u32), OSMajorVersion (u32), OSMinorVersion (u32), AssemblyRef (AssemblyRef index)
0x26 File 0x26xxxxxx Flags (u32), Name (#Strings), HashValue (#Blob)
0x27 ExportedType 0x27xxxxxx Flags (u32), TypeDefId (u32), TypeName (#Strings), TypeNamespace (#Strings), Implementation (Implementation (coded))
0x28 ManifestResource 0x28xxxxxx Offset (u32), Flags (u32), Name (#Strings), Implementation (Implementation (coded))
0x29 NestedClass 0x29xxxxxx NestedClass (TypeDef index), EnclosingClass (TypeDef index)
0x2A GenericParam 0x2Axxxxxx Number (u16), Flags (u16), Owner (TypeOrMethodDef (coded)), Name (#Strings)
0x2B MethodSpec 0x2Bxxxxxx Method (MethodDefOrRef (coded)), Instantiation (#Blob)
0x2C GenericParamConstraint 0x2Cxxxxxx Owner (GenericParam index), Constraint (TypeDefOrRef (coded))
0x30 Document 0x30xxxxxx Name (#Blob), HashAlgorithm (#GUID), Hash (#Blob), Language (#GUID)
0x31 MethodDebugInformation 0x31xxxxxx Document (Document index), SequencePoints (#Blob)
0x32 LocalScope 0x32xxxxxx Method (MethodDef index), ImportScope (ImportScope index), VariableList (LocalVariable index), ConstantList (LocalConstant index), StartOffset (u32), Length (u32)
0x33 LocalVariable 0x33xxxxxx Attributes (u16), Index (u16), Name (#Strings)
0x34 LocalConstant 0x34xxxxxx Name (#Strings), Signature (#Blob)
0x35 ImportScope 0x35xxxxxx Parent (ImportScope index), Imports (#Blob)
0x36 StateMachineMethod 0x36xxxxxx MoveNextMethod (MethodDef index), KickoffMethod (MethodDef index)
0x37 CustomDebugInformation 0x37xxxxxx Parent (HasCustomDebugInformation (coded)), Kind (#GUID), Value (#Blob)

Ids 0x2D-0x2F are unused. Tables 0x30-0x37 live in Format:Portable PDB files; there, indexes into type-system tables (MethodDef in LocalScope, StateMachineMethod) are sized by the row counts of the #Pdb stream.

Coded indexes

A coded index stores row << tag_bits | tag; the tag selects the table. It is 2 bytes when every table it can point to has fewer than 2^(16 - tag_bits) rows, otherwise 4 (Fact:.NET metadata (ECMA-335)/behavior/Column widths).

Coded index Tag bits Tables by tag
TypeDefOrRef 2 0 TypeDef, 1 TypeRef, 2 TypeSpec
HasConstant 2 0 Field, 1 Param, 2 Property
HasCustomAttribute 5 0 MethodDef, 1 Field, 2 TypeRef, 3 TypeDef, 4 Param, 5 InterfaceImpl, 6 MemberRef, 7 Module, 8 DeclSecurity, 9 Property, 10 Event, 11 StandAloneSig, 12 ModuleRef, 13 TypeSpec, 14 Assembly, 15 AssemblyRef, 16 File, 17 ExportedType, 18 ManifestResource, 19 GenericParam, 20 GenericParamConstraint, 21 MethodSpec
HasFieldMarshal 1 0 Field, 1 Param
HasDeclSecurity 2 0 TypeDef, 1 MethodDef, 2 Assembly
MemberRefParent 3 0 TypeDef, 1 TypeRef, 2 ModuleRef, 3 MethodDef, 4 TypeSpec
HasSemantics 1 0 Event, 1 Property
MethodDefOrRef 1 0 MethodDef, 1 MemberRef
MemberForwarded 1 0 Field, 1 MethodDef
Implementation 2 0 File, 1 AssemblyRef, 2 ExportedType
CustomAttributeType 3 0 (unused), 1 (unused), 2 MethodDef, 3 MemberRef, 4 (unused)
ResolutionScope 2 0 Module, 1 ModuleRef, 2 AssemblyRef, 3 TypeRef
TypeOrMethodDef 1 0 TypeDef, 1 MethodDef
HasCustomDebugInformation 5 0 MethodDef, 1 Field, 2 TypeRef, 3 TypeDef, 4 Param, 5 InterfaceImpl, 6 MemberRef, 7 Module, 8 DeclSecurity, 9 Property, 10 Event, 11 StandAloneSig, 12 ModuleRef, 13 TypeSpec, 14 Assembly, 15 AssemblyRef, 16 File, 17 ExportedType, 18 ManifestResource, 19 GenericParam, 20 GenericParamConstraint, 21 MethodSpec, 22 Document, 23 LocalScope, 24 LocalVariable, 25 LocalConstant, 26 ImportScope

Example: a CustomAttribute.Type value 0x0123 with 3 tag bits is tag 3 (MemberRef), row 0x24, i.e. the attribute constructor is MemberRef token 0x0A000024.

Evidence & references

  • ECMA-335 6th edition, Partition II chapter 22 (tables) and 24.2.6 (coded indexes); Portable PDB v1.0 specification (dotnet/runtime docs/design/specs/PortablePdb-Metadata.md).
  • dnlib at commit 9ab9b58ab31b99b3f6cdef36efec613fc11ddbe2: src/DotNet/MD/DotNetTableSizes.cs lines 125-405 (columns of every table, GenericParam variant for version 1.1 at 337-355), src/DotNet/MD/CodedToken.cs lines 11-90, src/DotNet/MD/Table.cs lines 7-115.
  • The table above was generated from the schema of Code:.NET metadata (ECMA-335)/dotnetmd (Python), which reads 432 framework assemblies identically to dnfile (row counts and TypeDef/MethodDef/MemberRef/CustomAttribute rows).