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
//! Image and data loading for emulation.
//!
//! This module provides loaders for mapping PE images and raw data into the
//! emulation address space. It serves as the bridge between on-disk file formats
//! and the in-memory representation needed for emulation.
//!
//! # Overview
//!
//! The loader module contains two main components:
//!
//! - **[`PeLoader`]** - Parses and maps Portable Executable (PE) files, handling
//! section alignment, memory protection, and optional relocation
//! - **[`DataLoader`]** - Maps raw byte data without any format interpretation
//!
//! # Architecture
//!
//! ```text
//! +---------------+ +----------------+
//! | PE File | --> | PeLoader | --+
//! +---------------+ +----------------+ |
//! v
//! +---------------+ +----------------+ +------------------+
//! | Raw Data | --> | DataLoader | -->| AddressSpace |
//! +---------------+ +----------------+ +------------------+
//! ```
//!
//! Both loaders ultimately map data into an
//! [`AddressSpace`](crate::emulation::memory::AddressSpace), but they differ
//! in how they interpret and process the input:
//!
//! - `PeLoader` understands PE structure, respects section boundaries, and can
//! apply relocations for non-preferred base addresses
//! - `DataLoader` treats input as opaque bytes and maps them directly
//!
//! # Choosing a Loader
//!
//! | Scenario | Recommended Loader |
//! |----------|-------------------|
//! | Loading .exe/.dll for analysis | [`PeLoader`] |
//! | Loading .NET assemblies | [`PeLoader`] (detects CLR header) |
//! | Loading raw shellcode | [`DataLoader`] |
//! | Creating stack/heap regions | [`DataLoader`] |
//! | Loading arbitrary binary data | [`DataLoader`] |
//!
//! # Components
//!
//! ## PE Loading
//!
//! - [`PeLoader`] - Main PE image loader with configurable options
//! - [`PeLoaderConfig`] - Configuration for PE loading (base address, permissions, etc.)
//! - [`LoadedImage`] - Metadata about a loaded PE image
//! - [`LoadedSection`] - Information about an individual PE section
//!
//! ## Data Loading
//!
//! - [`DataLoader`] - Raw data mapping utility
//! - [`MappedRegionInfo`] - Metadata about a mapped memory region
//!
//! # Example
//!
//! ```ignore
//! use dotscope::emulation::loader::{PeLoader, DataLoader};
//! use dotscope::emulation::memory::{AddressSpace, MemoryProtection};
//!
//! // Create an address space
//! let address_space = AddressSpace::new();
//!
//! // Load a PE file
//! let loader = PeLoader::new();
//! let image = loader.load_file(
//! Path::new("target.exe"),
//! &address_space,
//! )?;
//! println!("Loaded {} at 0x{:X}", image.name, image.base_address);
//!
//! // Map a stack region
//! let stack = DataLoader::map_zeroed(
//! &address_space,
//! 0x7FFE0000,
//! 0x100000,
//! "stack",
//! MemoryProtection::READ | MemoryProtection::WRITE,
//! )?;
//! ```
pub use ;
pub use ;