From 85db2b507f3f69b32811c54a89d9ac7bbbc46121 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Mon, 3 Jan 2022 03:20:12 -0800 Subject: feat(driver): commit primer --- crates/windows-kernel-rs/src/string.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 crates/windows-kernel-rs/src/string.rs (limited to 'crates/windows-kernel-rs/src/string.rs') diff --git a/crates/windows-kernel-rs/src/string.rs b/crates/windows-kernel-rs/src/string.rs new file mode 100644 index 0000000..71ad169 --- /dev/null +++ b/crates/windows-kernel-rs/src/string.rs @@ -0,0 +1,17 @@ +use windows_kernel_sys::base::UNICODE_STRING; + +pub fn create_unicode_string(s: &[u16]) -> UNICODE_STRING { + let len = s.len(); + + let n = if len > 0 && s[len - 1] == 0 { + len - 1 + } else { + len + }; + + UNICODE_STRING { + Length: (n * 2) as u16, + MaximumLength: (len * 2) as u16, + Buffer: s.as_ptr() as _, + } +} -- cgit v1.2.3