Created
February 22, 2023 12:29
-
-
Save dvas0004/a04810778dc8f855c9bfe5250220fca5 to your computer and use it in GitHub Desktop.
Convert binary SID to name in Rust: https://blog.davidvassallo.me/?p=3980
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn bytes_to_sid(binary :&Vec<u8>) -> String { | |
let version = binary[0]; | |
let length = binary[1] as usize; | |
let authority = u64::from_be_bytes([0, 0, binary[2], binary[3], binary[4], binary[5], binary[6], binary[7]]); | |
let mut string = format!("S-{}-{}", version, authority); | |
let binary = &binary[8..]; | |
assert_eq!(binary.len(), 4 * length); | |
for i in 0..length { | |
let start = 4 * i; | |
let end = start + 4; | |
let value = u32::from_le_bytes(binary[start..end].try_into().unwrap()); | |
string += &format!("-{}", value); | |
} | |
string | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment