1 /*++ 2 3 Copyright (c) Microsoft Corporation 4 5 Module Name: 6 7 FxString.hpp 8 9 Abstract: 10 11 This module implements a simple string class to operate on 12 unicode strings. 13 14 Author: 15 16 17 18 19 Environment: 20 21 Both kernel and user mode 22 23 Revision History: 24 25 26 --*/ 27 #ifndef _FXSTRING_H_ 28 #define _FXSTRING_H_ 29 30 class FxString : public FxObject { 31 public: 32 // 33 // Length describes the length of the string in bytes (not WCHARs) 34 // MaximumLength describes the size of the buffer in bytes 35 // 36 UNICODE_STRING m_UnicodeString; 37 38 public: 39 FxString( 40 __in PFX_DRIVER_GLOBALS FxDriverGlobals 41 ); 42 43 ~FxString(); 44 45 VOID 46 __inline ReleaseString(__out PUNICODE_STRING ReleaseTo)47 ReleaseString( 48 __out PUNICODE_STRING ReleaseTo 49 ) 50 { 51 RtlCopyMemory(ReleaseTo, &m_UnicodeString, sizeof(UNICODE_STRING)); 52 RtlZeroMemory(&m_UnicodeString, sizeof(m_UnicodeString)); 53 } 54 55 __inline operator PUNICODE_STRING()56 operator PUNICODE_STRING( 57 ) 58 { 59 return &m_UnicodeString; 60 } 61 62 PUNICODE_STRING 63 __inline GetUnicodeString(VOID)64 GetUnicodeString( 65 VOID 66 ) 67 { 68 return &m_UnicodeString; 69 } 70 71 _Must_inspect_result_ 72 NTSTATUS 73 Assign( 74 __in PCWSTR SourceString 75 ); 76 77 _Must_inspect_result_ 78 NTSTATUS 79 Assign( 80 __in const UNICODE_STRING* UnicodeString 81 ); 82 83 __inline 84 USHORT Length(VOID)85 Length( 86 VOID 87 ) 88 { 89 return m_UnicodeString.Length; 90 } 91 92 __inline 93 USHORT ByteLength(__in BOOLEAN IncludeNull)94 ByteLength( 95 __in BOOLEAN IncludeNull 96 ) 97 { 98 if (IncludeNull) { 99 return m_UnicodeString.Length + sizeof(UNICODE_NULL); 100 } 101 else { 102 return m_UnicodeString.Length; 103 } 104 } 105 106 __inline 107 USHORT CharacterLength(VOID)108 CharacterLength( 109 VOID 110 ) 111 { 112 return m_UnicodeString.Length / sizeof(WCHAR); 113 } 114 115 __inline 116 USHORT MaximumLength(VOID)117 MaximumLength( 118 VOID 119 ) 120 { 121 return m_UnicodeString.MaximumLength; 122 } 123 124 __inline 125 USHORT MaximumByteLength(VOID)126 MaximumByteLength( 127 VOID 128 ) 129 { 130 return m_UnicodeString.MaximumLength; 131 } 132 133 __inline 134 USHORT MaximumCharacterLength(VOID)135 MaximumCharacterLength( 136 VOID 137 ) 138 { 139 return m_UnicodeString.MaximumLength / sizeof(WCHAR); 140 } 141 142 __inline 143 PWCHAR Buffer(VOID)144 Buffer( 145 VOID 146 ) 147 { 148 return m_UnicodeString.Buffer; 149 } 150 }; 151 152 #endif // _FXSTRING_H_ 153