smb_msg/ioctl/
common.rs

1use std::ops::{Deref, DerefMut};
2
3/// A trait that helps calculating the size of the buffer for IOCTL requests.
4// TODO: Make sure it is tested for all types of IOCTL requests.
5pub trait IoctlRequestContent {
6    /// Returns the size of the buffer for IOCTL requests -- the size of the ENCODED data, in bytes.
7    fn get_bin_size(&self) -> u32;
8}
9
10impl IoctlRequestContent for () {
11    fn get_bin_size(&self) -> u32 {
12        0
13    }
14}
15
16/// Utility structure to represent inner value of Ioctl requests
17/// that have no defined struct (i.e. they are treated as raw byte buffers).
18#[binrw::binrw]
19#[derive(Debug, PartialEq, Eq)]
20pub struct IoctlBuffer {
21    #[br(parse_with = binrw::helpers::until_eof)]
22    buffer: Vec<u8>,
23}
24
25impl From<Vec<u8>> for IoctlBuffer {
26    fn from(buffer: Vec<u8>) -> Self {
27        Self { buffer }
28    }
29}
30
31impl From<&[u8]> for IoctlBuffer {
32    fn from(buffer: &[u8]) -> Self {
33        Self {
34            buffer: buffer.to_vec(),
35        }
36    }
37}
38
39impl IoctlRequestContent for IoctlBuffer {
40    fn get_bin_size(&self) -> u32 {
41        self.len() as u32
42    }
43}
44
45impl Deref for IoctlBuffer {
46    type Target = Vec<u8>;
47
48    fn deref(&self) -> &Self::Target {
49        &self.buffer
50    }
51}
52
53impl DerefMut for IoctlBuffer {
54    fn deref_mut(&mut self) -> &mut Self::Target {
55        &mut self.buffer
56    }
57}