1use maple_rs::{Maple, Result};
2use std::fs;
3use std::path::Path;
4
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 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 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}