Skip to main content

macho_cpp/
lib.rs

1#![deny(missing_docs)]
2//! C++ RTTI, vtable, and architecture-aware ABI inference.
3//!
4//! Depend on this crate directly for C++ structure recovery without the `macho`
5//! façade: build a [`VtableIndex`] or [`build_typeinfo_index`] from a
6//! [`macho_core::MachoFile`] or a borrowed byte source.
7
8pub use macho_core::{format, model};
9
10/// The error module.
11pub mod error;
12#[cfg(feature = "fixups")]
13pub(crate) use error::Error;
14pub use error::{CppError, CppErrorKind, Result};
15
16#[cfg(feature = "abi")]
17pub mod abi;
18mod abi_types;
19#[cfg(feature = "itanium-rtti")]
20mod strict_rtti;
21#[cfg(feature = "itanium-rtti")]
22mod strict_vtable;
23#[cfg(feature = "fixups")]
24/// The typeinfo module.
25pub mod typeinfo;
26/// The types module.
27pub mod types;
28#[cfg(feature = "fixups")]
29/// The vtable module.
30pub mod vtable;
31
32pub use abi_types::{ArgumentTypeHint, CppBodyAnalysis, CppBodyKind, CppReturnChannel};
33#[cfg(feature = "itanium-rtti")]
34pub use strict_rtti::{
35    ItaniumBaseRecord, ItaniumPointeeRecord, ItaniumTypeInfoFamily, ItaniumTypeInfoRecord,
36    StrictPointerAuthentication, StrictPointerEncoding, StrictPointerObservation,
37    StrictPointerTarget, StrictRttiBatch, StrictRttiConservation, StrictRttiGap, StrictRttiGapCode,
38    StrictRttiLimits, StrictRttiObservation, StrictRttiObservationKind, StrictRttiOutcome,
39    StrictRttiRecord, decode_strict_rtti, decode_strict_rtti_from_source,
40};
41#[cfg(feature = "itanium-rtti")]
42pub use strict_vtable::{
43    ItaniumThunkAdjustment, ItaniumVtableAddressPointRecord, ItaniumVtableAddressPointSource,
44    ItaniumVtableAmbiguousWordRecord, ItaniumVtableExtentSource, ItaniumVtableGroupRecord,
45    ItaniumVtableOffsetRecord, ItaniumVtableOffsetRole, ItaniumVtableSlotRecord,
46    ItaniumVtableSlotRole, ItaniumVtableSymbolKind, ItaniumVttEntryRecord, ItaniumVttRecord,
47    StrictVtableBatch, StrictVtableLimits, StrictVtableRecord, decode_strict_vtables,
48    decode_strict_vtables_from_source,
49};
50#[cfg(feature = "fixups")]
51pub use typeinfo::{build_typeinfo_index, build_typeinfo_index_from_source};
52pub use types::{
53    CppBaseClass, CppConfidence, CppEvidence, CppEvidenceKind, CppTypeInfoKind, CppTypeInfoNode,
54};
55#[cfg(feature = "fixups")]
56pub use vtable::{SlotTarget, VtableEntry, VtableIndex, VtableSlot};
57
58#[cfg(feature = "fixups")]
59use crate::model::macho_file::MachoFile;
60
61#[cfg(feature = "fixups")]
62fn parse_source<'data, S>(source: &'data S) -> Result<MachoFile<'data>>
63where
64    S: AsRef<[u8]> + ?Sized,
65{
66    match macho_core::parse(source.as_ref())? {
67        macho_core::model::container::MachoContainer::Thin(macho) => Ok(macho),
68        macho_core::model::container::MachoContainer::Fat(_) => Err(Error::unsupported(
69            "borrowed source contains a universal Mach-O; select an architecture explicitly",
70        )),
71    }
72}