问题描述
我试图让不同的页面受保护和不受保护,例如我的模块中有 10 个页面,我只想保护 5 个页面(写时复制),其他的则不会。我该怎么做?
编辑:我使用的是 Windows 10 x64。
解决方法
在您的情况下,您必须查看 Windows API:VirtualProtect。 您可以在提供的链接中找到函数原型。
您想使用 PAGE_WRITECOPY 标志在您的网页上设置正确的保护:
auto virtualAddress {reinterpret_cast<PVOID>(desiredAddress)};
SIZE_T size {0x1000}; // not guaranteed to be 0x1000
DWORD oldProtection {};
const auto newProtection {PAGE_WRITECOPY};
const auto successful = VirtualProtect(virtualAddress,size,newProtection,&oldProtection) != 0;