在win7中无法打开TDI连接
NTSTATUS
TdiFuncs_OpenConnection(PWSTR pTransDevName, PHANDLE pTdiHandle, PFILE_OBJECT *pFileObject)
{
NTSTATUS NtStatus = STATUS_INSUFFICIENT_RESOURCES;
UNICODE_STRING usTdiDriverNameString;
OBJECT_ATTRIBUTES oaTdiDriverNameAttributes;
IO_STATUS_BLOCK IoStatusBlock;
char DataBlob[sizeof(FILE_FULL_EA_INFORMATION) + TDI_CONNECTION_CONTEXT_LENGTH + 300] = {0};
PFILE_FULL_EA_INFORMATION pExtendedAttributesInformation = (PFILE_FULL_EA_INFORMATION)&DataBlob;
int dwEASize = 0;
/*
* Initialize the name of the device to be opened. ZwCreateFile
* takes an OBJECT_ATTRIBUTES structure as the name of the device
* to open. This is then a two step process.
*
* 1 - Create a UNICODE_STRING data structure from a unicode string.
* 2 - Create a OBJECT_ATTRIBUTES data structure from a UNICODE_STRING.
*
*/
RtlInitUnicodeString(&usTdiDriverNameString, pTransDevName);
InitializeObjectAttributes(&oaTdiDriverNameAttributes,
&usTdiDriverNameString,
OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
NULL,
NULL);
/*
* The second step is to initialize the Extended Attributes data structure.
*
* EaName = TdiConnectionContext, 0, Your User Defined Context Data
* (Actually a pointer to it)
* EaNameLength = Length of TdiConnectionContext
* EaValueLength = Entire Length
*/
RtlCopyMemory(&pExtendedAttributesInformation->EaName, TdiConnectionContext, TDI_CONNECTION_CONTEXT_LENGTH);
pExtendedAttributesInformation->EaNameLength = TDI_CONNECTION_CONTEXT_LENGTH;
pExtendedAttributesInformation->EaValueLength = TDI_CONNECTION_CONTEXT_LENGTH;
/* Must be at least TDI_CONNECTION_CONTEXT_LENGTH */
dwEASize = sizeof(DataBlob);
NtStatus = ZWCreateFile(pTdiHandle,
FILE_READ_EA | FILE_WRITE_EA,
&oaTdiDriverNameAttributes,
&IoStatusBlock,
NULL,//0,
FILE_ATTRIBUTE_NORMAL,
0,
FILE_OPEN_IF,
0,
pExtendedAttributesInformation,
dwEASize
);
if (!NT_SUCCESS(NtStatus))
{
DebugPrint(("ZwCreateFile failed with status %x\n", NtStatus));
return NtStatus;
}
if(NT_SUCCESS(NtStatus))
{
NtStatus = ObReferenceObjectByHandle(*pTdiHandle,
GENERIC_READ | GENERIC_WRITE,
NULL, KernelMode,
(PVOID *)pFileObject, NULL);
DebugPrint(("TdiFuncs_OpenConnection ObReferenceObjectByHandle %x\n", NtStatus));
if(!NT_SUCCESS(NtStatus))
{
ZwClose(*pTdiHandle);
}
}
return NtStatus;
}
在winxp中ZWCreateFile这个函数返回成功
而在win7中,ZWCreateFile返回c000000d,即:无效参数
TdiFuncs_OpenConnection(PWSTR pTransDevName, PHANDLE pTdiHandle, PFILE_OBJECT *pFileObject)
{
NTSTATUS NtStatus = STATUS_INSUFFICIENT_RESOURCES;
UNICODE_STRING usTdiDriverNameString;
OBJECT_ATTRIBUTES oaTdiDriverNameAttributes;
IO_STATUS_BLOCK IoStatusBlock;
char DataBlob[sizeof(FILE_FULL_EA_INFORMATION) + TDI_CONNECTION_CONTEXT_LENGTH + 300] = {0};
PFILE_FULL_EA_INFORMATION pExtendedAttributesInformation = (PFILE_FULL_EA_INFORMATION)&DataBlob;
int dwEASize = 0;
/*
* Initialize the name of the device to be opened. ZwCreateFile
* takes an OBJECT_ATTRIBUTES structure as the name of the device
* to open. This is then a two step process.
*
* 1 - Create a UNICODE_STRING data structure from a unicode string.
* 2 - Create a OBJECT_ATTRIBUTES data structure from a UNICODE_STRING.
*
*/
RtlInitUnicodeString(&usTdiDriverNameString, pTransDevName);
InitializeObjectAttributes(&oaTdiDriverNameAttributes,
&usTdiDriverNameString,
OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
NULL,
NULL);
/*
* The second step is to initialize the Extended Attributes data structure.
*
* EaName = TdiConnectionContext, 0, Your User Defined Context Data
* (Actually a pointer to it)
* EaNameLength = Length of TdiConnectionContext
* EaValueLength = Entire Length
*/
RtlCopyMemory(&pExtendedAttributesInformation->EaName, TdiConnectionContext, TDI_CONNECTION_CONTEXT_LENGTH);
pExtendedAttributesInformation->EaNameLength = TDI_CONNECTION_CONTEXT_LENGTH;
pExtendedAttributesInformation->EaValueLength = TDI_CONNECTION_CONTEXT_LENGTH;
/* Must be at least TDI_CONNECTION_CONTEXT_LENGTH */
dwEASize = sizeof(DataBlob);
NtStatus = ZWCreateFile(pTdiHandle,
FILE_READ_EA | FILE_WRITE_EA,
&oaTdiDriverNameAttributes,
&IoStatusBlock,
NULL,//0,
FILE_ATTRIBUTE_NORMAL,
0,
FILE_OPEN_IF,
0,
pExtendedAttributesInformation,
dwEASize
);
if (!NT_SUCCESS(NtStatus))
{
DebugPrint(("ZwCreateFile failed with status %x\n", NtStatus));
return NtStatus;
}
if(NT_SUCCESS(NtStatus))
{
NtStatus = ObReferenceObjectByHandle(*pTdiHandle,
GENERIC_READ | GENERIC_WRITE,
NULL, KernelMode,
(PVOID *)pFileObject, NULL);
DebugPrint(("TdiFuncs_OpenConnection ObReferenceObjectByHandle %x\n", NtStatus));
if(!NT_SUCCESS(NtStatus))
{
ZwClose(*pTdiHandle);
}
}
return NtStatus;
}
在winxp中ZWCreateFile这个函数返回成功
而在win7中,ZWCreateFile返回c000000d,即:无效参数
...全文
相关推荐
TDI驱动源代码
这个是TDI驱动,本来做这个驱动的目的, 是想在应用层程序实时动态获得每个进程打开的网络端口的变化情况。 因为想不到更好的办法,同时也要兼容WIN7和WINXP,所以才使用TDI来实现。 代码是自己开发的框架,没借用tdifw等源码, 代码测试可在 64和32位位win7,winxp上运行。 除了实现获得动态变化的端口之外, 还顺便实现了每个进程的流量监控,以及每个进程的每个连接的流量情况, 还有简单的禁止某个进程访问网络,至于每个进程限速的功能,暂时没实现, 有兴趣的朋友可在此基础上做扩展, 等你做好之后就能把握理解360流量防火墙的限速的核心部分了。 应用层部分只提供了接口代码,没有做更详
Win7 64位系统下超级终端安装与使用全指南
htmltable {th, td {th {pre {简介:超级终端(HyperTerminal)是Windows系统中用于串行通信的经典工具,尽管在Win7 64位版本中不再内置,但可通过第三方组件“HyperTRM x64”手动安装并恢复功能。本文详细介绍如何在C:\Windows\System32目录部署该工具,并通过“运行”命令启动。
tdifw,win tdi防火墙
tdi层网络防火墙, 亲测可用。 tdi在winxp、win7及以前设备好用,新设备接口可能更换了。
基于TDI的个人防火墙源代码
基于TDI的个人防火墙源代码 基于TDI的个人防火墙源代码
altera usb blaster驱动 win7 64bit
altera usb blaster驱动 win7 64bit可用


驱动开发/核心开发
