// 纯粹做个记录,微软源码
1 #include "Unicode_String_Ring0.h" //bp Unicode_String_Ring0!DriverEntry
NTSTATUS DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegisterPath)
{
NTSTATUS Status = STATUS_SUCCESS;
PDEVICE_OBJECT DeviceObject = NULL; DriverObject->DriverUnload = DriverUnload; Test(); return Status;
} void Test()
{
//初始化
//StringInitTest(); //拷贝操作
//StringCopyTest(); //字符串比较
//StringCompareTest(); //字符串变大写
//StringToUpperTest(); //字符串与整型相互转化
//StringToIntegerTest(); //ANSI_STRING字符串与UNICODE_STRING字符串相互转换
StringConverTest(); } //初始化
void StringInitTest()
{
//Sub_1();//常量初始化
//Sub_2();
Sub_3();//堆
}
void Sub_1()
{
//UNICODE_STRING
//常量初始化
UNICODE_STRING v1;
RtlInitUnicodeString(&v1, L"HelloWorld"); //v1.Buffer = 常量指针
//v1.Length = 20
//v1.MaximumLength = 22 DbgPrint("%wZ\r\n", &v1);//Unicode打印L"" /*
//常量初始化ANSI_STRING
//(1)用RtlInitAnsiString初始化字符串
ANSI_STRING AnsiString;
CHAR * string = "hello";
//初始化ANSI_STRING字符串
RtlInitAnsiString(&AnsiString, string);
DbgPrint("AnsiString:%Z\n", &AnsiString);
*/
}
void Sub_2()
{
UNICODE_STRING v1;
WCHAR BufferData[] = L"HelloWorld";
v1.Buffer = BufferData;
v1.Length = wcslen(BufferData) * sizeof(WCHAR);
v1.MaximumLength = (wcslen(BufferData) + ) * sizeof(WCHAR); DbgPrint("%wZ\r\n", &v1);
}
void Sub_3()
{
UNICODE_STRING v1;
WCHAR BufferData[] = L"HelloWorld"; v1.Length = wcslen(BufferData) * sizeof(WCHAR);
v1.MaximumLength = (wcslen(BufferData) + ) * sizeof(WCHAR);
v1.Buffer = ExAllocatePool(PagedPool, v1.MaximumLength); RtlZeroMemory(v1.Buffer, v1.MaximumLength);
RtlCopyMemory(v1.Buffer, BufferData, v1.Length); DbgPrint("%wZ\r\n", &v1); if (v1.Buffer != NULL)
{
ExFreePool(v1.Buffer);
v1.Buffer = NULL;
v1.Length = v1.MaximumLength = ;
}
} //拷贝操作
void StringCopyTest()
{
UNICODE_STRING SourceString;
RtlInitUnicodeString(&SourceString, L"HelloWorld"); UNICODE_STRING DestinationString = { };
DestinationString.Buffer = (PWSTR)ExAllocatePool(PagedPool, BUFFER_SIZE);
DestinationString.MaximumLength = BUFFER_SIZE; RtlCopyUnicodeString(&DestinationString, &SourceString); DbgPrint("SourceString:%wZ\r\n", &SourceString);
DbgPrint("DestinationString:%wZ\n", &DestinationString); RtlFreeUnicodeString(&DestinationString);
} //字符串比较
void StringCompareTest()
{
//初始化UnicodeString1
UNICODE_STRING UnicodeString1;
RtlInitUnicodeString(&UnicodeString1,L"HELLOWORLD"); //初始化UnicodeString2
UNICODE_STRING UnicodeString2;
//RtlInitUnicodeString(&UnicodeString2, L"Hello");
//RtlInitUnicodeString(&UnicodeString2, L"HELLOWORLD");
RtlInitUnicodeString(&UnicodeString2, L"helloworld"); if (RtlEqualUnicodeString(
&UnicodeString1,
&UnicodeString2,
TRUE
//If TRUE,
//case should be ignored when doing the comparison.
)
)
{
DbgPrint("UnicodeString1 and UnicodeString2 are equal\n");
}
else
{
DbgPrint("UnicodeString1 and UnicodeString2 are NOT equal\n");
} } //字符串变大写
void StringToUpperTest()
{
UNICODE_STRING SourceString;
RtlInitUnicodeString(&SourceString, L"Hello World"); UNICODE_STRING DestinationString;
DestinationString.Buffer = (PWSTR)ExAllocatePool(PagedPool, BUFFER_SIZE);
DestinationString.MaximumLength = BUFFER_SIZE; //变化前
DbgPrint("变化前:%wZ\n", &SourceString);
//变大写
RtlUpcaseUnicodeString(
&DestinationString, //DestinationString
&SourceString, //SourceString
FALSE//Specifies if RtlUpcaseUnicodeString is to allocate the buffer space for the DestinationString.
//If it does, the buffer must be deallocated by calling RtlFreeUnicodeString.
); //变化后
DbgPrint("变化后:%wZ\n", &DestinationString); RtlFreeUnicodeString(&DestinationString);
} //字符串与整型相互转化
void StringToIntegerTest()
{
//(1)字符串转换成数字
UNICODE_STRING UnicodeString1;
RtlInitUnicodeString(&UnicodeString1, L"-100"); ULONG lNumber;
NTSTATUS Status =
RtlUnicodeStringToInteger(//第二个参数Base
&UnicodeString1,
//10,//-100是10进制 //输出-100
//16,//-100是16进制 //输出-256
, //-100是8进制 //输出-64
&lNumber
); if (NT_SUCCESS(Status))
{
DbgPrint("Conver to integer succussfully!\n");
DbgPrint("Result:%d\n", lNumber);
}
else
{
DbgPrint("Conver to integer unsuccessfully!\n");
}
//(2)数字转换成字符串
UNICODE_STRING UnicodeString2 = { };
UnicodeString2.Buffer = (PWSTR)ExAllocatePool(PagedPool, BUFFER_SIZE);
UnicodeString2.MaximumLength = BUFFER_SIZE; Status = RtlIntegerToUnicodeString(//同上 第二参数是Base
,
//10, //输出200
//8, //输出310
, //输出 C8
&UnicodeString2
); /*
HEX C8
DEC 200
OCT 310
*/ if (NT_SUCCESS(Status))
{
DbgPrint("Conver to string succussfully!\n");
DbgPrint("Result:%wZ\n", &UnicodeString2);
}
else
{
DbgPrint("Conver to string unsuccessfully!\n");
} //销毁UnicodeString2
//注意!!UnicodeString1不用销毁
RtlFreeUnicodeString(&UnicodeString2); } //ANSI_STRING字符串与UNICODE_STRING字符串相互
void StringConverTest()
{
//(1)将UNICODE_STRING字符串转换成ANSI_STRING字符串
//初始化UnicodeString1
UNICODE_STRING UnicodeString1;
RtlInitUnicodeString(&UnicodeString1, L"HelloWorld"); ANSI_STRING AnsiString1;
NTSTATUS Status = RtlUnicodeStringToAnsiString(
&AnsiString1,
&UnicodeString1,
TRUE
//TRUE if this routine is to allocate the buffer space for the DestinationString.
//If it does, the buffer must be deallocated by calling RtlFreeAnsiString.
); if (NT_SUCCESS(Status))
{
DbgPrint("Conver succussfully!\n");
DbgPrint("Result:%Z\n", &AnsiString1);
}
else
{
DbgPrint("Conver unsuccessfully!\n");
} //销毁AnsiString1
RtlFreeAnsiString(&AnsiString1); //(2)将ANSI_STRING字符串转换成UNICODE_STRING字符串 ANSI_STRING AnsiString2;
RtlInitString(&AnsiString2, "HelloWorld"); UNICODE_STRING UnicodeString2;
Status = RtlAnsiStringToUnicodeString(
&UnicodeString2,
&AnsiString2,
TRUE
//Specifies if this routine should allocate the buffer space for the destination string.
//If it does, the caller must deallocate the buffer by calling RtlFreeUnicodeString. ); if (NT_SUCCESS(Status))
{
DbgPrint("Conver succussfully!\n");
DbgPrint("Result:%wZ\n", &UnicodeString2);
}
else
{
DbgPrint("Conver unsuccessfully!\n");
} //销毁UnicodeString2
RtlFreeUnicodeString(&UnicodeString2);
} VOID DriverUnload(PDRIVER_OBJECT DriverObject)
{
DbgPrint("DriverUnload()\r\n");
}
 #include <ntifs.h>

 #define BUFFER_SIZE 0x400

 void Test();

 //初始化操作
void StringInitTest();
void Sub_1();//常量初始化
void Sub_2();
void Sub_3(); //拷贝操作
void StringCopyTest(); //字符串比较
void StringCompareTest(); //字符串变大写
void StringToUpperTest(); //字符串与整型相互转化
void StringToIntegerTest(); //ANSI_STRING字符串与UNICODE_STRING字符串相互
void StringConverTest(); VOID DriverUnload(PDRIVER_OBJECT DriverObject);

Ring3层的话不能直接使用UnicodeString、AnsiString,需要自己定义出来,并且部分相关的函数需要自己实现,得参照微软的源代码,本人正在写,写好了发出来,也是Ring0的这些基本的操作。

老实说字符串操作是很大的一个部分,之前就被一个String的输出到txt文件的问题卡过,还是要好好总结这些基础的东西,感觉要是能有完全的手册就好了MSDN。。。String Manipulation (CRT)。。。。唉看英语还是慢,个人琐碎。

vs自动生成的ReadMe.txt是UTF-8  开头有EF BB BF

UnicodeString基本操作(Ring0)的更多相关文章

  1. UnicodeString基本操作(Ring3)

    // Unicode_String_Ring3.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include "Unicode ...

  2. Key/Value之王Memcached初探:二、Memcached在.Net中的基本操作

    一.Memcached ClientLib For .Net 首先,不得不说,许多语言都实现了连接Memcached的客户端,其中以Perl.PHP为主. 仅仅memcached网站上列出的语言就有: ...

  3. Android Notification 详解(一)——基本操作

    Android Notification 详解(一)--基本操作 版权声明:本文为博主原创文章,未经博主允许不得转载. 微博:厉圣杰 源码:AndroidDemo/Notification 文中如有纰 ...

  4. Android Notification 详解——基本操作

    Android Notification 详解 版权声明:本文为博主原创文章,未经博主允许不得转载. 前几天项目中有用到 Android 通知相关的内容,索性把 Android Notificatio ...

  5. 三、Redis基本操作——List

    小喵的唠叨话:前面我们介绍了Redis的string的数据结构的原理和操作.当时我们提到Redis的键值对不仅仅是字符串.而这次我们就要介绍Redis的第二个数据结构了,List(链表).由于List ...

  6. 二、Redis基本操作——String(实战篇)

    小喵万万没想到,上一篇博客,居然已经被阅读600次了!!!让小喵感觉压力颇大.万一有写错的地方,岂不是会误导很多筒子们.所以,恳请大家,如果看到小喵的博客有什么不对的地方,请尽快指正!谢谢! 小喵的唠 ...

  7. 一、Redis基本操作——String(原理篇)

    小喵的唠叨话:最近京东图书大减价,小喵手痒了就买了本<Redis设计与实现>[1]来看看.这里权当小喵看书的笔记啦.这一系列的模式,主要是先介绍Redis的实现原理(可能很大一部分会直接照 ...

  8. Linq查询基本操作

    摘要:本文介绍Linq查询基本操作(查询关键字) - from 子句 - where 子句 - select子句 - group 子句 - into 子句 - orderby 子句 - join 子句 ...

  9. C++ map的基本操作和使用

    原文地址:http://blog.sina.com.cn/s/blog_61533c9b0100fa7w.html Map是c++的一个标准容器,她提供了很好一对一的关系,在一些程序中建立一个map可 ...

随机推荐

  1. 《DSP using MATLAB》Problem 5.19

    代码: function [X1k, X2k] = real2dft(x1, x2, N) %% --------------------------------------------------- ...

  2. 浅谈log4j-2

    //配置日志输出的定义,主要有三点:1:输出什么级别的日志信息,2:将日志信息输出到那里,3:输出的日志以什么格式展示 public static void main(String[] args) { ...

  3. 使用netlify-statuskit 进行系统业务状态报告

    netlify-statuskit 是netlify 团队开源的一款类似github status 的脚手架website,使用此工具 我们可以对于我们系统模块进行报告,同时对于故障时,我们可以进行故 ...

  4. redis服务以及phpredis扩展的安装

    一.下载软件包 下载redis wget http://download.redis.io/releases/redis-3.0.7.tar.gz 下载redis的php扩展 wget http:// ...

  5. create a simple COM object

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAArsAAAGYCAIAAADN0b3QAAAgAElEQVR4nO29749c1b2nW/4Lzh8wUr

  6. node 学习资料

    Node 学习资料: 资料名称 网址 Node.js 中文API文档 http://nodejs.cn/api/ Node 菜鸟教程 http://www.runoob.com/nodejs/node ...

  7. PyCharm中的Console自动换行

    菜单栏-> File -> Settings -> Editor -> General -> Console,选中右侧Use soft wraps in console前 ...

  8. Jenkins进阶-邮件通知(9)

    公司内部每天大概会发布N多版本,也不能派员工一直去盯着版本发布,所以希望发布完成后通知相关人员,Jenkins最早采用通知机制就是短信和邮件,由于短信成本很高,所以我们一般在发布结束后会采用邮件.现在 ...

  9. Pyhanlp自然语言处理中的新词识别

    新词发现 本“新词发现”模块基于信息熵和互信息两种算法,可以在无语料的情况下提取一段长文本中的词语,并支持过滤掉系统中已存在的“旧词”,得到新词列表. 调用方法 静态方法 一句话静态调用接口已经封装到 ...

  10. const引用返回值

    一.引用 引用是别名 必须在定义引用时进行初始化.初始化是指明引用指向哪个对象的唯一方法. const 引用是指向 const 对象的引用: ; const int &refVal = iva ...