最近想学习一点内核态驱动开发,看了《寒江独钓》第一章安装驱动就遇到问题。网上搜索解决方法无果,最后还是问老师得以解决。
1)首先,使用XP系统,下载WDK。
https://www.microsoft.com/en-us/download/details.aspx?id=11800
2)写第一个first.c文件和makefile以及SOURCES文件
first.c
#include <ntddk.h>
void DriverUnload(IN PDRIVER_OBJECT driver)
{
DbgPrint("first:Our driver is unloading...\r\n");
}
NTSTATUS DriverEntry(PDRIVER_OBJECT driver, PUNICODE_STRING reg_path)
{
DbgPrint("first:Hello,I am fucking back!");
driver->DriverUnload = DriverUnload;
return STATUS_SUCCESS;
}
make!IF 0
Copyright (C) Microsoft Corporation, 1999 - 2002
Module Name:
makefile.
Notes:
DO NOT EDIT THIS FILE!!! Edit .\sources. if you want to add a new source
file to this component. This file merely indirects to the real make file
that is shared by all the driver components of the Windows NT DDK
!ENDIF
!INCLUDE $(NTMAKEENV)\makefile.def
SOURCES
TARGETNAME=first
TARGETTYPE=DRIVER
TARGETPATH=obj
SOURCES=first.c
3)打开编译环境
在对应目录下build即可完成,或根据报错修改。
4)使用SRVINSTW.EXE用来安装驱动。
注意:安装驱动在填写路径的时候一定要写到最后first.sys,否则安装完会报错:错误2001。其实主要就是这个小问题研究了好久,网上的其它人有提出类似问题却没人解答,在此补充。