如何在模块中创建复制写保护页面?

问题描述

我试图让不同的页面受保护和不受保护,例如我的模块中有 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;

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...