Skip to content

Commit

Permalink
Simplifies CLSID decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
mmalecot committed Nov 4, 2023
1 parent 05b8b0b commit d0aaa13
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/readers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,16 @@ impl crate::FileFormat {
// Reads and decodes the CLSID.
let mut buffer = [0; 16];
reader.read_exact(&mut buffer)?;
let clsid = format!(
"{:02x}{:02x}{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}",
buffer[3], buffer[2], buffer[1], buffer[0],
buffer[5], buffer[4],
buffer[7], buffer[6],
buffer[8], buffer[9],
buffer[10], buffer[11], buffer[12], buffer[13], buffer[14], buffer[15]
);
let clsid = [3, 2, 1, 0, 5, 4, 7, 6, 8, 9, 10, 11, 12, 13, 14, 15]
.iter()
.map(|&index| {
if index == 5 || index == 7 || index == 8 || index == 10 {
format!("-{:02x}", buffer[index])
} else {
format!("{:02x}", buffer[index])
}
})
.collect::<String>();

// Checks the CLSID and returns the corresponding variant.
Ok(match clsid.as_str() {
Expand Down

0 comments on commit d0aaa13

Please sign in to comment.