Directly constructed NT KMode driver in VisualStudio98

zhaozj2021-02-11  212

Directly constructing NT KMODE driver in Visualstudio98 Shenzhen Di Rui Computer Technology Co., Ltd. Jiang Zongwen ---- Microsoft Visualstudio98 is a powerful C and C program development environment, including several features I (believe it is also the majority of C and C programmers They like: color syntax sensitive, source code browsing, class and file browsing, direct positioning syntax errors, etc. ---- However, such a good tool, let many NT KMode driver developers are very annoyed because she (He) does not directly use VS98. MS is provided by a prehistoric difficulty command line tool build! Don't say that many of the spiritual disorderly Last Line Incomplete generated during Build runtime, the most troublesome is to make mistakes and find The implementation and definition of the function. ---- In fact, Build also uses the same compilation and connectors as VS, and makes VS a little customization, we can wake up from the above nightmares. ---- 1. Create kmode Project: ---- Select the File / New menu item from VS98 and generate a new Win32 Dynamic-Link Library project. ---- 2. Change all configurations options: ---- Select Project / Settings / All Configurations Go to C / C labels, as follows: 2.1 Remove Enable Exception Handling in Category "C / C Language".

2.2 Select the calling convention in the Category "Code Generation" to __stdcall,

And Struct Member Alignment is 8-Bytes.

2.3 Set "Not use ..." in Category "Precompiled Headers".

2.4 Enter the definition in category "preProcessor" _x86_ = 1, i386 = 1, std_call = 1,

Condition_handling = 1, Win32_Lean_and_

Mean = 1, NT_UP = 1, NT_INST = 0, Win32 = 100,

_NT1X_ = 100, WinNT = 1, _WIN32_WINNT = 0x0400,

DEVL = 1, ndebug, _dll = 1, _idwbuild,

DBCS, PRC, KKBUGFIX, DBCS_VERT, Fe_SB.

And add include directory D: / DDK / INC

(If you have a different setting when you install DDK, write your set value).

Go to the LINK tag, customize the following:

2.5 Remove generate debug info in Category "General" and select Ignore All

Default libaries and doesn't produpe .lib. Plus you in Object / Library Modules

The library to be connected is generally int64.lib ntoskrnl.lib hal.lib.

2.6 Remove the ProGram Database check box in Category "Custom".

2.7 Setting entry-point symbol to DriveRentry @ 8 in Category "Output".

Go to the Resource tag, add D: / DDK / INC to the include directory, and define symbols _x86_ = 1, i386 = 1,

STD_CALL, CONDition_Handling = 1,

NT_UP = 1, NT_INST = 0, Win32 = 100, _NT1X_ = 100, WinNT = 1,

_WIN32_WINNT = 0x0400, Win32_Lean_and

_Mean = 1, DEVL = 1, ndebug, _dll = 1, _idwbuild,

DBCS, PRC, KKBUGFIX, DBCS_VERT, Fe_SB.

---- 3. Custom win32 debug option (ie check build): ---- Choose Project / Settings / Win32 Debug, turn to C / C label, as a change: 3.1 Select Debug Info in Category "General"

In C7 Compatible. Increase DBG = 1, FPO = 0,

RDRDBG, SRVDBG these symbols to

Before the symbol in Preprocessor Definitions. And in

PROJECT OPTIONS final Add

/ GF / Qifdiv- / QIF three compilation options.

Go to the LINK tag, customize the following:

3.2 Setting the output file in Category "General" is

Debug / mydriver.sys (you want to produce SYS

File). Then in the last addition of Project Options / libpath: "D: / DDK / LIB / I386 / Checked"

/ Subsystem: native These two connection options.

Go to the Resource tag, add symbol definition DBG = 1, fpo = 0, RDRDBG, SRVDBG.

---- Unfortunately, you can't debug the Kmode driver from the VS. This has to improve the improvement of MS, but now we have to use Windbg. And slow, we can't use the options that use the options just set up .sys file debugging, Because Windbg requires the / debug: full and / debugtype: Both option, VS98 supports both (you can try). One solution is to delete .sys file, manual (from the command line) after the connection is completed Above) Running LINK, which is much smashed. In fact, VS can automatically run some commands after the connection is completed, as long as you go to the Post-Build Step tag setting. I set this: link / nologo @mydriver. lnk

Rebase -b 0x10000 -x debug debug / mydriver.sys

If exist debug / mydriver.dbg del / f debug / mydriver.dbg

Move Debug / Sys / MyDriver.dbg Debug

Rd debug / sys

---- Millive Test File MyDriver.dbg You can remember to copy the Winnt / Symbols / Sys directory to the adjustment control machine. The MyDriver.lnk is a link command file, the content is as follows: -Machine: i386

-Mege: _Page = PAGE

-Mege: _Text = .text

-SECTION: Init, D

-Opt: Ref

-Incremental: NO

-Force: Multiple

-Release

-Fullbuild

-Ignore: 4001, 4037, 4039, 4065, 4070, 4078, 4087, 4089, 4096-nodefaultlib

-debug: NOTMAPPED, FULL

-debugType: Both

-Version: 4.00

-SVERSION: 4.00

-Pdb: None

-Mege: .rdata = .text

-Optidata

-Driver

-ALIGN: 0X20

-Subsystem: Native, 4.00

-BASE: 0x10000

-ENTRY: DRIVERENTRY @ 8

-Out: Debug / MyDriver.sys

Debug / mydriver.res

Debug / mydrv1.obj

Debug / mydrv2.obj

D: /ddk/lib/i386/checked/int64.lib

D: /ddk/lib/i386/checked/ntoskrnl.lib

D: /ddk/lib/i386/checked/hal.lib

---- This long string command is from build.log, there is any doubt can refer to the online manual. ---- Now mostly automated, a little inconvenient is to add a source file In the.lnk file, it will increase the line .Obj, but there is more than the meant, that is not as good as it is. It's good to increase the source file frequently. ---- 4. Custom Win32 Release option (ie Free Build), it is much simpler. ---- Choose Project / Settings / Win32 Release, go to the C / C tag, as follows: 4.1 Select Debug Info in Category "General"

In none. Add FPO = 1 to PreProcessor

The symbols in Definitions before. Then select the optimization method you like.

Go to the LINK tag, customize the following:

4.2 Setting the output file in Category "General" is

RELASE / MyDriver.sys. Then in Project

Options' last added / libpath: "D: / DDK / lib / i386 / free" / subsystem: native.

Go to the Resource tag, increase the symbol definition fpo = 1.

---- Good, all settings are completed. After adding your source file to Project, you can press F7 (constructed), experience the fast and convenient feeling of VS98's tool development KMode driver, I believe that is big with build Different. ---- This article has some contents to refer to MSDN's article "The Windows NT Kernel-Mode Driver Cookbook, Featuring Visual C " (Thanservis Ruediger R.asche), most of themselves Work experience, I hope to help everyone.

转载请注明原文地址:https://www.9cbs.com/read-4029.html

New Post(0)