diff options
author | Johannes Stoelp <johannes.stoelp@gmail.com> | 2022-04-27 23:48:33 +0200 |
---|---|---|
committer | Johannes Stoelp <johannes.stoelp@gmail.com> | 2022-04-27 23:48:33 +0200 |
commit | 9c46d94b30bce282a590f8a6dcbec4498f7e18b0 (patch) | |
tree | b598f252070c3ac9f4447e071eddc61974e46ac0 /examples | |
download | elfload-9c46d94b30bce282a590f8a6dcbec4498f7e18b0.tar.gz elfload-9c46d94b30bce282a590f8a6dcbec4498f7e18b0.zip |
initial commit of elfload
Diffstat (limited to 'examples')
-rw-r--r-- | examples/ls.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/examples/ls.rs b/examples/ls.rs new file mode 100644 index 0000000..94da7e8 --- /dev/null +++ b/examples/ls.rs @@ -0,0 +1,24 @@ +use elfload::Elf; + +fn main() { + let ls_bytes = include_bytes!("/bin/ls"); + + match Elf::parse(ls_bytes) { + Ok(elf) => { + println!("ELF machine: {:?} entry: 0x{:08x}", elf.machine, elf.entry); + for l in &elf.load_segments { + println!( + "LOAD: vaddr: 0x{:08x} zero_pad: {:8} {}{}{}", + l.vaddr, + l.zero_pad, + if l.x { 'X' } else { '-' }, + if l.w { 'W' } else { '-' }, + if l.r { 'R' } else { '-' } + ); + } + } + Err(e) => { + eprintln!("Parsing /bin/ls ELF file failed with {:?}.", e); + } + } +} |