码迷,mamicode.com
首页 > 其他好文 > 详细

节属性 转 页属性

时间:2014-12-11 00:15:41      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   ar   color   sp   for   strong   on   

1. 定义也属性数组

 1     // Protection flags for memory pages (Executable, Readable, Writeable)
 2     static int ProtectionFlags[2][2][2] = {
 3         {
 4             // not executable
 5             {PAGE_NOACCESS, PAGE_WRITECOPY},
 6             {PAGE_READONLY, PAGE_READWRITE},
 7         }, {
 8             // executable
 9             {PAGE_EXECUTE, PAGE_EXECUTE_WRITECOPY},
10             {PAGE_EXECUTE_READ, PAGE_EXECUTE_READWRITE},
11         },
12     };

 

2. 解析节属性,转换为页属性

 1     // loop through all sections and change access flags
 2     for (i=0; i < module->headers->FileHeader.NumberOfSections; i++, section++) {
 3         DWORD protect, oldProtect, size;
 4         int executable = (section->Characteristics & IMAGE_SCN_MEM_EXECUTE) != 0;
 5         int readable =   (section->Characteristics & IMAGE_SCN_MEM_READ) != 0;
 6         int writeable =  (section->Characteristics & IMAGE_SCN_MEM_WRITE) != 0;
 7 
 8         // determine protection flags based on characteristics
 9         protect = ProtectionFlags[executable][readable][writeable];
10         if (section->Characteristics & IMAGE_SCN_MEM_NOT_CACHED) {
11             protect |= PAGE_NOCACHE;
12         }
13 
14         // determine size of region
15         size = section->SizeOfRawData;
16         if (size > 0) {
17             // change memory access flags
18             VirtualProtect((LPVOID)((POINTER_TYPE)section->Misc.PhysicalAddress | imageOffset), size, protect, &oldProtect);
19         }
20     }

 

节属性 转 页属性

标签:style   blog   io   ar   color   sp   for   strong   on   

原文地址:http://www.cnblogs.com/luzhiyuan/p/4156597.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!