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

1. 工具

vc6.0

WINDDK 3790.1830

Dbgview

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

2. 代码

first.c

 ///
/// @file first.c
/// @author crazy_chu
/// @date2008-11-1
/// #include <ntddk.h> // 提供一个Unload函数只是为了
VOID DriverUnload(PDRIVER_OBJECT driver)
{
// 但是实际上我们什么都不做,只打印一句话:
DbgPrint("first: Our driver is unloading…\r\n");
} // DriverEntry,入口函数。相当于main。
NTSTATUS DriverEntry(PDRIVER_OBJECT driver, PUNICODE_STRING reg_path)
{
#if DBG
_asm int
#endif
// 这是我们的内核模块的入口,可以在这里写入我们想写的东西。
// 我在这里打印一句话。因为”Hello,world” 常常被高手耻笑,所以
// 我们打印一点别的。
DbgPrint("first: Hello, my salary!"); // 设置一个卸载函数便于这个函数能退出。
driver->DriverUnload = DriverUnload;
return STATUS_SUCCESS;
}

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

 TARGETNAME=first
TARGETTYPE=DRIVER
SOURCES=first.c
TARGETPATH=obj

mybuild.bat

 set root=%~d0
set curdir=%cd%
set ddk_path=d:\WINDDK\3790~1.183\bin
del %ddk_path%\ChngeDir.bat
echo %root%>>%ddk_path%\ChngeDir.bat
echo cd %curdir%>>%ddk_path%\ChngeDir.bat
echo build>>%ddk_path%\ChngeDir.bat
call %ddk_path%\setenv.bat d:\WINDDK\3790~1.183 chk WXP
call %ddk_path%\ChngeDir.bat
pause

3. 学习书籍

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

上一篇:设计模式之策略模式(strategy)


下一篇:Android笔记——Android中数据的存储方式(二)