阅读:2826回复:2
用ZwCreateFile 打开 \Device\Tcp求助!
我用ZwCrateFile 打开 \\Device\\Tcp 出错,总是提示系统无法打开文件 代码如下,请帮忙看看:
NTSTATUS status; UNICODE_STRING DeviceName; OBJECT_ATTRIBUTES Attr; IO_STATUS_BLOCK IoStatus; char Buffer[sizeof(FILE_FULL_EA_INFORMATION) + TDI_TRANSPORT_ADDRESS_LENGTH + sizeof(TA_IP_ADDRESS)+1]; PTA_IP_ADDRESS pSin; PFILE_FULL_EA_INFORMATION pEa; RtlInitUnicodeString(&DeviceName,L"\\Device\\Tcp"); DebugPrint("%T",&DeviceName); //初始化对象属性 InitializeObjectAttributes( &Attr, &DeviceName, OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, NULL, NULL ); pEa = (PFILE_FULL_EA_INFORMATION)Buffer; if(pEa == NULL) { DebugPrint("InitializeObjectAttributes error"); } pEa->NextEntryOffset= 0; pEa->Flags = 0; pEa->EaNameLength = TDI_TRANSPORT_ADDRESS_LENGTH; pEa->EaValueLength = sizeof(TA_IP_ADDRESS); RtlCopyMemory ( pEa->EaName, TdiTransportAddress, pEa->EaNameLength + 1 ); pSin=(PTA_IP_ADDRESS) ( pEa->EaName + pEa->EaNameLength + 1); pSin->TAAddressCount=1; pSin->Address[0].AddressLength = TDI_ADDRESS_LENGTH_IP; pSin->Address[0].AddressType = TDI_ADDRESS_TYPE_IP; pSin->Address[0].Address[0].sin_port = 0; //INADDR_ANY 本地任何的IP地址和端口 pSin->Address[0].Address[0].in_addr = 0; // INADDR_ANY 192.168.1.30 RtlZeroMemory ( pSin->Address[ 0 ].Address[ 0 ].sin_zero, sizeof ( pSin->Address[ 0 ].Address[ 0 ].sin_zero ) ); //打开对象,获得对象句柄 status = ZwCreateFile( pHandle, GENERIC_READ | GENERIC_WRITE, &Attr, &IoStatus, NULL, FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE, FILE_OPEN, 0, pEa, sizeof(Buffer)); if(!NT_SUCCESS(status)) { DebugPrint("ZwCreateFile failed"); DebugPrint("%d\n",IoStatus.Information); return IoStatus.Status; } |
|
沙发#
发布于:2009-10-18 23:32
楼主这个 问题解决了吗?
我好像也遇到这样的问题了 |
|
|
板凳#
发布于:2009-10-18 23:46
我的错误是0x80000014 The extended attribute (EA) list is inconsistent.
我也不知道Ea怎么没对,望知道的人帮忙指点一下 我得代码 CHAR Buffer[sizeof (FILE_FULL_EA_INFORMATION) + TDI_CONNECTION_CONTEXT_LENGTH]; PFILE_FULL_EA_INFORMATION Ea = (PFILE_FULL_EA_INFORMATION)(Buffer); IO_STATUS_BLOCK IoStatus; RtlInitUnicodeString(&Name, L"\\Device\\Tcp"); InitializeObjectAttributes(&Attr, &Name,OBJ_CASE_INSENSITIVE, 0, 0); Ea->NextEntryOffset = 0; Ea->Flags = 0; Ea->EaNameLength = TDI_CONNECTION_CONTEXT_LENGTH; Ea->EaValueLength = 0; RtlCopyMemory(Ea->EaName, TdiConnectionContext, Ea->EaNameLength + 1); Status = ZwCreateFile(Handle, 0, &Attr, &IoStatus, 0, FILE_ATTRIBUTE_NORMAL, 0, FILE_OPEN, 0, Ea, sizeof(Buffer)); |
|
|