-
Notifications
You must be signed in to change notification settings - Fork 201
Expand file tree
/
Copy pathctx.rs
More file actions
55 lines (50 loc) · 1.55 KB
/
Copy pathctx.rs
File metadata and controls
55 lines (50 loc) · 1.55 KB
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
use crate::{
container::Container,
pe::{options, section_table},
};
/// A binary parsing context for PE parser
#[derive(Debug, Copy, Clone)]
pub(crate) struct PeCtx<'a> {
pub(crate) container: Container,
pub(crate) le: scroll::Endian,
pub(crate) sections: &'a [section_table::SectionTable],
pub(crate) file_alignment: u32,
pub(crate) opts: options::ParseOptions,
pub(crate) bytes: &'a [u8], // full binary view
}
impl<'a> PeCtx<'a> {
/// Make a new instance of [PeCtx]
pub(crate) fn new(
container: Container,
le: scroll::Endian,
sections: &'a [section_table::SectionTable],
file_alignment: u32,
opts: options::ParseOptions,
bytes: &'a [u8],
) -> Self {
Self {
container,
le,
sections,
file_alignment,
opts,
bytes,
}
}
/// Whether this binary container context is "big" or not
pub(crate) fn is_big(self) -> bool {
self.container.is_big()
}
/// Whether this binary container context is little endian or not
pub(crate) fn is_little_endian(self) -> bool {
self.le.is_little()
}
/// Return a dubious pointer/address byte size for the container
pub(crate) fn size(self) -> usize {
match self.container {
// TODO: require pointer size initialization/setting or default to container size with these values, e.g., avr pointer width will be smaller iirc
Container::Little => 4,
Container::Big => 8,
}
}
}