blob: 7a189bf3eb8ac534bd12ec867e9e5dbfd2485686 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
mod structs;
use crate::structs::ElfHeader;
#[repr(C)]
#[derive(Debug)]
struct Elf {
header: &'static ElfHeader,
}
impl Elf {
pub fn new(bytes: &[u8]) -> Elf {
let header = unsafe { &*(bytes.as_ptr() as *const ElfHeader) };
assert_eq!(&header.ident.magic, b"\x7fELF");
Elf {
header
}
}
}
fn main() {
let data = include_bytes!("../elf");
let elf = Elf::new(&data[..]);
println!("{:?}", elf);
}
|