MCPcopy Index your code
hub / github.com/b1tg/rust-windows-shellcode / compare_str_u16

Function compare_str_u16

shellcode/src/utils.rs:9–25  ·  view source on GitHub ↗
(s: &str, u: *const u16)

Source from the content-addressed store, hash-verified

7}
8
9fn compare_str_u16(s: &str, u: *const u16) -> bool {
10 unsafe {
11 let len = (0..).take_while(|&i| *u.offset(i) != 0).count();
12 let slice = core::slice::from_raw_parts(u, len);
13 let s_len = s.len();
14 if len != s_len {
15 return false;
16 }
17 let ss = s.as_bytes();
18 for i in 0..len {
19 if slice[i] != ss[i] as u16 {
20 return false;
21 }
22 }
23 return true;
24 }
25}
26
27// TODO: use alloc
28pub fn str_to_u16_ptr(s: &str, buf: &mut [u16]) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected