Created
September 13, 2017 09:04
-
-
Save mitsuhiko/82e6e5c9c71a087e677853546b9ff785 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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