-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathexec_mode.rs
65 lines (57 loc) · 1.81 KB
/
exec_mode.rs
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
// Certain casts are required only on Windows. Inform Clippy to ignore them.
#![allow(clippy::unnecessary_cast)]
use libipt_sys::{
pt_event__bindgen_ty_1__bindgen_ty_8, pt_exec_mode_ptem_16bit, pt_exec_mode_ptem_32bit,
pt_exec_mode_ptem_64bit, pt_exec_mode_ptem_unknown,
};
use std::convert::TryFrom;
use num_enum::TryFromPrimitive;
#[derive(Clone, Copy, TryFromPrimitive, Debug, PartialEq)]
#[repr(u32)]
pub enum ExecModeType {
Bit16 = pt_exec_mode_ptem_16bit as u32,
Bit32 = pt_exec_mode_ptem_32bit as u32,
Bit64 = pt_exec_mode_ptem_64bit as u32,
Unknown = pt_exec_mode_ptem_unknown as u32,
}
/// An execution mode change
#[derive(Clone, Copy, Debug)]
pub struct ExecMode(pub(super) pt_event__bindgen_ty_1__bindgen_ty_8);
impl ExecMode {
/// The address at which the event is effective
#[must_use]
pub fn ip(&self) -> u64 {
self.0.ip
}
/// The execution mode
#[must_use]
#[expect(clippy::missing_panics_doc)]
pub fn mode(&self) -> ExecModeType {
ExecModeType::try_from(self.0.mode as u32).unwrap()
}
}
#[cfg(test)]
mod test {
use super::super::Payload;
use super::*;
use crate::event::Event;
use libipt_sys::{pt_event, pt_event_type_ptev_exec_mode};
use std::mem;
#[test]
fn test_exec_mode_payload() {
let mut evt: pt_event = unsafe { mem::zeroed() };
evt.type_ = pt_event_type_ptev_exec_mode;
evt.variant.exec_mode = pt_event__bindgen_ty_1__bindgen_ty_8 {
ip: 11,
mode: pt_exec_mode_ptem_32bit,
};
let payload: Payload = Event(evt).into();
match payload {
Payload::ExecMode(e) => {
assert_eq!(e.ip(), 11);
assert_eq!(e.mode(), ExecModeType::Bit32);
}
_ => unreachable!("oof"),
}
}
}