Skip to main content

macho_core/format/
mod.rs

1/// The constants module.
2pub mod constants;
3mod container;
4/// The fat module.
5pub mod fat;
6/// The io module.
7pub mod io;
8/// The load_commands module.
9pub mod load_commands;
10/// The macho module.
11pub mod macho;
12/// The relocations module.
13pub mod relocations;
14/// The sections module.
15pub mod sections;
16/// The symbols module.
17pub mod symbols;
18
19pub use container::{parse, parse_with_options};
20pub use fat::parse_fat_binary;
21pub use macho::parse_macho_file;
22pub use relocations::relocations_for_section;
23pub use symbols::{fold_symbols, parse_symbol_table, parse_symbols_at};
24
25use crate::model::container::MachoContainer;
26use crate::model::validate::Diagnostic;
27
28/// Policy for handling recoverable structural diagnostics.
29#[derive(Debug, Clone, Copy, PartialEq, Eq)]
30#[non_exhaustive]
31pub enum ParseMode {
32    /// Reject any error-severity structural diagnostic.
33    Strict,
34    /// Return the safe model together with recoverable diagnostics.
35    Forensic,
36}
37
38/// Hard bounds applied before input-derived allocation or iteration.
39#[derive(Debug, Clone, PartialEq, Eq)]
40pub struct ParseLimits {
41    /// Maximum architecture entries in one fat container.
42    pub max_fat_arches: usize,
43    /// Maximum load commands in one Mach-O image.
44    pub max_load_commands: usize,
45    /// Maximum sections in one Mach-O image.
46    pub max_sections: usize,
47    /// Maximum cumulative load-command string bytes in one image.
48    pub max_string_bytes: usize,
49}
50
51impl Default for ParseLimits {
52    fn default() -> Self {
53        Self {
54            max_fat_arches: 256,
55            max_load_commands: 10_000,
56            max_sections: 100_000,
57            max_string_bytes: 16 * 1024 * 1024,
58        }
59    }
60}
61
62/// Parse mode and hard resource limits.
63#[derive(Debug, Clone, PartialEq, Eq)]
64pub struct ParseOptions {
65    /// Recovery policy.
66    pub mode: ParseMode,
67    /// Hard limits.
68    pub limits: ParseLimits,
69}
70
71impl Default for ParseOptions {
72    fn default() -> Self {
73        Self {
74            mode: ParseMode::Strict,
75            limits: ParseLimits::default(),
76        }
77    }
78}
79
80/// Safe parsed model plus recoverable diagnostics.
81pub struct ParseOutcome<'data> {
82    /// Parsed thin or fat container.
83    pub container: MachoContainer<'data>,
84    /// Structural diagnostics emitted after safe parsing.
85    pub diagnostics: Vec<Diagnostic>,
86}