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
#[derive(Copy,Clone,PartialEq,Eq,Hash,Debug)]
pub enum SectMemAttrib {
ExecInstr,
Alloc,
Write,
MaskOS,
MaskProc,
}
pub trait SectionAttributes {
fn get_attributes<'a>(&'a self) -> &'a [SectMemAttrib];
fn is_exec_instr(&self) -> bool {
self.get_attributes()
.iter()
.filter(|x| **x == SectMemAttrib::ExecInstr)
.next()
.is_some()
}
fn is_write(&self) -> bool {
self.get_attributes()
.iter()
.filter(|x| **x == SectMemAttrib::Write)
.next()
.is_some()
}
fn is_alloc(&self) -> bool {
self.get_attributes()
.iter()
.filter(|x| **x == SectMemAttrib::Alloc)
.next()
.is_some()
}
fn is_mask_os(&self) -> bool {
self.get_attributes()
.iter()
.filter(|x| **x == SectMemAttrib::MaskOS)
.next()
.is_some()
}
fn is_mask_proc(&self) -> bool {
self.get_attributes()
.iter()
.filter(|x| **x == SectMemAttrib::MaskProc)
.next()
.is_some()
}
}
const ARR: &'static [(SectMemAttrib,u32)] = &[
(SectMemAttrib::Write, 0x1),
(SectMemAttrib::Alloc, 0x2),
(SectMemAttrib::ExecInstr, 0x4),
(SectMemAttrib::MaskOS, 0x0F000000),
(SectMemAttrib::MaskProc, 0xF0000000)
];
pub fn build_attributes(x: u32) -> Box<[SectMemAttrib]> {
ARR.iter()
.filter(|v| v.1.clone() & x > 0)
.map(|v| v.0)
.collect::<Vec<SectMemAttrib>>()
.into_boxed_slice()
}