parselnk/extra_data/
environment_variable_data_block.rs

1use super::Result;
2use crate::error::ExtraDataError;
3use std::io::{Cursor, Read};
4
5/// The EnvironmentVariableDataBlock structure specifies a path to environment variable information when the link target refers to a location that has a corresponding environment variable.
6#[derive(Clone, Debug, Default)]
7pub struct EnvironmentVariableDataBlock {
8    ///A 32-bit, unsigned integer that specifies the size of the EnvironmentVariableDataBlock structure. This value MUST be 0x00000314.
9    pub block_size: u32,
10
11    /// A 32-bit, unsigned integer that specifies the signature of the EnvironmentVariableDataBlock extra data section. This value MUST be 0xA0000001.
12    pub block_signature: u32,
13
14    /// A NULL-terminated string, defined by the system default code page, which specifies a path to environment variable information.
15    pub target_ansi: Option<Vec<u8>>,
16
17    /// An optional, NULL-terminated, Unicode string that specifies a path to environment variable information.
18    pub target_unicode: Option<Vec<u8>>,
19}
20
21impl EnvironmentVariableDataBlock {
22    /// Construct a new `EnvironmentVariableDataBlock`
23    pub(crate) fn new(
24        block_size: u32,
25        block_signature: u32,
26        cursor: &mut Cursor<Vec<u8>>,
27    ) -> Result<Self> {
28        let this = Self {
29            block_size,
30            block_signature,
31            target_ansi: {
32                let mut target_ansi = vec![0; 260];
33                cursor
34                    .read_exact(&mut target_ansi)
35                    .map_err(ExtraDataError::Read)?;
36                Some(target_ansi)
37            },
38            target_unicode: {
39                let mut target_unicode = vec![0; 520];
40                cursor
41                    .read_exact(&mut target_unicode)
42                    .map_err(ExtraDataError::Read)?;
43                Some(target_unicode)
44            },
45        };
46
47        Ok(this)
48    }
49}