Skip to content

Instantly share code, notes, and snippets.

@katlogic
Created August 18, 2016 21:14
Show Gist options
  • Save katlogic/3e20fc65c13ef66525d948c946236dd0 to your computer and use it in GitHub Desktop.
Save katlogic/3e20fc65c13ef66525d948c946236dd0 to your computer and use it in GitHub Desktop.
#include <windows.h>
#include <stdio.h>
static int data[1] __attribute__((aligned(4096))) = {1};
int main()
{
MEMORY_BASIC_INFORMATION info;
VirtualQuery(&data, &info, sizeof(info));
printf("%d\n", info.Protect==PAGE_WRITECOPY);
DWORD old, old2;
VirtualProtect(&data, 4096, PAGE_NOACCESS, &old); // ANY flag for that matter
VirtualProtect(&data, 4096, old, &old);
printf("%d\n", info.Protect==PAGE_WRITECOPY);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment