elf_utilities/header/
base.rs1use super::{Ehdr32, Ehdr64};
2
3pub(crate) enum Ehdr {
4 Ehdr64(Ehdr64),
5 Ehdr32(Ehdr32),
6}
7
8impl Ehdr {
9 pub fn as_64bit(&self) -> Ehdr64 {
10 match self {
11 Ehdr::Ehdr64(ehdr) => *ehdr,
12 _ => unreachable!(),
13 }
14 }
15 pub fn as_32bit(&self) -> Ehdr32 {
16 match self {
17 Ehdr::Ehdr32(ehdr) => *ehdr,
18 _ => unreachable!(),
19 }
20 }
21
22 pub fn pht_exists(&self) -> bool {
24 match self {
25 Ehdr::Ehdr64(ehdr) => ehdr.e_phnum != 0,
26 Ehdr::Ehdr32(ehdr) => ehdr.e_phnum != 0,
27 }
28 }
29
30 pub fn shnum(&self) -> usize {
31 match self {
32 Ehdr::Ehdr64(ehdr) => ehdr.e_shnum as usize,
33 Ehdr::Ehdr32(ehdr) => ehdr.e_shnum as usize,
34 }
35 }
36
37 pub fn phnum(&self) -> usize {
38 match self {
39 Ehdr::Ehdr64(ehdr) => ehdr.e_phnum as usize,
40 Ehdr::Ehdr32(ehdr) => ehdr.e_phnum as usize,
41 }
42 }
43
44 pub fn sht_start(&self) -> usize {
45 match self {
46 Ehdr::Ehdr64(ehdr) => ehdr.e_shoff as usize,
47 Ehdr::Ehdr32(ehdr) => ehdr.e_shoff as usize,
48 }
49 }
50 pub fn pht_start(&self) -> usize {
51 match self {
52 Ehdr::Ehdr64(ehdr) => ehdr.e_phoff as usize,
53 Ehdr::Ehdr32(ehdr) => ehdr.e_phoff as usize,
54 }
55 }
56 pub fn shstrndx(&self) -> usize {
57 match self {
58 Ehdr::Ehdr64(ehdr) => ehdr.e_shstrndx as usize,
59 Ehdr::Ehdr32(ehdr) => ehdr.e_shstrndx as usize,
60 }
61 }
62}