windows驱动编程入门(第一个程序)

1. 工具

vc6.0

WINDDK 3790.1830

Dbgview

驱动加载工具InstDrv32位/64位中文版

2. 代码

first.c

 1 ///
 2 /// @file first.c
 3 /// @author crazy_chu
 4 /// @date2008-11-1
 5 /// 
 6 
 7 #include <ntddk.h>
 8     
 9 // 提供一个Unload函数只是为了
10 VOID DriverUnload(PDRIVER_OBJECT driver)
11 {
12     // 但是实际上我们什么都不做,只打印一句话:
13     DbgPrint("first: Our driver is unloading…
");
14 }
15 
16 // DriverEntry,入口函数。相当于main。
17 NTSTATUS DriverEntry(PDRIVER_OBJECT driver, PUNICODE_STRING reg_path)
18 {
19 #if DBG
20        _asm int 3
21 #endif
22     // 这是我们的内核模块的入口,可以在这里写入我们想写的东西。
23     // 我在这里打印一句话。因为”Hello,world” 常常被高手耻笑,所以
24     // 我们打印一点别的。
25     DbgPrint("first: Hello, my salary!");
26 
27     // 设置一个卸载函数便于这个函数能退出。
28     driver->DriverUnload = DriverUnload;
29     return STATUS_SUCCESS;
30 }

makefile

!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 components of Windows NT (DDK)

!ENDIF

!INCLUDE $(NTMAKEENV)makefile.def

 sources

1 TARGETNAME=first
2 TARGETTYPE=DRIVER
3 SOURCES=first.c
4 TARGETPATH=obj

mybuild.bat

 1 set root=%~d0
 2 set curdir=%cd%
 3 set ddk_path=d:WINDDK3790~1.183bin
 4 del %ddk_path%ChngeDir.bat
 5 echo %root%>>%ddk_path%ChngeDir.bat
 6 echo cd %curdir%>>%ddk_path%ChngeDir.bat
 7 echo build>>%ddk_path%ChngeDir.bat
 8 call %ddk_path%setenv.bat d:WINDDK3790~1.183 chk WXP
 9 call %ddk_path%ChngeDir.bat
10 pause

3. 学习书籍

寒江独钓-Windows内核安全编程

原文地址:https://www.cnblogs.com/yasepix/p/4801096.html