MemoryModuleBuilder

Struct MemoryModuleBuilder 

Source
pub struct MemoryModuleBuilder {
    pub resolve_imports: bool,
    pub process_relocations: bool,
    pub call_dll_main: bool,
    pub ignore_missing_imports: bool,
    pub is_application_dll: bool,
    pub alloc_function: Option<CustomAllocFunction>,
    pub free_function: Option<CustomFreeFunction>,
    pub load_library_function: Option<CustomLoadLibraryFunction>,
    pub get_proc_address_function: Option<CustomGetProcAddressFunction>,
    pub free_library_function: Option<CustomFreeLibraryFunction>,
    pub user_data: *mut c_void,
}

Fields§

§resolve_imports: bool§process_relocations: bool§call_dll_main: bool§ignore_missing_imports: bool§is_application_dll: bool§alloc_function: Option<CustomAllocFunction>§free_function: Option<CustomFreeFunction>§load_library_function: Option<CustomLoadLibraryFunction>§get_proc_address_function: Option<CustomGetProcAddressFunction>§free_library_function: Option<CustomFreeLibraryFunction>§user_data: *mut c_void

Implementations§

Source§

impl MemoryModuleBuilder

Source

pub fn new() -> Self

Examples found in repository?
examples/test_application_dll.rs (line 45)
5fn main() -> maple_rs::Result<()> {
6    println!("Testing focus.dll as an application DLL...");
7
8    // Change to the test/focus directory so dependencies are found
9    let current_dir = env::current_dir().expect("Failed to get current directory");
10    let focus_dir = current_dir.join("test").join("focus");
11    env::set_current_dir(&focus_dir).expect("Failed to change to focus directory");
12    println!("Changed working directory to: {:?}", focus_dir);
13
14    // Read the focus.dll file
15    let dll_data = fs::read("focus.dll").expect("Failed to read focus.dll");
16    println!("Loaded {} bytes from focus.dll", dll_data.len());
17
18    // Test 1: Load as application DLL using the new convenient method
19    println!("\nTest 1: Loading using Maple::load_application_dll_from_memory()...");
20    match Maple::load_application_dll_from_memory(&dll_data) {
21        Ok(module) => {
22            println!("Successfully loaded focus.dll as application DLL!");
23            println!("Base address: {:?}", module.base_address());
24            println!("Size: {} bytes", module.size());
25
26            println!("Executing DLL application...");
27            match module.execute_dll_application() {
28                Ok(()) => {
29                    println!("DLL application started successfully!");
30                    println!("Waiting 5 seconds to let the application run...");
31                    std::thread::sleep(std::time::Duration::from_secs(5));
32                }
33                Err(e) => {
34                    println!("Failed to execute DLL application: {}", e);
35                }
36            }
37        }
38        Err(e) => {
39            println!("Failed to load focus.dll as application DLL: {}", e);
40        }
41    }
42
43    // Test 2: Load using the builder with application DLL settings
44    println!("\nTest 2: Loading using MemoryModuleBuilder with application DLL settings...");
45    match MemoryModuleBuilder::new()
46        .resolve_imports(true)
47        .process_relocations(true)
48        .call_dll_main(false) // Don't auto-call DllMain
49        .is_application_dll(true)
50        .load_from_memory(&dll_data)
51    {
52        Ok(module) => {
53            println!("Successfully loaded focus.dll with builder!");
54            println!("Base address: {:?}", module.base_address());
55            println!("Size: {} bytes", module.size());
56
57            println!("Manually executing DLL application...");
58            match module.execute_dll_application() {
59                Ok(()) => {
60                    println!("DLL application started successfully!");
61                    println!("Waiting 5 seconds to let the application run...");
62                    std::thread::sleep(std::time::Duration::from_secs(5));
63                }
64                Err(e) => {
65                    println!("Failed to execute DLL application: {}", e);
66                }
67            }
68        }
69        Err(e) => {
70            println!("Failed to load focus.dll with builder: {}", e);
71        }
72    }
73
74    // Restore working directory
75    env::set_current_dir(&current_dir).expect("Failed to restore working directory");
76
77    println!("\nTest completed!");
78    Ok(())
79}
Source

pub fn resolve_imports(self, resolve: bool) -> Self

Examples found in repository?
examples/test_application_dll.rs (line 46)
5fn main() -> maple_rs::Result<()> {
6    println!("Testing focus.dll as an application DLL...");
7
8    // Change to the test/focus directory so dependencies are found
9    let current_dir = env::current_dir().expect("Failed to get current directory");
10    let focus_dir = current_dir.join("test").join("focus");
11    env::set_current_dir(&focus_dir).expect("Failed to change to focus directory");
12    println!("Changed working directory to: {:?}", focus_dir);
13
14    // Read the focus.dll file
15    let dll_data = fs::read("focus.dll").expect("Failed to read focus.dll");
16    println!("Loaded {} bytes from focus.dll", dll_data.len());
17
18    // Test 1: Load as application DLL using the new convenient method
19    println!("\nTest 1: Loading using Maple::load_application_dll_from_memory()...");
20    match Maple::load_application_dll_from_memory(&dll_data) {
21        Ok(module) => {
22            println!("Successfully loaded focus.dll as application DLL!");
23            println!("Base address: {:?}", module.base_address());
24            println!("Size: {} bytes", module.size());
25
26            println!("Executing DLL application...");
27            match module.execute_dll_application() {
28                Ok(()) => {
29                    println!("DLL application started successfully!");
30                    println!("Waiting 5 seconds to let the application run...");
31                    std::thread::sleep(std::time::Duration::from_secs(5));
32                }
33                Err(e) => {
34                    println!("Failed to execute DLL application: {}", e);
35                }
36            }
37        }
38        Err(e) => {
39            println!("Failed to load focus.dll as application DLL: {}", e);
40        }
41    }
42
43    // Test 2: Load using the builder with application DLL settings
44    println!("\nTest 2: Loading using MemoryModuleBuilder with application DLL settings...");
45    match MemoryModuleBuilder::new()
46        .resolve_imports(true)
47        .process_relocations(true)
48        .call_dll_main(false) // Don't auto-call DllMain
49        .is_application_dll(true)
50        .load_from_memory(&dll_data)
51    {
52        Ok(module) => {
53            println!("Successfully loaded focus.dll with builder!");
54            println!("Base address: {:?}", module.base_address());
55            println!("Size: {} bytes", module.size());
56
57            println!("Manually executing DLL application...");
58            match module.execute_dll_application() {
59                Ok(()) => {
60                    println!("DLL application started successfully!");
61                    println!("Waiting 5 seconds to let the application run...");
62                    std::thread::sleep(std::time::Duration::from_secs(5));
63                }
64                Err(e) => {
65                    println!("Failed to execute DLL application: {}", e);
66                }
67            }
68        }
69        Err(e) => {
70            println!("Failed to load focus.dll with builder: {}", e);
71        }
72    }
73
74    // Restore working directory
75    env::set_current_dir(&current_dir).expect("Failed to restore working directory");
76
77    println!("\nTest completed!");
78    Ok(())
79}
Source

pub fn process_relocations(self, process: bool) -> Self

Examples found in repository?
examples/test_application_dll.rs (line 47)
5fn main() -> maple_rs::Result<()> {
6    println!("Testing focus.dll as an application DLL...");
7
8    // Change to the test/focus directory so dependencies are found
9    let current_dir = env::current_dir().expect("Failed to get current directory");
10    let focus_dir = current_dir.join("test").join("focus");
11    env::set_current_dir(&focus_dir).expect("Failed to change to focus directory");
12    println!("Changed working directory to: {:?}", focus_dir);
13
14    // Read the focus.dll file
15    let dll_data = fs::read("focus.dll").expect("Failed to read focus.dll");
16    println!("Loaded {} bytes from focus.dll", dll_data.len());
17
18    // Test 1: Load as application DLL using the new convenient method
19    println!("\nTest 1: Loading using Maple::load_application_dll_from_memory()...");
20    match Maple::load_application_dll_from_memory(&dll_data) {
21        Ok(module) => {
22            println!("Successfully loaded focus.dll as application DLL!");
23            println!("Base address: {:?}", module.base_address());
24            println!("Size: {} bytes", module.size());
25
26            println!("Executing DLL application...");
27            match module.execute_dll_application() {
28                Ok(()) => {
29                    println!("DLL application started successfully!");
30                    println!("Waiting 5 seconds to let the application run...");
31                    std::thread::sleep(std::time::Duration::from_secs(5));
32                }
33                Err(e) => {
34                    println!("Failed to execute DLL application: {}", e);
35                }
36            }
37        }
38        Err(e) => {
39            println!("Failed to load focus.dll as application DLL: {}", e);
40        }
41    }
42
43    // Test 2: Load using the builder with application DLL settings
44    println!("\nTest 2: Loading using MemoryModuleBuilder with application DLL settings...");
45    match MemoryModuleBuilder::new()
46        .resolve_imports(true)
47        .process_relocations(true)
48        .call_dll_main(false) // Don't auto-call DllMain
49        .is_application_dll(true)
50        .load_from_memory(&dll_data)
51    {
52        Ok(module) => {
53            println!("Successfully loaded focus.dll with builder!");
54            println!("Base address: {:?}", module.base_address());
55            println!("Size: {} bytes", module.size());
56
57            println!("Manually executing DLL application...");
58            match module.execute_dll_application() {
59                Ok(()) => {
60                    println!("DLL application started successfully!");
61                    println!("Waiting 5 seconds to let the application run...");
62                    std::thread::sleep(std::time::Duration::from_secs(5));
63                }
64                Err(e) => {
65                    println!("Failed to execute DLL application: {}", e);
66                }
67            }
68        }
69        Err(e) => {
70            println!("Failed to load focus.dll with builder: {}", e);
71        }
72    }
73
74    // Restore working directory
75    env::set_current_dir(&current_dir).expect("Failed to restore working directory");
76
77    println!("\nTest completed!");
78    Ok(())
79}
Source

pub fn call_dll_main(self, call: bool) -> Self

Examples found in repository?
examples/test_application_dll.rs (line 48)
5fn main() -> maple_rs::Result<()> {
6    println!("Testing focus.dll as an application DLL...");
7
8    // Change to the test/focus directory so dependencies are found
9    let current_dir = env::current_dir().expect("Failed to get current directory");
10    let focus_dir = current_dir.join("test").join("focus");
11    env::set_current_dir(&focus_dir).expect("Failed to change to focus directory");
12    println!("Changed working directory to: {:?}", focus_dir);
13
14    // Read the focus.dll file
15    let dll_data = fs::read("focus.dll").expect("Failed to read focus.dll");
16    println!("Loaded {} bytes from focus.dll", dll_data.len());
17
18    // Test 1: Load as application DLL using the new convenient method
19    println!("\nTest 1: Loading using Maple::load_application_dll_from_memory()...");
20    match Maple::load_application_dll_from_memory(&dll_data) {
21        Ok(module) => {
22            println!("Successfully loaded focus.dll as application DLL!");
23            println!("Base address: {:?}", module.base_address());
24            println!("Size: {} bytes", module.size());
25
26            println!("Executing DLL application...");
27            match module.execute_dll_application() {
28                Ok(()) => {
29                    println!("DLL application started successfully!");
30                    println!("Waiting 5 seconds to let the application run...");
31                    std::thread::sleep(std::time::Duration::from_secs(5));
32                }
33                Err(e) => {
34                    println!("Failed to execute DLL application: {}", e);
35                }
36            }
37        }
38        Err(e) => {
39            println!("Failed to load focus.dll as application DLL: {}", e);
40        }
41    }
42
43    // Test 2: Load using the builder with application DLL settings
44    println!("\nTest 2: Loading using MemoryModuleBuilder with application DLL settings...");
45    match MemoryModuleBuilder::new()
46        .resolve_imports(true)
47        .process_relocations(true)
48        .call_dll_main(false) // Don't auto-call DllMain
49        .is_application_dll(true)
50        .load_from_memory(&dll_data)
51    {
52        Ok(module) => {
53            println!("Successfully loaded focus.dll with builder!");
54            println!("Base address: {:?}", module.base_address());
55            println!("Size: {} bytes", module.size());
56
57            println!("Manually executing DLL application...");
58            match module.execute_dll_application() {
59                Ok(()) => {
60                    println!("DLL application started successfully!");
61                    println!("Waiting 5 seconds to let the application run...");
62                    std::thread::sleep(std::time::Duration::from_secs(5));
63                }
64                Err(e) => {
65                    println!("Failed to execute DLL application: {}", e);
66                }
67            }
68        }
69        Err(e) => {
70            println!("Failed to load focus.dll with builder: {}", e);
71        }
72    }
73
74    // Restore working directory
75    env::set_current_dir(&current_dir).expect("Failed to restore working directory");
76
77    println!("\nTest completed!");
78    Ok(())
79}
Source

pub fn ignore_missing_imports(self, ignore: bool) -> Self

Source

pub fn is_application_dll(self, is_app_dll: bool) -> Self

Examples found in repository?
examples/test_application_dll.rs (line 49)
5fn main() -> maple_rs::Result<()> {
6    println!("Testing focus.dll as an application DLL...");
7
8    // Change to the test/focus directory so dependencies are found
9    let current_dir = env::current_dir().expect("Failed to get current directory");
10    let focus_dir = current_dir.join("test").join("focus");
11    env::set_current_dir(&focus_dir).expect("Failed to change to focus directory");
12    println!("Changed working directory to: {:?}", focus_dir);
13
14    // Read the focus.dll file
15    let dll_data = fs::read("focus.dll").expect("Failed to read focus.dll");
16    println!("Loaded {} bytes from focus.dll", dll_data.len());
17
18    // Test 1: Load as application DLL using the new convenient method
19    println!("\nTest 1: Loading using Maple::load_application_dll_from_memory()...");
20    match Maple::load_application_dll_from_memory(&dll_data) {
21        Ok(module) => {
22            println!("Successfully loaded focus.dll as application DLL!");
23            println!("Base address: {:?}", module.base_address());
24            println!("Size: {} bytes", module.size());
25
26            println!("Executing DLL application...");
27            match module.execute_dll_application() {
28                Ok(()) => {
29                    println!("DLL application started successfully!");
30                    println!("Waiting 5 seconds to let the application run...");
31                    std::thread::sleep(std::time::Duration::from_secs(5));
32                }
33                Err(e) => {
34                    println!("Failed to execute DLL application: {}", e);
35                }
36            }
37        }
38        Err(e) => {
39            println!("Failed to load focus.dll as application DLL: {}", e);
40        }
41    }
42
43    // Test 2: Load using the builder with application DLL settings
44    println!("\nTest 2: Loading using MemoryModuleBuilder with application DLL settings...");
45    match MemoryModuleBuilder::new()
46        .resolve_imports(true)
47        .process_relocations(true)
48        .call_dll_main(false) // Don't auto-call DllMain
49        .is_application_dll(true)
50        .load_from_memory(&dll_data)
51    {
52        Ok(module) => {
53            println!("Successfully loaded focus.dll with builder!");
54            println!("Base address: {:?}", module.base_address());
55            println!("Size: {} bytes", module.size());
56
57            println!("Manually executing DLL application...");
58            match module.execute_dll_application() {
59                Ok(()) => {
60                    println!("DLL application started successfully!");
61                    println!("Waiting 5 seconds to let the application run...");
62                    std::thread::sleep(std::time::Duration::from_secs(5));
63                }
64                Err(e) => {
65                    println!("Failed to execute DLL application: {}", e);
66                }
67            }
68        }
69        Err(e) => {
70            println!("Failed to load focus.dll with builder: {}", e);
71        }
72    }
73
74    // Restore working directory
75    env::set_current_dir(&current_dir).expect("Failed to restore working directory");
76
77    println!("\nTest completed!");
78    Ok(())
79}
Source

pub fn alloc_function(self, func: CustomAllocFunction) -> Self

Source

pub fn free_function(self, func: CustomFreeFunction) -> Self

Source

pub fn load_library_function(self, func: CustomLoadLibraryFunction) -> Self

Source

pub fn get_proc_address_function( self, func: CustomGetProcAddressFunction, ) -> Self

Source

pub fn free_library_function(self, func: CustomFreeLibraryFunction) -> Self

Source

pub fn user_data(self, data: *mut c_void) -> Self

Source

pub fn load_from_memory(self, data: &[u8]) -> Result<Box<dyn MemoryModule>>

Examples found in repository?
examples/test_application_dll.rs (line 50)
5fn main() -> maple_rs::Result<()> {
6    println!("Testing focus.dll as an application DLL...");
7
8    // Change to the test/focus directory so dependencies are found
9    let current_dir = env::current_dir().expect("Failed to get current directory");
10    let focus_dir = current_dir.join("test").join("focus");
11    env::set_current_dir(&focus_dir).expect("Failed to change to focus directory");
12    println!("Changed working directory to: {:?}", focus_dir);
13
14    // Read the focus.dll file
15    let dll_data = fs::read("focus.dll").expect("Failed to read focus.dll");
16    println!("Loaded {} bytes from focus.dll", dll_data.len());
17
18    // Test 1: Load as application DLL using the new convenient method
19    println!("\nTest 1: Loading using Maple::load_application_dll_from_memory()...");
20    match Maple::load_application_dll_from_memory(&dll_data) {
21        Ok(module) => {
22            println!("Successfully loaded focus.dll as application DLL!");
23            println!("Base address: {:?}", module.base_address());
24            println!("Size: {} bytes", module.size());
25
26            println!("Executing DLL application...");
27            match module.execute_dll_application() {
28                Ok(()) => {
29                    println!("DLL application started successfully!");
30                    println!("Waiting 5 seconds to let the application run...");
31                    std::thread::sleep(std::time::Duration::from_secs(5));
32                }
33                Err(e) => {
34                    println!("Failed to execute DLL application: {}", e);
35                }
36            }
37        }
38        Err(e) => {
39            println!("Failed to load focus.dll as application DLL: {}", e);
40        }
41    }
42
43    // Test 2: Load using the builder with application DLL settings
44    println!("\nTest 2: Loading using MemoryModuleBuilder with application DLL settings...");
45    match MemoryModuleBuilder::new()
46        .resolve_imports(true)
47        .process_relocations(true)
48        .call_dll_main(false) // Don't auto-call DllMain
49        .is_application_dll(true)
50        .load_from_memory(&dll_data)
51    {
52        Ok(module) => {
53            println!("Successfully loaded focus.dll with builder!");
54            println!("Base address: {:?}", module.base_address());
55            println!("Size: {} bytes", module.size());
56
57            println!("Manually executing DLL application...");
58            match module.execute_dll_application() {
59                Ok(()) => {
60                    println!("DLL application started successfully!");
61                    println!("Waiting 5 seconds to let the application run...");
62                    std::thread::sleep(std::time::Duration::from_secs(5));
63                }
64                Err(e) => {
65                    println!("Failed to execute DLL application: {}", e);
66                }
67            }
68        }
69        Err(e) => {
70            println!("Failed to load focus.dll with builder: {}", e);
71        }
72    }
73
74    // Restore working directory
75    env::set_current_dir(&current_dir).expect("Failed to restore working directory");
76
77    println!("\nTest completed!");
78    Ok(())
79}

Trait Implementations§

Source§

impl Default for MemoryModuleBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. 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> 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, 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.