Struct Module

Source
pub struct Module { /* private fields */ }
Expand description

Represents a loaded .net module.

let module = Module::from_file(r#"Example.Net.dll"#);

for ty in module.types().values() {
   for method in ty.methods().values() {
       println!("{}", method.name());
   }
}

Implementations§

Source§

impl Module

Source

pub fn from_path(path: impl AsRef<Path>) -> Result<Self>

Load a .net assembly from the given path and resolve its dependancies with the default PathAssemblyResolver resolver.

let module = Module::from_path(r#"Example.Net.dll"#)?;
Examples found in repository?
examples/load_module.rs (line 4)
3fn main() {
4    let module = Module::from_path(r#"C:\re\dnspy\bin\dnlib.dll"#).unwrap();
5    println!("loaded {}", module.module().value().name());
6}
More examples
Hide additional examples
examples/simple.rs (line 4)
3fn main() {
4    let module = Module::from_path(r#"C:\re\dnspy\bin\dnlib.dll"#).unwrap();
5    println!("loaded");
6
7    for ty in module.types().values() {
8        println!("{} {{", ty);
9        if ty.is_enum() {
10            for field in ty
11                .fields()
12                .values()
13                .filter(|x| !x.flags().contains(FieldFlags::SpecialName))
14            {
15                println!("\t{},", field.name());
16            }
17        } else {
18            for field in ty.fields().values() {
19                println!("\t{};", field);
20            }
21        }
22
23        println!("\n");
24
25        for method in ty.methods().values() {
26            println!("\t{};", method);
27        }
28
29        println!("}}");
30    }
31}
Source

pub fn from_path_no_resolve(path: impl AsRef<Path>) -> Result<Self>

Load a .net assembly from the given path but do not reolve its dependancies.

let module = Module::from_path_no_resolve(r#"Example.Net.dll"#)?;
Source

pub fn from_metadata(metadada: &Metadata<'_>) -> Result<Self>

Load a .net assembly from metadata. This will not resolve the modules dependancies.

let data = std::fs::read("Example.Net.dll").unwrap();
let md = Metadata::parse(&data).unwrap();
let loaded_module = Module::from_metadata(&md).unwrap();
Source

pub fn load_dependancies( &self, resolver: &mut impl AssemblyResolver, ) -> Result<()>

Attempts to load the refrenced assemblies using the given resolver. This will panic if there is a refrence holding any of the AssemblyRef in this module.

Source

pub fn module(&self) -> EntryView<'_, ModuleDef>

Returns the module infomation of the current module as a EntryView.

Examples found in repository?
examples/load_module.rs (line 5)
3fn main() {
4    let module = Module::from_path(r#"C:\re\dnspy\bin\dnlib.dll"#).unwrap();
5    println!("loaded {}", module.module().value().name());
6}
Source

pub fn type_refs(&self) -> EntryCollection<'_, TypeRef>

Returns an EntryCollection of TypeRef with all the type refrences inside the current module.

Source

pub fn types(&self) -> EntryCollection<'_, TypeDef>

Returns all the type refrences inside the current module.

let module = Module::default();

for ty in module.types().values() {
    println!("{}", ty);
}
Examples found in repository?
examples/simple.rs (line 7)
3fn main() {
4    let module = Module::from_path(r#"C:\re\dnspy\bin\dnlib.dll"#).unwrap();
5    println!("loaded");
6
7    for ty in module.types().values() {
8        println!("{} {{", ty);
9        if ty.is_enum() {
10            for field in ty
11                .fields()
12                .values()
13                .filter(|x| !x.flags().contains(FieldFlags::SpecialName))
14            {
15                println!("\t{},", field.name());
16            }
17        } else {
18            for field in ty.fields().values() {
19                println!("\t{};", field);
20            }
21        }
22
23        println!("\n");
24
25        for method in ty.methods().values() {
26            println!("\t{};", method);
27        }
28
29        println!("}}");
30    }
31}
Source

pub fn all_fields(&self) -> EntryCollection<'_, Field>

Returns all the fields defined in the module regardless of the parent type.

If you want the associated type, use TypeDef::fields.

let module = Module::default();

for field in module.all_fields().values() {
    println!("{} {}", field.signature(), field.name());
}
Source

pub fn all_methods(&self) -> EntryCollection<'_, Method>

Returns all the methods defined in the module regardless of the parent type.

If you want the associated type, use TypeDef::methods.

let module = Module::default();

for method in module.all_methods().values() {
   println!("{}", method.name());
}
Source

pub fn all_params(&self) -> EntryCollection<'_, Param>

Returns all the parameters defined in the module regardless of the parent method.

If you want the associated method, use Method::params.

let module = Module::default();

for param in module.all_params().values() {
    println!("{}", param.name());
}
Source

pub fn all_type_specs(&self) -> EntryCollection<'_, TypeSpec>

Returns all the type specs defined in the module.

Source

pub fn module_ref(&self) -> EntryCollection<'_, ModuleRef>

Returns all the modules refrenced in the module.

Source

pub fn assembly_ref(&self) -> EntryCollection<'_, AssemblyRef>

Returns all the assemblies refrenced in the module.

Trait Implementations§

Source§

impl Clone for Module

Source§

fn clone(&self) -> Module

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

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Module

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Module

Source§

fn default() -> Module

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Module

§

impl !RefUnwindSafe for Module

§

impl !Send for Module

§

impl !Sync for Module

§

impl Unpin for Module

§

impl !UnwindSafe for Module

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.