首页
社区
课程
招聘
[旧帖] 了解unicode_string结构 0.00雪花
2009-3-10 10:34 5129

[旧帖] 了解unicode_string结构 0.00雪花

2009-3-10 10:34
5129
在windbg中获得_unicode_string结构如下,
随之而来的一个问题就是这个结构中的Length,
MaximumLength保存的是bytes数量还是widechars数量
kd> dt  _unicode_string
nt!_UNICODE_STRING
   +0x000 Length           : Uint2B
   +0x002 MaximumLength    : Uint2B
   +0x004 Buffer           : Ptr32 Uint2B

nt!RtlInitUnicodeString:
8052af2c 57              push    edi   ;esp->edi  esp+4->ret  esp+8->_unicode_string  esp+c->address of unicode string buffer
8052af2d 8b7c240c        mov     edi,dword ptr [esp+0Ch] ; put the buffer address to edi
8052af31 8b542408        mov     edx,dword ptr [esp+8]         ; put _unicode_string address to edx
8052af35 c70200000000    mov     dword ptr [edx],0          ; set _unicode_string.Length, _unicode_string.Maximumlength equals        

                                                         ; Zero
8052af3b 897a04          mov     dword ptr [edx+4],edi   ; put the address of unicode string buffer to_unicode_string.Buffer
8052af3e 0bff            or      edi,edi                 ; if the address is zero  then Exit.
8052af40 7422            je      nt!RtlInitUnicodeString+0x38 (8052af64)
8052af42 83c9ff          or      ecx,0FFFFFFFFh                 ; set ecx equals Zero       
kd> u
nt!RtlInitUnicodeString+0x19:
8052af45 33c0            xor     eax,eax                  ;set eax equals Zero
8052af47 f266af          repne scas word ptr es:[edi]    ;注意scas 后面是word 所有执行not后ecx中存放的是buffer的widechar数量
8052af4a f7d1            not     ecx                          ;得到widechar buffer 的 bytes 数量,存放在ecx中
8052af4c d1e1            shl     ecx,1                          ;shl为左移操作,处理后ecx中存放的应该是string buffer的bytes数
8052af4e 81f9feff0000    cmp     ecx,0FFFEh             ;比较是不是该字符串数量超过1个word所能表示的最大bytes数量
                                                        ;要是超过,_unicode_string.MaximumLength 会被设置成0FFFEH
                                                        ;_unicode_string.Length会被设置成0FFFCH                                   

                                                        ;所有unicode_string结构所能表示的最大字符串长度会是0fffch个字符
                                                        ;(不包含后面的Widechar NULL字符)
8052af54 7605            jbe     nt!RtlInitUnicodeString+0x2f (8052af5b)
8052af56 b9feff0000      mov     ecx,0FFFEh                ;设置ecx euqals 0fffeh,只有在字符过大的时候会发生
8052af5b 66894a02        mov     word ptr [edx+2],cx        ;设置unicode_string.MaximumLength
kd> u
nt!RtlInitUnicodeString+0x33:
8052af5f 49              dec     ecx
8052af60 49              dec     ecx ;从这里大家就能看出来length一般等于Maximumlength-2
8052af61 66890a          mov     word ptr [edx],cx        ;设置unicode_string.Lenght
8052af64 5f              pop     edi                        ;弹出edi
8052af65 c20800          ret     8                        ;反回继续执行

通过从上面的函数理解了unicode_string.Length 和MaximumLenth成员存放的是unicode string 的bytes数量.  查msdn会更快了解~

[培训]内核驱动高级班,冲击BAT一流互联网大厂工 作,每周日13:00-18:00直播授课

收藏
点赞0
打赏
分享
最新回复 (1)
雪    币: 152
活跃值: (15)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
XSJS 2009-3-10 11:57
2
0
MSDN里说得很清楚了。。。。不过这样也是学习啊
游客
登录 | 注册 方可回帖
返回