Skip to main content

read

Function read 

Source
pub fn read(bytes: &[u8]) -> Result<Object, ReadError>
Expand description

Reads an ELF file into an object, with the default Limits.

§Errors

A ReadError saying what is wrong: BadMagic for bytes that are not ELF, Truncated when a structure runs past the input, Malformed when fields contradict the format or each other, Unsupported for valid ELF the model cannot represent, LimitExceeded when a budget is exceeded, and Invalid when the decoded object breaks a model rule. It never panics, whatever the bytes.

§Examples

use object_lang::{Architecture, FileKind};

let exe = object_lang::elf::executable(Architecture::X86_64, &[0xeb, 0xfe])?; // jmp .
let obj = object_lang::elf::read(&exe)?;
assert_eq!(obj.kind(), FileKind::Executable);
assert_eq!(obj.sections()[0].data(), &[0xeb, 0xfe]);