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
/// A ROP gadget
#[derive(Clone, Debug)]
pub struct Gadget {
bytes: Vec<u8>,
instructions: Vec<String>,
offset: u64,
}
impl Gadget {
/// Create a new ROP gadget. This is the result of `GadgetFinder::find`.
///
/// * `offset` - Offset into buffer which was searched for gadgets where
/// this gadget was found.
/// * `length` - The length of this gadget in bytes.
/// * `instructions` - The human-readable text representation of the
/// instructions in this ROP gadget.
/// * `bytes` - The bytes of the instructions in this gadget.
pub fn new(
offset: u64,
instructions: Vec<String>,
bytes: Vec<u8>
) -> Gadget {
Gadget {
bytes: bytes,
instructions: instructions,
offset: offset,
}
}
/// Get the bytes for this gadget.
pub fn bytes(&self) -> &[u8] {
&self.bytes
}
/// Get the human-readable strings of the instructions for this gadget.
pub fn instructions(&self) -> &[String] {
&self.instructions
}
/// Get the length of this gadget in bytes.
pub fn len(&self) -> usize {
self.bytes.len()
}
/// Get the offset into the searched buffer where this gadget was found.
pub fn offset(&self) -> u64 {
self.offset
}
/// Set the bytes for this gadget.
pub fn set_bytes(&mut self, bytes: Vec<u8>) {
self.bytes = bytes;
}
/// Set the instruction strings for this gadget.
pub fn set_instructions(&mut self, instructions: Vec<String>) {
self.instructions = instructions;
}
/// Set offset for this gadget
pub fn set_offset(&mut self, offset: u64) {
self.offset = offset;
}
}