Winapi 使用page_guard保护监视内存更改

Winapi 使用page_guard保护监视内存更改,winapi,memory-address,Winapi,Memory Address,有一个特定的内存区域(DWORD值)不断变化,我想跟踪这些变化 我决定使用PAGE_GUARD保护该区域,以便知道何时访问该区域: int main(void) { SetUnhandledExceptionFilter(exception_filter); //The memory region I want to monitor DWORD* addr= (DWORD*)0x00B8CFD0; //Add page guard protection

有一个特定的内存区域(DWORD值)不断变化,我想跟踪这些变化

我决定使用PAGE_GUARD保护该区域,以便知道何时访问该区域:

int main(void)
{
    SetUnhandledExceptionFilter(exception_filter);

    //The memory region I want to monitor
    DWORD* addr= (DWORD*)0x00B8CFD0;

    //Add page guard protection
    DWORD oldProtection;
    if (!VirtualProtect(addr, sizeof(DWORD), PAGE_READWRITE | PAGE_GUARD, &oldProtection))
        return 1;

    //The exception will occur and at this point I know the memory was accessed
    *addr = 1000;

    return 0;
}

LONG WINAPI exception_filter(PEXCEPTION_POINTERS pExcepPointers)
{
    if(pExcepPointers->ExceptionRecord->ExceptionCode == STATUS_GUARD_PAGE_VIOLATION)
    {
        //the memory region is being accessed
        //but how can I track the new modification?
    }

    return EXCEPTION_CONTINUE_EXECUTION;
}
这很好,但是,我希望从exception_过滤器中读取新值(在本例中为1000)。可能吗


我已经尝试了pExcepPointers的所有属性,但到目前为止无法获得任何相关信息。

CPU没有提供此信息。您可以尝试解析错误指令。或者您可以设置陷阱标志,让处理器单步运行,然后再次查看内存。或者您可以设置
DRn
0我不知道trap标志,但它工作得很好,谢谢!我应该能够毫无问题地使用这个技巧,对吧?假设程序没有使用trap标志玩自己的把戏,并且假设在此期间没有其他线程写入内存。