Overview
DynamoRIO provides:- User-mode interception - No kernel drivers required
- Binary instrumentation - Works on any Windows executable
- System call hooks - Intercept at user-kernel boundary
- Multi-architecture - Supports both 32-bit and 64-bit
Architecture
DynamoRIO Client
Dr.Semu implements a DynamoRIO client inDrSemu/DrSemu.cpp:
DrSemu/DrSemu.cpp:113-284
Client Execution
Dr.Semu is loaded into the target process:drrun.exe):
- Creates the target process suspended
- Injects
dynamorio.dllinto the process - Loads the Dr.Semu client (
DrSemu.dll) - Transfers control to the client
- Resumes the target process
System Call Interception
1. System Call Filtering
First, filter which system calls to intercept:DrSemu.cpp:413-417
This filters hundreds of system calls down to ~70 relevant ones for malware analysis.
2. Pre-Syscall Handler
Intercept before the system call executes:DrSemu.cpp:419-741
3. Post-Syscall Handler
Intercept after the system call completes:DrSemu.cpp:743-755
Post-handlers can:
- Read return values
- Access output parameters
- Log results
Monitored System Calls
Dr.Semu monitors ~70 system calls across several categories:File System (20+ calls)
Location:DrSemu.cpp:429-508
NtCreateFile/NtOpenFile- Open filesNtWriteFile- Write to filesNtDeleteFile- Delete filesNtQueryInformationFile- Query file infoNtSetInformationFile- Set file infoNtQueryAttributesFile- Get file attributesNtCreateSection- Create file mappingNtMapViewOfSection- Map file into memoryNtQueryDirectoryFile- Enumerate directoryNtFlushBuffersFile- Flush file buffers
Registry (30+ calls)
Location:DrSemu.cpp:511-628
NtOpenKey/NtOpenKeyEx- Open registry keysNtCreateKey- Create registry keysNtDeleteKey/NtDeleteValueKey- Delete keys/valuesNtQueryKey/NtQueryValueKey- Query registry dataNtSetValueKey- Write registry valuesNtEnumerateKey/NtEnumerateValueKey- Enumerate keys/valuesNtLoadKey/NtSaveKey- Load/save hives
Process/Thread (15+ calls)
Location:DrSemu.cpp:631-679
NtCreateUserProcess- Create processNtOpenProcess/NtOpenThread- Open process/threadNtWriteVirtualMemory- Write process memoryNtProtectVirtualMemory- Change memory protectionNtSetContextThread- Modify thread contextNtSuspendProcess- Suspend processNtQueryInformationProcess- Query process infoNtQueryVirtualMemory- Query memory infoNtDelayExecution- Sleep
System Information (5+ calls)
Location:DrSemu.cpp:681-697
NtQuerySystemInformation- Query system infoNtLoadDriver- Load kernel driverNtUserSystemParametersInfo- System parametersNtRaiseHardError- Display error dialog
Object Management (10+ calls)
Location:DrSemu.cpp:699-735
NtCreateMutant/NtOpenMutant- MutexesNtCreateEvent/NtOpenEvent- EventsNtCreateSemaphore/NtOpenSemaphore- SemaphoresNtWaitForSingleObject- Wait for objectNtQueryObject- Query object infoNtCreateMailslotFile- Create mailslot
Function Wrapping
Dr.Semu also wraps high-level API functions:DrSemu.cpp:772-790
This uses DynamoRIO’s drwrap extension to intercept function calls:
DrSemu.cpp:757-769
Parameter Access
Handlers extract system call parameters from registers/stack:filesystem_handlers.hpp are more complex.
Path Translation
Handlers translate virtual paths to real paths:Filesystem Path Translation
Virtual path:\Device\HarddiskVolume2\dr_semu_0\Windows\System32\kernel32.dll
Translated to: \Device\HarddiskVolume2\Windows\System32\kernel32.dll
The virtual root (\dr_semu_0) is stripped.
Registry Path Translation
Virtual path:\Registry\Machine\Software\Microsoft\Windows
Translated to: \Registry\Machine\dr_semu_0!Software\Microsoft\Windows
The VM prefix is inserted after the root key.
Behavior Logging
All intercepted operations are logged to JSON:DrSemu.cpp:369-392 (in event_exit())
The JSON file contains:
- System call name
- Parameters (file paths, registry keys, etc.)
- Timestamps
- Return values
- Thread ID
Process Management
Child Process Tracking
When malware creates child processes:DrSemu.cpp:636-638, 750-753
DynamoRIO automatically follows child processes and injects the Dr.Semu client into them.
Process Termination
Dr.Semu uses “nudge” mechanism for clean termination:DrSemu.cpp:69-84
This allows the launcher to gracefully terminate all monitored processes.
Soft Kill Support
DrSemu.cpp:86-94
This intercepts process termination attempts and converts them to nudges.
Time Management
Dr.Semu can set execution time limits:DrSemu.cpp:34-40, 226-230
This creates a watchdog thread that terminates the process after a timeout.
Command-Line Options
The client receives options from the launcher:DrSemu.cpp:134-146
Example command line:
Architecture Support
Dr.Semu detects 32-bit vs 64-bit:DrSemu.cpp:234
DynamoRIO provides separate clients:
DrSemu.dll- 32-bit client for 32-bit processesDrSemu64.dll- 64-bit client for 64-bit processes
Static Analysis Integration
Before instrumentation, Dr.Semu performs static analysis:DrSemu.cpp:238-248
This uses the pe-parse library to extract:
- PE headers
- Imported functions
- Exported functions
- Sections
- Resources
Performance Considerations
System Call Filtering
Filtering reduces overhead:- Only ~70 of 400+ system calls are intercepted
- Uninteresting calls execute at native speed
- Typical overhead: 10-30%
Concurrent Logging
Uses thread-safe concurrent vector:DrSemu/includes.h:43-45
Multiple threads can log simultaneously without locks.
Memory Overhead
DynamoRIO uses code cache:- Basic blocks are translated once
- Cached for reuse
- Memory usage: 10-50 MB typically
Debugging
Enable DynamoRIO Logging
Client Logging
Usedr_printf() for debugging:
DrSemu.cpp:125-128
Source Files
DynamoRIO integration:DrSemu/DrSemu.cpp- Main client implementationDrSemu/includes.h- Headers and dependenciesDrSemu/filesystem_handlers.hpp- File system call handlersDrSemu/registry_handlers.hpp- Registry call handlersDrSemu/process_handlers.hpp- Process/thread handlersDrSemu/system_handlers.hpp- System information handlersDrSemu/COM_handlers.hpp- COM function handlersDrSemu/networking_handlers.hpp- Network function handlersDrSemu/object_handlers.hpp- Object management handlers
Related Resources
Related Components
- Virtual Filesystem - ProjFS-based file isolation
- Registry Redirection - Registry hive cloning