Driver development 5: How to Use VC to directly compile and connect to the DDK driver

Source: Internet
Author: User

Content:
Using VC ++ 6.0 to edit (not compile) the driver's source file is a good choice, especially with visual assist, it is more convenient. After editing, build in VC ++ to make it easier.
I have made some references on the M $ website. The DSW files generated by DS and the log files generated by build have references. In fact, the M $ site changes the VC setting based on the build log file. Me too
Limited to 2 k DDK, because xp ddk and 2003 DDK do not need VC ++ 6.0. When I use vc6 for build, I will tell you "compiler version not supported by Windows DDK", but I have not tried it further. (Note: There is a Bt method, so you can add the setting of XP. Of course, you must set the correct path and then use ultraedit to modify the DSP file, change Cl, midl, RC, and link to xp ddk Based on the configuration)
DDK has its own link, and 98 and 2 k DDK seem to be vc5. If I do this, I actually use the link of vc6.
The source, Dir, and make files are not considered.

The build of ddkis actually a tool called nmake, and nmakede the corresponding file such as cl.exe1_link.exe.
CL option settings, mainly pay attention to the include path of DDK. The link option is to let the link get a sys instead of exe.

Preparations:
1. Install DDK ). The directory name should not contain spaces.
2. Create a workspace and add your own C, H, and RC files.
3. Events, add checked, free, do not debug, release (in fact, this is not necessary, checked, debug, to see how you call it ).
The rest is to change the settings so that VC can build a sys file for you.

One by one. All the changes are under project-> setting. It is mainly concentrated in C/C ++ and link.
1. General, just one, not using MFC;
2. debug, there is nothing to change;
3. C/C ++:

1.1 General:
3.1.1 warning level, use level3, drive well, stability is overwhelming, and DDK sample is warning 3, warnings as errors is selected;
3.1.2 optimizations: For checked, I am disable (Debug). When SoftICE is used in the province, there will be variables that cannot be watched. For free, I am customize, which will be discussed later;
3.1.3 debug info, free is gone of course. You need to add it to your business. For checked, I use C7; VC's default program database for/"Edit & continue /", conflicts with the/driver option of link;
3.1.4 Preprocessor definitions. Some of them are not clear, and some may be used by DS. Below is a dsw I use.
Rdrdbg, srvdbg, FPO = 0, Win32 = 100, std_call, condition_handling = 1, nt_up = 1, nt_inst = 0, _ nt1x _ = 100, winnt = 1, _ win32_winnt = 0x0400, win32_lean_and_mean = 1, devl = 1, _ DLL = 1, _ x86 _ = 1, $ (CPU) = 1, ntversion =/'wdm/', winver = 0x500, ntdebug = ntsd, dbg = 1

Std_call is unnecessary. All the driver functions are _ stdcall. In fact, they are set elsewhere.
Winver = 0x500, because you are for 2 K. XP is 0X501, but it is useless. vc6 cannot be used anyway.
_ X86 _ = 1. If not, hey. This is not the value of CPU, such as alpha.
If dbg is free, do not define it, or set it to 0.
FPO, checked is 0, and free is 1. I think it should be fram-pointer omission.
Ntdebug = checked? Ntsd: ntsdnodebug
Win32_lean_and_mean, exclude rarely-used stuff from Windows headers, non-MFC, this can reduce the build time. It doesn't matter if you have more definitions. it's good if it doesn't affect others.
Nt_up, 0 indicates MP, multi-processor, and 1 indicates that you are using a single processor.
Nt_inst, set to turn on Instrumentation

Depending on the driver type, you may need to add other Preprocessor definitions, such as ndis imd, which requires ndis50, ndis_miniport_driver, and ndis50_miniport.
3.1.5 project options you only need to add the last few items, including/qifdiv-/QIF/qi0f, which can be found on msdn. It is worth mentioning that the debug setting of the workspace generated by VC has a GZ option by default. Catch release-build errors in debug build, which indicates error lnk2001 during compilation: unresolved external symbol _ chkesp. just remove it.
1.2 C ++ language is useless. Do not use rtti. Exception Handling is useless.
1.3 code generation uses _ stdcall for calling convention, and the rest do not matter (remember std_call );
1.4 There is nothing to say about customize. I generally use function-level linking. I will not choose eliminate duplicate strings because the GF option is added;
1.5 listing files: listing file type. You can modify the assembly code here;
1.6 optimizations checked is naturally disable and free. I chose full optimization, frame_popinter omission, and only _ inline. In fact, this is my personal experience;
1.7 precompiled headers. Check msdn. The default value is also acceptable;
1.8 Preprocessor definitions as mentioned earlier, focuses on additional include directories, $ (basedir) incddkwdm, $ (basedir) incddk, $ (basedir) Inc, $ (basedir) incwin98 ,.... inc. This is a DSW of mine. Therefore, if the basedir environment variable needs to be set, I will use the DS tool to start VC. It just helps you set it, of course, you can also directly write your DDK installation path. If the include path is not found, a large number of errors may occur, such as WDM. h errors... Is a question that many people ask;

4. Okay. It's the link's turn.
4.1 In general, select ignore all default libraries. You can select generate map file. Map Files are sometimes useful. For checked files, choose Generate debug info and link incrementally. For objects/library modules, add WDM. lib, etc. ntoskrnl. lib seems to have output some functions such as sprintf and strcat (Note 1). Other functions may need to be output according to driver, such as NDIS. LIB; Do not forget to change the output file nameto yourname.sys, but not yourname.exe.
4.2 Debug: The checked should be changed. Select debug info. I chose both formats;
4.3 one of the key points of input is additional lib path, $ (basedir) libchki386, which is used by one of my dsws. Checked fills in the checked lib path and free in the freelib path.
4.4 output in entry-point symbol, fill in DriverEntry, or _ driveentry @ 8, the same;
According to the link output, the base address should be set to 0x10000, the stack, and the reserve should be set to 0x40000, And the commit should be set to 0x1000; the version info should be set by yourself;
4.5 project options, important. Many options should be added directly here. To add:
/Machine: ix86, CPU-related
/Debug: full,/debugtype: both according to the M $ site, both of them are required for windbg to find your symbol, in addition, we also need to use linker to link it once separately. VC does not recognize/debug: full, and free will not solve this problem. According to the M $ method, you can write an lnk file, link it again in post-build step, and add link @ yourlnk. lnk. This lnk file can be extracted from the log file. It doesn't matter if you don't need windbg;
/Driver, use this linker option to build a Windows NT kernel mode driver, as described by msdn
/Ignore: 4001,4037, 4039,4065, 4070,4078, 4087,4089, 4096,4210 check msdn
/Merge: _ page = page/merge: _ text =. Text/section: init, D, and DriverEntry can be placed in the init section.
/Fullbuild
/Release, add checksum in the file header
/Force: Multiple
/OPT: ref/OPT: ICF/align: 0x20/osversion: 5.00/subsystem: Native

Pay special attention to/subsystem: Native and/driver.
A long string of/ignore allows you to pass through even if you select Warning Level 4. Warning Level 4 is a little abnormal.

In fact, most of the above is nonsense :). For most of the options, you can see the log file output by build. In this way, you can add necessary options based on your driver.

The more you write, the more you feel ignorant.

Please point out something wrong.

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.