Module streams
Expand description
Implementation of all metadata streams (tables, heaps, etc.) Metadata streams for .NET assemblies.
This module implements the parsing and representation of metadata streams according to the ECMA-335 standard. Streams store different types of CIL-related data including metadata tables, string heaps, binary data, and GUIDs.
§Stream Types
The .NET metadata format defines five standard stream types, each serving a specific purpose:
§String Heaps
#Strings- UTF-8 identifier strings heap containing type names, member names, etc. The first entry is always null (\0). All valid entries are null-terminated.#US- UTF-16 user string heap containing string literals from IL code. Each entry includes a length prefix and terminal byte for special character handling.
§Binary Data
#Blob- Binary heap containing signatures, custom attribute data, and other variable-length binary structures referenced by metadata tables.#GUID- Sequence of 128-bit GUIDs used for assembly identity and versioning.
§Metadata Tables
#~- Compressed metadata tables containing type definitions, method signatures, field layouts, and all structural information about the assembly.
§Iterator Support
All heap types (Strings, UserStrings, Blob, Guid) provide both indexed access via get()
methods and efficient iterator support for sequential traversal of all entries. Iterators
provide efficient access and delegate to the parent heap’s parsing logic for consistency.
§Examples
use dotscope::CilObject;
let assembly = CilObject::from_file("tests/samples/WindowsBase.dll".as_ref())?;
let file = assembly.file();
// Access string heap
if let Some(strings) = assembly.strings() {
let type_name = strings.get(0x123)?; // Get string at offset 0x123
// Iterate through all strings in the heap
for result in strings.iter() {
match result {
Ok((offset, string)) => println!("String at {}: '{}'", offset, string),
Err(e) => eprintln!("Error: {}", e),
}
}
}
// Access blob heap for signatures
if let Some(blob) = assembly.blob() {
let signature_data = blob.get(1)?; // Get blob at offset 1
// Iterate through all blobs
for result in blob.iter() {
match result {
Ok((offset, blob_data)) => println!("Blob at {}: {} bytes", offset, blob_data.len()),
Err(e) => eprintln!("Error: {}", e),
}
}
}
// Access GUID heap for assembly identifiers
if let Some(guid) = assembly.guids() {
let assembly_guid = guid.get(1)?; // Get GUID at index 1
// Iterate through all GUIDs
for result in guid.iter() {
match result {
Ok((index, guid_bytes)) => println!("GUID at {}: {:?}", index, guid_bytes),
Err(e) => eprintln!("Error: {}", e),
}
}
}
// Access user strings heap for string literals
if let Some(user_strings) = assembly.userstrings() {
let literal = user_strings.get(0x100)?; // Get user string at offset 0x100
// Iterate through all user strings
for result in user_strings.iter() {
match result {
Ok((offset, string)) => println!("User string at {}: '{}'", offset, string.to_string_lossy()),
Err(e) => eprintln!("Error: {}", e),
}
}
}
// Access metadata tables
if let Some(tables) = assembly.tables() {
let table_count = tables.table_count();
}§Implementation Notes
- All streams use compressed integer encoding for sizes and offsets
- String heaps use null-terminated UTF-8/UTF-16 encoding
- Blob heap entries are prefixed with compressed length values
- Metadata tables use token-based cross-references between entries
§References
- ECMA-335 6th Edition, Partition II, Section 24.2.2 - Stream Headers
- ECMA-335 6th Edition, Partition II, Section 22 - Metadata Tables
Modules§
- Assembly
Flags - All possible flags for
AssemblyFlags - Assembly
Hash Algorithm - All possible values for
AssemblyHashAlgorithm - Event
Attributes - All possible flags for
EventAttributes - Field
Attributes - All possible flags for
FieldAttributes - File
Attributes - All possible flags for
FileAttributes - Generic
Param Attributes - All possible flags for
GenericParamAttributes - Method
Semantics Attributes - All possible flags for
MethodSemanticsAttributes - Param
Attributes - All possible flags for
ParamAttributes - Property
Attributes - All possible flags for
PropertyAttributes - Type
Attributes - All possible flags for
TypeAttributes
Structs§
- Assembly
- Represents a .NET CIL binary (assembly), similar to
AssemblyRawbut with resolved indexes and owned data - Assembly
OsRaw - The
AssemblyOStable specifies which operating systems this assembly is targeted for,TableId= 0x22 - Assembly
Processor Raw - The
AssemblyProcessortable specifies which processors this assembly is targeted for,TableId= 0x21 - Assembly
Raw - Represents a .NET CIL binary (assembly),
TableId= 0x20 - Assembly
Ref - The
AssemblyReftable contains references to external assemblies, similar toAssemblyRefRawbut with resolved indexes and fully owned data. - Assembly
RefHash - The hash of a reference, is a variant of
AssemblyHashAlgorithm - Assembly
RefOs - The
AssemblyRefOStable specifies which operating systems a referenced assembly is targeted for, similar toAssemblyRefRawbut with resolved indexes and fully owned data. - Assembly
RefOs Raw - The
AssemblyRefOStable specifies which operating systems a referenced assembly is targeted for,TableId= 0x25 - Assembly
RefProcessor - The
AssemblyRefProcessortable specifies which processors a referenced assembly is targeted for, similar toAssemblyRefProcessorRawbut with resolved indexes and fully owned data. - Assembly
RefProcessor Raw - The
AssemblyRefProcessortable specifies which processors a referenced assembly is targeted for,TableId= 0x24 - Assembly
RefRaw - The
AssemblyReftable contains references to external assemblies,TableId= 0x23 - Blob
- ‘#Blob’ points to streams of bytes. There are chunks, which may not be accessible in between of others that are. Each ‘valid’ blob is pointed to by another table / index, and each contains their size encoded into the first byte.
- Blob
Iterator - Iterator over entries in the
#Blobheap - Class
Layout - The
ClassLayouttable specifies the layout of fields within a class (explicit layout), similar toClassLayoutRawbut with resolved indexes and owned data - Class
Layout Raw - The
ClassLayouttable specifies the layout of fields within a class (explicit layout),TableId= 0x0F - Coded
Index - The decoded version of a coded-index
- Coded
Index Type Iter - An iterator over the variants of CodedIndexType
- Constant
- The Constant table stores constant values for fields, parameters, and properties. Similar to
ConstantRawbut with resolved indexes and owned data - Constant
Raw - The Constant table stores constant values for fields, parameters, and properties.
TableId= 0x0B - Custom
Attribute - The
CustomAttributetable associates attributes with elements in various metadata tables. Similar toCustomAttributeRawbut with resolved indexes and owned data - Custom
Attribute Raw - The
CustomAttributetable associates attributes with elements in various metadata tables,TableId= 0x0C - Decl
Security - The
DeclSecuritytable holds security declarations for types, methods, and assemblies. Similar toDeclSecurityRawbut with resolved indexes and owned data - Decl
Security Raw - The
DeclSecuritytable holds security declarations for types, methods, and assemblies.TableId= 0x0E - Event
- Represents an Event that a Type can have. Similar to
EventRawbut with resolved indexes and owned data. - Event
MapEntry - The resolved
EventMapentry that maps events to their parent types. Similar toEventMapRawbut with resolved indexes and owned data. - Event
MapRaw - The
EventMaptable maps events to their parent types.TableId= 0x12 - Event
Raw - The Event table defines events for types. Each entry includes the event name, flags, and event type.
TableId= 0x14 - Exported
Type - The
ExportedTypetable contains information about types that are exported from the current assembly, but defined in other modules of the assembly. Similar toExportedTypeRawbut with resolved indexes and owned data - Exported
Type Raw - The
ExportedTypetable contains information about types that are exported from the current assembly, but defined in other modules of the assembly.TableId= 0x27 - Field
- The Field table defines fields for types in the
TypeDeftable. Similar toFieldRawbut with resolved indexes and owned data - Field
Layout - The
FieldLayouttable specifies the offset of fields within a type with explicit layout. Similar toFieldLayoutRawbut with resolved indexes and owned data - Field
Layout Raw - The
FieldLayouttable specifies the offset of fields within a type with explicit layout.TableId= 0x10 - Field
Marshal - The
FieldMarshaltable specifies marshaling information for fields and parameters. Similar toFieldMarshalRawbut with resolved indexes and owned data - Field
Marshal Raw - The
FieldMarshaltable specifies marshaling information for fields and parameters.TableId= 0x0D - Field
Raw - The Field table defines fields for types in the
TypeDeftable.TableId= 0x04 - Field
Rva - The
FieldRVAtable specifies the relative virtual address (RVA) of initial data for fields with theInitialValueattribute. Similar toFieldRVARawbut with resolved indexes and owned data - Field
RvaRaw - The
FieldRVAtable specifies the relative virtual address (RVA) of initial data for fields with theInitialValueattribute.TableId= 0x1D - File
- The File table lists the files that make up the current assembly. Similar to
FileRawbut with resolved indexes and owned data - FileRaw
- The File table lists the files that make up the current assembly.
TableId= 0x26 - Generic
Param - The
GenericParamtable defines generic parameters for generic types and methods. Similar toGenericParamRawbut with resolved indexes and owned data - Generic
Param Constraint - The
GenericParamConstrainttable defines constraints on generic parameters. Similar toGenericParamConstraintRawbut with resolved indexes and owned data - Generic
Param Constraint Raw - The
GenericParamConstrainttable defines constraints on generic parameters.TableId= 0x2C - Generic
Param Raw - The
GenericParamtable defines generic parameters for generic types and methods.TableId= 0x2A - Guid
- ‘#GUID’ is a heap, which contains a sequence of 128-bit GUIDs
- Guid
Iterator - Iterator over entries in the
#GUIDheap - ImplMap
- The
ImplMaptable holds information about platform invoke (P/Invoke) methods. Similar toImplMapRawbut with resolved indexes and owned data - Impl
MapRaw - The
ImplMaptable holds information about platform invoke (P/Invoke) methods.TableId= 0x1C - Interface
Impl - The
InterfaceImpltable defines interface implementations for types in theTypeDeftable. Similar toInterfaceImplbut with resolved indexes and owned data - Interface
Impl Raw - The
InterfaceImpltable defines interface implementations for types in theTypeDeftable.TableId= 0x09 - Manifest
Resource - The
ManifestResourcetable lists the resources for the assembly. Similar toManifestResourceRawbut with resolved indexes and owned data - Manifest
Resource Attributes - All possible flags for ManifestResourceAttributes
- Manifest
Resource Raw - The
ManifestResourcetable lists the resources for the assembly.TableId= 0x28 - Member
Ref - The
MemberReftable references members (fields or methods) of types defined in other modules. Similar toMemberRefRawbut with resolved indexes and owned data - Member
RefRaw - The
MemberReftable references members (fields or methods) of types defined in other modules.TableId= 0x0A - Metadata
Table - The foundation of any metadata table
- Method
DefRaw - The
MethodDeftable defines methods for types in theTypeDeftable.TableId= 0x06 - Method
Impl - The
MethodImpltable specifies which methods implement which methods for a class. Similar toMethodImplRawbut with resolved indexes and owned data - Method
Impl Raw - The
MethodImpltable specifies which methods implement which methods for a class.TableId= 0x19 - Method
Semantics - The
MethodSemanticstable specifies the relationship between methods and events or properties. It defines which methods are getters, setters, adders, removers, etc. Similar toConstantRawbut with resolved indexes and owned data - Method
Semantics Raw - The
MethodSemanticstable specifies the relationship between methods and events or properties. It defines which methods are getters, setters, adders, removers, etc.TableId= 0x18 - Method
Spec - The
MethodSpectable represents instantiations of generic methods. Similar toMethodSpecRawbut with resolved indexes and owned data - Method
Spec Raw - The
MethodSpectable represents instantiations of generic methods.TableId= 0x2B - Module
- The
Moduletable provides information about the current module, including its name, GUID (Mvid), and generation. There is only one row in this table for each PE file. Similar toModuleRawbut with resolved indexes and owned data. - Module
Raw - The
Moduletable provides information about the current module, including its name, GUID (Mvid), and generation. There is only one row in this table for each PE file. Table Id = 0x00 - Module
Ref - The
ModuleReftable contains references to external modules. Similar toModuleRefRawbut with resolved indexes and owned data - Module
RefRaw - The
ModuleReftable contains references to external modules.TableId= 0x1A - Nested
Class - The
NestedClasstable defines the relationship between nested types and their enclosing types. Similar toNestedClassRawbut with resolved indexes and owned data - Nested
Class Raw - The
NestedClasstable defines the relationship between nested types and their enclosing types.TableId= 0x29 - Param
- The
Paramtable defines parameters for methods in theMethodDeftable. Similar toParamRawbut with resolved indexes and owned data. - Param
Raw - The
Paramtable defines parameters for methods in theMethodDeftable.TableId= 0x08 - Property
- The
Propertytable defines properties for types. Each entry includes the property name, flags, and signature. Similar toPropertyRawbut with resolved indexes and owned data. - Property
MapEntry - The resolved
PropertyMapentry that maps properties to their parent types. Similar toPropertyMapRawbut with resolved indexes and owned data. - Property
MapRaw - The
PropertyMaptable maps properties to their parent types.TableId= 0x15 - Property
Raw - The
Propertytable defines properties for types. Each entry includes the property name, flags, and signature.TableId= 0x17 - Stand
Alone Sig - The
StandAloneSigtable stores signatures that are referenced directly rather than through a member. These are primarily used for local variables and method parameters. Similar toStandAloneSigbut with resolved indexes and owned data. - Stand
Alone SigRaw - The
StandAloneSigtable stores signatures that are referenced directly rather than through a member. These are primarily used for local variables and method parameters.TableId= 0x11 - Stream
Header - A stream header provides the names, and the position and length of a particular table or heap. Note that the length of a Stream header structure is not fixed, but depends on the length of its name field (a variable length null-terminated string).
- Strings
- ‘#Strings’ hold various identifiers which are referenced form other tables within the CIL metadata. e.g. various strings for reflection: function names, 0xclass names, 0xvariables, 0x…
- Strings
Iterator - Iterator over entries in the
#Stringsheap - Table
Info TableInfoholds information regarding the row count and reference index field sizes of all tables in this binary- Table
Iterator - Iterator to enumerate all rows of a table
- Table
RowInfo - Holds information about the size that reference index fields have
- Tables
Header - The
TablesHeaderstructure represents the header in the ‘#’ stream. ‘#’ which contains all the metadata used for reflection and execution of the CIL binary. - Type
DefRaw - The
TypeDeftable defines types (classes, interfaces, value types, enums) in the current module.TableId= 0x02 - Type
RefRaw - The
TypeReftable contains references to types defined in other modules or assemblies.TableId= 0x01 - Type
Spec - The
TypeSpectable defines type specifications through signatures. Similar toTypeSpecRawbut with resolved indexes and owned data - Type
Spec Raw TypeSpec, ID = 0x1B- User
Strings - The
UserStringsobject provides helper methods to access the data within the ‘#US’ heap. That heap contains all user defined Strings, and this object allows to interface with it, and parse and process it properly according to the standard. - User
Strings Iterator - Iterator over entries in the
#US(UserStrings) heap
Enums§
- Coded
Index Type - Represents all possible coded index types
- Member
RefSignature - Describes the signature of a
MemberRef - Table
Data - Represents all possible tables in a ‘#~’ CIL heap
- TableId
- Identifiers for the different metadata tables defined in the ECMA-335 specification.
Traits§
- RowDefinition
- Trait for common row functionality
Type Aliases§
- Assembly
List - A vector that holds a list of
Assembly - Assembly
Map - A map that holds the mapping of Token to parsed
Assembly - Assembly
Os - The
AssemblyOStable specifies which operating systems this assembly is targeted for,TableId= 0x22 - Assembly
OsList - A vector that holds a list of
AssemblyOs - Assembly
OsMap - A map that holds the mapping of Token to parsed
AssemblyOs - Assembly
OsRc - A reference to a
AssemblyOs - Assembly
Processor - The
AssemblyProcessortable specifies which processors this assembly is targeted for,TableId= 0x21 - Assembly
Processor List - A vector that holds a list of
AssemblyProcessor - Assembly
Processor Map - A map that holds the mapping of Token to parsed
AssemblyProcessor - Assembly
Processor Rc - A reference to a
AssemblyProcessor - Assembly
Rc - A reference to a
Assembly - Assembly
RefList - A vector that holds a list of
AssemblyRef - Assembly
RefMap - A map that holds the mapping of Token to parsed
AssemblyRef - Assembly
RefOs List - A vector that holds a list of
AssemblyRefOs - Assembly
RefOs Map - A map that holds the mapping of Token to parsed
AssemblyRefOs - Assembly
RefOs Rc - A reference to a
AssemblyRefOs - Assembly
RefProcessor List - A vector that holds a list of
AssemblyRefProcessor - Assembly
RefProcessor Map - A map that holds the mapping of Token to parsed
AssemblyRefProcessor - Assembly
RefProcessor Rc - A reference to a
AssemblyRefProcessor - Assembly
RefRc - A reference to a
AssemblyRef - Class
Layout List - A vector that holds a list of
ClassLayout - Class
Layout Map - A map that holds the mapping of Token to parsed
ClassLayout - Class
Layout Rc - A reference to a
ClassLayout - Constant
List - A vector that holds a list of
Constant - Constant
Map - A map that holds the mapping of Token to parsed
Constant - Constant
Rc - A reference to a
Constant - Custom
Attribute List - A vector that holds a list of
CustomAttribute - Custom
Attribute Map - A map that holds the mapping of Token to parsed
CustomAttribute - Custom
Attribute Rc - A reference to a
CustomAttribute - Decl
Security List - A vector that holds a list of
DeclSecurity - Decl
Security Map - A map that holds the mapping of Token to parsed
DeclSecurity - Decl
Security Rc - A reference to a
DeclSecurity - Event
List - A vector that holds a list of
Event - Event
Map - A map that holds the mapping of Token to parsed
Event - Event
MapEntry List - A vector that holds a list of resolved
EventMapEntry - Event
MapEntry Map - A map that holds the mapping of Token to parsed resolved
EventMapEntry - Event
MapEntry Rc - A reference to a resolved
EventMapEntry - EventRc
- A reference to an
Event - Exported
Type List - A vector that holds a list of
ExportedType - Exported
Type Map - A map that holds the mapping of Token to parsed
ExportedType - Exported
Type Rc - A reference to a
ExportedType - Field
Layout List - A vector that holds a list of
FieldLayout - Field
Layout Map - A map that holds the mapping of Token to parsed
FieldLayout - Field
Layout Rc - A reference to a
FieldLayout - Field
List - A vector that holds a list of
Field - Field
Map - A map that holds the mapping of Token to parsed
Field - Field
Marshal List - A vector that holds a list of
FieldMarshal - Field
Marshal Map - A map that holds the mapping of Token to parsed
FieldMarshal - Field
Marshal Rc - A reference to a
FieldMarshal - FieldRVA
List - A vector that holds a list of
FieldRVA - FieldRVA
Map - A map that holds the mapping of Token to parsed
FieldRVA - FieldRVA
Rc - A reference to a
FieldRVA - FieldRc
- A reference to a field
- File
List - A vector that holds a list of
File - FileMap
- A map that holds the mapping of Token to parsed
File - FileRc
- A reference to a
File - Generic
Param Constraint List - A vector that holds a list of
GenericParamConstraint - Generic
Param Constraint Map - A map that holds the mapping of Token to parsed
GenericParamConstraint - Generic
Param Constraint Rc - A reference to a
GenericParamConstraint - Generic
Param List - A vector that holds a list of
GenericParam - Generic
Param Map - A map that holds the mapping of Token to parsed
GenericParam - Generic
Param Rc - A reference to a
GenericParam - Impl
MapList - A vector that holds a list of
ImplMap - Impl
MapMap - A map that holds the mapping of Token to parsed
ImplMap - Impl
MapRc - A reference to a
ImplMap - Interface
Impl List - A vector that holds a list of
InterfaceImpl - Interface
Impl Map - A map that holds the mapping of Token to parsed
InterfaceImpl - Interface
Impl Rc - A reference to a
InterfaceImpl - Manifest
Resource List - A vector that holds a list of
ManifestResource - Manifest
Resource Map - A map that holds the mapping of Token to parsed
ManifestResource - Manifest
Resource Rc - A reference to a
ManifestResource - Member
RefList - A vector that holds a list of
MemberRef - Member
RefMap - A map that holds the mapping of Token to parsed
MemberRef - Member
RefRc - A reference to a
MemberRef - Method
Impl List - A vector that holds a list of
MethodImpl - Method
Impl Map - A map that holds the mapping of Token to parsed
MethodImpl - Method
Impl Rc - A reference to a
MethodImpl - Method
Semantics List - A vector that holds a list of
MethodSemantics - Method
Semantics Map - A map that holds the mapping of Token to parsed
MethodSemantics - Method
Semantics Rc - A reference to a
MethodSemantics - Method
Spec List - A vector that holds a list of
MethodSpec - Method
Spec Map - A map that holds the mapping of Token to parsed
MethodSpec - Method
Spec Rc - A reference to a
MethodSpec - Module
List - A vector that holds a list of
Module - Module
Map - A map that holds the mapping of Token to parsed
Module - Module
Rc - A reference to a
Module - Module
RefList - A vector that holds a list of
ModuleRef - Module
RefMap - A map that holds the mapping of Token to parsed
ModuleRef - Module
RefRc - A reference to a
ModuleRef - Nested
Class List - A vector that holds a list of
NestedClass - Nested
Class Map - A map that holds the mapping of Token to parsed
NestedClass - Nested
Class Rc - A reference to a
NestedClass - Param
List - A vector that holds a list of
Param - Param
Map - A map that holds the mapping of Token to parsed
Param - ParamRc
- Reference to a
Param - Property
List - A vector that holds a list of
Property - Property
Map - A map that holds the mapping of Token to parsed
Property - Property
MapEntry List - A vector that holds a list of resolved
PropertyMapEntry - Property
MapEntry Map - A map that holds the mapping of Token to parsed resolved
PropertyMapEntry - Property
MapEntry Rc - A reference to a resolved
PropertyMapEntry - Property
Rc - A reference to a
Property - Stand
Alone SigList - A vector that holds a list of
StandAloneSig - Stand
Alone SigMap - A map that holds the mapping of Token to parsed
StandAloneSig - Stand
Alone SigRc - A reference to a
StandAloneSig - Table
Info Ref - Cheap-copy reference to a
TableInfostructure - Type
Spec List - A vector that holds a list of
TypeSpec - Type
Spec Map - A map that holds the mapping of Token to parsed
TypeSpec - Type
Spec Rc - A reference to a
TypeSpec