• 生成驱动的两种编译方式


    本机:Windows7(64-bit)

    试验机:Windows7(32-bit)/WindowsXP


     

    1、利用wdk自带环境编译,这个比较简单,直接build就行

    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

     

    2、用vs2010+wdk7600编译,这个就比较复杂点,需要配置环境

     

    (1)新建空项目,命名为FirstDriver

     

    (2)生成,配置管理器

     

    (3)新建Driver

     

    (4)新建Driver,确定,关闭

     

    (5)属性管理器

     

    (6)添加属性表

     

    (7)命名为DriverTemplate.props

     

    (8)保存工程,将DriverTemplate.props内容改为如下:

    <?xml version="1.0" encoding="utf-8"?>
     
    <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
     
      <ImportGroup Label="PropertySheets" />
     
      <PropertyGroup Label="UserMacros" />
     
      <PropertyGroup>
     
        <ExecutablePath>C:WinDDK7600.16385.1inx86;$(ExecutablePath)</ExecutablePath>
     
      </PropertyGroup>
     
      <PropertyGroup>
     
        <IncludePath>C:WinDDK7600.16385.1incapi;C:WinDDK7600.16385.1incddk;C:WinDDK7600.16385.1inccrt;$(IncludePath)</IncludePath>
     
      </PropertyGroup>
     
      <PropertyGroup>
     
        <LibraryPath>C:WinDDK7600.16385.1libwin7i386;$(LibraryPath)</LibraryPath>
     
        <TargetExt>.sys</TargetExt>
     
        <LinkIncremental>false</LinkIncremental>
     
        <GenerateManifest>false</GenerateManifest>
     
      </PropertyGroup>
     
      <ItemDefinitionGroup>
     
        <ClCompile>
     
          <PreprocessorDefinitions>_X86_;DBG</PreprocessorDefinitions>
     
          <CallingConvention>StdCall</CallingConvention>
     
          <ExceptionHandling>false</ExceptionHandling>
     
          <BasicRuntimeChecks>Default</BasicRuntimeChecks>
     
          <BufferSecurityCheck>false</BufferSecurityCheck>
     
          <CompileAs>Default</CompileAs>
     
          <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
     
        </ClCompile>
     
        <Link>
     
          <AdditionalDependencies>ntoskrnl.lib;wdm.lib;wdmsec.lib;wmilib.lib;ndis.lib;Hal.lib;MSVCRT.LIB;LIBCMT.LIB;%(AdditionalDependencies)</AdditionalDependencies>
     
        </Link>
     
        <Link>
     
          <IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries>
     
          <EnableUAC>false</EnableUAC>
     
          <SubSystem>Native</SubSystem>
     
          <EntryPointSymbol>DriverEntry</EntryPointSymbol>
     
          <BaseAddress>0x10000</BaseAddress>
     
          <RandomizedBaseAddress>
     
          </RandomizedBaseAddress>
     
          <DataExecutionPrevention>
     
          </DataExecutionPrevention>
     
          <GenerateDebugInformation>true</GenerateDebugInformation>
     
          <Driver>Driver</Driver>
     
        </Link>
     
      </ItemDefinitionGroup>
     
      <ItemGroup />
     
    </Project>

     

    (9)添加第一个驱动源码,编译,成功!

     

    
    #include <ntddk.h>
        
    
    VOID DriverUnload(PDRIVER_OBJECT driver)
    {
    
        DbgPrint("first: Our driver is unloading…");
    }
    
    // DriverEntry,入口函数。相当于main。
    NTSTATUS DriverEntry(PDRIVER_OBJECT driver, PUNICODE_STRING reg_path)
    {
    #if DBG
    //       _asm int 3
    #endif
    
        DbgPrint("first: Hello, my salary!
    ");
    
        // 设置一个卸载函数便于这个函数能退出。
        driver->DriverUnload = DriverUnload;
        return STATUS_SUCCESS;
    }
     

     

    注意:

    1->>wdk路径要根据个人具体来配置

    2->>该props文件内容是为Windows7-32配置的,如果要配置Windows7-64要重新改动,请自行谷歌

  • 相关阅读:
    zookeeperclient代码解读
    封装scrollView 循环滚动,tableViewCell(连载) mvc
    PHP经典项目案例-(一)博客管理系统5
    Android插件化(三)载入插件apk中的Resource资源
    比树莓派配置好接地气的香蕉派上手初体验
    HDU Group
    JVM 类的卸载
    JVM 自定义类加载器
    JVM 初始化阶段例子
    JVM 初始化阶段例子 final常量
  • 原文地址:https://www.cnblogs.com/YangARTuan/p/10383366.html
Copyright © 2020-2023  润新知