mach_object/lib.rs
1//! Mach-O File Format Parser for Rust
2//!
3//! # Examples
4//!
5//! ```
6//! use std::io::{Read, Cursor};
7//! use std::fs::File;
8//! use mach_object::{OFile, CPU_TYPE_X86_64, MachCommand, LoadCommand};
9//!
10//! let mut f = File::open("tests/helloworld").unwrap();
11//! let mut buf = Vec::new();
12//! let size = f.read_to_end(&mut buf).unwrap();
13//! let mut cur = Cursor::new(&buf[..size]);
14//! if let OFile::MachFile { ref header, ref commands } = OFile::parse(&mut cur).unwrap() {
15//! assert_eq!(header.cputype, CPU_TYPE_X86_64);
16//! assert_eq!(header.ncmds as usize, commands.len());
17//! for &MachCommand(ref cmd, cmdsize) in commands {
18//! if let &LoadCommand::Segment64 { ref segname, ref sections, .. } = cmd {
19//! println!("segment: {}", segname);
20//!
21//! for ref sect in sections {
22//! println!(" section: {}", sect.sectname);
23//! }
24//! }
25//! }
26//! }
27//! ```
28//!
29//! For more detail, please check the unit tests
30//! and the [otool](https://github.com/flier/rust-macho/blob/master/examples/otool.rs) example.
31//!
32#[macro_use]
33extern crate bitflags;
34#[macro_use]
35extern crate lazy_static;
36#[macro_use]
37extern crate log;
38
39mod commands;
40mod consts;
41#[cfg(feature = "display")]
42mod display;
43mod errors;
44mod export;
45mod loader;
46mod opcode;
47mod symbol;
48
49pub use crate::commands::*;
50pub use crate::consts::*;
51pub use crate::errors::Error as MachError;
52pub use crate::export::{ExportKind, ExportSymbol, ExportTrie, ExportType};
53pub use crate::loader::{ArHeader, CheckedSlice, FatArch, FatHeader, MachCommand, MachHeader, OFile, RanLib};
54pub use crate::opcode::{
55 Bind, BindOpCode, BindOpCodes, BindSymbol, BindSymbolFlags, BindSymbolType, LazyBind, LazyBindSymbol, Rebase,
56 RebaseOpCode, RebaseOpCodes, RebaseSymbol, WeakBind, WeakBindSymbol,
57};
58pub use crate::symbol::{Symbol, SymbolIter, SymbolReference};