pub struct SyscallEvent {
pub pid: i32,
pub number: u64,
pub name: Option<&'static str>,
pub args: [u64; 6],
pub ret: Option<i64>,
pub decoded_args: Vec<DecodedArg>,
}
pub enum DecodedArg {
Raw(u64),
Fd(i32),
Path(String),
Flags(String),
Buf(Vec<u8>, usize),
Addr(u64),
Int(i64),
Size(u64),
}
impl std::fmt::Display for DecodedArg {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
DecodedArg::Raw(v) => write!(f, "{:#x}", v),
DecodedArg::Fd(fd) => {
match *fd {
-100 => write!(f, "AT_FDCWD"),
_ => write!(f, "{}", fd),
}
}
DecodedArg::Path(s) => write!(f, "\"{}\"", s),
DecodedArg::Flags(s) => write!(f, "{}", s),
DecodedArg::Buf(bytes, total_len) => {
write!(f, "\"")?;
for &b in bytes.iter().take(32) {
match b {
b'\n' => write!(f, "\\n")?,
b'\r' => write!(f, "\\r")?,
b'\t' => write!(f, "\\t")?,
b'\\' => write!(f, "\\\\")?,
b'"' => write!(f, "\\\"")?,
0x20..=0x7e => write!(f, "{}", b as char)?,
_ => write!(f, "\\x{:02x}", b)?,
}
}
write!(f, "\"")?;
if *total_len > 32 {
write!(f, "...({} bytes)", total_len)?;
}
Ok(())
}
DecodedArg::Addr(v) => {
if *v == 0 {
write!(f, "NULL")
} else {
write!(f, "{:#x}", v)
}
}
DecodedArg::Int(v) => write!(f, "{}", v),
DecodedArg::Size(v) => write!(f, "{}", v),
}
}
}