monistode_binutils/executable/segments/
flags.rs

1use crate::Serializable;
2
3#[derive(Debug, Clone, Copy)]
4pub struct SegmentFlags {
5    pub executable: bool,
6    pub writable: bool,
7    pub readable: bool,
8    pub special: bool,
9}
10
11impl Serializable for SegmentFlags {
12    fn serialize(&self) -> Vec<u8> {
13        let mut byte = 0u8;
14        if self.executable {
15            byte |= 0b00000001;
16        }
17        if self.writable {
18            byte |= 0b00000010;
19        }
20        if self.readable {
21            byte |= 0b00000100;
22        }
23        if self.special {
24            byte |= 0b00001000;
25        }
26        vec![byte]
27    }
28    fn deserialize(data: &[u8]) -> Result<(usize, Self), crate::SerializationError> {
29        let byte = data.get(0).ok_or(crate::SerializationError::DataTooShort)?;
30        Ok((
31            1,
32            SegmentFlags {
33                executable: byte & 0b00000001 != 0,
34                writable: byte & 0b00000010 != 0,
35                readable: byte & 0b00000100 != 0,
36                special: byte & 0b00001000 != 0,
37            },
38        ))
39    }
40}