Skip to main content

dmidecode/structures/
011_oem_strings.rs

1//! OEM Strings (Type 11)
2//!
3//! This SMBIOS structure contains free-form strings defined by the OEM. Examples of this are part
4//! numbers for system reference documents, contact information for the manufacturer, etc.
5
6use crate::{MalformedStructureError, RawStructure, StructureStrings};
7
8/// Contains free-form strings defined by the OEM
9#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
10pub struct OemStrings<'a> {
11    /// Specifies the structure’s handle
12    pub handle: u16,
13    /// OEM defined strings
14    pub strings: StructureStrings<'a>,
15}
16
17impl<'a> OemStrings<'a> {
18    pub(crate) fn try_from(structure: RawStructure<'a>) -> Result<Self, MalformedStructureError> {
19        let strings = structure.strings();
20        Ok(OemStrings {
21            handle: structure.handle,
22            strings,
23        })
24    }
25}
26
27#[cfg(test)]
28mod tests {
29    use pretty_assertions::assert_eq as pretty_assert_eq;
30    use std::prelude::v1::*;
31
32    #[test]
33    fn oem_strings() {
34        use super::*;
35        use crate::{InfoType, RawStructure};
36
37        let sample = vec!["$HUA001UK10000", "$HUA0464", "$XXX0000"];
38        let structure = RawStructure {
39            version: (3, 4).into(),
40            info: InfoType::OemStrings,
41            length: 0x05,
42            handle: 0x001E,
43            // Remove 4 bytes from `dmidecode -H 8 -u` 'Header and Data'
44            data: &[
45                0x03, // Strings count
46            ],
47            strings: &[
48                // $HUA001UK10000
49                0x24, 0x48, 0x55, 0x41, 0x30, 0x30, 0x31, 0x55, 0x4B, 0x31, 0x30, 0x30, 0x30, 0x30,
50                0x00, // $HUA0464
51                0x24, 0x48, 0x55, 0x41, 0x30, 0x34, 0x36, 0x34, 0x00, // $XXX0000
52                0x24, 0x58, 0x58, 0x58, 0x30, 0x30, 0x30, 0x30, 0x00, 0x00,
53            ],
54        };
55        let result = OemStrings::try_from(structure).unwrap();
56
57        pretty_assert_eq!(sample, result.strings.collect::<Vec<_>>());
58    }
59
60    #[test]
61    fn dmi_bin() {
62        use super::*;
63        use crate::{EntryPoint, Structure, StructureStrings};
64        const DMIDECODE_BIN: &[u8] = include_bytes!("../../tests/data/dmi.0.bin");
65        let entry_point = EntryPoint::search(DMIDECODE_BIN).unwrap();
66        let oem_strings = entry_point
67            .structures(&DMIDECODE_BIN[(entry_point.smbios_address() as usize)..])
68            .filter_map(|s| {
69                if let Err(ref s) = s {
70                    println!("{s}");
71                }
72                s.ok().filter(|s| matches!(s, Structure::OemStrings(_)))
73            })
74            .collect::<Vec<_>>();
75
76        let sample = OemStrings {
77            handle: 0x0B00,
78            strings: StructureStrings::new(&[
79                // Dell System
80                0x44, 0x65, 0x6C, 0x6C, 0x20, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6D, 0x00, // 5[0000]
81                0x35, 0x5B, 0x30, 0x30, 0x30, 0x30, 0x5D, 0x00, // 14[1]
82                0x31, 0x34, 0x5B, 0x31, 0x5D, 0x00, // 26[0]
83                0x32, 0x36, 0x5B, 0x30, 0x5D, 0x00, // 17[20106865E85AE75B]
84                0x31, 0x37, 0x5B, 0x32, 0x30, 0x31, 0x30, 0x36, 0x38, 0x36, 0x35, 0x45, 0x38, 0x35, 0x41, 0x45, 0x37,
85                0x35, 0x42, 0x5D, 0x00, // 17[201559E55BE4282A]
86                0x31, 0x37, 0x5B, 0x32, 0x30, 0x31, 0x35, 0x35, 0x39, 0x45, 0x35, 0x35, 0x42, 0x45, 0x34, 0x32, 0x38,
87                0x32, 0x41, 0x5D, 0x00, // 18[0]
88                0x31, 0x38, 0x5B, 0x30, 0x5D, 0x00, // 19[1]
89                0x31, 0x39, 0x5B, 0x31, 0x5D, 0x00, // 19[1]
90                0x31, 0x39, 0x5B, 0x31, 0x5D, 0x00, //
91                0x00,
92            ]),
93        };
94        let result = oem_strings
95            .iter()
96            .find_map(|s| match s {
97                Structure::OemStrings(os) => Some(os),
98                _ => None,
99            })
100            .unwrap();
101        pretty_assert_eq!(&sample, result, "Sample\n{:?}\nResult\n{:?}", sample, result);
102
103        let string_sample = vec![
104            "Dell System",
105            "5[0000]",
106            "14[1]",
107            "26[0]",
108            "17[20106865E85AE75B]",
109            "17[201559E55BE4282A]",
110            "18[0]",
111            "19[1]",
112            "19[1]",
113        ];
114        pretty_assert_eq!(string_sample, result.strings.collect::<Vec<_>>(), "Strings");
115    }
116}