logo资料库

Windows Kernel Programming 9781977593375.pdf

第1页 / 共393页
第2页 / 共393页
第3页 / 共393页
第4页 / 共393页
第5页 / 共393页
第6页 / 共393页
第7页 / 共393页
第8页 / 共393页
资料共393页,剩余部分请下载后查看
Table of Contents
Chapter 1: Windows Internals Overview
Processes
Virtual Memory
Page States
System Memory
Threads
Thread Stacks
System Services (a.k.a. System Calls)
General System Architecture
Handles and Objects
Object Names
Accessing Existing Objects
Chapter 2: Getting Started with Kernel Development
Installing the Tools
Creating a Driver Project
The DriverEntry and Unload Routines
Deploying the Driver
Simple Tracing
Exercises
Summary
Chapter 3: Kernel Programming Basics
General Kernel Programming Guidelines
Unhandled Exceptions
Termination
Function Return Values
IRQL
C++ Usage
Testing and Debugging
Debug vs. Release Builds
The Kernel API
Functions and Error Codes
Strings
Dynamic Memory Allocation
Lists
The Driver Object
Device Objects
Summary
Chapter 4: Driver from Start to Finish
Introduction
Driver Initialization
Passing Information to the Driver
Client / Driver Communication Protocol
Creating the Device Object
Client Code
The Create and Close Dispatch Routines
The DeviceIoControl Dispatch Routine
Installing and Testing
Summary
Chapter 5: Debugging
Debugging Tools for Windows
Introduction to WinDbg
Tutorial: User mode debugging basics
Kernel Debugging
Local Kernel Debugging
Local kernel Debugging Tutorial
Full Kernel Debugging
Configuring the Target
Configuring the Host
Kernel Driver Debugging Tutorial
Summary
Chapter 6: Kernel Mechanisms
Interrupt Request Level
Raising and Lowering IRQL
Thread Priorities vs. IRQLs
Deferred Procedure Calls
Using DPC with a Timer
Asynchronous Procedure Calls
Critical Regions and Guarded Regions
Structured Exception Handling
Using __try/__except
Using __try/__finally
Using C++ RAII Instead of __try / __finally
System Crash
Crash Dump Information
Analyzing a Dump File
System Hang
Thread Synchronization
Interlocked Operations
Dispatcher Objects
Mutex
Fast Mutex
Semaphore
Event
Executive Resource
High IRQL Synchronization
The Spin Lock
Work Items
Summary
Chapter 7: The I/O Request Packet
Introduction to IRPs
Device Nodes
IRP Flow
IRP and I/O Stack Location
Viewing IRP Information
Dispatch Routines
Completing a Request
Accessing User Buffers
Buffered I/O
Direct I/O
User Buffers for IRP_MJ_DEVICE_CONTROL
Putting it All Together: The Zero Driver
Using a Precompiled Header
The DriverEntry Routine
The Read Dispatch Routine
The Write Dispatch Routine
Test Application
Summary
Chapter 8: Process and Thread Notifications
Process Notifications
Implementing Process Notifications
The DriverEntry Routine
Handling Process Exit Notifications
Handling Process Create Notifications
Providing Data to User Mode
The User Mode Client
Thread Notifications
Image Load Notifications
Exercises
Summary
Chapter 9: Object and Registry Notifications
Object Notifications
Pre-Operation Callback
Post-Operation Callback
The Process Protector Driver
Object Notification Registration
Managing Protected Processes
The Pre-Callback
The Client Application
Registry Notifications
Handling Pre-Notifications
Handling Post-Operations
Performance Considerations
Implementing Registry Notifications
Handling Registry Callback
Modified Client Code
Exercises
Summary
Chapter 10: Introduction to File System Mini-Filters
Introduction
Loading and Unloading
Initialization
Operations Callback Registration
The Altitude
Installation
INF Files
Installing the Driver
Processing I/O Operations
Pre Operation Callbacks
Post Operation Callbacks
The Delete Protector Driver
Handling Pre-Create
Handling Pre-Set Information
Some Refactoring
Generalizing the Driver
Testing the Modified Driver
File Names
File Name Parts
RAII FLT_FILE_NAME_INFORMATION wrapper
The Alternate Delete Protector Driver
Handling Pre-Create and Pre-Set Information
Testing the Driver
Contexts
Managing Contexts
Initiating I/O Requests
The File Backup Driver
The Post Create Callback
The Pre-Write Callback
The Post-Cleanup Callback
Testing the Driver
Restoring Backups
User Mode Communication
Creating the Communication Port
User Mode Connection
Sending and Receiving Messages
Enhanced File Backup Driver
The User Mode Client
Debugging
Exercises
Summary
Chapter 11: Miscellaneous Topics
Driver Signing
Driver Verifier
Example Driver Verifier Sessions
Using the Native API
Filter Drivers
Filter Driver Implementation
Attaching Filters
Attaching Filters at Arbitrary Time
Filter Cleanup
More on Hardware-Based Filter Drivers
Device Monitor
Adding a Device to Filter
Removing a Filter Device
Initialization and Unload
Handling Requests
Testing the Driver
Results of Requests
Driver Hooking
Kernel Libraries
Summary
Windows Kernel Programming Pavel Yosifovich This book is for sale at http://leanpub.com/windowskernelprogramming This version was published on 2019-10-10 This is a Leanpub book. Leanpub empowers authors and publishers with the Lean Publishing process. Lean Publishing is the act of publishing an in-progress ebook using lightweight tools and many iterations to get reader feedback, pivot until you have the right book and build traction once you do. © 2019 Pavel Yosifovich
CONTENTS Contents Chapter 1: Windows Internals Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Processes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Virtual Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Page States . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . System Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Threads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Thread Stacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . System Services (a.k.a. System Calls) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . General System Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Handles and Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Object Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Accessing Existing Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1 3 5 5 6 7 9 10 13 14 17 Chapter 2: Getting Started with Kernel Development . . . . . . . . . . . . . . . . . . . . . . . . 20 20 21 22 25 28 31 31 Installing the Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Creating a Driver Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The DriverEntry and Unload Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Deploying the Driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Simple Tracing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 3: Kernel Programming Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 32 33 33 34 34 34 35 36 36 37 38 General Kernel Programming Guidelines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Unhandled Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Termination . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Function Return Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . IRQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . C++ Usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Testing and Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Debug vs. Release Builds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The Kernel API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Functions and Error Codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Strings (C)2019 Pavel Yosifovich
CONTENTS Dynamic Memory Allocation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The Driver Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Device Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 42 44 45 48 Chapter 4: Driver from Start to Finish . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 49 50 52 53 54 57 59 60 64 67 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Driver Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Passing Information to the Driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Client / Driver Communication Protocol . . . . . . . . . . . . . . . . . . . . . . . . . . . . Creating the Device Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Client Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The Create and Close Dispatch Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The DeviceIoControl Dispatch Routine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Installing and Testing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Tutorial: User mode debugging basics Debugging Tools for Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Introduction to WinDbg . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Kernel Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Local Kernel Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Local kernel Debugging Tutorial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Full Kernel Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Configuring the Target . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Configuring the Host . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Chapter 5: Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 68 69 70 87 88 89 96 97 99 Kernel Driver Debugging Tutorial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104 Interrupt Request Level Using DPC with a Timer Chapter 6: Kernel Mechanisms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 Raising and Lowering IRQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108 Thread Priorities vs. IRQLs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 Deferred Procedure Calls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 Critical Regions and Guarded Regions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114 Structured Exception Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114 Using __try/__except . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116 Using __try/__finally . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 Using C++ RAII Instead of __try / __finally . . . . . . . . . . . . . . . . . . . . . . . 119 System Crash . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 Asynchronous Procedure Calls (C)2019 Pavel Yosifovich
CONTENTS Crash Dump Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124 Analyzing a Dump File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128 System Hang . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 Thread Synchronization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 Interlocked Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 Dispatcher Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 Mutex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 Fast Mutex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140 Semaphore . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142 Event . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142 Executive Resource . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143 High IRQL Synchronization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144 The Spin Lock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146 Work Items . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 Completing a Request Accessing User Buffers Chapter 7: The I/O Request Packet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152 Introduction to IRPs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152 Device Nodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153 IRP Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 IRP and I/O Stack Location . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159 Viewing IRP Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162 Dispatch Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166 Buffered I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167 Direct I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171 User Buffers for IRP_MJ_DEVICE_CONTROL . . . . . . . . . . . . . . . . . . . . . . . . . . 176 Putting it All Together: The Zero Driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177 Using a Precompiled Header . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178 The DriverEntry Routine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180 The Read Dispatch Routine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182 The Write Dispatch Routine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 Test Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185 Chapter 8: Process and Thread Notifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186 Process Notifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189 Implementing Process Notifications The DriverEntry Routine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192 Handling Process Exit Notifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194 Handling Process Create Notifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197 Providing Data to User Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199 (C)2019 Pavel Yosifovich
CONTENTS The User Mode Client . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201 Thread Notifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204 Image Load Notifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209 Chapter 9: Object and Registry Notifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210 Object Notifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210 Pre-Operation Callback . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212 Post-Operation Callback . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215 The Process Protector Driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216 Object Notification Registration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217 Managing Protected Processes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218 The Pre-Callback . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222 The Client Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223 Registry Notifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226 Handling Pre-Notifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228 Handling Post-Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228 Performance Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229 Implementing Registry Notifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229 Handling Registry Callback . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231 Modified Client Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235 Chapter 10: Introduction to File System Mini-Filters . . . . . . . . . . . . . . . . . . . . . . . . 236 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237 Loading and Unloading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238 Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240 Operations Callback Registration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243 The Altitude . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247 Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250 INF Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250 Installing the Driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258 Pre Operation Callbacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258 Post Operation Callbacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263 Handling Pre-Create . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264 Handling Pre-Set Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 269 Some Refactoring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272 Generalizing the Driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281 Testing the Modified Driver The Delete Protector Driver Processing I/O Operations (C)2019 Pavel Yosifovich
CONTENTS File Names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282 File Name Parts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284 RAII FLT_FILE_NAME_INFORMATION wrapper . . . . . . . . . . . . . . . . . . . . . . . . 287 The Alternate Delete Protector Driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289 Handling Pre-Create and Pre-Set Information . . . . . . . . . . . . . . . . . . . . . . . . . 296 Testing the Driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299 Contexts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299 Managing Contexts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301 Initiating I/O Requests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303 The File Backup Driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304 The Post Create Callback . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307 The Pre-Write Callback . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312 The Post-Cleanup Callback . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319 Testing the Driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320 Restoring Backups . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321 User Mode Communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323 Creating the Communication Port . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323 User Mode Connection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325 Sending and Receiving Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 326 Enhanced File Backup Driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327 The User Mode Client . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 330 Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 332 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 336 Example Driver Verifier Sessions Using the Native API Filter Drivers Chapter 11: Miscellaneous Topics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337 Driver Signing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337 Driver Verifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 352 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 353 Filter Driver Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355 Attaching Filters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 356 Attaching Filters at Arbitrary Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358 Filter Cleanup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 360 More on Hardware-Based Filter Drivers . . . . . . . . . . . . . . . . . . . . . . . . . . . . 361 Device Monitor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 362 Adding a Device to Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 364 Removing a Filter Device . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367 Initialization and Unload . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369 Handling Requests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371 Testing the Driver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 374 Results of Requests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 378 (C)2019 Pavel Yosifovich
CONTENTS Driver Hooking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 380 Kernel Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 384 (C)2019 Pavel Yosifovich
分享到:
收藏