[Anti-Analysis] Watching Memory Regions using GetWriteWatch API
Protecting Code and Uncovering Debuggers by Watching Memory
I have been exploring some anti-debug techniques listed in the CheckPoint Anti-Debug Knowledge Base. This one really caught my attention. It uses the Kernel32.GetWriteWatch API to detect changes to a memory region (including changes made by debuggers).
Using this API is more efficient than manually calculating checksums, and it can be used to protect sensitive code (e.g. hooks and shellcodes).
I developed this small sample that protects a shellcode (which executes calc.exe). In case the process is attached to a debugger and breakpoints are set at the region containing the shellcode, our watchdog thread catches the tampering and logs an event.

![[Anti-Analysis] Watching Memory Regions using GetWriteWatch API](https://cdn.hashnode.com/res/hashnode/image/upload/v1769440973805/1d380909-fc52-4962-9cd4-e7f84430dba0.jpeg?w=1600&h=840&fit=crop&crop=entropy&auto=compress,format&format=webp)