hao 0.0.19

Read, edit, create and write .net assemblies
Documentation
//! Every table read into memory at once: see [`TablesValues`].

use crate::{error::Result, io::ReadData};

use super::{tables::*, TablesStreamReader};

/// Every table's rows, read into memory in stream order through
/// [`TablesStreamReader`]. The Portable PDB Document table is not included.
#[derive(Debug, Clone)]
pub struct TablesValues {
    /// Module rows: this module's name and MVID.
    pub module: Vec<ModulesTableRow>,
    /// TypeRef rows: types from other modules and assemblies.
    pub type_ref: Vec<TypeRefTableRow>,
    /// TypeDef rows: types defined in this module.
    pub type_def: Vec<TypeDefTableRow>,
    /// FieldPtr rows: field indirection, in unoptimized `#-` metadata only.
    pub field_ptr: Vec<FieldPtrTableRow>,
    /// Field rows: fields defined in this module.
    pub field: Vec<FieldTableRow>,
    /// MethodPtr rows: method indirection, in unoptimized `#-` metadata only.
    pub method_ptr: Vec<MethodPtrTableRow>,
    /// MethodDef rows: methods defined in this module.
    pub method: Vec<MethodTableRow>,
    /// ParamPtr rows: parameter indirection, in unoptimized `#-` metadata only.
    pub param_ptr: Vec<ParamPtrTableRow>,
    /// Param rows: parameter names and flags.
    pub param: Vec<ParamTableRow>,
    /// InterfaceImpl rows: the interfaces each type implements.
    pub interface_impl: Vec<InterfaceImplTableRow>,
    /// MemberRef rows: references to methods and fields of other types.
    pub member_ref: Vec<MemberRefTableRow>,
    /// Constant rows: default values of fields, parameters and properties.
    pub constant: Vec<ConstantTableRow>,
    /// CustomAttribute rows: custom attributes.
    pub custom_attribute: Vec<CustomAttributeTableRow>,
    /// FieldMarshal rows: native marshalling of fields and parameters.
    pub field_marshal: Vec<FieldMarshalTableRow>,
    /// DeclSecurity rows: declarative security attributes.
    pub decl_security: Vec<DeclSecurityTableRow>,
    /// ClassLayout rows: explicit packing and size of types.
    pub class_layout: Vec<ClassLayoutTableRow>,
    /// FieldLayout rows: explicit field offsets.
    pub field_layout: Vec<FieldLayoutTableRow>,
    /// StandAloneSig rows: local variable and `calli` signatures.
    pub stand_alone_sig: Vec<StandAloneSigTableRow>,
    /// EventMap rows: which events each type owns.
    pub event_map: Vec<EventMapTableRow>,
    /// EventPtr rows: event indirection, in unoptimized `#-` metadata only.
    pub event_ptr: Vec<EventPtrTableRow>,
    /// Event rows: events.
    pub event: Vec<EventTableRow>,
    /// PropertyMap rows: which properties each type owns.
    pub property_map: Vec<PropertyMapTableRow>,
    /// PropertyPtr rows: property indirection, in unoptimized `#-` metadata only.
    pub property_ptr: Vec<PropertyPtrTableRow>,
    /// Property rows: properties.
    pub property: Vec<PropertyTableRow>,
    /// MethodSemantics rows: property and event accessors.
    pub method_semantics: Vec<MethodSemanticsTableRow>,
    /// MethodImpl rows: explicit overrides.
    pub method_impl: Vec<MethodImplTableRow>,
    /// ModuleRef rows: referenced modules and native libraries.
    pub module_ref: Vec<ModuleRefTableRow>,
    /// TypeSpec rows: constructed types: generic instances, arrays, pointers.
    pub type_spec: Vec<TypeSpecTableRow>,
    /// ImplMap rows: P/Invoke mappings.
    pub impl_map: Vec<ImplMapTableRow>,
    /// FieldRVA rows: initial data of fields.
    pub field_rva: Vec<FieldRVATableRow>,
    /// ENCLog rows: the Edit and Continue log.
    pub enc_log: Vec<ENCLogTableRow>,
    /// ENCMap rows: the Edit and Continue token map.
    pub enc_map: Vec<ENCMapTableRow>,
    /// The Assembly row: this assembly's name, version and key. Exactly one
    /// row is read, so this doesn't suit a netmodule, which has none.
    pub assembly: AssemblyTableRow,
    /// AssemblyProcessor rows: unused; ignored by the runtime.
    pub assembly_processor: Vec<AssemblyProcessorTableRow>,
    /// AssemblyOS rows: unused; ignored by the runtime.
    pub assembly_os: Vec<AssemblyOSTableRow>,
    /// AssemblyRef rows: referenced assemblies.
    pub assembly_ref: Vec<AssemblyRefTableRow>,
    /// AssemblyRefProcessor rows: unused; ignored by the runtime.
    pub assembly_ref_processor: Vec<AssemblyRefProcessorTableRow>,
    /// AssemblyRefOS rows: unused; ignored by the runtime.
    pub assembly_ref_os: Vec<AssemblyRefOSTableRow>,
    /// File rows: the other files of a multi-file assembly.
    pub file: Vec<FileTableRow>,
    /// ExportedType rows: exported and forwarded types.
    pub exported_type: Vec<ExportedTypeTableRow>,
    /// ManifestResource rows: embedded and linked resources.
    pub manifest_resource: Vec<ManifestResourceTableRow>,
    /// NestedClass rows: the enclosing type of each nested type.
    pub nested_class: Vec<NestedClassTableRow>,
    /// GenericParam rows: generic parameters of types and methods.
    pub generic_param: Vec<GenericParamTableRow>,
    /// MethodSpec rows: generic method instances.
    pub method_spec: Vec<MethodSpecTableRow>,
    /// GenericParamConstraint rows: constraints on generic parameters.
    pub generic_param_constraint: Vec<GenericParamConstraintTableRow>,
    /// MethodDebugInformation rows: Portable PDB: sequence points.
    pub method_debug_information: Vec<MethodDebugInformationTableRow>,
    /// LocalScope rows: Portable PDB: local variable scopes.
    pub local_scope: Vec<LocalScopeTableRow>,
    /// LocalVariable rows: Portable PDB: local variable names.
    pub local_variable: Vec<LocalVariableTableRow>,
    /// LocalConstant rows: Portable PDB: local constants.
    pub local_constant: Vec<LocalConstantTableRow>,
    /// ImportScope rows: Portable PDB: namespace imports.
    pub import_scope: Vec<ImportScopeTableRow>,
    /// StateMachineMethod rows: Portable PDB: async and iterator kickoff methods.
    pub state_machine_method: Vec<StateMachineMethodTableRow>,
    /// CustomDebugInformation rows: Portable PDB: custom debug information.
    pub custom_debug_information: Vec<CustomDebugInformationTableRow>,
}

impl<'a> ReadData<TablesValues> for TablesStreamReader<'a> {
    fn read(&mut self) -> Result<TablesValues> {
        Ok(TablesValues {
            module: self.read_rows(self.header.table_locations.module)?,
            type_ref: self.read_rows(self.header.table_locations.type_ref)?,
            type_def: self.read_rows(self.header.table_locations.type_def)?,
            field_ptr: self.read_rows(self.header.table_locations.field_ptr)?,
            field: self.read_rows(self.header.table_locations.field)?,
            method_ptr: self.read_rows(self.header.table_locations.method_ptr)?,
            method: self.read_rows(self.header.table_locations.method)?,
            param_ptr: self.read_rows(self.header.table_locations.param_ptr)?,
            param: self.read_rows(self.header.table_locations.param)?,
            interface_impl: self.read_rows(self.header.table_locations.interface_impl)?,
            member_ref: self.read_rows(self.header.table_locations.member_ref)?,
            constant: self.read_rows(self.header.table_locations.constant)?,
            custom_attribute: self.read_rows(self.header.table_locations.custom_attribute)?,
            field_marshal: self.read_rows(self.header.table_locations.field_marshal)?,
            decl_security: self.read_rows(self.header.table_locations.decl_security)?,
            class_layout: self.read_rows(self.header.table_locations.class_layout)?,
            field_layout: self.read_rows(self.header.table_locations.field_layout)?,
            stand_alone_sig: self.read_rows(self.header.table_locations.stand_alone_sig)?,
            event_map: self.read_rows(self.header.table_locations.event_map)?,
            event_ptr: self.read_rows(self.header.table_locations.event_ptr)?,
            event: self.read_rows(self.header.table_locations.event)?,
            property_map: self.read_rows(self.header.table_locations.property_map)?,
            property_ptr: self.read_rows(self.header.table_locations.property_ptr)?,
            property: self.read_rows(self.header.table_locations.property)?,
            method_semantics: self.read_rows(self.header.table_locations.method_semantics)?,
            method_impl: self.read_rows(self.header.table_locations.method_impl)?,
            module_ref: self.read_rows(self.header.table_locations.module_ref)?,
            type_spec: self.read_rows(self.header.table_locations.type_spec)?,
            impl_map: self.read_rows(self.header.table_locations.impl_map)?,
            field_rva: self.read_rows(self.header.table_locations.field_rva)?,
            enc_log: self.read_rows(self.header.table_locations.enc_log)?,
            enc_map: self.read_rows(self.header.table_locations.enc_map)?,
            assembly: self.read()?,
            assembly_processor: self.read_rows(self.header.table_locations.assembly_processor)?,
            assembly_os: self.read_rows(self.header.table_locations.assembly_os)?,
            assembly_ref: self.read_rows(self.header.table_locations.assembly_ref)?,
            assembly_ref_processor: self
                .read_rows(self.header.table_locations.assembly_ref_processor)?,
            assembly_ref_os: self.read_rows(self.header.table_locations.assembly_ref_os)?,
            file: self.read_rows(self.header.table_locations.file)?,
            exported_type: self.read_rows(self.header.table_locations.exported_type)?,
            manifest_resource: self.read_rows(self.header.table_locations.manifest_resource)?,
            nested_class: self.read_rows(self.header.table_locations.nested_class)?,
            generic_param: self.read_rows(self.header.table_locations.generic_param)?,
            method_spec: self.read_rows(self.header.table_locations.method_spec)?,
            generic_param_constraint: self
                .read_rows(self.header.table_locations.generic_param_constraint)?,
            method_debug_information: self
                .read_rows(self.header.table_locations.method_debug_information)?,
            local_scope: self.read_rows(self.header.table_locations.local_scope)?,
            local_variable: self.read_rows(self.header.table_locations.local_variable)?,
            local_constant: self.read_rows(self.header.table_locations.local_constant)?,
            import_scope: self.read_rows(self.header.table_locations.import_scope)?,
            state_machine_method: self
                .read_rows(self.header.table_locations.state_machine_method)?,
            custom_debug_information: self
                .read_rows(self.header.table_locations.custom_debug_information)?,
        })
    }
}