15 releases

0.1.15 Mar 2, 2021
0.1.14 Nov 21, 2019
0.1.13 Sep 27, 2018
0.1.12 May 23, 2018
0.1.1 Nov 1, 2016

#238 in Parser implementations

Download history 109/week @ 2021-02-23 128/week @ 2021-03-02 101/week @ 2021-03-09 90/week @ 2021-03-16 88/week @ 2021-03-23 87/week @ 2021-03-30 74/week @ 2021-04-06 102/week @ 2021-04-13 55/week @ 2021-04-20 59/week @ 2021-04-27 63/week @ 2021-05-04 40/week @ 2021-05-11 61/week @ 2021-05-18 41/week @ 2021-05-25 50/week @ 2021-06-01 71/week @ 2021-06-08

376 downloads per month
Used in otool

Apache-2.0

235KB
4K SLoC

rust-macho travis crate docs

Mach-O File Format Parser for Rust

Usage

To use, add the following line to Cargo.toml under [dependencies]:

mach_object = "0.1"

or alternatively,

mach_object = { git = "https://github.com/flier/rust-macho.git" }

Examples

Use OFile::parse to read the mach-o file from a &[u8] slice.

use std::io::{Read, Cursor};
use std::fs::File;
use mach_object::{OFile, CPU_TYPE_X86_64, MachCommand, LoadCommand};

let mut f = File::open("test/helloworld").unwrap();
let mut buf = Vec::new();
let size = f.read_to_end(&mut buf).unwrap();
let mut cur = Cursor::new(&buf[..size]);
if let OFile::MachFile { ref header, ref commands } = OFile::parse(&mut cur).unwrap() {
    assert_eq!(header.cputype, CPU_TYPE_X86_64);
    assert_eq!(header.ncmds as usize, commands.len());
    for &MachCommand(ref cmd, cmdsize) in commands {
        if let &LoadCommand::Segment64 { ref segname, ref sections, .. } = cmd {
            println!("segment: {}", segname);

            for ref sect in sections {
                println!("  section: {}", sect.sectname);
            }
        }
    }
}

For more detail, please check the unit tests and the otool example.

Dependencies

~1.2–1.8MB
~39K SLoC