找回密码
 立即注册→加入我们

QQ登录

只需一步,快速开始

搜索
热搜: 下载 VB C 实现 编写
查看: 7440|回复: 1

关于RtlInitUnicodeString感想

[复制链接]

307

主题

228

回帖

7349

积分

用户组: 真·技术宅

UID
2
精华
76
威望
291 点
宅币
5599 个
贡献
253 次
宅之契约
0 份
在线时间
949 小时
注册时间
2014-1-25
发表于 2015-5-21 21:55:30 | 显示全部楼层 |阅读模式

欢迎访问技术宅的结界,请注册或者登录吧。

您需要 登录 才可以下载或查看,没有账号?立即注册→加入我们

×

  1. VOID RtlInitUnicodeString (OUT PUNICODE_STRING DestinationString,IN PCWSTR SourceString OPTIONAL)
  2. {
  3.     SIZE_T Length;
  4.     DestinationString->MaximumLength = 0;
  5.     DestinationString->Length = 0;
  6.     DestinationString->Buffer = (PWSTR)SourceString;
  7.     if (ARGUMENT_PRESENT(SourceString))
  8.     {
  9.         Length = wcslen(SourceString) * sizeof(WCHAR);
  10.         ASSERT(Length < MAX_USTRING);
  11.         if(Length >= MAX_USTRING)
  12.         {
  13.             Length = MAX_USTRING - sizeof(UNICODE_NULL);
  14.         }
  15.         DestinationString->Length = (USHORT)Length;
  16.         DestinationString->MaximumLength = (USHORT)(Length + sizeof(UNICODE_NULL));
  17.     }
  18.     return;
  19. }

  20. NTSTATUS RtlInitUnicodeStringEx ( OUT PUNICODE_STRING DestinationString,IN PCWSTR SourceString OPTIONAL)
  21. {
  22.     SIZE_T Length;
  23.     DestinationString->Length = 0;
  24.     DestinationString->MaximumLength = 0;
  25.     DestinationString->Buffer = (PWSTR)SourceString;
  26.     if (ARGUMENT_PRESENT(SourceString))
  27.     {
  28.         Length = wcslen(SourceString);
  29.         // We are actually limited to 32765 characters since we want to store a meaningful MaximumLength also.
  30.         if (Length > (UNICODE_STRING_MAX_CHARS - 1))
  31.         {
  32.             return STATUS_NAME_TOO_LONG;
  33.         }
  34.         Length *= sizeof(WCHAR);
  35.         DestinationString->Length = (USHORT)Length;
  36.         DestinationString->MaximumLength = (USHORT)(Length + sizeof(WCHAR));
  37.     }
  38.     return STATUS_SUCCESS;
  39. }
复制代码


从以上代码可见,这2个函数会将传入的字符串指针直接赋值给结构体,这样的话,如果传入的是栈字符串,那么UNICODE_STIRNG只能在当前域内使用,不能存储到其他生命周期更长的地方,否则栈恢复以后读取到不正确的数据,
然而传入一个全局字符串是可以的,例如:

UNICODE_STRING str1;
void func()
{
  WCHAR buf[]=L"lich";
  RtlInitUnicodeString(&str1,buf);
}
这是错误写法
回复

使用道具 举报

307

主题

228

回帖

7349

积分

用户组: 真·技术宅

UID
2
精华
76
威望
291 点
宅币
5599 个
贡献
253 次
宅之契约
0 份
在线时间
949 小时
注册时间
2014-1-25
 楼主| 发表于 2015-5-24 18:09:46 | 显示全部楼层
未导出,但极为有用的符号

8055a854          nt!ObpSymbolicLinkObjectType = <no type information>
8055c0a0          nt!ExSemaphoreObjectType = <no type information>
8055286c          nt!IoControllerObjectType = <no type information>
80671d38          nt!CmpKeyObjectType = <no type information>
8055c008          nt!ExEventPairObjectType = <no type information>
80551040          nt!DbgkDebugObjectType = <no type information>
8055c53c          nt!ExDesktopObjectType = <no type information>
8055c00c          nt!ExTimerObjectType = <no type information>
8055c578          nt!ExCallbackObjectType = <no type information>
8055c000          nt!ExProfileObjectType = <no type information>
8055c004          nt!ExMutantObjectType = <no type information>
80552860          nt!IoDriverObjectType = <no type information>
805b8052          nt!ObCreateObjectType (<no parameter info>)
80552858          nt!IoFileObjectType = <no type information>
8055bb58          nt!WmipGuidObjectType = <no type information>
8055285c          nt!IoDeviceHandlerObjectType = <no type information>
805597c0          nt!MmSectionObjectType = <no type information>
8055a7f0          nt!ObpTypeObjectType = <no type information>
8055a820          nt!ObpDirectoryObjectType = <no type information>
80671884          nt!SeTokenObjectType = <no type information>
8055c4c0          nt!ExEventObjectType = <no type information>
8055bfd4          nt!ExpKeyedEventObjectType = <no type information>
80552864          nt!IoDeviceObjectType = <no type information>
80552870          nt!IoAdapterObjectType = <no type information>
80554a08          nt!LpcPortObjectType = <no type information>
80552868          nt!IoCompletionObjectType = <no type information>
80554a04          nt!LpcWaitablePortObjectType = <no type information>
8055c540          nt!ExWindowStationObjectType = <no type information>
805b7fb4          nt!ObpDeleteObjectType (<no parameter info>)
805ea574          nt!SepSetAuditInfoForObjectType (<no parameter info>)
回复 赞! 靠!

使用道具 举报

QQ|Archiver|小黑屋|技术宅的结界 ( 滇ICP备16008837号 )|网站地图

GMT+8, 2024-5-6 14:32 , Processed in 0.034053 second(s), 28 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表