elf_utilities/segment/
segment_type.rs1use crate::*;
4
5#[derive(Debug, Eq, Ord, PartialEq, PartialOrd)]
6pub enum Type {
7 Null,
9 Load,
11 Dynamic,
13 Interp,
15 Note,
17 ShLib,
19 Phdr,
21 TLS,
23 Num,
25 GNUEHFrame,
27 GNUStack,
29 GNURelRO,
31 Any(Elf64Word),
33}
34
35impl Type {
36 pub fn to_bytes(&self) -> Elf64Word {
37 match self {
38 Self::Null => 0,
39 Self::Load => 1,
40 Self::Dynamic => 2,
41 Self::Interp => 3,
42 Self::Note => 4,
43 Self::ShLib => 5,
44 Self::Phdr => 6,
45 Self::TLS => 7,
46 Self::Num => 8,
47 Self::GNUEHFrame => 0x6474e550,
48 Self::GNUStack => 0x6474e551,
49 Self::GNURelRO => 0x6474e552,
50 Self::Any(c) => *c,
51 }
52 }
53}
54
55impl From<Elf64Word> for Type {
56 fn from(bytes: Elf64Word) -> Self {
57 match bytes {
58 0 => Self::Null,
59 1 => Self::Load,
60 2 => Self::Dynamic,
61 3 => Self::Interp,
62 4 => Self::Note,
63 5 => Self::ShLib,
64 6 => Self::Phdr,
65 7 => Self::TLS,
66 8 => Self::Num,
67 0x6474e550 => Self::GNUEHFrame,
68 0x6474e551 => Self::GNUStack,
69 0x6474e552 => Self::GNURelRO,
70 _ => Self::Any(bytes),
71 }
72 }
73}