Skip to main content

winptap_native/
protocol.rs

1//! Offline parsers for statically observed control replies.
2//! These observations do not authorize issuing the corresponding IOCTLs.
3use winptap_core::*;
4/// Observed output size of the modern create-session call on the research DLL.
5pub const CREATE_SESSION_REPLY_SIZE: usize = 0x210;
6#[derive(Debug, PartialEq, Eq)]
7pub struct SessionReply {
8    pub identifier: u64,
9    pub opaque: [u8; 520],
10}
11pub fn parse_session_reply(bytes: &[u8]) -> Result<SessionReply> {
12    if bytes.len() != CREATE_SESSION_REPLY_SIZE {
13        return Err(Error::InvalidData("native session reply size"));
14    }
15    Ok(SessionReply {
16        identifier: u64::from_le_bytes(bytes[..8].try_into().unwrap()),
17        opaque: bytes[8..].try_into().unwrap(),
18    })
19}
20#[cfg(test)]
21mod tests {
22    use super::*;
23    #[test]
24    fn reject_every_wrong_size() {
25        for size in 0..1024 {
26            assert_eq!(
27                parse_session_reply(&vec![0; size]).is_ok(),
28                size == CREATE_SESSION_REPLY_SIZE
29            );
30        }
31    }
32}