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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//! Type definitions for section header types.

use crate::*;

#[derive(Debug, Eq, Ord, PartialEq, PartialOrd)]
pub enum TYPE {
    /// Section header table entry unused
    NULL,
    /// Program data
    PROGBITS,
    /// Symbol table
    SYMTAB,
    /// String table
    STRTAB,
    /// Relocation entries with addends
    RELA,
    /// Symbol hash table
    HASH,
    /// Dynamic linking information
    DYNAMIC,
    /// Notes
    NOTE,
    /// Program space with no data(.bss)
    NOBITS,
    /// Relocation entries, no addends
    REL,
    /// Reserved
    SHLIB,
    /// Dynamic linker symbol table
    DYNSYM,
    /// Array of constructors
    INITARRAY,
    /// Array of destructors
    FINIARRAY,
    /// Array of preconstructors
    PREINITARRAY,
    /// Section group
    GROUP,
    /// Extended section indices
    SYMTABSHNDX,
    /// Number of defined types
    NUM,
    ANY(Elf64Word),
}

impl TYPE {
    pub fn to_bytes(&self) -> Elf64Word {
        match self {
            Self::NULL => 0,
            Self::PROGBITS => 1,
            Self::SYMTAB => 2,
            Self::STRTAB => 3,
            Self::RELA => 4,
            Self::HASH => 5,
            Self::DYNAMIC => 6,
            Self::NOTE => 7,
            Self::NOBITS => 8,
            Self::REL => 9,
            Self::SHLIB => 10,
            Self::DYNSYM => 11,
            Self::INITARRAY => 14,
            Self::FINIARRAY => 15,
            Self::PREINITARRAY => 16,
            Self::GROUP => 17,
            Self::SYMTABSHNDX => 18,
            Self::NUM => 19,
            Self::ANY(c) => *c,
        }
    }
}

impl From<Elf64Word> for TYPE {
    fn from(bytes: Elf64Word) -> Self {
        match bytes {
            0 => Self::NULL,
            1 => Self::PROGBITS,
            2 => Self::SYMTAB,
            3 => Self::STRTAB,
            4 => Self::RELA,
            5 => Self::HASH,
            6 => Self::DYNAMIC,
            7 => Self::NOTE,
            8 => Self::NOBITS,
            9 => Self::REL,
            10 => Self::SHLIB,
            11 => Self::DYNSYM,
            14 => Self::INITARRAY,
            15 => Self::FINIARRAY,
            16 => Self::PREINITARRAY,
            17 => Self::GROUP,
            18 => Self::SYMTABSHNDX,
            19 => Self::NUM,
            _ => Self::ANY(bytes),
        }
    }
}