Module cor20header
Expand description
Implementation of the Header of CIL CLR 2.0 (Cor20) header parsing for .NET assemblies.
This module provides parsing functionality for the CLI (Common Language Infrastructure) header
found in .NET assemblies. The CLI header is located at the IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR
data directory of PE files and contains essential metadata required by the .NET runtime.
§Architecture
The module implements parsing for the 72-byte CLI header structure defined by ECMA-335 II.24.3.3. The header contains fixed-size fields arranged in a specific order, with comprehensive validation of field values according to the specification.
§Header Structure
The CLI header consists of:
- Header information: Size (4 bytes) and runtime version (4 bytes)
- Metadata directory: RVA and size of the metadata root (8 bytes)
- Runtime control: Flags and entry point token (8 bytes)
- Optional directories: Resources, strong names, VTable fixups (48 bytes)
§Key Components
crate::metadata::cor20header::Cor20Header- Main structure representing the parsed CLI header- Comprehensive field validation according to ECMA-335 requirements
- Support for all CLI header features including mixed-mode assemblies
§Usage Examples
§Basic Header Parsing
use dotscope::metadata::cor20header::Cor20Header;
// Parse CLI header from PE file data
let header_data: &[u8] = &[/* 72 bytes of CLI header */];
let cli_header = Cor20Header::read(header_data)?;
println!("Runtime version: {}.{}",
cli_header.major_runtime_version,
cli_header.minor_runtime_version);
println!("Metadata at RVA: 0x{:X}, size: {} bytes",
cli_header.meta_data_rva,
cli_header.meta_data_size);§Runtime Flag Analysis
use dotscope::metadata::cor20header::Cor20Header;
let header_bytes: &[u8] = &[/* CLI header data */];
let header = Cor20Header::read(&header_bytes)?;
// Check common runtime flags
const COMIMAGE_FLAGS_ILONLY: u32 = 0x00000001;
const COMIMAGE_FLAGS_32BITREQUIRED: u32 = 0x00000002;
if header.flags & COMIMAGE_FLAGS_ILONLY != 0 {
println!("Assembly contains only managed code");
}
if header.flags & COMIMAGE_FLAGS_32BITREQUIRED != 0 {
println!("Assembly requires 32-bit runtime");
}§Thread Safety
All types and functions in this module are thread-safe. The crate::metadata::cor20header::Cor20Header
struct contains only primitive types and is std::marker::Send and std::marker::Sync.
The parsing function is stateless and can be called concurrently from multiple threads.
§Integration
This module integrates with:
crate::File- PE file parsing to locate the CLI headercrate::metadata- Metadata parsing using header informationcrate::Error- Error handling for malformed headers
§Standards Compliance
- ECMA-335: Full compliance with CLI header specification (II.24.3.3)
- PE Format: Correct interpretation of data directory entries
- Validation: Comprehensive field validation per specification requirements
§Reference
Structs§
- Cor20
Flags - COR20 runtime flags wrapper with human-readable Display.
- Cor20
Header - The CLI (Common Language Infrastructure) header for .NET assemblies.