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();