elf_utilities/section/
section_flag.rs

1//! Type definitions for section header flags.
2
3use crate::*;
4
5#[derive(PartialEq, Eq, PartialOrd, Ord, Debug, Clone, Copy, Hash)]
6/// Section flags
7pub enum Flag {
8    /// Writable
9    Write,
10    /// Occupies memory during execution
11    Alloc,
12    /// Executable
13    ExecInstr,
14    /// Might be merged
15    Merge,
16    /// Contains nul-terminated strings
17    Strings,
18    /// `sh_info' contains SHT index
19    InfoLink,
20    /// Preserve order after combining
21    LinkOrder,
22    /// Non-standard OS specific handling required
23    OSNonConforming,
24    /// Section is member of a group
25    Group,
26    /// Section hold thread-local data
27    TLS,
28    /// Section with compressed data
29    COMPRESSED,
30}
31
32impl Into<Elf32Word> for Flag {
33    fn into(self) -> Elf32Word {
34        match self {
35            Flag::Write => 1 << 0,
36            Flag::Alloc => 1 << 1,
37            Flag::ExecInstr => 1 << 2,
38            Flag::Merge => 1 << 4,
39            Flag::Strings => 1 << 5,
40            Flag::InfoLink => 1 << 6,
41            Flag::LinkOrder => 1 << 7,
42            Flag::OSNonConforming => 1 << 8,
43            Flag::Group => 1 << 9,
44            Flag::TLS => 1 << 10,
45            Flag::COMPRESSED => 1 << 11,
46        }
47    }
48}
49
50impl Into<Elf64Xword> for Flag {
51    fn into(self) -> Elf64Xword {
52        match self {
53            Flag::Write => 1 << 0,
54            Flag::Alloc => 1 << 1,
55            Flag::ExecInstr => 1 << 2,
56            Flag::Merge => 1 << 4,
57            Flag::Strings => 1 << 5,
58            Flag::InfoLink => 1 << 6,
59            Flag::LinkOrder => 1 << 7,
60            Flag::OSNonConforming => 1 << 8,
61            Flag::Group => 1 << 9,
62            Flag::TLS => 1 << 10,
63            Flag::COMPRESSED => 1 << 11,
64        }
65    }
66}
67
68impl From<Elf32Word> for Flag {
69    fn from(v: Elf32Word) -> Self {
70        match v {
71            0b1 => Flag::Write,
72            0b10 => Flag::Alloc,
73            0b100 => Flag::ExecInstr,
74            0b1000 => Flag::Merge,
75            0b10000 => Flag::Strings,
76            0b100000 => Flag::InfoLink,
77            0b1000000 => Flag::LinkOrder,
78            0b10000000 => Flag::OSNonConforming,
79            0b100000000 => Flag::Group,
80            0b1000000000 => Flag::TLS,
81            0b10000000000 => Flag::COMPRESSED,
82            _ => unimplemented!(),
83        }
84    }
85}
86
87impl From<Elf64Xword> for Flag {
88    fn from(v: Elf64Xword) -> Self {
89        match v {
90            0b1 => Flag::Write,
91            0b10 => Flag::Alloc,
92            0b100 => Flag::ExecInstr,
93            0b1000 => Flag::Merge,
94            0b10000 => Flag::Strings,
95            0b100000 => Flag::InfoLink,
96            0b1000000 => Flag::LinkOrder,
97            0b10000000 => Flag::OSNonConforming,
98            0b100000000 => Flag::Group,
99            0b1000000000 => Flag::TLS,
100            0b10000000000 => Flag::COMPRESSED,
101            _ => unimplemented!(),
102        }
103    }
104}