1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
//! # maple-rs
//!
//! A Rust library for loading Windows PE executables and DLLs directly from memory,
//! without needing to write them to disk first. This is a modern, safe Rust replacement
//! for the C memorymodule library.
//!
//! ## ⚠️ Security Notice
//!
//! This library enables loading and executing code from memory buffers, which can be used
//! for legitimate purposes such as:
//! - Dynamic code loading in game engines
//! - Plugin systems
//! - Testing and debugging tools
//! - Memory-efficient application packaging
//!
//! However, it could also be misused for malicious purposes. Users are responsible for
//! ensuring they only load trusted code and comply with all applicable laws and
//! security policies.
//!
//! ## Features
//!
//! - **In-Memory Loading**: Load PE executables (.exe) and libraries (.dll) from memory
//! - **Full PE Support**: Complete PE parsing, import resolution, and relocation processing
//! - **Native Execution**: Code runs exactly as if loaded from disk
//! - **Memory Safety**: Proper memory management with automatic cleanup
//! - **Cross-Platform Ready**: Windows implementation complete, Linux planned
//!
//! ## Quick Start
//!
//! ```rust,no_run
//! use maple_rs::{Maple, Result};
//! use std::fs;
//!
//! fn main() -> Result<()> {
//! // Load an executable from memory
//! let data = fs::read("program.exe")?;
//! let module = Maple::load_executable_from_memory(&data)?;
//!
//! // Execute the program's entry point
//! module.execute_entry_point()?;
//!
//! Ok(())
//! }
//! ```
//!
//! ## Advanced Usage
//!
//! ```rust,no_run
//! use maple_rs::{MemoryModuleBuilder, Result};
//! use std::fs;
//!
//! fn main() -> Result<()> {
//! let data = fs::read("library.dll")?;
//!
//! let module = MemoryModuleBuilder::new()
//! .resolve_imports(true)
//! .process_relocations(true)
//! .call_dll_main(true)
//! .load_from_memory(&data)?;
//!
//! // Get a function from the loaded library
//! let function = module.get_proc_address("MyFunction")?;
//!
//! Ok(())
//! }
//! ```
//!
//! ## Platform Support
//!
//! - **Windows**: Full support for PE executables and DLLs
//! - **Linux**: Placeholder implementation (planned for future release)
//!
//! ## Error Handling
//!
//! All operations return a `Result<T, MapleError>` with comprehensive error information:
//!
//! ```rust,no_run
//! use maple_rs::{Maple, MapleError};
//! # let data = b"dummy data";
//!
//! match Maple::load_executable_from_memory(data) {
//! Ok(module) => {
//! // Successfully loaded
//! },
//! Err(MapleError::InvalidPEFormat(msg)) => {
//! eprintln!("Invalid PE file: {}", msg);
//! },
//! Err(MapleError::MemoryAllocation(msg)) => {
//! eprintln!("Memory allocation failed: {}", msg);
//! },
//! Err(e) => {
//! eprintln!("Other error: {}", e);
//! }
//! }
//! ```
pub use MapleError;
pub use ;
/// Result type alias for all maple-rs operations.
pub type Result<T> = Result;
/// Main entry point for the maple-rs library.
///
/// Provides convenient static methods for loading executables and libraries
/// from memory buffers.
;