1. Hello driver!

Source: Internet
Author: User
Tags virtual environment

I. Prepare the tool

 

1, windbg

2, dbgview

3, wdk

4. Driver loading Tool

5. Virtual Machine Software

6. Download symbols official website search (symbols)

 

Ii. Virtual Machine environment Configuration

1. Install the XP operating system

2. Add the serial port //./pipe/com_1 to the VM.

3. Configure the boot. ini file and add the following code to the last line:

Multi (0) disk (0) RDISK (0) Partition (1) /Windows = "Microsoft Windows XP Professional"/noexecute = optin/fastdetect/debug/debugport = COM1/baudrate = 115200

 

3. Configure windbg

1. In the windbgdirectory, choose "windbg.exe" to create a shortcut.-> "shortcut", right-click "properties", and add the following code to the target windbg.exe:

Note: This shortcut is used for dual-host mode!

2. Set the windbgsymbol file, and open windbg.exe-> file-> symbol file path-> enter the symbols installation path.

 

4. Write the next hello driver for testing.

1. Create a text file driverhello. C and copy the following code:

# Include <ntddk. h> </P> <p> // provides an unload function value to enable the program to be dynamically uninstalled for debugging </P> <p> void driverunload (pdriver_object driver) </P> <p >{< br/> // print a sentence <br/> dbuplint ("Bye driver !! /R/N "); <br/>}</P> <p> // DriverEntry, entry function. Equivalent to main </P> <p> ntstatus DriverEntry (pdriver_object driver, punicode_string reg_path) </P> <p >{< br/> // only one sentence is output here </P> <p> dbuplint ("Hello driver! /R/N "); </P> <p> // set an unmount function to facilitate function exit <br/> driver-> driverunload = driverunload; <br/> return STATUS_SUCCESS; </P> <p >}</P> <p>

 

2. Create two text files named makefile and sources and paste the following code:

// Makefile

########## Paste the following code ######################## ####

! Ifdef ntmakeenv

# Do not edit this file !!! Edit./joycpl. Inc. If you want to add a new
# Source file to this component. This file merely indirects to
# Build Environment specific common make file.

! Include $ (ntmakeenv)/makefile. Def

! Else

# Win 95
#

Root = ..
Win32 = true
! Include.../../build. mk

! Endif

########################################

 

 

// Sources File

########## Paste the following code ######################## ##

! If 0

Copyright (c) 1989-2000 Microsoft Corporation

! Endif

Linker_stacksize =-Stack: 4096,1024

# Compile for Win95 for widest compatibility
Chicago _product = 1
Win32_ie_version = 0x0300

Umtype = Windows

Targetname = driverhello
Targetpath = OBJ
Targettype = driver
Sources = driverhello. c

 

 

5. Compile

1. After wdk is installed, you can find it in the Start Menu program.

Windows XP checked Build Environment

Windows XP Free Build Environment

The above two items

2. Select checked (equivalent to the debug mode in VC) to enter the legendary black screen white window.

3. Run the DOS command to change the current path to your driverhello project directory.

4. Enter build

5. Check the prompt after execution. If you are sure there is no error, go to the project directory and find a driverhello. SYS file.

 

6. Local debugging

1. Open dbgview.exe to wait for the output of debugging information.

2. Open the driver loading tool and load the driverhello. SYS file-> Start-> stop-> uninstall to observe the output in sequence.

 

 

VII. Dual-machine debugging

1. Modify the source code and add the breakpoint as follows:

# Include <ntddk. h> </P> <p> // provides an unload function value to enable the program to be dynamically uninstalled for debugging </P> <p> void driverunload (pdriver_object driver) </P> <p >{</P> <p> // print a sentence </P> <p> dbuplint ("Bye driver !! /R/N "); </P> <p >}</P> <p> // DriverEntry, entry function. Equivalent to main </P> <p> ntstatus DriverEntry (pdriver_object driver, punicode_string reg_path) </P> <p >{< br/> # If dbg <br/> _ asm int 3 <br/> # endif </P> <p> // here only output a sentence </P> <p> dbuplint ("Hello driver! /R/N "); </P> <p> // set an unmount function to facilitate function exit </P> <p> driver-> driverunload = driverunload; </P> <p> return STATUS_SUCCESS; </P> <p >}</P> <p>

 

2. Start the configured XP Virtual Machine environment (driver loading tool is required in the virtual environment) --> select debug mode for startup> black screen, and wait for the following step.

3. Open windbg.exe (the created shortcut). If the connection is normal, a prompt is displayed. Check the command line in the Command window and enter g to run the VM normally.

 

4. If the VM runs normally, open the driver loading tool and choose "LOAD"> "start"> "stop"> "Uninstall" to view the output information in windbg.exe.

 

 

A Hello driver !!! All drivers are welcome to discuss software-driven issues!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.