1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use rand::distributions::Alphanumeric;
use rand::{thread_rng, Rng};
pub fn rand_string() -> String {
thread_rng()
.sample_iter(&Alphanumeric)
.take(10)
.map(char::from)
.collect()
}
pub fn parse_unk_size_null_utf16_string(v: &[u8]) -> String {
String::from_utf16_lossy(
v.chunks_exact(2)
.into_iter()
.take_while(|&a| a[0] != 0 && a[1] == 0)
.map(|a| u16::from_ne_bytes([a[0], a[1]]))
.collect::<Vec<u16>>()
.as_slice(),
)
.to_string()
}
pub fn parse_null_utf16_string(v: &[u8]) -> String {
String::from_utf16_lossy(
v.chunks_exact(2)
.into_iter()
.map(|a| u16::from_ne_bytes([a[0], a[1]]))
.collect::<Vec<u16>>()
.as_slice(),
)
.trim_matches(char::default())
.to_string()
}
pub fn parse_utf16_guid(v: &[u8]) -> String {
String::from_utf16_lossy(
v.chunks_exact(2)
.into_iter()
.map(|a| u16::from_ne_bytes([a[0], a[1]]))
.collect::<Vec<u16>>()
.as_slice(),
)
.trim_matches(char::default())
.trim_matches('{')
.trim_matches('}')
.to_string()
}