1. 新建一个驱动项目
Visual C++ > Windows Drivers > Empty WDM Driver, 取名为FirstDriver

2. 在项目中添加一个c文件
取名为Frist.c


3. 编写入口函数
内核驱动有统一的入口函数,名字叫 DriverEntry.
DriverUnload是内核驱动的移除函数。
//First.c
#include "ntddk.h"
VOID DriverUnload(PDRIVER_OBJECT DriverObject)
{
if (DriverObject != NULL)
{
DbgPrint("[%ws]Driver Upload,Driver Object Address:%p",__FUNCTIONW__,DriverObject);
}
return;
}
NTSTATUS DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
{
DbgPrint("[%ws]Hello Kernal World",__FUNCTIONW__);
if (RegistryPath != NULL)
{
DbgPrint("[%ws]Driver RegistryPath:%wZ\n", __FUNCTIONW__,RegistryPath);
}
if (DriverObject != NULL)
{
DbgPrint("[%ws]Driver Object Address:%p\n", __FUNCTIONW__, DriverObject);
DriverObject->DriverUnload = DriverUnload;
}
return STATUS_SUCCESS;
}
?4.编译驱动
驱动程序和应用程序不同,64位的的版本不兼容32位的,因此需要针对x64和x86分别编译。
VS2017中右击解决方案> Build Solution

?在?FirstDriver\x64\Debug路径下能看到编译之后的文件:

?.sys就是驱动文件。
?
|