1. Define also an attribute array
1 //Protection flags for Memory pages (executable, readable, writeable)2 Static intprotectionflags[2][2][2] = {3 {4 //Not executable5 {page_noaccess, page_writecopy},6 {page_readonly, page_readwrite},7 }, {8 //executable9 {page_execute, page_execute_writecopy},Ten {page_execute_read, page_execute_readwrite}, One }, A};
2. Parsing section properties, converting to page properties
1 //Loop through all sections and change access flags2 for(i=0; I < module->headers->fileheader.numberofsections; i++, section++) {3 DWORD Protect, oldprotect, size;4 intExecutable = (Section->characteristics & image_scn_mem_execute)! =0;5 intreadable = (Section->characteristics & image_scn_mem_read)! =0;6 intwriteable = (Section->characteristics & image_scn_mem_write)! =0;7 8 //determine protection flags based on characteristics9protect =protectionflags[executable][readable][writeable];Ten if(Section->characteristics &image_scn_mem_not_cached) { OneProtect |=Page_nocache; A } - - //determine size of region theSize = section->Sizeofrawdata; - if(Size >0) { - //Change Memory Access flags -VirtualProtect ((LPVOID) ((pointer_type) section->misc.physicaladdress | imageoffset), size, protect, &oldprotect); + } -}
Section property Page Properties