From 525f5347ed7628ee6313db5ce2154c5f81c27560 Mon Sep 17 00:00:00 2001 From: desbma-s1n Date: Mon, 27 May 2024 15:31:38 +0200 Subject: [PATCH] refactor: rename SyscallArg to Expression --- src/strace/mod.rs | 12 +- src/strace/parser/mod.rs | 310 +++++++++++++++++++-------------------- src/strace/parser/peg.rs | 10 +- src/summarize.rs | 52 +++---- 4 files changed, 192 insertions(+), 192 deletions(-) diff --git a/src/strace/mod.rs b/src/strace/mod.rs index 2f774a3..7e8e75d 100644 --- a/src/strace/mod.rs +++ b/src/strace/mod.rs @@ -16,7 +16,7 @@ pub struct Syscall { pub pid: u32, pub rel_ts: f64, pub name: String, - pub args: Vec, + pub args: Vec, pub ret_val: SyscallRetVal, } @@ -27,7 +27,7 @@ pub enum BufferType { } #[derive(Debug, Clone, PartialEq)] -pub enum SyscallArg { +pub enum Expression { Buffer { value: Vec, type_: BufferType, @@ -36,15 +36,15 @@ pub enum SyscallArg { value: IntegerExpression, metadata: Option>, }, - Struct(HashMap), - Array(Vec), + Struct(HashMap), + Array(Vec), Macro { name: String, - args: Vec, + args: Vec, }, } -impl SyscallArg { +impl Expression { pub fn metadata(&self) -> Option<&[u8]> { match self { Self::Integer { metadata, .. } => metadata.as_deref(), diff --git a/src/strace/parser/mod.rs b/src/strace/parser/mod.rs index ba0078c..fc642a0 100644 --- a/src/strace/parser/mod.rs +++ b/src/strace/parser/mod.rs @@ -106,7 +106,7 @@ mod tests { use pretty_assertions::assert_eq; - use crate::strace::{BufferType, IntegerExpression, SyscallArg}; + use crate::strace::{BufferType, Expression, IntegerExpression}; use super::*; @@ -124,33 +124,33 @@ mod tests { rel_ts: 0.000054, name: "mmap".to_owned(), args: vec![ - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::NamedConst("NULL".to_owned()), metadata: None, }, - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(8192), metadata: None }, - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::BinaryOr(vec![ IntegerExpression::NamedConst("PROT_READ".to_owned()), IntegerExpression::NamedConst("PROT_WRITE".to_owned()), ]), metadata: None }, - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::BinaryOr(vec![ IntegerExpression::NamedConst("MAP_PRIVATE".to_owned()), IntegerExpression::NamedConst("MAP_ANONYMOUS".to_owned()), ]), metadata:None }, - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(-1), metadata: None }, - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(0), metadata: None }, @@ -170,22 +170,22 @@ mod tests { rel_ts: 0.000011, name: "mmap".to_owned(), args: vec![ - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(0x7f2fce8dc000), metadata: None }, - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(1396736), metadata: None }, - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::BinaryOr(vec![ IntegerExpression::NamedConst("PROT_READ".to_owned()), IntegerExpression::NamedConst("PROT_EXEC".to_owned()), ]), metadata: None }, - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::BinaryOr(vec![ IntegerExpression::NamedConst("MAP_PRIVATE".to_owned()), IntegerExpression::NamedConst("MAP_FIXED".to_owned()), @@ -193,11 +193,11 @@ mod tests { ]), metadata: None }, - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(3), metadata: None }, - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(0x26000), metadata: None }, @@ -221,11 +221,11 @@ mod tests { rel_ts: 0.000036, name: "access".to_owned(), args: vec![ - SyscallArg::Buffer { + Expression::Buffer { value: "/etc/ld.so.preload".as_bytes().to_vec(), type_: BufferType::Unknown }, - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::NamedConst("R_OK".to_owned()), metadata: None, }, @@ -249,45 +249,45 @@ mod tests { rel_ts: 0.000064, name: "rt_sigaction".to_owned(), args: vec![ - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::NamedConst("SIGTERM".to_owned()), metadata: None, }, - SyscallArg::Struct(HashMap::from([ + Expression::Struct(HashMap::from([ ( "sa_handler".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::NamedConst("SIG_DFL".to_owned()), metadata: None, }, ), ( "sa_mask".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::BinaryNot(Box::new(IntegerExpression::NamedConst("RT_1".to_owned()))), metadata: None, }, ), ( "sa_flags".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::NamedConst("SA_RESTORER".to_owned()), metadata: None, }, ), ( "sa_restorer".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(0x7f6da716c510), metadata: None }, ), ])), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::NamedConst("NULL".to_owned()), metadata: None, }, - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(8), metadata: None }, @@ -307,19 +307,19 @@ mod tests { rel_ts: 0.002174, name: "rt_sigprocmask".to_owned(), args: vec![ - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::NamedConst( "SIG_SETMASK".to_owned(), ), metadata: None, }, - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::NamedConst( "[]".to_owned(), ), metadata: None, }, - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::BinaryNot( Box::new(IntegerExpression::NamedConst( "RT_1".to_owned(), @@ -327,7 +327,7 @@ mod tests { ), metadata: None, }, - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal( 8, ), @@ -353,25 +353,25 @@ mod tests { rel_ts: 0.000010, name: "newfstatat".to_owned(), args: vec![ - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::NamedConst("AT_FDCWD".to_owned()), metadata: None, }, - SyscallArg::Buffer { + Expression::Buffer { value: "/a/path".as_bytes().to_vec(), type_: BufferType::Unknown }, - SyscallArg::Struct(HashMap::from([ + Expression::Struct(HashMap::from([ ( "st_dev".to_owned(), - SyscallArg::Macro { + Expression::Macro { name: "makedev".to_owned(), args: vec![ - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(0xfd), metadata: None, }, - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(1), metadata: None, }, @@ -380,14 +380,14 @@ mod tests { ), ( "st_ino".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(26427782), metadata: None }, ), ( "st_mode".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::BinaryOr(vec![ IntegerExpression::NamedConst("S_IFDIR".to_owned()), IntegerExpression::NamedConst("0755".to_owned()) @@ -397,90 +397,90 @@ mod tests { ), ( "st_nlink".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(2), metadata: None }, ), ( "st_uid".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(1000), metadata: None }, ), ( "st_gid".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(1000), metadata: None }, ), ( "st_blksize".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(4096), metadata: None }, ), ( "st_blocks".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(112), metadata: None }, ), ( "st_size".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(53248), metadata: None }, ), ( "st_atime".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(1689948680), metadata: None }, ), ( "st_atime_nsec".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(28467954), metadata: None }, ), ( "st_mtime".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(1692975712), metadata: None }, ), ( "st_mtime_nsec".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(252908565), metadata: None }, ), ( "st_ctime".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(1692975712), metadata: None }, ), ( "st_ctime_nsec".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(252908565), metadata: None }, ), ])), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(0), metadata: None }, @@ -504,15 +504,15 @@ mod tests { rel_ts: 0.000017, name: "getrandom".to_owned(), args: vec![ - SyscallArg::Buffer { + Expression::Buffer { value: vec![0x42, 0x18, 0x81, 0x90, 0x40, 0x63, 0x1a, 0x2c], type_: BufferType::Unknown }, - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(8), metadata: None }, - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::NamedConst("GRND_NONBLOCK".to_owned()), metadata: None, }, @@ -536,71 +536,71 @@ mod tests { rel_ts: 0.000033, name: "fstatfs".to_owned(), args: vec![ - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(6), metadata: None }, - SyscallArg::Struct(HashMap::from([ + Expression::Struct(HashMap::from([ ( "f_type".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::NamedConst("EXT2_SUPER_MAGIC".to_owned()), metadata: None, }, ), ( "f_bsize".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(4096), metadata: None }, ), ( "f_blocks".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(231830864), metadata: None }, ), ( "f_bfree".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(38594207), metadata: None }, ), ( "f_bavail".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(26799417), metadata: None }, ), ( "f_files".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(58957824), metadata: None }, ), ( "f_ffree".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(54942232), metadata: None }, ), ( "f_fsid".to_owned(), - SyscallArg::Struct(HashMap::from([ + Expression::Struct(HashMap::from([ ( "val".to_owned(), - SyscallArg::Array(vec![ - SyscallArg::Integer { + Expression::Array(vec![ + Expression::Integer { value: IntegerExpression::Literal(1360496552), metadata: None }, - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(2460437074), metadata: None }, @@ -610,21 +610,21 @@ mod tests { ), ( "f_namelen".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(255), metadata: None }, ), ( "f_frsize".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(4096), metadata: None }, ), ( "f_flags".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::BinaryOr(vec![ IntegerExpression::NamedConst("ST_VALID".to_owned()), IntegerExpression::NamedConst("ST_NOATIME".to_owned()) @@ -648,71 +648,71 @@ mod tests { rel_ts: 0.000028, name: "fstatfs".to_owned(), args: vec![ - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(3), metadata: None }, - SyscallArg::Struct(HashMap::from([ + Expression::Struct(HashMap::from([ ( "f_type".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::NamedConst("PROC_SUPER_MAGIC".to_owned()), metadata: None, }, ), ( "f_bsize".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(4096), metadata: None }, ), ( "f_blocks".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(0), metadata: None }, ), ( "f_bfree".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(0), metadata: None }, ), ( "f_bavail".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(0), metadata: None }, ), ( "f_files".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(0), metadata: None }, ), ( "f_ffree".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(0), metadata: None }, ), ( "f_fsid".to_owned(), - SyscallArg::Struct(HashMap::from([ + Expression::Struct(HashMap::from([ ( "val".to_owned(), - SyscallArg::Array(vec![ - SyscallArg::Integer { + Expression::Array(vec![ + Expression::Integer { value: IntegerExpression::Literal(0), metadata: None }, - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(0), metadata: None }, @@ -722,21 +722,21 @@ mod tests { ), ( "f_namelen".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(255), metadata: None }, ), ( "f_frsize".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(4096), metadata: None }, ), ( "f_flags".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::BinaryOr(vec![ IntegerExpression::NamedConst("ST_VALID".to_owned()), IntegerExpression::NamedConst("ST_NOSUID".to_owned()), @@ -768,15 +768,15 @@ mod tests { rel_ts: 0.000033, name: "openat".to_owned(), args: vec![ - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::NamedConst("AT_FDCWD".to_owned()), metadata: Some(vec![0x2f, 0x68, 0x6f, 0x6d, 0x65, 0x2f, 0x6d, 0x64, 0x65, 0x2f, 0x73, 0x72, 0x63, 0x2f, 0x73, 0x68, 0x68]), }, - SyscallArg::Buffer { + Expression::Buffer { value: vec![0x2e, 0x2e], type_: BufferType::Unknown, }, - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::BinaryOr(vec![ IntegerExpression::NamedConst("O_RDONLY".to_owned()), IntegerExpression::NamedConst("O_NONBLOCK".to_owned()), @@ -805,29 +805,29 @@ mod tests { rel_ts: 0.000194, name: "sendto".to_owned(), args: vec![ - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(15), metadata: Some(vec![115, 111, 99, 107, 101, 116, 58, 91, 53, 52, 49, 56, 50, 49, 51, 93]) }, - SyscallArg::Array(vec![ - SyscallArg::Struct(HashMap::from([ + Expression::Array(vec![ + Expression::Struct(HashMap::from([ ( "nlmsg_len".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(20), metadata: None, }, ), ( "nlmsg_type".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::NamedConst("RTM_GETADDR".to_owned()), metadata: None, }, ), ( "nlmsg_flags".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::BinaryOr(vec![ IntegerExpression::NamedConst("NLM_F_REQUEST".to_owned()), IntegerExpression::NamedConst("NLM_F_DUMP".to_owned()), @@ -837,61 +837,61 @@ mod tests { ), ( "nlmsg_seq".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(1694010548), metadata: None, }, ), ( "nlmsg_pid".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(0), metadata: None, }, ), ])), - SyscallArg::Struct(HashMap::from([ + Expression::Struct(HashMap::from([ ( "ifa_family".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::NamedConst("AF_UNSPEC".to_owned()), metadata: None, }, ), ])), ]), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(20), metadata: None, }, - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(0), metadata: None, }, - SyscallArg::Struct(HashMap::from([ + Expression::Struct(HashMap::from([ ( "sa_family".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::NamedConst("AF_NETLINK".to_owned()), metadata: None, }, ), ( "nl_pid".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(0), metadata: None, }, ), ( "nl_groups".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(0), metadata: None, }, ), ])), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(12), metadata: None, }, @@ -928,27 +928,27 @@ mod tests { rel_ts: 0.000023, name: "bind".to_owned(), args: vec![ - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(4), metadata: Some("socket:[4184522]".as_bytes().to_vec()) }, - SyscallArg::Struct(HashMap::from([ + Expression::Struct(HashMap::from([ ( "sa_family".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::NamedConst("AF_UNIX".to_owned()), metadata: None, }, ), ( "sun_path".to_owned(), - SyscallArg::Buffer { + Expression::Buffer { value: "b193d0b0ccd705f9/bus/systemctl/".as_bytes().to_vec(), type_: BufferType::AbstractPath, }, ), ])), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(34), metadata: None, }, @@ -967,24 +967,24 @@ mod tests { rel_ts: 0.000022, name: "bind".to_owned(), args: vec![ - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(6), metadata: Some(vec![115, 111, 99, 107, 101, 116, 58, 91, 56, 49, 53, 54, 57, 51, 93]), }, - SyscallArg::Struct(HashMap::from([ + Expression::Struct(HashMap::from([ ( "sa_family".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::NamedConst("AF_INET".to_owned()), metadata: None, }, ), ( "sin_port".to_owned(), - SyscallArg::Macro { + Expression::Macro { name: "htons".to_owned(), args: vec![ - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(8025), metadata: None, }, @@ -993,10 +993,10 @@ mod tests { ), ( "sin_addr".to_owned(), - SyscallArg::Macro { + Expression::Macro { name: "inet_addr".to_owned(), args: vec![ - SyscallArg::Buffer { + Expression::Buffer { value: vec![49, 50, 55, 46, 48, 46, 48, 46, 49], type_: BufferType::Unknown, }, @@ -1004,7 +1004,7 @@ mod tests { } ), ])), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(16), metadata: None, }, @@ -1028,18 +1028,18 @@ mod tests { rel_ts: 0.000038, name: "prlimit64".to_owned(), args: vec![ - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(0), metadata: None, }, - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::NamedConst("RLIMIT_NOFILE".to_owned()), metadata: None, }, - SyscallArg::Struct(HashMap::from([ + Expression::Struct(HashMap::from([ ( "rlim_cur".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Multiplication(vec![ IntegerExpression::Literal(512), IntegerExpression::Literal(1024), @@ -1049,7 +1049,7 @@ mod tests { ), ( "rlim_max".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Multiplication(vec![ IntegerExpression::Literal(512), IntegerExpression::Literal(1024), @@ -1058,7 +1058,7 @@ mod tests { }, ), ])), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::NamedConst("NULL".to_owned()), metadata: None, }, @@ -1082,39 +1082,39 @@ mod tests { rel_ts: 0.000075, name: "epoll_ctl".to_owned(), args: vec![ - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(3), metadata: Some(vec![97, 110, 111, 110, 95, 105, 110, 111, 100, 101, 58, 91, 101, 118, 101, 110, 116, 112, 111, 108, 108, 93]), }, - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::NamedConst("EPOLL_CTL_ADD".to_owned()), metadata: None, }, - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(4), metadata: Some(vec![115, 111, 99, 107, 101, 116, 58, 91, 55, 51, 49, 53, 57, 56, 93]), }, - SyscallArg::Struct(HashMap::from([ + Expression::Struct(HashMap::from([ ( "events".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::NamedConst("EPOLLIN".to_owned()), metadata: None, }, ), ( "data".to_owned(), - SyscallArg::Struct(HashMap::from([ + Expression::Struct(HashMap::from([ ( "u32".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(4), metadata: None, } ), ( "u64".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(4), metadata: None, } @@ -1137,32 +1137,32 @@ mod tests { rel_ts: 0.000130, name: "epoll_pwait".to_owned(), args: vec![ - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(4), metadata: Some(vec![0x61, 0x6e, 0x6f, 0x6e, 0x5f, 0x69, 0x6e, 0x6f, 0x64, 0x65, 0x3a, 0x5b, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x70, 0x6f, 0x6c, 0x6c, 0x5d]), }, - SyscallArg::Array(vec![ - SyscallArg::Struct(HashMap::from([ + Expression::Array(vec![ + Expression::Struct(HashMap::from([ ( "events".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::NamedConst("EPOLLOUT".to_owned()), metadata: None, }, ), ( "data".to_owned(), - SyscallArg::Struct(HashMap::from([ + Expression::Struct(HashMap::from([ ( "u32".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(833093633), metadata: None, } ), ( "u64".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(9163493471957811201), metadata: None, } @@ -1170,27 +1170,27 @@ mod tests { ])) ), ])), - SyscallArg::Struct(HashMap::from([ + Expression::Struct(HashMap::from([ ( "events".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::NamedConst("EPOLLOUT".to_owned()), metadata: None, }, ), ( "data".to_owned(), - SyscallArg::Struct(HashMap::from([ + Expression::Struct(HashMap::from([ ( "u32".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(800587777), metadata: None, } ), ( "u64".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(9163493471925305345), metadata: None, } @@ -1199,19 +1199,19 @@ mod tests { ), ])), ]), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(128), metadata: None, }, - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(0), metadata: None, }, - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::NamedConst("NULL".to_owned()), metadata: None, }, - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(0), metadata: None, }, @@ -1243,21 +1243,21 @@ mod tests { rel_ts: 0.000002, name: "clock_gettime".to_owned(), args: vec![ - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::NamedConst("CLOCK_REALTIME".to_owned()), metadata: None, }, - SyscallArg::Struct(HashMap::from([ + Expression::Struct(HashMap::from([ ( "tv_sec".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(1130322148), metadata: None, }, ), ( "tv_nsec".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(3977000), metadata: None, }, @@ -1271,23 +1271,23 @@ mod tests { rel_ts: 0.000003, name: "select".to_owned(), args: vec![ - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(4), metadata: None, }, - SyscallArg::Array(vec![SyscallArg::Integer { + Expression::Array(vec![Expression::Integer { value: IntegerExpression::Literal(3), metadata: None, },]), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::NamedConst("NULL".to_owned()), metadata: None, }, - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::NamedConst("NULL".to_owned()), metadata: None, }, - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::NamedConst("NULL".to_owned()), metadata: None, }, diff --git a/src/strace/parser/peg.rs b/src/strace/parser/peg.rs index c76bf5b..df76789 100644 --- a/src/strace/parser/peg.rs +++ b/src/strace/parser/peg.rs @@ -4,7 +4,7 @@ use itertools::Itertools; use pest::iterators::Pair; use pest::Parser as _; -use crate::strace::{BufferType, IntegerExpression, Syscall, SyscallArg}; +use crate::strace::{BufferType, Expression, IntegerExpression, Syscall}; use super::ParseResult; @@ -59,18 +59,18 @@ fn buf_val(pair: Pair) -> Option> { ) } -impl From> for SyscallArg { +impl From> for Expression { fn from(pair: Pair) -> Self { match pair.as_node_tag() { - Some("expr_int") => SyscallArg::Integer { + Some("expr_int") => Expression::Integer { value: pair_descend(pair, 1).unwrap().into(), metadata: None, }, - Some("buf") => SyscallArg::Buffer { + Some("buf") => Expression::Buffer { value: buf_val(pair).unwrap(), type_: BufferType::Unknown, }, - Some("struct") => SyscallArg::Struct( + Some("struct") => Expression::Struct( pair.into_inner() .map(|m| { let (name, val) = m.into_inner().next_tuple().unwrap(); diff --git a/src/summarize.rs b/src/summarize.rs index 79f521d..9707b54 100644 --- a/src/summarize.rs +++ b/src/summarize.rs @@ -7,7 +7,7 @@ use std::path::{Path, PathBuf}; use lazy_static::lazy_static; -use crate::strace::{BufferType, IntegerExpression, Syscall, SyscallArg}; +use crate::strace::{BufferType, Expression, IntegerExpression, Syscall}; use crate::systemd::{SocketFamily, SocketProtocol}; /// A high level program runtime action @@ -191,10 +191,10 @@ fn is_fd_pseudo_path(path: &[u8]) -> bool { /// Extract path for socket address structure if it's a non abstract one fn socket_address_uds_path( - members: &HashMap, + members: &HashMap, syscall: &Syscall, ) -> Option { - if let Some(SyscallArg::Buffer { + if let Some(Expression::Buffer { value: b, type_: BufferType::Unknown, }) = members.get("sun_path") @@ -230,11 +230,11 @@ where flags_idx, }) => { let (mut path, flags) = if let ( - Some(SyscallArg::Buffer { + Some(Expression::Buffer { value: b, type_: BufferType::Unknown, }), - Some(SyscallArg::Integer { value: e, .. }), + Some(Expression::Integer { value: e, .. }), ) = (syscall.args.get(*path_idx), syscall.args.get(*flags_idx)) { @@ -270,11 +270,11 @@ where flags_idx, }) => { let (mut path_src, mut path_dst) = if let ( - Some(SyscallArg::Buffer { + Some(Expression::Buffer { value: b1, type_: BufferType::Unknown, }), - Some(SyscallArg::Buffer { + Some(Expression::Buffer { value: b2, type_: BufferType::Unknown, }), @@ -300,7 +300,7 @@ where }; let exchange = if let Some(flags_idx) = flags_idx { - let flags = if let Some(SyscallArg::Integer { value: flags, .. }) = + let flags = if let Some(Expression::Integer { value: flags, .. }) = syscall.args.get(*flags_idx) { flags @@ -340,7 +340,7 @@ where relfd_idx, path_idx, }) => { - let mut path = if let Some(SyscallArg::Buffer { + let mut path = if let Some(Expression::Buffer { value: b, type_: BufferType::Unknown, }) = syscall.args.get(*path_idx) @@ -358,8 +358,8 @@ where } Some(SyscallInfo::Network { sockaddr_idx }) => { let (af, addr) = - if let Some(SyscallArg::Struct(members)) = syscall.args.get(*sockaddr_idx) { - let af = if let Some(SyscallArg::Integer { + if let Some(Expression::Struct(members)) = syscall.args.get(*sockaddr_idx) { + let af = if let Some(Expression::Integer { value: IntegerExpression::NamedConst(af), .. }) = members.get("sa_family") @@ -385,7 +385,7 @@ where } if name == "bind" { - let fd = if let Some(SyscallArg::Integer { + let fd = if let Some(Expression::Integer { value: IntegerExpression::Literal(fd), .. }) = syscall.args.first() @@ -406,7 +406,7 @@ where } } Some(SyscallInfo::SetScheduler) => { - let policy = if let Some(SyscallArg::Integer { value, .. }) = syscall.args.get(1) { + let policy = if let Some(Expression::Integer { value, .. }) = syscall.args.get(1) { value } else { anyhow::bail!("Unexpected args for {}: {:?}", name, syscall.args); @@ -416,7 +416,7 @@ where } } Some(SyscallInfo::Socket) => { - let af = if let Some(SyscallArg::Integer { + let af = if let Some(Expression::Integer { value: IntegerExpression::NamedConst(af), .. }) = syscall.args.first() @@ -428,7 +428,7 @@ where actions.push(ProgramAction::NetworkActivity { af }); let proto_flags = - if let Some(SyscallArg::Integer { value, .. }) = syscall.args.get(1) { + if let Some(Expression::Integer { value, .. }) = syscall.args.get(1) { value.flags() } else { anyhow::bail!("Unexpected args for {}: {:?}", name, syscall.args); @@ -441,7 +441,7 @@ where } } Some(SyscallInfo::Mmap { prot_idx }) => { - let prot = if let Some(SyscallArg::Integer { value: prot, .. }) = + let prot = if let Some(Expression::Integer { value: prot, .. }) = syscall.args.get(*prot_idx) { prot @@ -496,23 +496,23 @@ mod tests { rel_ts: 0.000083, name: "renameat".to_owned(), args: vec![ - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::NamedConst("AT_FDCWD".to_owned()), metadata: Some(temp_dir_src.path().as_os_str().as_bytes().to_vec()), }, - SyscallArg::Buffer { + Expression::Buffer { value: "a".as_bytes().to_vec(), type_: BufferType::Unknown, }, - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::NamedConst("AT_FDCWD".to_owned()), metadata: Some(temp_dir_dst.path().as_os_str().as_bytes().to_vec()), }, - SyscallArg::Buffer { + Expression::Buffer { value: "b".as_bytes().to_vec(), type_: BufferType::Unknown, }, - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::NamedConst("RENAME_NOREPLACE".to_owned()), metadata: None, }, @@ -540,27 +540,27 @@ mod tests { rel_ts: 0.000036, name: "connect".to_owned(), args: vec![ - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(4), metadata: Some("/run/user/1000/systemd/private".as_bytes().to_vec()), }, - SyscallArg::Struct(HashMap::from([ + Expression::Struct(HashMap::from([ ( "sa_family".to_owned(), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::NamedConst("AF_UNIX".to_owned()), metadata: None, }, ), ( "sun_path".to_owned(), - SyscallArg::Buffer { + Expression::Buffer { value: "/run/user/1000/systemd/private".as_bytes().to_vec(), type_: BufferType::Unknown, }, ), ])), - SyscallArg::Integer { + Expression::Integer { value: IntegerExpression::Literal(33), metadata: None, },