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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
use ::NTSTATUS;
pub trait NativeString {
fn size(&self) -> u16;
fn max_size(&self) -> u16;
fn is_empty(&self) -> bool {
self.size() == 0u16
}
}
#[repr(C)]
pub struct UNICODE_STRING
{
pub Length: u16,
pub MaximumLength: u16,
pub Buffer: *const u16,
}
#[repr(C)]
pub struct ANSI_STRING
{
pub Length: u16,
pub MaximumLength: u16,
pub Buffer: *const u8,
}
impl NativeString for UNICODE_STRING
{
fn size(&self) -> u16 { self.Length }
fn max_size(&self) -> u16 { self.MaximumLength }
}
impl UNICODE_STRING
{
}
impl Default for UNICODE_STRING {
fn default() -> Self {
UNICODE_STRING { Length: 0, MaximumLength: 0, Buffer: ::core::ptr::null() }
}
}
impl<'a> From<&'a [u8]> for ANSI_STRING {
fn from(s: &'a [u8]) -> Self {
let len = s.len();
let n = if len > 0 && s[len-1] == 0 { len - 1 } else { len };
ANSI_STRING { Length: n as u16, MaximumLength: len as u16, Buffer: s.as_ptr() }
}
}
pub type AnsiString = ANSI_STRING;
pub type UnicodeString = UNICODE_STRING;
pub type CONST_UNICODE_STRING = UNICODE_STRING;
pub type CONST_ANSI_STRING = ANSI_STRING;
extern "system"
{
pub fn RtlIntegerToUnicodeString(Value: u32, Base: u32, String: &mut UNICODE_STRING) -> NTSTATUS;
pub fn RtlInt64ToUnicodeString(Value: u64, Base: u32, String: &mut UNICODE_STRING) -> NTSTATUS;
pub fn RtlUnicodeStringToInteger(String: &CONST_UNICODE_STRING, Base: u32, Value: &mut u32) -> NTSTATUS;
pub fn RtlUnicodeStringToAnsiString(DestinationString: &mut ANSI_STRING, SourceString: &CONST_UNICODE_STRING, AllocateDestination: bool) -> NTSTATUS;
pub fn RtlUnicodeStringToAnsiSize(SourceString: &CONST_UNICODE_STRING) -> u32;
pub fn RtlAnsiStringToUnicodeString(DestinationString: &mut UNICODE_STRING, SourceString: &CONST_ANSI_STRING, AllocateDestination: bool) -> NTSTATUS;
pub fn RtlAnsiStringToUnicodeSize(SourceString: &CONST_ANSI_STRING) -> u32;
pub fn RtlCompareUnicodeString (String1: &CONST_UNICODE_STRING, String2: &CONST_UNICODE_STRING, CaseInSensitive: bool) -> i32;
pub fn RtlCompareString (String1: &CONST_ANSI_STRING, String2: &CONST_ANSI_STRING, CaseInSensitive: bool) -> i32;
pub fn RtlEqualUnicodeString(String1: &CONST_UNICODE_STRING, String2: &CONST_UNICODE_STRING) -> bool;
pub fn RtlEqualString(String1: &CONST_ANSI_STRING, String2: &CONST_ANSI_STRING) -> bool;
pub fn RtlFreeAnsiString(UnicodeString: &mut ANSI_STRING);
pub fn RtlFreeUnicodeString(UnicodeString: &mut UNICODE_STRING);
}