开发者

How can I protect specific areas of memory with Win32 API?

开发者 https://www.devze.com 2023-02-17 19:43 出处:网络
Suppose I have a buffer of say 100 bytes as in char *pBuffer =开发者_如何学Go new char[100]; and I want to pass this to a third party function with specific instruction that it write into only the top

Suppose I have a buffer of say 100 bytes as in char *pBuffer =开发者_如何学Go new char[100]; and I want to pass this to a third party function with specific instruction that it write into only the top half and that the bottom half is out of limits. How can I enforce that with Win32 API?

Thanks.

PS: This particular example might not be perfect but I am clear about my question.


You'll need to use VirtualProtect to mark the last half as readonly. Since VirtualProtect works with pages, not bytes, you will in your example need to VirtualAlloc PAGE_SIZE + 50 bytes, and adjust pBuffer so it matches your requirements.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号