开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜