Skip to content

Instantly share code, notes, and snippets.

@mitsuhiko
Created September 13, 2017 09:04
Show Gist options
  • Save mitsuhiko/82e6e5c9c71a087e677853546b9ff785 to your computer and use it in GitHub Desktop.
Save mitsuhiko/82e6e5c9c71a087e677853546b9ff785 to your computer and use it in GitHub Desktop.
pub struct FatObject<'a> {
byteview: ByteView<'a>,
kind: FatObjectKind<'a>,
}
impl<'a> FatObject<'a> {
/// Provides a view to an object file from a byteview.
pub fn parse(byteview: ByteView<'a>) -> Result<FatObject<'a>> {
let kind = {
let buf = byteview.as_bytes();
let mut cur = Cursor::new(buf);
match goblin::peek(&mut cur)? {
Hint::Elf(_) => FatObjectKind::Elf(elf::Elf::parse(buf)?),
Hint::Mach(_) => FatObjectKind::MachO(mach::Mach::parse(buf)?),
Hint::MachFat(_) => FatObjectKind::MachO(mach::Mach::parse(buf)?),
_ => {
return Err(ErrorKind::UnsupportedObjectFile.into());
}
}
};
Ok(FatObject { byteview, kind })
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment