aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/README.md
blob: 62a5f72367b83c9eb69c836abc143ba12fe07613 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# Windows 7 drivers

This is a collection of basic Windows 7 drivers.
These are actually not drivers as such (in the sense that they don't actually
manage any hardware), but rather kernel modules.

## Development

### Prerequisites

The drivers are compiled using the Windows Driver Kit Version 7.1.0.

I've developed a set of batch files to facilitate building the drivers and
cleaning after the build.
The binaries are copied into the "bin" directory under the root directory.

To set up the development environment, start a new `cmd` session, and run

    C:\WinDDK\7600.16385.1\bin\setenv.bat C:\WinDDK\7600.16385.1 fre WIN7 no_oacr

Of course, you may want to provide other `setenv.bat` parameters according to
your needs.
For example, to compile for x86-64, call `setenv.bat` like this:

    C:\WinDDK\7600.16385.1\bin\setenv.bat C:\WinDDK\7600.16385.1 fre x64 WIN7 no_oacr

Then navigate to the root directory and call `setenv.bat`:

    setenv.bat

### Code signing

Driver binaries are signed using the self-signed certificate issued by
"windows7_drivers" from "Trusted Root Certification Authorities" store.
You can generate this certificate using `add_cert.bat` (make sure to set up the
development environment first).
To verify it's there, you can use the `certmgr.msc` utility.

Driver binaries are automatically signed during builds, but you can also sign
one manually by passing the path to a .sys file to `sign.bat`.

### Build & clean

To build every driver under the "src" directory, call `build_drivers.bat`.
To build a particular driver, pass the path to the driver source directory to
`build_driver.bat`.
Driver binaries are copied to the "bin" directory.

Cleaning after a driver build includes deleting log and object files in the
driver source directory and deleting the binaries from the "bin" directory.
To clean after every driver in the "src" directory, call `clean_drivers.bat`.
To clean after a particular driver, pass the path to the driver source
directory to `clean_driver.bat`.

## Installation

To install a driver as a service, you can use the `sc` utility.
For example, to install a driver "C:\test.sys" as a "test" service, run

    sc create test type= kernel binPath= C:\test.sys

You can then load/unload the driver by using the `net` utility to start/stop
the corresponding service.

    net start test
    net stop test

To uninstall a driver, delete the corresponding service using `sc`.

    sc delete test

Please note, that **64-bit versions of Windows 7 disallow loading 32-bit
drivers**!

You may also need to explicitly enable loading self-signed drivers on 64-bit
versions of Windows.
One way is to use the `bcdedit` utility:

    bcdedit /set testsigning on

Then restart your computer and you should be all set!

## Debugging

You can debug a driver using WinDbg.
To enable kernel debugging, you can use the `msconfig` utility (navigate to
"Boot" -> "Advanced options..." and check "Debug") or the `bcdedit` utility:

    bcdedit /debug on
    bcdedit /dbgsettings serial debugport:1 baudrate:115200

Restart your computer for these settings to take effect.

If a driver is loaded on a separate physical machine, you can connect to a
physical COM port from another host with WinDbg installed and enable kernel
debugging via "File" -> "Kernel Debug...".
You might need to restart the debuggee a couple of times in order to enter the
kernel debugging mode.

If a driver is running on a virtual machine, the conventional approach is to
expose a COM port via a named pipe.
You can then connect to the pipe from WinDbg installed on the host.
Refer to your virtualization software's documentation for more details.

## Licensing

This project, including all of the files and their contents, is licensed under
the terms of the MIT License.
See LICENSE.txt for details.