1 ASCII字符串和寬字符串
char型,記錄ansi字符集。每個字符一個字節。以0標誌結束。在KdPrint中用%s輸出。
寬字符型,wchar_t,描述unicode字符集的字符串,每個字符兩個字節,以0標誌結束。通過L來體現。在KdPrint中用%S輸出。
CHAR *string = "Hello";
WCHAR *string2 = L"hello";
KdPrint("%s\n", string);
KdPrint("%S\n", string2);
2 ANSI_STRING字符串和UNICODE_STRING字符串
DDK不鼓勵用 1 中所示的C語言字符串,因爲C的字符串處理函數易導致緩衝區溢出等錯誤(如忘記對長度進行檢查)。而鼓勵用DDK自己定義的字符串。
typedef struct _STRING {
USHORT Length; //字符的長度
USHORT MaximumLength;//整個字符緩衝區的最大長度
PCHAR Buffer; //緩衝區的指針
} ANSI_STRING *PANSI_STRING;
注意STRING不是以0結束的。
typedef struct _UNICODE_STRING {
USHORT Length;
USHORT MaximumLength;
PWSTR Buffer;
} UNICODE_STRING *PUNICODE_STRING;
用%Z輸出 ANSI_STRING字符串,用%wZ輸出 UNICODE_STRING
UNICODE_STRING uniString;
KdPrint("%wZ", &uniString);
3 字符串初始化與銷燬
使用DDK提供的相應函數
VOID RtlInitAnsiString(),VOID RtlInitUnicodeString(),ExAllocatePool(),wcslen(),RtlCopyMemory(),ExFreePool(),RtlFreeAnsiString(),RtlFreeUnicodeString();
4 字符串複製
使用DDK提供的相應函數
RtlCopyString(),RtlCopyUnicodeString();
5 字符串比較
使用DDK提供的相應函數
RtlCompareString(),RtlCompareUnicodeString(),RtlEqualString(),RtlEqualUnicodeString();
6 字符串轉換爲大寫
RtlUpperString(),RtlUpcaseUnicodeString();
7 字符串與整型互轉
RtlUnicodeStringToInteger(),RtlIntegerToUnicodeString();
8 ANSI_STRING字符串與UNICODE_STRING字符串相互轉換
RtlUnicodeStringToAnsiString(),RtlAnsiStringToUnicodeString();