// 纯粹做个记录,微软源码
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. 关于vs设置其他主题配色问题

    可以再网上找其他的.vssettings文件导入 导入方法如下: 一般vs会将你之前设置下的配色方案自动保存下来,你也可以直接覆盖 2019-03-21  17:31:07

  2. 铁三测试题——权限、你是管理员吗?——WP

    权限 [题目描述]:你是管理员吗? [解题链接]:http://ctf4.shiyanbar.com/web/root/index.php 首先看题,提到“权限”,“管理员”,这就是说涉及到管理员的账 ...

  3. javascrpit的理解

    1.什么是Javascrpt? 轻量级 .编程语言 HTML+css -->设计 参数的默认值设置 函数的闭包: 浏览器加载整个页面的过程 浏览器:多线程 1.js引擎 2.UI渲染 3.事件线 ...

  4. Redis(三)源source编译

    背景: 自己电脑是win7 32bit的,而想要Redis4.0的版本,但是在网上没找到,所以自己干脆download源source,自己build,安装. 最后,目前达到的状态是,windows下s ...

  5. ORM 创建manytomay的三种方法 反向查询 和一些 双下方法版学员管理系统3

    老师信息管理   三种创建多对对外键的方式常用第二种和第三种 思考 三种方式创建多对多外键方式及其优缺点. 外键的查询和使用 1外键的创建: 在数据库表中的表现形式 如何连表查询和使用 表里边:  s ...

  6. Benchmarking Zeebe: An Intro to How Zeebe Scales Horizontally and How We Measure It

    Written by Felix Müller and Mike Winters on Jun 12 2018 in the Inside Zeebe category. In the past fe ...

  7. 使用ipns 解决ipfs 内容更新的问题

    ipds 可以使用dnslink 解决域名访问的问题,但是内容变更我们就会有新的hashid 解决方法我们可以使用ipns ,同时解决dnslink 解决域名的问题 环境准备 docker-compo ...

  8. Web读取指定的config文件的内容

    需求: 什么时候会用到动态改变Web.config内的值? 在Web.config定义了一个全局设置值A,因为程序运行中满足了某个条件,要将A的值改变 Web.config中定义: <appSe ...

  9. js 字符串转对象

    使用eval var test = '{ colkey: "col", colsinfo: "NameList" }' var obj2 = eval(&quo ...

  10. VNC Viewer连接打开remote display的VMware虚拟机出现闪退

    只需修改vnc option里面Advanced-->expert-->ColourLevel的值为“rgb222” or “full”即可. 说明:rgb111--8 colours,r ...