Skip to main content

Metadata

Struct Metadata 

Source
pub struct Metadata {
Show 51 fields pub root: MetadataRoot, pub strings: StringsHeap, pub user_strings: UserStringsHeap, pub guids: GuidHeap, pub blobs: BlobHeap, pub tables_header: TablesHeader, pub modules: Vec<ModuleRow>, pub type_refs: Vec<TypeRefRow>, pub type_defs: Vec<TypeDefRow>, pub field_ptrs: Vec<FieldPtrRow>, pub fields: Vec<FieldRow>, pub method_ptrs: Vec<MethodPtrRow>, pub method_defs: Vec<MethodDefRow>, pub param_ptrs: Vec<ParamPtrRow>, pub params: Vec<ParamRow>, pub interface_impls: Vec<InterfaceImplRow>, pub member_refs: Vec<MemberRefRow>, pub constants: Vec<ConstantRow>, pub custom_attributes: Vec<CustomAttributeRow>, pub field_marshals: Vec<FieldMarshalRow>, pub decl_securities: Vec<DeclSecurityRow>, pub class_layouts: Vec<ClassLayoutRow>, pub field_layouts: Vec<FieldLayoutRow>, pub stand_alone_sigs: Vec<StandAloneSigRow>, pub event_maps: Vec<EventMapRow>, pub event_ptrs: Vec<EventPtrRow>, pub events: Vec<EventRow>, pub property_maps: Vec<PropertyMapRow>, pub property_ptrs: Vec<PropertyPtrRow>, pub properties: Vec<PropertyRow>, pub method_semantics: Vec<MethodSemanticsRow>, pub method_impls: Vec<MethodImplRow>, pub module_refs: Vec<ModuleRefRow>, pub type_specs: Vec<TypeSpecRow>, pub impl_maps: Vec<ImplMapRow>, pub field_rvas: Vec<FieldRvaRow>, pub enc_logs: Vec<EncLogRow>, pub enc_maps: Vec<EncMapRow>, pub assemblies: Vec<AssemblyRow>, pub assembly_processors: Vec<AssemblyProcessorRow>, pub assembly_oses: Vec<AssemblyOsRow>, pub assembly_refs: Vec<AssemblyRefRow>, pub assembly_ref_processors: Vec<AssemblyRefProcessorRow>, pub assembly_ref_oses: Vec<AssemblyRefOsRow>, pub files: Vec<FileRow>, pub exported_types: Vec<ExportedTypeRow>, pub manifest_resources: Vec<ManifestResourceRow>, pub nested_classes: Vec<NestedClassRow>, pub generic_params: Vec<GenericParamRow>, pub method_specs: Vec<MethodSpecRow>, pub generic_param_constraints: Vec<GenericParamConstraintRow>,
}
Expand description

Parsed CLR metadata with read/write support.

Fields§

§root: MetadataRoot

The metadata root (BSJB header).

§strings: StringsHeap

The #Strings heap.

§user_strings: UserStringsHeap

The #US (user strings) heap.

§guids: GuidHeap

The #GUID heap.

§blobs: BlobHeap

The #Blob heap.

§tables_header: TablesHeader

The tables header.

§modules: Vec<ModuleRow>

Module table rows (0x00).

§type_refs: Vec<TypeRefRow>

TypeRef table rows (0x01).

§type_defs: Vec<TypeDefRow>

TypeDef table rows (0x02).

§field_ptrs: Vec<FieldPtrRow>

FieldPtr table rows (0x03) - only in uncompressed #- streams.

§fields: Vec<FieldRow>

Field table rows (0x04).

§method_ptrs: Vec<MethodPtrRow>

MethodPtr table rows (0x05) - only in uncompressed #- streams.

§method_defs: Vec<MethodDefRow>

MethodDef table rows (0x06).

§param_ptrs: Vec<ParamPtrRow>

ParamPtr table rows (0x07) - only in uncompressed #- streams.

§params: Vec<ParamRow>

Param table rows (0x08).

§interface_impls: Vec<InterfaceImplRow>

InterfaceImpl table rows (0x09).

§member_refs: Vec<MemberRefRow>

MemberRef table rows (0x0A).

§constants: Vec<ConstantRow>

Constant table rows (0x0B).

§custom_attributes: Vec<CustomAttributeRow>

CustomAttribute table rows (0x0C).

§field_marshals: Vec<FieldMarshalRow>

FieldMarshal table rows (0x0D).

§decl_securities: Vec<DeclSecurityRow>

DeclSecurity table rows (0x0E).

§class_layouts: Vec<ClassLayoutRow>

ClassLayout table rows (0x0F).

§field_layouts: Vec<FieldLayoutRow>

FieldLayout table rows (0x10).

§stand_alone_sigs: Vec<StandAloneSigRow>

StandAloneSig table rows (0x11).

§event_maps: Vec<EventMapRow>

EventMap table rows (0x12).

§event_ptrs: Vec<EventPtrRow>

EventPtr table rows (0x13) - only in uncompressed #- streams.

§events: Vec<EventRow>

Event table rows (0x14).

§property_maps: Vec<PropertyMapRow>

PropertyMap table rows (0x15).

§property_ptrs: Vec<PropertyPtrRow>

PropertyPtr table rows (0x16) - only in uncompressed #- streams.

§properties: Vec<PropertyRow>

Property table rows (0x17).

§method_semantics: Vec<MethodSemanticsRow>

MethodSemantics table rows (0x18).

§method_impls: Vec<MethodImplRow>

MethodImpl table rows (0x19).

§module_refs: Vec<ModuleRefRow>

ModuleRef table rows (0x1A).

§type_specs: Vec<TypeSpecRow>

TypeSpec table rows (0x1B).

§impl_maps: Vec<ImplMapRow>

ImplMap table rows (0x1C).

§field_rvas: Vec<FieldRvaRow>

FieldRva table rows (0x1D).

§enc_logs: Vec<EncLogRow>

EncLog table rows (0x1E) - Edit-and-Continue log.

§enc_maps: Vec<EncMapRow>

EncMap table rows (0x1F) - Edit-and-Continue mapping.

§assemblies: Vec<AssemblyRow>

Assembly table rows (0x20, usually 0 or 1).

§assembly_processors: Vec<AssemblyProcessorRow>

AssemblyProcessor table rows (0x21) - deprecated.

§assembly_oses: Vec<AssemblyOsRow>

AssemblyOs table rows (0x22) - deprecated.

§assembly_refs: Vec<AssemblyRefRow>

AssemblyRef table rows (0x23).

§assembly_ref_processors: Vec<AssemblyRefProcessorRow>

AssemblyRefProcessor table rows (0x24) - deprecated.

§assembly_ref_oses: Vec<AssemblyRefOsRow>

AssemblyRefOs table rows (0x25) - deprecated.

§files: Vec<FileRow>

File table rows (0x26) - multi-file assemblies.

§exported_types: Vec<ExportedTypeRow>

ExportedType table rows (0x27) - type forwarders.

§manifest_resources: Vec<ManifestResourceRow>

ManifestResource table rows (0x28).

§nested_classes: Vec<NestedClassRow>

NestedClass table rows (0x29).

§generic_params: Vec<GenericParamRow>

GenericParam table rows (0x2A).

§method_specs: Vec<MethodSpecRow>

MethodSpec table rows (0x2B).

§generic_param_constraints: Vec<GenericParamConstraintRow>

GenericParamConstraint table rows (0x2C).

Implementations§

Source§

impl Metadata

Source

pub fn parse(data: &[u8]) -> Result<Self>

Parse metadata from raw bytes.

Source

pub fn version(&self) -> &str

Get the runtime version string.

Source

pub fn assembly(&self) -> Option<AssemblyInfo>

Get assembly information if this is an assembly (not a netmodule).

Source

pub fn types(&self) -> Vec<TypeInfo>

Get all type definitions.

Source

pub fn methods(&self) -> Vec<MethodInfo>

Get all method definitions.

Source

pub fn assembly_refs(&self) -> Vec<AssemblyRefInfo>

Get all assembly references.

Source

pub fn get_type_def(&self, index: u32) -> Option<&TypeDefRow>

Get the TypeDef row at the given 1-based index.

Source

pub fn get_type_ref(&self, index: u32) -> Option<&TypeRefRow>

Get the TypeRef row at the given 1-based index.

Source

pub fn get_type_spec(&self, index: u32) -> Option<&TypeSpecRow>

Get the TypeSpec row at the given 1-based index.

Source

pub fn resolve_type(&self, coded_index: &CodedIndex) -> Option<ResolvedType>

Resolve a TypeDefOrRef coded index to a type reference.

Source

pub fn get_base_type(&self, type_def_index: u32) -> Option<ResolvedType>

Get the base type of a TypeDef by index (1-based).

Source

pub fn get_interfaces(&self, type_def_index: u32) -> Vec<ResolvedType>

Get all interfaces implemented by a TypeDef (1-based index).

Source

pub fn get_type_methods(&self, type_def_index: u32) -> Vec<(u32, &MethodDefRow)>

Get methods belonging to a TypeDef (1-based index).

Source

pub fn get_type_fields(&self, type_def_index: u32) -> Vec<(u32, &FieldRow)>

Get fields belonging to a TypeDef (1-based index).

Source

pub fn find_type( &self, name: &str, namespace: Option<&str>, ) -> Option<(u32, &TypeDefRow)>

Find a TypeDef by name (exact match).

Source

pub fn get_method_owner(&self, method_index: u32) -> Option<(u32, &TypeDefRow)>

Get the owning type of a method (1-based method index).

Source

pub fn get_field_owner(&self, field_index: u32) -> Option<(u32, &TypeDefRow)>

Get the owning type of a field (1-based field index).

Source

pub fn validate(&self) -> Vec<String>

Validate the metadata structure.

Performs structural integrity checks including:

  • Required tables are present (Module must have at least 1 row)
  • String indices are within bounds
  • GUID indices are within bounds
  • Blob indices are within bounds
  • Table index references are valid

Returns a list of validation errors. An empty list means the metadata is valid.

Source

pub fn validate_strict(&self) -> Result<()>

Validate that the metadata is structurally correct.

Returns Ok(()) if valid, or Err with the first validation error.

Source§

impl Metadata

Source

pub fn write(&self) -> Vec<u8>

Write the metadata to bytes.

Note: This is a simplified write that may not produce byte-identical output for complex metadata. It’s suitable for modified metadata that will be re-embedded into a PE file.

Source

pub fn write_to(&self, writer: &mut Writer)

Write the metadata to a writer.

Trait Implementations§

Source§

impl Clone for Metadata

Source§

fn clone(&self) -> Metadata

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Metadata

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.