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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
use crate::elf;
use crate::read::{Bytes, ReadError, Result};
use super::FileHeader;
#[derive(Debug, Clone)]
pub struct VerdefIterator<'data, Elf: FileHeader> {
endian: Elf::Endian,
data: Bytes<'data>,
}
impl<'data, Elf: FileHeader> VerdefIterator<'data, Elf> {
pub(super) fn new(endian: Elf::Endian, data: &'data [u8]) -> Self {
VerdefIterator {
endian,
data: Bytes(data),
}
}
pub fn next(
&mut self,
) -> Result<Option<(&'data elf::Verdef<Elf::Endian>, VerdauxIterator<'data, Elf>)>> {
if self.data.is_empty() {
return Ok(None);
}
let verdef = self
.data
.read_at::<elf::Verdef<_>>(0)
.read_error("ELF verdef is too short")?;
let mut verdaux_data = self.data;
verdaux_data
.skip(verdef.vd_aux.get(self.endian) as usize)
.read_error("Invalid ELF vd_aux")?;
let verdaux =
VerdauxIterator::new(self.endian, verdaux_data.0, verdef.vd_cnt.get(self.endian));
let next = verdef.vd_next.get(self.endian);
if next != 0 {
self.data
.skip(next as usize)
.read_error("Invalid ELF vd_next")?;
} else {
self.data = Bytes(&[]);
}
Ok(Some((verdef, verdaux)))
}
}
#[derive(Debug, Clone)]
pub struct VerdauxIterator<'data, Elf: FileHeader> {
endian: Elf::Endian,
data: Bytes<'data>,
count: u16,
}
impl<'data, Elf: FileHeader> VerdauxIterator<'data, Elf> {
pub(super) fn new(endian: Elf::Endian, data: &'data [u8], count: u16) -> Self {
VerdauxIterator {
endian,
data: Bytes(data),
count,
}
}
pub fn next(&mut self) -> Result<Option<&'data elf::Verdaux<Elf::Endian>>> {
if self.count == 0 {
return Ok(None);
}
let verdaux = self
.data
.read_at::<elf::Verdaux<_>>(0)
.read_error("ELF verdaux is too short")?;
self.data
.skip(verdaux.vda_next.get(self.endian) as usize)
.read_error("Invalid ELF vda_next")?;
self.count -= 1;
Ok(Some(verdaux))
}
}
#[derive(Debug, Clone)]
pub struct VerneedIterator<'data, Elf: FileHeader> {
endian: Elf::Endian,
data: Bytes<'data>,
}
impl<'data, Elf: FileHeader> VerneedIterator<'data, Elf> {
pub(super) fn new(endian: Elf::Endian, data: &'data [u8]) -> Self {
VerneedIterator {
endian,
data: Bytes(data),
}
}
pub fn next(
&mut self,
) -> Result<
Option<(
&'data elf::Verneed<Elf::Endian>,
VernauxIterator<'data, Elf>,
)>,
> {
if self.data.is_empty() {
return Ok(None);
}
let verneed = self
.data
.read_at::<elf::Verneed<_>>(0)
.read_error("ELF verneed is too short")?;
let mut vernaux_data = self.data;
vernaux_data
.skip(verneed.vn_aux.get(self.endian) as usize)
.read_error("Invalid ELF vn_aux")?;
let vernaux =
VernauxIterator::new(self.endian, vernaux_data.0, verneed.vn_cnt.get(self.endian));
let next = verneed.vn_next.get(self.endian);
if next != 0 {
self.data
.skip(next as usize)
.read_error("Invalid ELF vn_next")?;
} else {
self.data = Bytes(&[]);
}
Ok(Some((verneed, vernaux)))
}
}
#[derive(Debug, Clone)]
pub struct VernauxIterator<'data, Elf: FileHeader> {
endian: Elf::Endian,
data: Bytes<'data>,
count: u16,
}
impl<'data, Elf: FileHeader> VernauxIterator<'data, Elf> {
pub(super) fn new(endian: Elf::Endian, data: &'data [u8], count: u16) -> Self {
VernauxIterator {
endian,
data: Bytes(data),
count,
}
}
pub fn next(&mut self) -> Result<Option<&'data elf::Vernaux<Elf::Endian>>> {
if self.count == 0 {
return Ok(None);
}
let vernaux = self
.data
.read_at::<elf::Vernaux<_>>(0)
.read_error("ELF vernaux is too short")?;
self.data
.skip(vernaux.vna_next.get(self.endian) as usize)
.read_error("Invalid ELF vna_next")?;
self.count -= 1;
Ok(Some(vernaux))
}
}