This project demonstrates how the Windows Desktop Window Manager (DWM) enforces the WDA_EXCLUDEFROMCAPTURE flag at the kernel level. It calls an undocumented internal function (win32kfull!GreProtectSpriteContent) to mark any window as excluded from screen capture, effectively making it invisible to all user‑mode capture APIs.
The code serves as a research proof‑of‑concept for understanding the boundary between user‑mode and kernel‑mode window management. It is intended to illustrate how deeply the capture-exclusion mechanism is embedded in the Windows graphics stack and how the documented user-mode API (SetWindowDisplayAffinity) relates to lower-level enforcement.
- The driver creates a device
\Device\HideWindowand a symbolic link\DosDevices\HideWindow(accessible as\\.\HideWindowfrom user‑mode). - A user‑mode application (
protect.exe) sends an IOCTL containing the HWND of a target window. - The driver locates the internal
win32kfull!GreProtectSpriteContentfunction (address must be updated manually due to KASLR) and calls it with that HWND and the flag0x11(WDA_EXCLUDEFROMCAPTURE). - After the call, the Desktop Window Manager applies the corresponding capture-exclusion state in a way that mirrors the behavior associated with the official
SetWindowDisplayAffinitypath.
- In Visual Studio 2022 (with WDK), create a new Empty WDM Driver project.
- Add
HideWindow.cto the Source Files folder. - Set solution platform to x64.
- Build → Build Solution. The
.sysfile will be inx64\Release\.
Compile protect.c with any C compiler (GCC, MSVC, etc.):
gcc -o protect.exe protect.c- Enable test signing and reboot:
bcdedit /set testsigning on Restart-Computer
- Copy
HideWindow.sysandprotect.exeto a folder on the target machine (e.g.,C:\Drivers). - Install and start the driver (as Administrator):
sc.exe create HideWindow type= kernel binPath= C:\Drivers\HideWindow.sys sc.exe start HideWindow
- Run
protect.exein any console window (not Administrator):C:\Drivers\protect.exe - The console window will no longer appear in screen captures taken with different tools.
- When done, stop and delete the driver (as Administrator):
sc.exe stop HideWindow sc.exe delete HideWindow
- Because of KASLR, the address of
GreProtectSpriteContentchanges after every reboot. You need to update the#define GRE_PROTECT_SPRITE_CONTENT_ADDRinHideWindow.cwith the new address found in WinDbg:Then rebuild the driver.lkd> x win32kfull!GreProtectSpriteContent * - The driver only works on Windows 10 and 11 (it relies on an internal function that exists in those versions).
- Address hardcoding: The function address must be updated manually after each reboot. This is a direct consequence of KASLR and the fact that
GreProtectSpriteContentis not exported. A more robust research implementation would need a safer and more maintainable way to resolve the address dynamically. - Windows version sensitivity: The signature and availability of internal functions can change with Windows updates. This code was tested on build 19041 (Windows 10 2004).
- Minimal validation: The driver does not validate the HWND it receives; a malformed handle could lead to unpredictable behaviour. In a real driver, proper validation would be essential.
- Test signing only: The driver is signed with a test certificate and requires
testsigningmode. For deployment on locked‑down systems, a valid EV certificate or disabled DSE would be needed – neither is recommended for production.
This project started from a technical question: "How does the WDA_EXCLUDEFROMCAPTURE flag actually work below the official API?"
The public function SetWindowDisplayAffinity can be detected with GetWindowDisplayAffinity, so we wanted to see whether the exclusion is truly enforced at the kernel level.
By reverse‑engineering win32kfull.sys we located the internal function GreProtectSpriteContent – the routine that ultimately implements the flag. Calling it directly bypasses the user‑mode API and confirms that the protection is applied inside the Desktop Window Manager, completely invisible to any user‑mode process.
The experiment shows that any security mechanism that depends solely on user‑mode cooperation can be observed or circumvented from user‑mode itself. This is a fundamental design reality of Windows, not a vulnerability – it simply highlights the boundary between user and kernel space, a topic well understood by operating‑system researchers and kernel developers.
This project is licensed under the MIT License - see the LICENSE file for details.