winapi - 带有 ConDrv 设备的 NtOpenFile() 显示 0xC0000005 错误
问题描述
我在模仿conhost.exe
和condrv.sys
司机之间的联系。所以我将 conhost.exe 中的代码复制到一个简单的 C 文件中并编译它。但NtOpenFile()
总是显示0xc0000005
错误。这是代码片段。
RtlInitUnicodeString(&DestinationString, L"\\Device\\ConDrv\\Server");
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
ObjectAttributes.RootDirectory = 0;
ObjectAttributes.Attributes = OBJ_CASE_INSENSITIVE;
ObjectAttributes.ObjectName = &DestinationString;
ObjectAttributes.SecurityDescriptor = 0;
status = NtOpenFile(&Handle, GENERIC_ALL, &ObjectAttributes, &IoStatusBlock, 0, 0);
如何修改该代码以正常工作?我做错什么了吗?
解决方案
感谢@RbMm 的建议。该OBJECT_ATTRIBUTES
结构定义为:
typedef struct _OBJECT_ATTRIBUTES {
ULONG Length;
HANDLE RootDirectory;
PUNICODE_STRING ObjectName;
ULONG Attributes;
PVOID SecurityDescriptor;
PVOID SecurityQualityOfService;
} OBJECT_ATTRIBUTES;
typedef OBJECT_ATTRIBUTES *POBJECT_ATTRIBUTES;
错误显示是因为我忘记了SecurityQualityOfService
零。因此,从内存中剩余的任何内容中NtOpenFile()
获取SecurityQualityOfService
值。它显示0xC0000005
又名。内存访问冲突。我添加ObjectAttributes.SecurityQualityOfService = 0;
并且它有效。
推荐阅读
- edi - Pokitdok / X12 - 检查合格批次数据
- reactjs - Reactjs和打字稿错误TS2322:类型不可分配给类型'IntrinsicAttributes&IntrinsicClassAttributes
- javascript - 该链接未在新标签中打开
- jms - 如何将 WildFly 连接到远程 Artemis 服务器
- javascript - 居中的 div 没有正确溢出
- javafx - JavaFX 我应该如何构建我的包?
- vba - 日期过滤器通过Excel VBA隐藏所有单元格
- python - 引发异常后如何重新启动 PyQt 应用程序
- node.js - 在节点中构建我的 Web 服务器
- javascript - 如何在 Vuex 商店创建后手动添加 getter/mutations?