阅读:3195回复:27
通过GUID,访问驱动. 但createfile总是失败. BLUE大侠 请进
我在用DS的kbfilter的例程, 并写了个用户模式的程序想访问kbfilter.
问题在,我用kbfilter的GUID能得到DEVICEPATH, 但无法使用createfile.我的用法如下; HANDLE hd = CreateFile( ifDetail->DevicePath,// 用GUID得到的设备路径 ACPI#.....{43819946-4910...} GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); 运行到这儿, 就是ACCESS DINY. 版主,请帮帮忙。 先谢了 [编辑 - 2/26/03 by drank] |
|
沙发#
发布于:2003-02-19 11:07
我需要帮助.......................
|
|
板凳#
发布于:2003-02-19 11:24
用户被禁言,该主题自动屏蔽! |
|
地板#
发布于:2003-02-19 12:27
感谢zoujie 的帮忙.
我来仔细看看, 不过zoujie, 你能解释一下指定了FILE_DEVICE_SECURE_OPEN 的意义何在吗 |
|
地下室#
发布于:2003-02-19 13:53
Recent security reviews in the Windows file systems team have pointed out that the FILE_SECURE_DEVICE_OPEN characteristic needs to be set for file system device objects that do not support naming. For example, a physical media file system typically creates a named device object.
This named device object is then, in turn, registered with the I/O Manager so that it will receive mount requests on devices of the specified type. Thus, the I/O Manager calls a FILE_DEVICE_CD_ROM_FILE_SYSTEM to mount devices of type FILE_DEVICE_CD_ROM. Because these device objects do not support naming structure (that is, you do not open \\Cdfs\\Myfile, for example) they need to indicate this when they create their device objects by specifying the FILE_SECURE_DEVICE_OPEN characteristic. |
|
|
5楼#
发布于:2003-02-19 16:27
已经可以得到HANDLE了,
我把createfile中的desiredaccess 设定为generic_write之后就好了 但在接下来的调用deviceiocontrol中始终失败. 用的是一些我自己定义的IOCTL code. 请问为什么???? |
|
6楼#
发布于:2003-02-19 20:05
把你如何使用GUID能得到DEVICEPATH的代码也贴出来,好让我仔细分析一下,好吗?
|
|
7楼#
发布于:2003-02-19 21:34
谢谢blue;
另,有看到说, 2000中的键盘鼠标驱动是系统独享的,应用程序不能打开. 这可能吗????? 请看代码: ////////////GUID的声明 DEFINE_GUID(Kbfilter_GUID, 0x43819946, 0xb8af, 0x4910, 0x9f, 0xde, 0xd2, 0x96, 0x25, 0x5c, 0x1c, 0x59 ); //////////////////IOCTL的声明 #define IOCTL_MaskSwitch_Require CTL_CODE(FILE_DEVICE_KEYBOARD, 0x1080, METHOD_NEITHER, FILE_ANY_ACCESS) #define IOCTL_MaskSwitch_Cancel CTL_CODE(FILE_DEVICE_KEYBOARD, 0x1100, METHOD_NEITHER, FILE_ANY_ACCESS) ///////////通过GUID获得HANDLE的代码 HANDLE CKBMASKDlg::GetDeviceViaInterface( GUID* pGuid, DWORD instance) { // Get handle to relevant device information set HDEVINFO info = SetupDiGetClassDevs(pGuid, NULL, NULL, DIGCF_PRESENT | DIGCF_INTERFACEDEVICE); if(info==INVALID_HANDLE_VALUE) { printf(\"No HDEVINFO available for this GUID\\n\"); return NULL; } // Get interface data for the requested instance SP_INTERFACE_DEVICE_DATA ifdata; ifdata.cbSize = sizeof(ifdata); if(!SetupDiEnumDeviceInterfaces(info, NULL, pGuid, instance, &ifdata)) { printf(\"No SP_INTERFACE_DEVICE_DATA available for this GUID instance\\n\"); SetupDiDestroyDeviceInfoList(info); return NULL; } // Get size of symbolic link name DWORD ReqLen; SetupDiGetDeviceInterfaceDetail(info, &ifdata, NULL, 0, &ReqLen, NULL); PSP_INTERFACE_DEVICE_DETAIL_DATA ifDetail = (PSP_INTERFACE_DEVICE_DETAIL_DATA)(new char[ReqLen]); if( ifDetail==NULL) { SetupDiDestroyDeviceInfoList(info); return NULL; } // Get symbolic link name ifDetail->cbSize = sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA); if( !SetupDiGetDeviceInterfaceDetail(info, &ifdata, ifDetail, ReqLen, NULL, NULL)) { SetupDiDestroyDeviceInfoList(info); delete ifDetail; return NULL; } printf(\"Symbolic link is %s\\n\",ifDetail->DevicePath); // Open file HANDLE rv = CreateFile( ifDetail->DevicePath, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if( rv==INVALID_HANDLE_VALUE) { rv = NULL; ShowLastError(GetLastError()); MessageBox(\"Fail to get handle\",NULL,MB_OK); } delete ifDetail; SetupDiDestroyDeviceInfoList(info); return rv; } //////////////通过HANDLE实现控制的代码 void CKBMASKDlg::OnMr() { // TODO: Add your control notification handler code here HANDLE hKb = GetDeviceViaInterface((LPGUID)&Kbfilter_GUID,0); if (!hKb) return; if (!DeviceIoControl(hKb,IOCTL_MaskSwitch_Require,NULL,0,NULL,0,NULL,NULL)) { ShowLastError(GetLastError()); MessageBox(\"device io control failed\",NULL,MB_OK); } CloseHandle(hKb); } |
|
8楼#
发布于:2003-02-21 11:32
go up
|
|
9楼#
发布于:2003-02-21 18:55
无人指点吗?
blue大侠, 跑哪儿去了 |
|
10楼#
发布于:2003-02-21 20:33
只能回答一个问题,鼠标键盘的确是独享的。
另外,最后GETLASTERROR显示的是什么? |
|
11楼#
发布于:2003-02-21 22:31
getlasterror() 显示的是 access is denied
|
|
12楼#
发布于:2003-02-22 01:17
为什么不用si跟进去看看呢?
|
|
13楼#
发布于:2003-02-22 12:48
si, 我不会用,
还请arthurtu简要介绍一下. 我如何才能跟进去?? 跟进去后看什么?? |
|
14楼#
发布于:2003-02-22 16:42
在你的IOCODE对应的函数或dispatch函数上下个断点,看看为什么会返回错误,是哪条语句。
先用symbol loader加载你的driver的symbol,translate。 softice,ctrl+d,sym看你的driver的sym,bpx在函数上下断点。 |
|
15楼#
发布于:2003-02-22 21:29
thks,arthurtu
我试一下先 |
|
16楼#
发布于:2003-02-24 23:06
楼主如果还不死心,看下面的摘录:
This is an example of a class of problems that lots of people have with HID devices, to wit: (1) Very hard to install a filter driver for a collection without filtering everything in the class, because HIDCLASS essentially instantiates the collection device object on the fly. (2) Hard to get custom IOCTLs into such a filter because standard class drivers routinely fail to pass them down. (That\'s the case you\'re commenting on.) (3) Very hard to get custom IOCTLs into a HID minidriver because (a) HIDCLASS fails IRP_MJ_CREATE for a non-collection device object, and (b) HIDCLASS fails non-standard IOCTLs without passing them to the minidriver. The \"approved\" way of dealing with this is to define custom feature \"reports\", which is pretty easy from the driver side. It\'s a real pain from the application side, though, because it\'s very hard to determine which collection you need to open in order to communicate with your own driver. Couldn\'t somebody at Microsoft try to solve these problems, or at least come up with workarounds that us mortals can live with? -- Walter Oney |
|
17楼#
发布于:2003-02-25 11:23
to tjm:
我只是想做一个可以在98和2000中都能使用的控制按键的过滤驱动. 不要把我吓倒了. to all 与键盘按键数据有关的是哪种 IRP. 我需要从IRP的完成例程还是从中断服务例程去获得按键数据????? [编辑 - 2/25/03 by drank] |
|
18楼#
发布于:2003-02-25 13:02
你最好别看 ddk 的filter,看看driverstudio的例程 kbfilter 吧。
它在里面做了两个device,一个是 filterControlDevice,用来与应用程序通讯。 另一个是keyBortdFilterDevice.用来hook 键盘的。 并且带有测试的应用程序。 位置在 example\\nt\\下面。 |
|
|
19楼#
发布于:2003-02-25 13:59
kbfilter不能在98下使用, 且我不知到如何能在应用程序中与kbfilter通信.
|
|
上一页
下一页