pub struct Maple;
Expand description
Main entry point for the maple-rs library.
Provides convenient static methods for loading executables and libraries from memory buffers.
Implementations§
Source§impl Maple
impl Maple
Sourcepub fn load_library_from_memory(data: &[u8]) -> Result<Box<dyn MemoryModule>>
pub fn load_library_from_memory(data: &[u8]) -> Result<Box<dyn MemoryModule>>
Loads a DLL/library from a memory buffer.
§Arguments
data
- Raw bytes of the PE file to load
§Returns
Returns a MemoryModule
trait object that can be used to interact with
the loaded library, including getting function addresses.
§Example
use maple_rs::Maple;
use std::fs;
let dll_data = fs::read("library.dll").unwrap();
let module = Maple::load_library_from_memory(&dll_data).unwrap();
let func = module.get_proc_address("MyFunction").unwrap();
§Errors
Returns MapleError
if:
- The PE format is invalid
- Memory allocation fails
- Import resolution fails
- Platform is not supported
Examples found in repository?
examples/load_demo.rs (line 49)
5fn main() -> Result<()> {
6 let demo_path = Path::new("test/demo.exe");
7 let dll_path = Path::new("test/makcu-cpp.dll");
8
9 if !demo_path.exists() {
10 eprintln!("demo.exe not found in test directory");
11 return Ok(());
12 }
13
14 if !dll_path.exists() {
15 eprintln!("makcu-cpp.dll not found in test directory");
16 return Ok(());
17 }
18
19 println!("First, copy makcu-cpp.dll to current directory so demo.exe can find it...");
20 if dll_path.exists() {
21 let _ = fs::copy(dll_path, "makcu-cpp.dll");
22 }
23
24 println!("Loading demo.exe from memory...");
25 let demo_data = fs::read(demo_path)?;
26
27 println!("Creating memory module...");
28 match Maple::load_executable_from_memory(&demo_data) {
29 Ok(module) => {
30 println!("Successfully loaded demo.exe into memory");
31 println!("Base address: {:p}", module.base_address());
32 println!("Size: {} bytes", module.size());
33 println!("Is loaded: {}", module.is_loaded());
34
35 println!("Executing entry point...");
36 match module.execute_entry_point() {
37 Ok(_) => println!("Entry point executed successfully"),
38 Err(e) => eprintln!("Failed to execute entry point: {}", e),
39 }
40 }
41 Err(e) => {
42 eprintln!("Failed to load demo.exe: {}", e);
43 }
44 }
45
46 println!("\nLoading makcu-cpp.dll from memory...");
47 let dll_data = fs::read(dll_path)?;
48
49 match Maple::load_library_from_memory(&dll_data) {
50 Ok(module) => {
51 println!("Successfully loaded makcu-cpp.dll into memory");
52 println!("Base address: {:p}", module.base_address());
53 println!("Size: {} bytes", module.size());
54 println!("Is loaded: {}", module.is_loaded());
55 }
56 Err(e) => {
57 eprintln!("Failed to load makcu-cpp.dll: {}", e);
58 }
59 }
60
61 // Clean up the copied DLL
62 if Path::new("makcu-cpp.dll").exists() {
63 println!("\nCleaning up copied DLL...");
64 if let Err(e) = fs::remove_file("makcu-cpp.dll") {
65 eprintln!("Warning: Failed to clean up makcu-cpp.dll: {}", e);
66 } else {
67 println!("Cleaned up makcu-cpp.dll");
68 }
69 }
70
71 Ok(())
72}
Sourcepub fn load_executable_from_memory(data: &[u8]) -> Result<Box<dyn MemoryModule>>
pub fn load_executable_from_memory(data: &[u8]) -> Result<Box<dyn MemoryModule>>
Loads an executable from a memory buffer.
§Arguments
data
- Raw bytes of the PE executable to load
§Returns
Returns a MemoryModule
trait object that can be used to execute
the program’s entry point.
§Example
use maple_rs::Maple;
use std::fs;
let exe_data = fs::read("program.exe").unwrap();
let module = Maple::load_executable_from_memory(&exe_data).unwrap();
module.execute_entry_point().unwrap();
§Errors
Returns MapleError
if:
- The PE format is invalid
- Memory allocation fails
- Import resolution fails
- Platform is not supported
Examples found in repository?
examples/load_demo.rs (line 28)
5fn main() -> Result<()> {
6 let demo_path = Path::new("test/demo.exe");
7 let dll_path = Path::new("test/makcu-cpp.dll");
8
9 if !demo_path.exists() {
10 eprintln!("demo.exe not found in test directory");
11 return Ok(());
12 }
13
14 if !dll_path.exists() {
15 eprintln!("makcu-cpp.dll not found in test directory");
16 return Ok(());
17 }
18
19 println!("First, copy makcu-cpp.dll to current directory so demo.exe can find it...");
20 if dll_path.exists() {
21 let _ = fs::copy(dll_path, "makcu-cpp.dll");
22 }
23
24 println!("Loading demo.exe from memory...");
25 let demo_data = fs::read(demo_path)?;
26
27 println!("Creating memory module...");
28 match Maple::load_executable_from_memory(&demo_data) {
29 Ok(module) => {
30 println!("Successfully loaded demo.exe into memory");
31 println!("Base address: {:p}", module.base_address());
32 println!("Size: {} bytes", module.size());
33 println!("Is loaded: {}", module.is_loaded());
34
35 println!("Executing entry point...");
36 match module.execute_entry_point() {
37 Ok(_) => println!("Entry point executed successfully"),
38 Err(e) => eprintln!("Failed to execute entry point: {}", e),
39 }
40 }
41 Err(e) => {
42 eprintln!("Failed to load demo.exe: {}", e);
43 }
44 }
45
46 println!("\nLoading makcu-cpp.dll from memory...");
47 let dll_data = fs::read(dll_path)?;
48
49 match Maple::load_library_from_memory(&dll_data) {
50 Ok(module) => {
51 println!("Successfully loaded makcu-cpp.dll into memory");
52 println!("Base address: {:p}", module.base_address());
53 println!("Size: {} bytes", module.size());
54 println!("Is loaded: {}", module.is_loaded());
55 }
56 Err(e) => {
57 eprintln!("Failed to load makcu-cpp.dll: {}", e);
58 }
59 }
60
61 // Clean up the copied DLL
62 if Path::new("makcu-cpp.dll").exists() {
63 println!("\nCleaning up copied DLL...");
64 if let Err(e) = fs::remove_file("makcu-cpp.dll") {
65 eprintln!("Warning: Failed to clean up makcu-cpp.dll: {}", e);
66 } else {
67 println!("Cleaned up makcu-cpp.dll");
68 }
69 }
70
71 Ok(())
72}
More examples
examples/load_focus.rs (line 54)
5fn main() -> Result<()> {
6 let focus_path = Path::new("test/focus/focus.exe");
7
8 if !focus_path.exists() {
9 eprintln!("focus.exe not found in test/focus directory");
10 return Ok(());
11 }
12
13 // Check if all the required DLLs are present in the focus directory
14 let dll_files = [
15 "abseil_dll.dll",
16 "jpeg62.dll",
17 "libcrypto-3-x64.dll",
18 "liblzma.dll",
19 "libpng16.dll",
20 "libprotobuf.dll",
21 "libsharpyuv.dll",
22 "libwebp.dll",
23 "libwebpdecoder.dll",
24 "opencv_core4.dll",
25 "opencv_dnn4.dll",
26 "opencv_highgui4.dll",
27 "opencv_imgcodecs4.dll",
28 "opencv_imgproc4.dll",
29 "opencv_videoio4.dll",
30 "tiff.dll",
31 "zlib1.dll",
32 ];
33
34 println!("Copying required DLLs to current directory...");
35 for dll in &dll_files {
36 let dll_path = Path::new("test/focus").join(dll);
37 if dll_path.exists() {
38 if let Err(e) = fs::copy(&dll_path, dll) {
39 eprintln!("Warning: Failed to copy {}: {}", dll, e);
40 } else {
41 println!("Copied {}", dll);
42 }
43 } else {
44 eprintln!("Warning: {} not found", dll);
45 }
46 }
47
48 println!("\nLoading focus.exe from memory...");
49 let focus_data = fs::read(focus_path)?;
50
51 println!("Creating memory module...");
52 println!("Focus.exe size: {} bytes", focus_data.len());
53
54 match Maple::load_executable_from_memory(&focus_data) {
55 Ok(module) => {
56 println!("Successfully loaded focus.exe into memory");
57 println!("Base address: {:p}", module.base_address());
58 println!("Size: {} bytes", module.size());
59 println!("Is loaded: {}", module.is_loaded());
60
61 println!("\nExecuting GUI application entry point...");
62 println!("Note: This will launch the focus.exe GUI application from memory!");
63
64 match module.execute_entry_point() {
65 Ok(_) => println!("Entry point executed successfully (GUI should have appeared)"),
66 Err(e) => eprintln!("Failed to execute entry point: {}", e),
67 }
68 }
69 Err(e) => {
70 eprintln!("Failed to load focus.exe: {}", e);
71 }
72 }
73
74 // Clean up copied DLLs
75 println!("\nCleaning up copied DLLs...");
76 for dll in &dll_files {
77 if Path::new(dll).exists() {
78 let _ = fs::remove_file(dll);
79 }
80 }
81
82 Ok(())
83}
Auto Trait Implementations§
impl Freeze for Maple
impl RefUnwindSafe for Maple
impl Send for Maple
impl Sync for Maple
impl Unpin for Maple
impl UnwindSafe for Maple
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more