首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >手动操作UNICODE_STRING时崩溃

手动操作UNICODE_STRING时崩溃
EN

Stack Overflow用户
提问于 2011-10-25 17:05:50
回答 1查看 529关注 0票数 0

我在手动操作UNICODE_STRING时遇到了非常奇怪的崩溃(对我来说)

代码语言:javascript
复制
UNICODE_STRING ustrName;
UNICODE_STRING ustrPortName;
UNICODE_STRING linkName;
UCHAR m_COMPortName[6];

RtlInitUnicodeString(&ustrName, L"PortName");
status = WdfStringCreate(NULL, WDF_NO_OBJECT_ATTRIBUTES, &strPortName);
if(NT_SUCCESS(status)) // String created
{   status = WdfRegistryQueryString (hKey, &ustrName, strPortName); // strPortName is now "COM8"
    if (NT_SUCCESS (status)) {
        WdfStringGetUnicodeString(strPortName, &ustrPortName);
        m_COMPortName[0] = (UCHAR)ustrPortName.Buffer[0];
        m_COMPortName[1] = (UCHAR)ustrPortName.Buffer[1];
        m_COMPortName[2] = (UCHAR)ustrPortName.Buffer[2];
        m_COMPortName[3] = (UCHAR)ustrPortName.Buffer[3];
        m_COMPortName[4] = (UCHAR)ustrPortName.Buffer[4];
        m_COMPortName[5] = 0; // Force a null-termination
    }

}
WdfRegistryClose(hKey);

RtlInitUnicodeString(&linkName, L"\\??\\COM123"); // Init with lets say COM123, Breakpoint here...
linkName.Buffer[7] = (USHORT)m_COMPortName[3]; // First digit in the COM-port number // ** THIS LINE CRASH **
linkName.Buffer[8] = (USHORT)m_COMPortName[4]; // Second digit in the COM-port number // (if any else NULL)
linkName.Buffer[9] = (USHORT)m_COMPortName[5]; // Third digit in the COM-port number // (if any else NULL)

拆卸:

代码语言:javascript
复制
902de533 6840072e90      push    offset mydriver! ?? ::FNODOBFM::'string' (902e0740) ** Breakpoint here (same as above...) **
902de538 8d45f8          lea     eax,[ebp-8]
902de53b 50              push    eax
902de53c ff1528202e90    call    dword ptr [mydriver!_imp__RtlInitUnicodeString (902e2028)]
902de542 660fb60d23392e90 movzx   cx,byte ptr [mydriver!m_COMPortName+0x3 (902e3923)] ** Start of the crashing line **
902de54a 8b55fc          mov     edx,dword ptr [ebp-4] ** Seems ok **
902de54d 66894a0e        mov     word ptr [edx+0Eh],cx    ds:0023:902e074e=0031 ** CRASH!!! **
902de551 660fb60524392e90 movzx   ax,byte ptr [mydriver!m_COMPortName+0x4 (902e3924)]
902de559 8b4dfc          mov     ecx,dword ptr [ebp-4]
902de55c 66894110        mov     word ptr [ecx+10h],ax
902de560 660fb61525392e90 movzx   dx,byte ptr [mydriver!m_COMPortName+0x5 (902e3925)]
902de568 8b45fc          mov     eax,dword ptr [ebp-4]
902de56b 66895012        mov     word ptr [eax+12h],dx

linkNamem_COMPortName在手表中看起来都是正确的。怎么了?

另一种解决方案是以某种方式将unicode字符串L"\\??\\"与动态读取的unicode字符串L"COMx"连接。但我不知道该怎么做。我知道MultiByteToWideChar,但我不太喜欢使用它,因为它需要windows.h,并且当我将该文件包含到我的小型KMDF驱动程序项目中时,编译器会给我很多错误……

在WinDDK 7600.16385.1 (KMDF)中为Windows Vista编写的所有代码

EN

回答 1

Stack Overflow用户

发布于 2012-02-14 01:06:35

来自MSDN RtlUnicodeStringInit

将UNICODE_STRING结构的缓冲区成员设置为参数指定的源地址

linkName缓冲区指向一个常量(L"\\??\\COM123"),因此当您试图修改它时,它会崩溃。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7887013

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档