mach_object

Mach-O File Format Parser for Rust

12 releases

0.1.12 May 23, 2018
0.1.10 Apr 11, 2018
0.1.9 Mar 15, 2018
0.1.6 Dec 7, 2017
0.1.1 Nov 1, 2016

#98 in Parser implementations

Download history 52/week @ 2018-05-26 49/week @ 2018-06-02 8/week @ 2018-06-09 69/week @ 2018-06-16 21/week @ 2018-06-23 93/week @ 2018-06-30 29/week @ 2018-07-07 9/week @ 2018-07-14 42/week @ 2018-07-21 90/week @ 2018-07-28 160/week @ 2018-08-04 109/week @ 2018-08-11 13/week @ 2018-08-18

70 downloads per month

Apache-2.0

234KB
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

~1MB
~14K SLoC