WINDWOS 驱动开发笔记-------持续更新

来源:互联网 发布:qq炫舞ktv网络连接失败 编辑:程序博客网 时间:2024/06/06 05:05

1. UNICODE_STRING 中的length 是 in bytes !

2. UNICODE_STRING 只能用一个已有的字符串指针来初始化,系统不负责分配buffer的空间。

3. 忘记releasespinlock后,如果是过滤驱动或者SSDTHOOK 之类的驱动,会出现 “ IRQL >passive_level ” 的crash ,因为Keaquirespinlock 会将当前IRQL提升至 dispatch_level ,如果忘记了release 则会以dispatch_level的IRQL返回三环。因此会crash.!

4. 锻炼身体很重要,如果解决问题没有思路中,那就去跑步吧。跑个40分钟回来,问题就解决了!

5. 文件过滤驱动,如果想在POST 操作中修改IO返回给上层的BUFFER 中的数据,

   a. 先在pre 操作中分配一个新的BUFFER 并赋值给Data 中相应的BUFFER指针。

   b. 在POST操作中,Data 中的Buffer指针又会变成用户的buffer, 但是其中没有数据,实际的数据被IO管理器写到了之前分配的buffer中。

   c. 可以修改在PRE中分配的BUFFER数据内容,然后在将这些内容拷贝到用户的buffer 中。具体方法请参考DDK例子代码swapBuffers.c

6. 在注册表过滤驱动中在pre 中如果要修改目的路径,那么不能直接修改数据,而是调用ZwRegxxxx 函数,然后将调用的结果填写到pre的参数中。即,由你提他做。

7. 三环注册表与内核注册表的对应关系

 HKEY_LOCAL_MACHINE\Registry\Machine HKEY_USERS\Registry\UserHKEY_CLASSES_ROOT \Registry\Software\ClassesHKEY_CURRENT_CONFIG     \Registry\SYSTEM\CurrentControlSet\Hardware Profiles\Current

HKEY_CURRENT_USER  =\Registry\User 下的一个子健

8. 驱动运行在user 线程上下文时,是能够访问用户空间内存的,但是不能释放用户空间内存。

Drivers cannot allocate user-space virtual memory because they run in kernel mode. In addition, a driver cannot access memory through user-mode virtual addresses unless it is running in the context of the user-mode thread that caused the driver's current I/O operation and it is using that thread's virtual addresses.

Only highest-level drivers, such as FSDs, can be sure their dispatch routines will be called in the context of such a user-mode thread. A highest-level driver can callMmProbeAndLockPages to lock down a user buffer before setting up an IRP for lower drivers.

Lowest-level and intermediate drivers that set up their device objects for buffered I/O or direct I/O can rely on the I/O manager or a highest-level driver to pass valid access to locked-down user buffers or to system-space buffers in IRPs.

9. IRP_DIRECTORY_CONTRAL  查找一个指定的文件时,如果驱动想返回 “空” 那么 iostatus 要 赋值为 STATUS_OBJECT_NAME_NOT_FOUND ,这样三环LastError 才会是 ERROR_FILE_NOT_FOUND

10 IRP_MJ_CREATE 通过Options参数的低24位来识别当前对象是文件还是目录是不准的,打开文件时具体是文件夹还是文件不会出现在这里的。


0 0
原创粉丝点击