pub struct ElfParser { /* private fields */ }
Expand description
An 32-bit/64-bit ELF parser.
Implementations§
Source§impl ElfParser
impl ElfParser
Sourcepub fn parse_elf_file<'a>(
&'a self,
b: &'a [u8],
) -> Result<ElfFile, ElfParserError<&'a [u8]>>
pub fn parse_elf_file<'a>( &'a self, b: &'a [u8], ) -> Result<ElfFile, ElfParserError<&'a [u8]>>
parses the entire of the given ELF file.
Examples found in repository?
examples/demo.rs (line 16)
3fn main() {
4 let args: Vec<String> = args().collect();
5 if args.len() != 2 {
6 panic!("usage: demo <elf-filepath>")
7 }
8
9 let mut f = File::open(&args[1]).expect("failed to open elf-file");
10
11 let mut buf = Vec::with_capacity(4096);
12 let _ = f.read_to_end(&mut buf).expect("failed to read elf-file");
13
14 let parser = pelf::parser::ElfParserConfig::new().build();
15 let elf = parser
16 .parse_elf_file(&buf)
17 .expect("failed to parse elf-file");
18
19 match elf {
20 pelf::file::ElfFile::Elf64(elf64) => {
21 dump_elf64_file(elf64);
22 }
23 _ => unimplemented!(),
24 }
25}
Sourcepub fn parse_raw_elf_file<'a>(
&'a self,
b: &'a [u8],
) -> Result<RawElfFile, ElfParserError<&'a [u8]>>
pub fn parse_raw_elf_file<'a>( &'a self, b: &'a [u8], ) -> Result<RawElfFile, ElfParserError<&'a [u8]>>
parses the entire of the given ELF file. that may return the “raw” representation of the ELF file.
Examples found in repository?
examples/raw-demo.rs (line 16)
3fn main() {
4 let args: Vec<String> = args().collect();
5 if args.len() != 2 {
6 panic!("usage: demo <elf-filepath>")
7 }
8
9 let mut f = File::open(&args[1]).expect("failed to open elf-file");
10
11 let mut buf = Vec::with_capacity(4096);
12 let _ = f.read_to_end(&mut buf).expect("failed to read elf-file");
13
14 let parser = pelf::parser::ElfParserConfig::new().build();
15 let elf = parser
16 .parse_raw_elf_file(&buf)
17 .expect("failed to parse elf-file");
18
19 match elf {
20 pelf::file::RawElfFile::Elf64(elf64) => {
21 dump_elf64_file(elf64);
22 }
23 _ => unimplemented!(),
24 }
25}
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ElfParser
impl RefUnwindSafe for ElfParser
impl Send for ElfParser
impl Sync for ElfParser
impl Unpin for ElfParser
impl UnwindSafe for ElfParser
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more