|
| 1 | +use std::fmt; |
| 2 | +use types::{EfiVariable, EfiVariableAttribute}; |
| 3 | + |
| 4 | +pub struct Verbose<'a>(pub &'a EfiVariable<'a>); |
| 5 | +pub struct Decimal<'a>(pub &'a EfiVariable<'a>); |
| 6 | + |
| 7 | +impl fmt::Display for Decimal<'_> { |
| 8 | + fn fmt(&self, f:&mut fmt::Formatter<'_>) -> fmt::Result { |
| 9 | + for (i, b) in self.0.data.iter().enumerate() { |
| 10 | + if (i > 0) && (i % 16 == 0) { |
| 11 | + f.write_str(" ")?; |
| 12 | + } |
| 13 | + if i % 16 < 8 { |
| 14 | + f.write_str(&format!("{} ", b))?; |
| 15 | + } else { |
| 16 | + f.write_str(&format!(" {}", b))?; |
| 17 | + } |
| 18 | + } |
| 19 | + return Ok(()); |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +impl fmt::Display for Verbose<'_> { |
| 24 | + fn fmt(&self, f:&mut fmt::Formatter<'_>) -> fmt::Result { |
| 25 | + f.write_str(&format!("GUID: {}\n", self.0.guid))?; |
| 26 | + f.write_str(&format!("Name: \"{}\"\n", self.0.name))?; |
| 27 | + f.write_str("Attributes:\n")?; |
| 28 | + let mut sorted_attrs:Vec<&EfiVariableAttribute> = |
| 29 | + self.0.attributes.clone().into_iter().collect(); |
| 30 | + sorted_attrs.sort_unstable_by(|a1, a2| <u32>::from(*a1).cmp(&<u32>::from(*a2))); |
| 31 | + for a in sorted_attrs.iter() { |
| 32 | + f.write_str(&format!("\t{}\n", String::from(*a)))?; |
| 33 | + } |
| 34 | + |
| 35 | + f.write_str("Value:\n")?; |
| 36 | + for i in (0..self.0.data.len()).step_by(16) { |
| 37 | + f.write_str(&format!("{:08x} ", i))?; |
| 38 | + |
| 39 | + let mut decode:[u8; 16] = [0; 16]; |
| 40 | + let mut line_iter = self.0.data.iter().skip(i); |
| 41 | + for j in i..i + 16 { |
| 42 | + match line_iter.next() { |
| 43 | + Some(c) => { |
| 44 | + if (0x20 < *c) && (*c < 0x7e) { |
| 45 | + decode[j - i] = u32::from(*c) as u8; |
| 46 | + } else { |
| 47 | + decode[j - i] = u32::from('.') as u8; |
| 48 | + } |
| 49 | + if j < i + 8 { |
| 50 | + f.write_str(&format!("{:02x} ", u8::from(*c)))?; |
| 51 | + } else { |
| 52 | + f.write_str(&format!(" {:02x}", u8::from(*c)))?; |
| 53 | + } |
| 54 | + } |
| 55 | + None => { |
| 56 | + decode[j - i] = u32::from(' ') as u8; |
| 57 | + f.write_str(" ")?; |
| 58 | + } |
| 59 | + }; |
| 60 | + } |
| 61 | + f.write_str(&format!(" |{}|\n", std::str::from_utf8(&decode).unwrap()))?; |
| 62 | + } |
| 63 | + f.write_str(&format!("{:08x}\n", self.0.data.len()))?; |
| 64 | + return Ok(()); |
| 65 | + } |
| 66 | +} |
0 commit comments