Overview
Unlike the filesystem which uses ProjFS, registry virtualization uses a different approach:- Hive cloning - Copy entire registry hives to disk
- Registry loading - Load clones as separate hives
- Path redirection - Redirect all registry access to cloned hives
- User-mode only - No kernel drivers required
Architecture
Virtual Registry Class
The core implementation is invirtual_registry class:
virtual_FS_REG/virtual_reg.h
How It Works
1. Hive Enumeration
First, enumerate all subkeys under the root hives:virtual_reg.cpp:11-51
2. Hive Saving
Save each registry hive to disk:virtual_reg.cpp:53-89
This uses the Windows reg save command to save registry hives. For example:
3. Hive Loading
Load the cloned hives under a unique prefix:virtual_reg.cpp:92-153
Registry Hierarchy
After loading, the registry structure looks like:! character separates the VM prefix from the hive name.
4. Registry Access Redirection
When malware accesses the registry, DynamoRIO intercepts system calls and redirects paths. For example, accessing:5. Cleanup on Exit
When analysis completes, unload and remove the virtual registry:virtual_reg.cpp:176-197
Unloading Hives
virtual_reg.cpp:155-173
Registry System Call Interception
Dr.Semu intercepts registry-related system calls using DynamoRIO:Monitored System Calls
FromDrSemu/DrSemu.cpp:512-628, these registry calls are hooked:
Basic Operations:
NtOpenKey- Open registry keyNtOpenKeyEx- Open registry key (extended)NtCreateKey- Create registry keyNtDeleteKey- Delete registry keyNtDeleteValueKey- Delete registry valueNtQueryKey- Query key informationNtQueryValueKey- Query value dataNtSetValueKey- Set value dataNtEnumerateKey- Enumerate subkeysNtEnumerateValueKey- Enumerate values
NtNotifyChangeKey- Monitor key changesNtNotifyChangeMultipleKeys- Monitor multiple keysNtCompactKeys- Compact registry keysNtCompressKey- Compress registry keyNtFlushKey- Flush key to disk
NtCreateKeyTransacted- Create key in transactionNtOpenKeyTransacted- Open key in transactionNtOpenKeyTransactedEx- Open key in transaction (extended)
NtLoadKey/NtLoadKey2/NtLoadKeyEx- Load registry hiveNtSaveKey/NtSaveKeyEx- Save registry hiveNtFreezeRegistry- Freeze registry for backupNtInitializeRegistry- Initialize registryNtLockRegistryKey- Lock registry key
NtQueryMultipleValueKey- Query multiple valuesNtQueryOpenSubKeys- Query open subkeysNtQueryOpenSubKeysEx- Query open subkeys (extended)
Handler Implementation
Handlers are implemented inregistry_handlers.hpp:
- Extracts system call parameters
- Translates registry paths (adds VM prefix)
- Logs the operation to JSON
- Allows the call to proceed with modified path
Storage Structure
Registry hives are stored on disk:Master Copies
The first time Dr.Semu runs, it creates master copies invirtual_reg/HKLM/ and virtual_reg/HKEY_USERS/. These are reused for subsequent runs to avoid re-saving.
Instance Copies
Each analysis instance gets its own copy with a unique prefix (dr_semu_0, dr_semu_1, etc.). This allows:
- Parallel execution of multiple samples
- Isolation between concurrent analyses
- Clean state for each sample
Performance Considerations
Initial Hive Saving
First run is slow due to hive saving:- Enumerates all registry keys
- Saves each hive to disk
- Can take 30-60 seconds
Hive Loading
Loading hives is relatively fast:- Uses Windows
reg loadcommand - Hives are memory-mapped, not fully loaded
- Takes a few seconds per instance
Runtime Performance
Once loaded:- Registry access is nearly native speed
- No additional redirection overhead
- Windows registry cache applies normally
Isolation Guarantees
What’s Isolated
Registry modifications made by malware:- Creating new keys
- Setting values
- Deleting keys/values
- Changing permissions
What’s Shared (Read-Only)
The isolation is copy-on-write-like:- Initial state is a snapshot of the real registry
- Changes don’t affect the host registry
- But changes also don’t sync back
Limitations
Real-time changes to the host registry during analysis are not reflected in the virtual registry, since it’s a point-in-time snapshot. Special keys likeHKEY_CURRENT_USER may require special handling depending on the user context.
Security Considerations
Privilege Requirements
Loading registry hives requires:- SeRestorePrivilege - To load hives
- SeBackupPrivilege - To save hives
- Administrator rights - Usually required
Key Filtering
Dr.Semu skips its own keys:virtual_reg.cpp:72-75
This prevents:
- Recursive cloning
- Interference with running instances
- Malware tampering with Dr.Semu state
Debugging Registry Redirection
View Loaded Hives
Use Registry Editor (regedit.exe):- Navigate to
HKEY_LOCAL_MACHINE - Look for keys named
dr_semu_*!* - These are the loaded virtual hives
Inspect Hive Files
Hive files invirtual_reg/ directory:
- Binary format (same as real registry hives)
- Can be loaded into Registry Editor using File → Load Hive
- Can be analyzed with registry forensic tools
Enable Logging
The code uses spdlog for logging:Source Files
Registry virtualization implementation:virtual_FS_REG/virtual_reg.h- Virtual registry class definitionvirtual_FS_REG/virtual_reg.cpp- Hive cloning and loading implementationvirtual_FS_REG/shared_config.h- Build configurationDrSemu/registry_handlers.hpp- System call handlers (referenced)
Related Components
The registry redirection works with:- Virtual Filesystem - File system isolation
- DynamoRIO Integration - System call interception and path translation