Made Process::setPermisions functions, to set memory page's permisions

develop
Warmist 2011-07-28 01:00:12 +03:00
parent a01004efd6
commit bc23cc9eca
3 changed files with 31 additions and 0 deletions

@ -25,6 +25,7 @@ distribution.
#include "Internal.h"
#include <dirent.h>
#include <errno.h>
#include <sys/mman.h>
#include <string>
#include <vector>
@ -176,4 +177,16 @@ string Process::getPath()
int Process::getPID()
{
return getpid();
}
bool Process::setPermisions(const t_memrange & range,const t_memrange &trgrange)
{
int result;
int protect=0;
if(trgrange.read)protect|=PROT_READ;
if(trgrange.write)protect|=PROT_WRITE;
if(trgrange.execute)protect|=PROT_EXECUTE;
result=mprotect((void *)range.start, range.end-range.start,protect);
return result==0;
}

@ -356,3 +356,18 @@ string Process::getPath()
string out(String);
return(out.substr(0,out.find_last_of("\\")));
}
bool Process::setPermisions(const t_memrange & range,const t_memrange &trgrange)
{
DWORD newprotect=0;
if(trgrange.read && !trgrange.write && !trgrange.execute)newprotect=PAGE_READONLY;
if(trgrange.read && trgrange.write && !trgrange.execute)newprotect=PAGE_READWRITE;
if(!trgrange.read && !trgrange.write && trgrange.execute)newprotect=PAGE_EXECUTE;
if(trgrange.read && !trgrange.write && trgrange.execute)newprotect=PAGE_EXECUTE_READ;
if(trgrange.read && trgrange.write && trgrange.execute)newprotect=PAGE_EXECUTE_READWRITE;
DWORD oldprotect=0;
bool result;
result=VirtualProtect((LPVOID)range.start,range.end-range.start,newprotect,&oldprotect);
return result;
}

@ -269,6 +269,9 @@ namespace DFHack
int getPID();
/// get the DF Process FilePath
std::string getPath();
/// modify permisions of memory range
bool setPermisions(const t_memrange & range,const t_memrange &trgrange);
private:
VersionInfo * my_descriptor;
PlatformSpecific *d;