Native C++ Integration with EaseFilter: Windows File System & Endpoint Security

Start Building Your Filter Driver PoC Today

Get the full-featured 30-day trial SDK for free. Includes pre-built C++ templates to test file monitor, file control, file encryption, registry, and process filters instantly.

Developing high-performance Endpoint Detection and Response (EDR) or Data Loss Prevention (DLP) systems for Windows demands low-latency access to the OS kernel. By utilizing the EaseFilter File Security SDK in native C++, system programmers can directly interface with a robust Windows mini-filter driver without writing hundreds of thousands of lines of WDM (Windows Driver Model) code.

This technical guide follows our comprehensive programming structure to explore the architectural implementation of EaseFilter natively in C++. You will learn how to configure filter rules, set up dedicated monitoring and control filters, manage process and registry lifecycles, and apply these capabilities to robust real-world security use cases.

Quick Reference: Using the EaseFilter SDK

How to Start the Filter:
Obtain the FilterControl singleton instance, ensure the mini-filter driver is running, and call StartFilter() with your desired filter types (e.g., FILE_SYSTEM_CONTROL), thread count, timeout, and license key.

How to Create a Filter Rule:
Instantiate a rule class (FileFilterRule, ProcessFilterRule, or RegistryFilterRule) with a target path or mask. Modify its properties and flags to fit your security requirements, add it using methods like AddFileFilter(), and activate it by calling SendConfigSettingsToFilter().

Monitoring and Controlling Rules:
Set the ControlFileIOEventFilter flag (e.g., PRE_CREATE) to route operations to user-space. This halts kernel I/O requests and passes a PMESSAGE_SEND_DATA struct to your registered C++ callback function, allowing you to inject custom logic and block threats natively.

Using accessFlags for Access Control:
Apply bitwise operations on the AccessFlags property to restrict risky permissions:

  • Anti-Ransomware: Deny rename, delete, and write access by setting flags like ~(ALLOW_WRITE_ACCESS | ALLOW_FILE_RENAME | ALLOW_FILE_DELETE).
  • Data Loss Prevention (DLP): Enforce transparent encryption and block plaintext reads using ENABLE_FILE_ENCRYPTION_RULE & ~ALLOW_READ_ENCRYPTED_FILES.
  • Whitelisting: Use AddProcessRight() to bypass restrictions for approved applications like backup agents.

File Monitor and Control Policies: Filter Rule

In the EaseFilter architecture, a Filter Rule acts as the configuration boundary for kernel interceptions. A rule defines the target scope (e.g., a specific folder path or wildcard like C:\TargetFolder\*) and the enforcement behavior (e.g., access rights or event triggers). You can use inclusion and exclusion masks to achieve granular control over when and where your filter rules trigger by file type, executing process, or user.

// Define a rule encompassing all files in a specific directory
FileFilterRule baseRule(L"C:\TargetFolder\*");
baseRule.ControlFileIOEventFilter = PRE_CREATE;

// 1. Exclude File Name Filter Mask: Prevent triggering on temp files or backups
baseRule.AddExcludeFileFilterMask(L"*.tmp");
baseRule.AddExcludeFileFilterMask(L"*.bak");

// 2. Include / Exclude Process Name Filter Mask: Restrict rule to specific processes
baseRule.AddIncludeProcessName(L"cmd.exe");
baseRule.AddExcludeProcessName(L"trusted_updater.exe");

// 3. Include / Exclude User Name Filter Mask: Enforce rule for specific users only
baseRule.AddIncludeUserName(L"DOMAIN\StandardUsers");
baseRule.AddExcludeUserName(L"DOMAIN\AdminUser");

// Attach the rule to the controller
filterControl->AddFileFilter(baseRule);

// Start the filter service after configuring the rules
if (!filterControl->StartFilter(filterType, threadCount, connectionTimeout, registerKey))
{
    wprintf(L"Start filter driver service failed.\n");
}

1. File Monitor Filter Driver

A file monitor filter passively observes I/O activity without blocking it. The EaseFilter SDK provides two distinct approaches for monitoring file system activity to optimize kernel performance based on your needs:

Real-Time I/O Monitoring (MonitorFileIOEventFilter)

Use this to monitor specific I/O events (like reads, writes, or property queries) immediately after they occur. You receive the telemetry in real-time, right after the file system completes the operation, while the file is still open.

FileFilterRule liveMonitorRule(L"C:\LiveAudit\*");

// Request telemetry immediately after a read or write operation occurs
liveMonitorRule.MonitorFileIOEventFilter = POST_READ | POST_WRITE;

filterControl->AddFileFilter(liveMonitorRule);

/* Inside your global NotificationCallback function:
   if (pSendMessage->MessageType == POST_READ || pSendMessage->MessageType == POST_WRITE) {
       wprintf(L"Real-Time Audit - File Accessed: %ws\n", pSendMessage->FileName);
   }
*/

Post-Close Monitoring (FileChangeEventFilter)

Use this to monitor events only after the file handle has been closed. Using FILE_WAS_CHANGED (or triggering NotifyFileWasChanged) is highly efficient for backup agents, cloud sync engines, or DLP scanners that only need to know when a file modification is fully complete and the file is safely released by the application.

FileFilterRule postCloseRule(L"C:\SyncFolder\*");

// Request telemetry only when a modified file is completely closed and released
postCloseRule.FileChangeEventFilter = FILE_WAS_CHANGED;

filterControl->AddFileFilter(postCloseRule);

/* Inside your global NotificationCallback function:
   if (pSendMessage->MessageType == FILE_WAS_CHANGED) {
       wprintf(L"Post-Close Audit - File Modified and Closed: %ws\n", pSendMessage->FileName);
   }
*/

2. File Control Filter Driver

A file control filter actively blocks unauthorized operations using two primary approaches:

  • Static Filter Rules (AccessFlags): This is the most performant method. By setting bitwise AccessFlags, the kernel driver evaluates and blocks the I/O request instantly in Ring 0. There is no context switch to user mode, resulting in virtually zero latency overhead. Best for strict, blanket policies.
  • Dynamic Filter Rules (ControlFileIOEventFilter): This allows you to register callbacks for complex, custom logic. While this provides maximum control, it introduces complexity and lower performance. The kernel driver must block the active I/O thread, send a message to user mode, and wait for your C++ application to return a verdict before allowing the file operation to proceed.
// --- 1. Static Rule Example (Ring 0 Evaluation) ---
// The kernel evaluates these bitwise AccessFlags instantly at the file system layer,
// blocking unauthorized I/O immediately without incurring user-mode context switch overhead.
FileFilterRule staticRule(L"C:\Secure\*");
ULONG safeAccess = ALLOW_MAX_ACCESS_RIGHT & ~(ALLOW_WRITE_ACCESS | ALLOW_FILE_RENAME | ALLOW_FILE_DELETE);
staticRule.AccessFlags = safeAccess;
staticRule.AddProcessRight(L"trusted_updater.exe", ALLOW_MAX_ACCESS_RIGHT);
filterControl->AddFileFilter(staticRule);

// --- 2. Dynamic Rule Example (User-Mode Callback) ---
FileFilterRule dynamicRule(L"C:\DynamicSecure\*");
// Route file open/create requests to user-space for dynamic evaluation
dynamicRule.ControlFileIOEventFilter = PRE_CREATE;
filterControl->AddFileFilter(dynamicRule);

/* Inside your global MessageCallback function:
   if (pSendMessage->MessageType == PRE_CREATE) {
       // Custom logic to determine if access should be granted
       if (IsUnauthorizedContext(pSendMessage)) {
           // Block the operation dynamically
           pReplyMessage->FilterStatus = FILTER_COMPLETE_PRE_OPERATION;
           pReplyMessage->ReturnStatus = STATUS_ACCESS_DENIED;
           return TRUE;
       }
   }
*/

3. Transparent File Encryption Filter Driver

To prevent data loss and unauthorized viewing, EaseFilter can transparently encrypt files on the fly. The kernel intercepts writes, encrypts the data chunks with AES-256, and attaches a DRM header. Authorized apps read plain text automatically; unauthorized apps see only ciphertext.

FileFilterRule cryptoRule(L"D:\Vault\*");

// Enforce encryption and block raw encrypted block reads from unauthorized apps
cryptoRule.AccessFlags = (ALLOW_MAX_ACCESS_RIGHT | ENABLE_FILE_ENCRYPTION_RULE) & (~ALLOW_READ_ENCRYPTED_FILES);

// Supply the 32-byte AES-256 master key
unsigned char aesKey[32] = { 0x60, 0x3d, 0xeb, /*...*/ 0xf4 };
cryptoRule.set_EncryptionKey(aesKey, sizeof(aesKey));

// Allow a specific app to read the decrypted stream transparently
cryptoRule.AddProcessRight(L"winword.exe", ALLOW_MAX_ACCESS_RIGHT);

filterControl->AddFileFilter(cryptoRule);

4. Process Filter Driver

Monitoring processes is essential for EDR solutions to intercept malware payloads. The ProcessFilterRule traps process creations and terminations system-wide.

// Define a process rule for all executables
ProcessFilterRule procRule(L"*");

// Enable EDR alerts for process start and exit events
procRule.ControlFlag = PROCESS_CREATION_NOTIFICATION | PROCESS_TERMINATION_NOTIFICATION;

filterControl->AddProcessFilter(procRule);

5. Registry Filter Driver

The registry filter protects critical system hives from tampering by unauthorized processes or scripts, operating natively below the application layer.

RegistryFilterRule regRule(L"*");

// Mask to protect a specific application registry key
regRule.RegistryKeyNameFilterMask = L"\REGISTRY\MACHINE\SOFTWARE\MySecurityApp\*";

// Remove registry modification rights
regRule.ControlFlag = REG_MAX_ACCESS_FLAG & ~(REG_ALLOW_RENAME_KEY | REG_ALLOW_DELETE_KEY | REG_ALLOW_CREATE_KEY);

filterControl->AddRegistryFilter(regRule);

6. Real-World Use Cases

Use Case 1: USB Device Control (Data Exfiltration Prevention)

Prevent users from copying sensitive corporate data to unauthorized removable USB drives by enforcing kernel-level write restrictions, while maintaining an audit trail of physical device connections.

// Apply global Volume Control Flags to manage USB behavior and notifications
filterControl->VolumeControlFlag = BLOCK_USB_WRITE | VOLUME_ATTACHED_NOTIFICATION | VOLUME_DETACHED_NOTIFICATION;

/* In your MessageCallback handler for Volume notifications:
   if (pSendMessage->MessageType == VOLUME_ATTACHED) {
       wprintf(L"[DEVICE ALERT] USB Drive Plugged In: %ws\n", pSendMessage->FileName);
   } else if (pSendMessage->MessageType == VOLUME_DETACHED) {
       wprintf(L"[DEVICE ALERT] USB Drive Removed: %ws\n", pSendMessage->FileName);
   }
*/

Use Case 2: Prevent File Copying and "Save As" Operations

Allow users to edit sensitive documents but prevent them from copying files to unprotected locations or executing application "Save As" commands to exfiltrate the data.

FileFilterRule copyRule(L"C:\SecureVault\*");

// Prevent the protected file from being copied out or saved as a new file
copyRule.AllowFileSaveAs = FALSE;
copyRule.EnableBlockSaveAs = TRUE;

filterControl->AddFileFilter(copyRule);

Use Case 3: Zero Trust Vault (Cryptographic Verification)

Ensure that only a specifically signed executable can open files in a highly secure folder. Renaming malware to "TrustedApp.exe" will not bypass this rule.

FileFilterRule ztRule(L"C:\ZeroTrustVault\*");
ztRule.AccessFlags = ALLOW_MAX_ACCESS_RIGHT;
ztRule.ControlFileIOEventFilter = PRE_CREATE;
filterControl->AddFileFilter(ztRule);

/* Inside your global MessageCallback function:
   if (pSendMessage->MessageType == PRE_CREATE) {
       // Suspend deadlock risks via exclusion if needed, then check signature
       if (!VerifyDigitalSignature(pSendMessage->ProcessId)) {
           // Block access if the signature doesn't match
           pReplyMessage->FilterStatus = FILTER_COMPLETE_PRE_OPERATION;
           pReplyMessage->ReturnStatus = STATUS_ACCESS_DENIED;
           return TRUE;
       }
   }
*/

Use Case 4: Transparent Sandboxing & Redirection

A legacy application is trying to write to `C:\System`. To prevent privilege elevation, you want to transparently redirect its writes to a sandbox folder without the application knowing.

FileFilterRule sandboxRule(L"C:\System\*");
sandboxRule.ControlFileIOEventFilter = PRE_CREATE;
filterControl->AddFileFilter(sandboxRule);

/* Inside your global MessageCallback function:
   if (pSendMessage->MessageType == PRE_CREATE && (pSendMessage->DesiredAccess & FILE_WRITE_DATA)) {
       // Redirect the file I/O request to a sandbox path
       wcscpy_s(pReplyMessage->ReparseFileName, MAX_PATH, L"C:\Sandbox\SimulatedSystemFile.tmp");
       pReplyMessage->FilterStatus = FILTER_COMPLETE_PRE_OPERATION;
       pReplyMessage->ReturnStatus = STATUS_REPARSE; // Triggers redirection
       return TRUE;
   }
*/

Conclusion

By leveraging the EaseFilter C++ SDK with this structured approach, systems engineers can bypass the massive learning curve of Windows kernel development. The native FilterControl architecture offers unparalleled performance and granular control, empowering developers to build sophisticated zero-trust security agents, high-speed DLP encryptors, and comprehensive EDR monitors natively.