能力值:
( LV13,RANK:1050 )
2 楼
打不开就对了。你把驱动中下面这句中的倒数第二个参数修改为FALSE。然后编译。就可以打开了。
Status=IoCreateDevice(pDriverObject,0,&devNameUnicd,FILE_DEVICE_UNKNOWN,
0,TRUE,&pDevice);
能力值:
( LV2,RANK:10 )
3 楼
改了以后还是不行。。而且 我刚翻的一个例子里 也是TRUE
能力值:
( LV13,RANK:1050 )
4 楼
IoCreateDevice中的参数Exclusive原文资料如下:
Exclusive - Indicates that the device object should be created with using
the exclusive object attribute.
NOTE: This flag should not be used for WDM drivers. Since only the
PDO is named, it is the only device object in a devnode attachment
stack that is openable. However, since this device object is created
by the underlying bus driver (which has no knowledge about what type
of device this is), there is no way to know whether this flag should
be set. Therefore, this parameter should always be FALSE for WDM
drivers. Drivers attached to the PDO (e.g., the function driver) must
enforce any exclusivity rules.
如果还是不行的话,建议以附件的方式传上来看看。你看到的例子是不是键盘过滤驱动?
能力值:
( LV2,RANK:10 )
5 楼
不是 键盘驱动 。。
只是通过 EPROCESS遍历进程
例子是 线程监控的 我似乎不能发附件,例子地址http://www.xfocus.net/articles/200503/788.html
能力值:
( LV12,RANK:370 )
6 楼
IRP_MJ_CREATE和IRP_MJ_CLOSE实现了吗?
能力值:
( LV2,RANK:10 )
7 楼
只是简单的实现:
case IRP_MJ_CREATE:
DbgPrint("Call IRP_MJ_CREATE\n");
break;
case IRP_MJ_CLOSE:
break;
能力值:
( LV12,RANK:370 )
8 楼
CompleteIrp了吗?
能力值:
( LV2,RANK:10 )
9 楼
pIrp->IoStatus.Status = status;
pIrp->IoStatus.Information = 0;
IoCompleteRequest (pIrp, IO_NO_INCREMENT);
能力值:
( LV2,RANK:10 )
10 楼
我把代码放上来 LS两位帮我看一下:
main文件:
#include <windows.h>
#include <stdio.h>
#include <winioctl.h>
#include "D:\\c\\define.h"
#include <string.h>
int main ()
{
HANDLE hDevice;
BOOL Status;
ULONG dwReturn;
char outBuf[4096];
hDevice=CreateFile("\\\\.\\MyEvent",GENERIC_READ | GENERIC_WRITE,
0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,
NULL);
if(hDevice==INVALID_HANDLE_VALUE)
{
printf("createfile wrong\n");
getchar();
return 0;
}
Status=DeviceIoControl(hDevice,IOCTL_PASSBUF,NULL,0,
outBuf,sizeof(outBuf),&dwReturn,NULL);
if(!Status)
{
printf("Io wrong\n");
getchar();
return 0;
}
printf("%s\n",outBuf);
Status = CloseHandle( hDevice );
getchar();
return 0;
}
驱动:
#include <ntddk.h>
#include <windef.h>
#include <define.h>
#define FLINKOFFSET 0x88
#define PIDOFFSET 0x84
UNICODE_STRING devNameUnicd,devLinkUnicd;
PKEVENT pEvent;
CHAR outBuf[255];
CHAR xxx[4096];
ULONG GetLocationOfProcessName()
{
ULONG pEProcess;
ULONG NameOffset;
pEProcess=(ULONG)PsGetCurrentProcess();
for(NameOffset=0;NameOffset<=PAGE_SIZE;NameOffset++)
{
if(!strncmp("System",(PCHAR)(pEProcess+NameOffset),strlen("System")))
{
return NameOffset;
}
}
return (ULONG)0;
}
VOID FindProcessByPId()
{
ULONG pEProcess;
ULONG FlinkAddress;
ULONG NameOffset;
PLIST_ENTRY pListEntry;
char* Name;
int i;
int Start_PId=0;
int Current_PId=0;
int Count=0;
pEProcess=(ULONG)PsGetCurrentProcess();
NameOffset=GetLocationOfProcessName();
FlinkAddress=pEProcess+FLINKOFFSET;
Name=(char*)(pEProcess+NameOffset);
Start_PId=*((int*)(pEProcess+PIDOFFSET));
Current_PId=Start_PId;
pListEntry=(PLIST_ENTRY)FlinkAddress;
while(Count==0||Current_PId!=Start_PId)
{
if(Current_PId<0) {Current_PId=0;}
DbgPrint("进程ID:%d 进程名:%s \n",Current_PId,Name);
sprintf(outBuf,"进程ID:%d 进程名:%s \n",Current_PId,Name);
if(Count==0) strcpy(xxx,outBuf);
else
strcat(xxx,outBuf);
pListEntry=pListEntry->Flink;
pEProcess=(ULONG)pListEntry-FLINKOFFSET;
Name=(char*)(pEProcess+NameOffset);
Current_PId=*((int*)(pEProcess+PIDOFFSET));
Count++;
}
}
NTSTATUS DeviceIoControlDispatch(IN PDEVICE_OBJECT pDeviceObject,IN PIRP pIrp)
{
PIO_STACK_LOCATION irpStack;
NTSTATUS Status;
PVOID InPutBuffer;
ULONG ioControlCode;
ULONG OutPutLen;
Status=STATUS_SUCCESS;
irpStack=IoGetCurrentIrpStackLocation(pIrp);
ioControlCode=irpStack->Parameters.DeviceIoControl.IoControlCode;
switch(irpStack->MajorFunction)
{
case IRP_MJ_CREATE:
DbgPrint("Call IRP_MJ_CREATE\n");
break;
case IRP_MJ_CLOSE:
break;
case IRP_MJ_DEVICE_CONTROL:
OutPutLen=irpStack->Parameters.DeviceIoControl.OutputBufferLength;
switch(ioControlCode)
{
case IOCTL_PASSBUF:
RtlCopyMemory(pIrp->UserBuffer,xxx, OutPutLen);
break;
default:
break;
}
break;
default:
DbgPrint("no match control\n");
break;
}
pIrp->IoStatus.Status = Status;
pIrp->IoStatus.Information = 0;
IoCompleteRequest (pIrp, IO_NO_INCREMENT);
return Status;
}
NTSTATUS OnUnload (IN PDRIVER_OBJECT pDriverObject)
{
NTSTATUS Status;
DbgPrint("Onload called\n");
if(pDriverObject->DeviceObject!=NULL)
{
Status=IoDeleteSymbolicLink(&devLinkUnicd);
if(!NT_SUCCESS(Status))
{
DbgPrint(("IoDeleteSymbolicLink() failed\n"));
return Status;
}
IoDeleteDevice(pDriverObject->DeviceObject);
}
return STATUS_SUCCESS;
}
NTSTATUS DriverEntry(IN PDRIVER_OBJECT pDriverObject,IN PUNICODE_STRING pRegistryPath)
{
NTSTATUS Status;
PDEVICE_OBJECT pDevice;
RtlInitUnicodeString(&devNameUnicd,L"\\Device\\MyEvent");
RtlInitUnicodeString(&devLinkUnicd,L"\\??\\MyEvent");
Status=IoCreateDevice(pDriverObject,0,&devNameUnicd,FILE_DEVICE_UNKNOWN,
0,FALSE,&pDevice);
if(!NT_SUCCESS(Status))
{
DbgPrint(("Can not create device.\n"));
return Status;
}
Status=IoCreateSymbolicLink(&devLinkUnicd,&devNameUnicd);
if(!NT_SUCCESS(Status))
{
DbgPrint(("Can not create device.\n"));
return Status;
}
pDriverObject->DriverUnload=OnUnload;
pDriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL]=pDriverObject->MajorFunction[IRP_MJ_CREATE]=
pDriverObject->MajorFunction[IRP_MJ_CLOSE]=DeviceIoControlDispatch;
FindProcessByPId();
return STATUS_SUCCESS;
}
能力值:
( LV2,RANK:10 )
11 楼
可以正常工作了。。。。。不知道是怎么回事刚刚。。。
谢谢LS两位,
方便的话不知道能不能留个常用邮箱或者qq 我最近做毕业设计 碰到不懂的话 能不能帮我解惑?
能力值:
( LV13,RANK:1050 )
12 楼
嗯,帮你看看
能力值:
( LV13,RANK:1050 )
13 楼
经过测试,发现没有问题。我的环境xp sp2, ddk版本是2600。1106
代码运行贴图如下:
上传的附件:
能力值:
( LV2,RANK:10 )
14 楼
阿南真棒 你去安启华了吗 ?
能力值:
( LV3,RANK:20 )
15 楼
combojiang大哥能留个邮箱否,小弟我不能发消息..以后好问问题 -_-