Exception Types
Windows exceptions fall into several categories:Hardware Exceptions
- Access Violation (
STATUS_ACCESS_VIOLATION): Reading/writing unmapped or protected memory - Guard Page Violation (
STATUS_GUARD_PAGE_VIOLATION): Accessing guard page (one-time exception) - Illegal Instruction (
STATUS_ILLEGAL_INSTRUCTION): Invalid opcode - Integer Division by Zero (
STATUS_INTEGER_DIVIDE_BY_ZERO): Division by zero - Single Step (
STATUS_SINGLE_STEP): Debug trap flag set - Breakpoint (
STATUS_BREAKPOINT): INT3 instruction
Software Exceptions
- Raised Exception (
NtRaiseException): Application-generated exception - Hard Error (
NtRaiseHardError): Critical system error
Exception Record
Exceptions are represented byEXCEPTION_RECORD structures:
ExceptionInformation contains:
[0]: Operation type (0=read, 1=write, 8=DEP violation)[1]: Virtual address that caused the fault
Exception Dispatch Flow
Exception Dispatch Implementation
Triggering an Exception
Fromexception_dispatch.cpp:212:
Stack Layout
The exception dispatcher builds a specific stack layout:Specific Exception Types
Access Violation
Fromexception_dispatch.cpp:256:
- Reading unmapped memory
- Writing read-only memory
- Executing non-executable memory
Guard Page Violation
- Stack growth detection: Automatically commit stack pages
- Heap debugging: Detect buffer overruns
- Copy-on-write: Implement lazy copying
Illegal Instruction
Breakpoint
INT3 instruction (opcode 0xCC), commonly used by debuggers.
Single Step
Debug Exceptions
Windows has special handling forINT 2Dh instructions used by debuggers:
From exception_dispatch.cpp:157:
Exception Continuation
After handling an exception, applications can:- Continue execution: Resume at the faulting instruction
- Continue search: Let the next handler try
- Unwind: Clean up and propagate exception
NtContinue syscall:
Raised Exceptions
Applications can manually raise exceptions:WOW64 Exception Handling
For 32-bit processes running under WOW64, exception dispatch uses the “Heaven’s Gate” mechanism to transition between 32-bit and 64-bit mode:Exception Callbacks
Sogen provides hooks for exception monitoring:- Logging: Record exception types and locations
- Analysis: Detect exception-based anti-analysis
- Debugging: Break on specific exception types
- Fuzzing: Track exception coverage
Next Steps
- Architecture - Overall emulator design
- Syscall Emulation - Exception-related syscalls
- Memory Management - Access violations and guard pages
- Threading - Per-thread exception handling