首页
社区
课程
招聘
[求助]驱动中用RtlInitUnicodeString初始化的UNICODE_STRING要不要释放?
发表于: 2008-3-6 14:12 25424

[求助]驱动中用RtlInitUnicodeString初始化的UNICODE_STRING要不要释放?

2008-3-6 14:12
25424
比如说我用RtlInitUnicodeString(&usMyInfo,L"This my info");初始化了一个unicode_string,那么当我的驱动退出时要不要去释放掉这个UNiCODE_STRING呢,DDK的文档中没有写要释放,但我总觉得不释放的话好像会有问题,请问到底要不要释放,如果要,应该怎样释放呢?

[课程]Linux pwn 探索篇!

收藏
免费 0
支持
分享
最新回复 (4)
雪    币: 454
活跃值: (1673)
能力值: ( LV3,RANK:30 )
在线值:
发帖
回帖
粉丝
2
是要释放滴,用RtlFreeUnicodeString
2008-3-6 14:21
0
雪    币: 214
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
DDK中说
The RtlFreeUnicodeString routine releases storage that was allocated by RtlAnsiStringToUnicodeString or RtlUpcaseUnicodeString.
并没说可以用来释放RtlInitUnicodeString初始化的UNICODE_STRING,这样用可靠吗?
2008-3-6 14:45
0
雪    币: 321
活跃值: (271)
能力值: ( LV13,RANK:1050 )
在线值:
发帖
回帖
粉丝
4
呵呵,不需要,看看RtlInitUnicodeString 做的事情就知道。
typedef struct _UNICODE_STRING {
    USHORT Length;
    USHORT MaximumLength;
    PWSTR  Buffer;
} UNICODE_STRING;

例如: RtlInitUnicodeString(&ntName, L"\\Device\\CallDevice");
lkd> u RtlInitUnicodeString l 30
ntdll!RtlInitUnicodeString:
7c9212d6 57              push    edi
7c9212d7 8b7c240c        mov     edi,dword ptr [esp+0Ch] ;参数L"\\Device\\CallDevice"
7c9212db 8b542408        mov     edx,dword ptr [esp+8]   ;参数&ntName
7c9212df c70200000000    mov     dword ptr [edx],0   ;ntName.Length = 0,ntName.MaximumLength = 0;
7c9212e5 897a04          mov     dword ptr [edx+4],edi;ntName.Buffer 指向 L"\\Device\\CallDevice"
7c9212e8 0bff            or      edi,edi; 判断参数2,L"\\Device\\CallDevice"是否为空
7c9212ea 7422            je      ntdll!RtlInitUnicodeString+0x38 (7c92130e); = 0,退出
              
7c9212ec 83c9ff          or      ecx,0FFFFFFFFh  ;开始计算长度
7c9212ef 33c0            xor     eax,eax
7c9212f1 f266af          repne scas word ptr es:[edi]
7c9212f4 f7d1            not     ecx
7c9212f6 d1e1            shl     ecx,1  ;ecx保存长度

7c9212f8 81f9feff0000    cmp     ecx,0FFFEh
7c9212fe 7605            jbe     ntdll!RtlInitUnicodeString+0x2f (7c921305)
7c921300 b9feff0000      mov     ecx,0FFFEh
7c921305 66894a02        mov     word ptr [edx+2],cx  ;ntName.MaximumLength = cx
7c921309 49              dec     ecx
7c92130a 49              dec     ecx
7c92130b 66890a          mov     word ptr [edx],cx ;ntName.Length = cx
7c92130e 5f              pop     edi
7c92130f c20800          ret     8
2008-3-6 15:00
0
雪    币: 200
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
5
如果你是RtlInitUnicodeString(&usMyInfo,L"This my info")
这样的话unicode_string中的buf指向的是&"This my info" 这个全局变量
所以不用释放
2008-3-6 15:10
0
游客
登录 | 注册 方可回帖
返回
//