Module cilobject
Expand description
Implementation of a loaded + parsed CIL binary High-level .NET assembly abstraction and metadata access.
This module provides the main entry point for analyzing .NET assemblies through the
crate::CilObject struct. It offers comprehensive access to all ECMA-335 metadata
tables, streams, type system, resources, and assembly information with efficient
memory management and thread-safe access patterns.
§Architecture
The module is built around a self-referencing pattern that ensures parsed metadata structures maintain valid references to the underlying file data without expensive copying. Key architectural components include:
- File Layer: Memory-mapped file access for efficient I/O
- Metadata Layer: Structured access to ECMA-335 metadata tables and streams
- Validation Layer: Configurable validation during loading
- Caching Layer: Thread-safe caching of parsed structures
§Key Components
crate::CilObject- Main entry point for .NET assembly analysiscrate::metadata::validation::ValidationConfig- Configuration for validation during loading
§Usage Examples
§Basic Assembly Loading
use dotscope::CilObject;
use std::path::Path;
// Load an assembly from file
let assembly = CilObject::from_file(Path::new("tests/samples/WindowsBase.dll"))?;
// Access basic assembly information
if let Some(module) = assembly.module() {
println!("Module: {}", module.name);
}
if let Some(assembly_info) = assembly.assembly() {
println!("Assembly: {}", assembly_info.name);
}§Memory-based Analysis
use dotscope::CilObject;
// Load from memory buffer (e.g., downloaded or embedded)
let file_data = std::fs::read("assembly.dll")?;
let assembly = CilObject::from_mem(file_data)?;
// Access metadata streams
if let Some(strings) = assembly.strings() {
if let Ok(name) = strings.get(1) {
println!("String at index 1: {}", name);
}
}§Error Handling
All operations return crate::Result<T> with comprehensive error information:
- File I/O errors: When files cannot be read or accessed
- Format errors: When PE or metadata format is invalid
- Validation errors: When validation checks fail during loading
- Memory errors: When insufficient memory is available
§Thread Safety
crate::CilObject is designed for thread-safe concurrent read access. Internal
caching and lazy loading use appropriate synchronization primitives to ensure
correctness in multi-threaded scenarios. All public APIs are Send and Sync.
§Integration
This module integrates with:
crate::disassembler- Method body disassembly and instruction decodingcrate::metadata::tables- Low-level metadata table accesscrate::metadata::typesystem- Type resolution and signature parsing- Low-level PE file parsing and memory management components
Structs§
- CilObject
- The self-referencing struct.