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§

AssemblyFlags
All possible flags for AssemblyFlags
AssemblyHashAlgorithm
All possible values for AssemblyHashAlgorithm
EventAttributes
All possible flags for EventAttributes
FieldAttributes
All possible flags for FieldAttributes
FileAttributes
All possible flags for FileAttributes
GenericParamAttributes
All possible flags for GenericParamAttributes
MethodSemanticsAttributes
All possible flags for MethodSemanticsAttributes
ParamAttributes
All possible flags for ParamAttributes
PropertyAttributes
All possible flags for PropertyAttributes
TypeAttributes
All possible flags for TypeAttributes

Structs§

Assembly
Represents a .NET CIL binary (assembly), similar to AssemblyRaw but with resolved indexes and owned data
AssemblyOsRaw
The AssemblyOS table specifies which operating systems this assembly is targeted for, TableId = 0x22
AssemblyProcessorRaw
The AssemblyProcessor table specifies which processors this assembly is targeted for, TableId = 0x21
AssemblyRaw
Represents a .NET CIL binary (assembly), TableId = 0x20
AssemblyRef
The AssemblyRef table contains references to external assemblies, similar to AssemblyRefRaw but with resolved indexes and fully owned data.
AssemblyRefHash
The hash of a reference, is a variant of AssemblyHashAlgorithm
AssemblyRefOs
The AssemblyRefOS table specifies which operating systems a referenced assembly is targeted for, similar to AssemblyRefRaw but with resolved indexes and fully owned data.
AssemblyRefOsRaw
The AssemblyRefOS table specifies which operating systems a referenced assembly is targeted for, TableId = 0x25
AssemblyRefProcessor
The AssemblyRefProcessor table specifies which processors a referenced assembly is targeted for, similar to AssemblyRefProcessorRaw but with resolved indexes and fully owned data.
AssemblyRefProcessorRaw
The AssemblyRefProcessor table specifies which processors a referenced assembly is targeted for, TableId = 0x24
AssemblyRefRaw
The AssemblyRef table 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.
BlobIterator
Iterator over entries in the #Blob heap
ClassLayout
The ClassLayout table specifies the layout of fields within a class (explicit layout), similar to ClassLayoutRaw but with resolved indexes and owned data
ClassLayoutRaw
The ClassLayout table specifies the layout of fields within a class (explicit layout), TableId = 0x0F
CodedIndex
The decoded version of a coded-index
CodedIndexTypeIter
An iterator over the variants of CodedIndexType
Constant
The Constant table stores constant values for fields, parameters, and properties. Similar to ConstantRaw but with resolved indexes and owned data
ConstantRaw
The Constant table stores constant values for fields, parameters, and properties. TableId = 0x0B
CustomAttribute
The CustomAttribute table associates attributes with elements in various metadata tables. Similar to CustomAttributeRaw but with resolved indexes and owned data
CustomAttributeRaw
The CustomAttribute table associates attributes with elements in various metadata tables, TableId = 0x0C
DeclSecurity
The DeclSecurity table holds security declarations for types, methods, and assemblies. Similar to DeclSecurityRaw but with resolved indexes and owned data
DeclSecurityRaw
The DeclSecurity table holds security declarations for types, methods, and assemblies. TableId = 0x0E
Event
Represents an Event that a Type can have. Similar to EventRaw but with resolved indexes and owned data.
EventMapEntry
The resolved EventMap entry that maps events to their parent types. Similar to EventMapRaw but with resolved indexes and owned data.
EventMapRaw
The EventMap table maps events to their parent types. TableId = 0x12
EventRaw
The Event table defines events for types. Each entry includes the event name, flags, and event type. TableId = 0x14
ExportedType
The ExportedType table contains information about types that are exported from the current assembly, but defined in other modules of the assembly. Similar to ExportedTypeRaw but with resolved indexes and owned data
ExportedTypeRaw
The ExportedType table 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 TypeDef table. Similar to FieldRaw but with resolved indexes and owned data
FieldLayout
The FieldLayout table specifies the offset of fields within a type with explicit layout. Similar to FieldLayoutRaw but with resolved indexes and owned data
FieldLayoutRaw
The FieldLayout table specifies the offset of fields within a type with explicit layout. TableId = 0x10
FieldMarshal
The FieldMarshal table specifies marshaling information for fields and parameters. Similar to FieldMarshalRaw but with resolved indexes and owned data
FieldMarshalRaw
The FieldMarshal table specifies marshaling information for fields and parameters. TableId = 0x0D
FieldRaw
The Field table defines fields for types in the TypeDef table. TableId = 0x04
FieldRva
The FieldRVA table specifies the relative virtual address (RVA) of initial data for fields with the InitialValue attribute. Similar to FieldRVARaw but with resolved indexes and owned data
FieldRvaRaw
The FieldRVA table specifies the relative virtual address (RVA) of initial data for fields with the InitialValue attribute. TableId = 0x1D
File
The File table lists the files that make up the current assembly. Similar to FileRaw but with resolved indexes and owned data
FileRaw
The File table lists the files that make up the current assembly. TableId = 0x26
GenericParam
The GenericParam table defines generic parameters for generic types and methods. Similar to GenericParamRaw but with resolved indexes and owned data
GenericParamConstraint
The GenericParamConstraint table defines constraints on generic parameters. Similar to GenericParamConstraintRaw but with resolved indexes and owned data
GenericParamConstraintRaw
The GenericParamConstraint table defines constraints on generic parameters. TableId = 0x2C
GenericParamRaw
The GenericParam table defines generic parameters for generic types and methods. TableId = 0x2A
Guid
‘#GUID’ is a heap, which contains a sequence of 128-bit GUIDs
GuidIterator
Iterator over entries in the #GUID heap
ImplMap
The ImplMap table holds information about platform invoke (P/Invoke) methods. Similar to ImplMapRaw but with resolved indexes and owned data
ImplMapRaw
The ImplMap table holds information about platform invoke (P/Invoke) methods. TableId = 0x1C
InterfaceImpl
The InterfaceImpl table defines interface implementations for types in the TypeDef table. Similar to InterfaceImpl but with resolved indexes and owned data
InterfaceImplRaw
The InterfaceImpl table defines interface implementations for types in the TypeDef table. TableId = 0x09
ManifestResource
The ManifestResource table lists the resources for the assembly. Similar to ManifestResourceRaw but with resolved indexes and owned data
ManifestResourceAttributes
All possible flags for ManifestResourceAttributes
ManifestResourceRaw
The ManifestResource table lists the resources for the assembly. TableId = 0x28
MemberRef
The MemberRef table references members (fields or methods) of types defined in other modules. Similar to MemberRefRaw but with resolved indexes and owned data
MemberRefRaw
The MemberRef table references members (fields or methods) of types defined in other modules. TableId = 0x0A
MetadataTable
The foundation of any metadata table
MethodDefRaw
The MethodDef table defines methods for types in the TypeDef table. TableId = 0x06
MethodImpl
The MethodImpl table specifies which methods implement which methods for a class. Similar to MethodImplRaw but with resolved indexes and owned data
MethodImplRaw
The MethodImpl table specifies which methods implement which methods for a class. TableId = 0x19
MethodSemantics
The MethodSemantics table specifies the relationship between methods and events or properties. It defines which methods are getters, setters, adders, removers, etc. Similar to ConstantRaw but with resolved indexes and owned data
MethodSemanticsRaw
The MethodSemantics table specifies the relationship between methods and events or properties. It defines which methods are getters, setters, adders, removers, etc. TableId = 0x18
MethodSpec
The MethodSpec table represents instantiations of generic methods. Similar to MethodSpecRaw but with resolved indexes and owned data
MethodSpecRaw
The MethodSpec table represents instantiations of generic methods. TableId = 0x2B
Module
The Module table 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 to ModuleRaw but with resolved indexes and owned data.
ModuleRaw
The Module table 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
ModuleRef
The ModuleRef table contains references to external modules. Similar to ModuleRefRaw but with resolved indexes and owned data
ModuleRefRaw
The ModuleRef table contains references to external modules. TableId = 0x1A
NestedClass
The NestedClass table defines the relationship between nested types and their enclosing types. Similar to NestedClassRaw but with resolved indexes and owned data
NestedClassRaw
The NestedClass table defines the relationship between nested types and their enclosing types. TableId = 0x29
Param
The Param table defines parameters for methods in the MethodDef table. Similar to ParamRaw but with resolved indexes and owned data.
ParamRaw
The Param table defines parameters for methods in the MethodDef table. TableId = 0x08
Property
The Property table defines properties for types. Each entry includes the property name, flags, and signature. Similar to PropertyRaw but with resolved indexes and owned data.
PropertyMapEntry
The resolved PropertyMap entry that maps properties to their parent types. Similar to PropertyMapRaw but with resolved indexes and owned data.
PropertyMapRaw
The PropertyMap table maps properties to their parent types. TableId = 0x15
PropertyRaw
The Property table defines properties for types. Each entry includes the property name, flags, and signature. TableId = 0x17
StandAloneSig
The StandAloneSig table stores signatures that are referenced directly rather than through a member. These are primarily used for local variables and method parameters. Similar to StandAloneSig but with resolved indexes and owned data.
StandAloneSigRaw
The StandAloneSig table stores signatures that are referenced directly rather than through a member. These are primarily used for local variables and method parameters. TableId = 0x11
StreamHeader
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…
StringsIterator
Iterator over entries in the #Strings heap
TableInfo
TableInfo holds information regarding the row count and reference index field sizes of all tables in this binary
TableIterator
Iterator to enumerate all rows of a table
TableRowInfo
Holds information about the size that reference index fields have
TablesHeader
The TablesHeader structure represents the header in the ‘#’ stream. ‘#’ which contains all the metadata used for reflection and execution of the CIL binary.
TypeDefRaw
The TypeDef table defines types (classes, interfaces, value types, enums) in the current module. TableId = 0x02
TypeRefRaw
The TypeRef table contains references to types defined in other modules or assemblies. TableId = 0x01
TypeSpec
The TypeSpec table defines type specifications through signatures. Similar to TypeSpecRaw but with resolved indexes and owned data
TypeSpecRaw
TypeSpec, ID = 0x1B
UserStrings
The UserStrings object 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.
UserStringsIterator
Iterator over entries in the #US (UserStrings) heap

Enums§

CodedIndexType
Represents all possible coded index types
MemberRefSignature
Describes the signature of a MemberRef
TableData
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§

AssemblyList
A vector that holds a list of Assembly
AssemblyMap
A map that holds the mapping of Token to parsed Assembly
AssemblyOs
The AssemblyOS table specifies which operating systems this assembly is targeted for, TableId = 0x22
AssemblyOsList
A vector that holds a list of AssemblyOs
AssemblyOsMap
A map that holds the mapping of Token to parsed AssemblyOs
AssemblyOsRc
A reference to a AssemblyOs
AssemblyProcessor
The AssemblyProcessor table specifies which processors this assembly is targeted for, TableId = 0x21
AssemblyProcessorList
A vector that holds a list of AssemblyProcessor
AssemblyProcessorMap
A map that holds the mapping of Token to parsed AssemblyProcessor
AssemblyProcessorRc
A reference to a AssemblyProcessor
AssemblyRc
A reference to a Assembly
AssemblyRefList
A vector that holds a list of AssemblyRef
AssemblyRefMap
A map that holds the mapping of Token to parsed AssemblyRef
AssemblyRefOsList
A vector that holds a list of AssemblyRefOs
AssemblyRefOsMap
A map that holds the mapping of Token to parsed AssemblyRefOs
AssemblyRefOsRc
A reference to a AssemblyRefOs
AssemblyRefProcessorList
A vector that holds a list of AssemblyRefProcessor
AssemblyRefProcessorMap
A map that holds the mapping of Token to parsed AssemblyRefProcessor
AssemblyRefProcessorRc
A reference to a AssemblyRefProcessor
AssemblyRefRc
A reference to a AssemblyRef
ClassLayoutList
A vector that holds a list of ClassLayout
ClassLayoutMap
A map that holds the mapping of Token to parsed ClassLayout
ClassLayoutRc
A reference to a ClassLayout
ConstantList
A vector that holds a list of Constant
ConstantMap
A map that holds the mapping of Token to parsed Constant
ConstantRc
A reference to a Constant
CustomAttributeList
A vector that holds a list of CustomAttribute
CustomAttributeMap
A map that holds the mapping of Token to parsed CustomAttribute
CustomAttributeRc
A reference to a CustomAttribute
DeclSecurityList
A vector that holds a list of DeclSecurity
DeclSecurityMap
A map that holds the mapping of Token to parsed DeclSecurity
DeclSecurityRc
A reference to a DeclSecurity
EventList
A vector that holds a list of Event
EventMap
A map that holds the mapping of Token to parsed Event
EventMapEntryList
A vector that holds a list of resolved EventMapEntry
EventMapEntryMap
A map that holds the mapping of Token to parsed resolved EventMapEntry
EventMapEntryRc
A reference to a resolved EventMapEntry
EventRc
A reference to an Event
ExportedTypeList
A vector that holds a list of ExportedType
ExportedTypeMap
A map that holds the mapping of Token to parsed ExportedType
ExportedTypeRc
A reference to a ExportedType
FieldLayoutList
A vector that holds a list of FieldLayout
FieldLayoutMap
A map that holds the mapping of Token to parsed FieldLayout
FieldLayoutRc
A reference to a FieldLayout
FieldList
A vector that holds a list of Field
FieldMap
A map that holds the mapping of Token to parsed Field
FieldMarshalList
A vector that holds a list of FieldMarshal
FieldMarshalMap
A map that holds the mapping of Token to parsed FieldMarshal
FieldMarshalRc
A reference to a FieldMarshal
FieldRVAList
A vector that holds a list of FieldRVA
FieldRVAMap
A map that holds the mapping of Token to parsed FieldRVA
FieldRVARc
A reference to a FieldRVA
FieldRc
A reference to a field
FileList
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
GenericParamConstraintList
A vector that holds a list of GenericParamConstraint
GenericParamConstraintMap
A map that holds the mapping of Token to parsed GenericParamConstraint
GenericParamConstraintRc
A reference to a GenericParamConstraint
GenericParamList
A vector that holds a list of GenericParam
GenericParamMap
A map that holds the mapping of Token to parsed GenericParam
GenericParamRc
A reference to a GenericParam
ImplMapList
A vector that holds a list of ImplMap
ImplMapMap
A map that holds the mapping of Token to parsed ImplMap
ImplMapRc
A reference to a ImplMap
InterfaceImplList
A vector that holds a list of InterfaceImpl
InterfaceImplMap
A map that holds the mapping of Token to parsed InterfaceImpl
InterfaceImplRc
A reference to a InterfaceImpl
ManifestResourceList
A vector that holds a list of ManifestResource
ManifestResourceMap
A map that holds the mapping of Token to parsed ManifestResource
ManifestResourceRc
A reference to a ManifestResource
MemberRefList
A vector that holds a list of MemberRef
MemberRefMap
A map that holds the mapping of Token to parsed MemberRef
MemberRefRc
A reference to a MemberRef
MethodImplList
A vector that holds a list of MethodImpl
MethodImplMap
A map that holds the mapping of Token to parsed MethodImpl
MethodImplRc
A reference to a MethodImpl
MethodSemanticsList
A vector that holds a list of MethodSemantics
MethodSemanticsMap
A map that holds the mapping of Token to parsed MethodSemantics
MethodSemanticsRc
A reference to a MethodSemantics
MethodSpecList
A vector that holds a list of MethodSpec
MethodSpecMap
A map that holds the mapping of Token to parsed MethodSpec
MethodSpecRc
A reference to a MethodSpec
ModuleList
A vector that holds a list of Module
ModuleMap
A map that holds the mapping of Token to parsed Module
ModuleRc
A reference to a Module
ModuleRefList
A vector that holds a list of ModuleRef
ModuleRefMap
A map that holds the mapping of Token to parsed ModuleRef
ModuleRefRc
A reference to a ModuleRef
NestedClassList
A vector that holds a list of NestedClass
NestedClassMap
A map that holds the mapping of Token to parsed NestedClass
NestedClassRc
A reference to a NestedClass
ParamList
A vector that holds a list of Param
ParamMap
A map that holds the mapping of Token to parsed Param
ParamRc
Reference to a Param
PropertyList
A vector that holds a list of Property
PropertyMap
A map that holds the mapping of Token to parsed Property
PropertyMapEntryList
A vector that holds a list of resolved PropertyMapEntry
PropertyMapEntryMap
A map that holds the mapping of Token to parsed resolved PropertyMapEntry
PropertyMapEntryRc
A reference to a resolved PropertyMapEntry
PropertyRc
A reference to a Property
StandAloneSigList
A vector that holds a list of StandAloneSig
StandAloneSigMap
A map that holds the mapping of Token to parsed StandAloneSig
StandAloneSigRc
A reference to a StandAloneSig
TableInfoRef
Cheap-copy reference to a TableInfo structure
TypeSpecList
A vector that holds a list of TypeSpec
TypeSpecMap
A map that holds the mapping of Token to parsed TypeSpec
TypeSpecRc
A reference to a TypeSpec