Visual Studio allows you to set breakpoints in a memory cell only 4 bytes long (on a 32-bit version of Windows). To catch memory access (read or write), you can use the following class:
struct protect_mem_t { protect_mem_t( void* addr, size_t size ) : addr(addr), size(size), is_protected(FALSE) { protect(); } ~protect_mem_t() { release(); } BOOL protect() { if ( !is_protected ) {
It changes the access mode on the selected memory pages. The page size is 4096 bytes on 32-bit systems. The exception will depend on each access to protected memory. This class is limited to use only for large areas of memory, but I hope this can be useful.
It can be used as follows:
source share