1use maple_rs::{Maple, Result};
2use std::fs;
3use std::path::Path;
4
5fn main() -> Result<()> {
6 let demo_path = Path::new("test/demo.exe");
7 let dll_path = Path::new("test/makcu-cpp.dll");
8 let focus_dll_path = Path::new("test/focus/focus.dll");
9
10 if !demo_path.exists() {
11 eprintln!("demo.exe not found in test directory");
12 return Ok(());
13 }
14
15 if !dll_path.exists() {
16 eprintln!("makcu-cpp.dll not found in test directory");
17 return Ok(());
18 }
19
20 println!("First, copy makcu-cpp.dll to current directory so demo.exe can find it...");
21 if dll_path.exists() {
22 let _ = fs::copy(dll_path, "makcu-cpp.dll");
23 }
24
25 println!("Loading demo.exe from memory...");
26 let demo_data = fs::read(demo_path)?;
27
28 println!("Creating memory module...");
29 match Maple::load_executable_from_memory(&demo_data) {
30 Ok(module) => {
31 println!("Successfully loaded demo.exe into memory");
32 println!("Base address: {:p}", module.base_address());
33 println!("Size: {} bytes", module.size());
34 println!("Is loaded: {}", module.is_loaded());
35
36 println!("Executing entry point...");
37 match module.execute_entry_point() {
38 Ok(_) => println!("Entry point executed successfully"),
39 Err(e) => eprintln!("Failed to execute entry point: {}", e),
40 }
41 }
42 Err(e) => {
43 eprintln!("Failed to load demo.exe: {}", e);
44 }
45 }
46
47 println!("\nLoading makcu-cpp.dll from memory...");
48 let dll_data = fs::read(dll_path)?;
49
50 match Maple::load_library_from_memory(&dll_data) {
51 Ok(module) => {
52 println!("Successfully loaded makcu-cpp.dll into memory");
53 println!("Base address: {:p}", module.base_address());
54 println!("Size: {} bytes", module.size());
55 println!("Is loaded: {}", module.is_loaded());
56 }
57 Err(e) => {
58 eprintln!("Failed to load makcu-cpp.dll: {}", e);
59 }
60 }
61
62 if focus_dll_path.exists() {
64 use std::env;
65
66 println!("\nTesting application DLL loading with focus.dll...");
67
68 let current_dir = env::current_dir().expect("Failed to get current directory");
70 let focus_dir = focus_dll_path.parent().unwrap();
71 env::set_current_dir(focus_dir).expect("Failed to change to focus directory");
72
73 let focus_dll_data = fs::read(focus_dll_path)?;
74 match Maple::load_application_dll_from_memory(&focus_dll_data) {
75 Ok(module) => {
76 println!("Successfully loaded focus.dll as application DLL");
77 println!("Base address: {:p}", module.base_address());
78 println!("Size: {} bytes", module.size());
79
80 println!("Executing application DLL (will run for 3 seconds)...");
81 match module.execute_dll_application() {
82 Ok(_) => {
83 println!("Application DLL started successfully!");
84 std::thread::sleep(std::time::Duration::from_secs(3));
85 }
86 Err(e) => eprintln!("Failed to execute application DLL: {}", e),
87 }
88 }
89 Err(e) => {
90 eprintln!("Failed to load focus.dll as application DLL: {}", e);
91 }
92 }
93
94 env::set_current_dir(¤t_dir).expect("Failed to restore working directory");
96 }
97
98 if Path::new("makcu-cpp.dll").exists() {
100 println!("\nCleaning up copied DLL...");
101 if let Err(e) = fs::remove_file("makcu-cpp.dll") {
102 eprintln!("Warning: Failed to clean up makcu-cpp.dll: {}", e);
103 } else {
104 println!("Cleaned up makcu-cpp.dll");
105 }
106 }
107
108 Ok(())
109}