|
|
|
@ -473,3 +473,42 @@ bool Process::setPermisions(const t_memrange & range,const t_memrange &trgrange)
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void* Process::memAlloc(const int length)
|
|
|
|
|
{
|
|
|
|
|
void *ret;
|
|
|
|
|
// returns 0 on error
|
|
|
|
|
ret = VirtualAlloc(0, length, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE);
|
|
|
|
|
if (!ret)
|
|
|
|
|
ret = (void*)-1;
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int Process::memDealloc(const void *ptr, const int length)
|
|
|
|
|
{
|
|
|
|
|
// can only free the whole region at once
|
|
|
|
|
// vfree returns 0 on error
|
|
|
|
|
return !VirtualFree(ptr, 0, MEM_RELEASE)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int Process::memProtect(const void *ptr, const int length, const int prot)
|
|
|
|
|
{
|
|
|
|
|
int prot_native = 0;
|
|
|
|
|
int old_prot = 0;
|
|
|
|
|
|
|
|
|
|
// only support a few constant combinations
|
|
|
|
|
if (prot == 0)
|
|
|
|
|
prot_native = PAGE_NOACCESS;
|
|
|
|
|
else if (prot == Process::MemProt::READ)
|
|
|
|
|
prot_native = PAGE_READONLY;
|
|
|
|
|
else if (prot == Process::MemProt::READ | Process::MemProt::WRITE)
|
|
|
|
|
prot_native = PAGE_READWRITE;
|
|
|
|
|
else if (prot == Process::MemProt::READ | Process::MemProt::WRITE | Process::MemProt::EXECUTE)
|
|
|
|
|
prot_native = PAGE_EXECUTE_READWRITE;
|
|
|
|
|
else if (prot == Process::MemProt::READ | Process::MemProt::EXECUTE)
|
|
|
|
|
prot_native = PAGE_EXECUTE_READ;
|
|
|
|
|
else
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
return !VirtualProtect(ptr, length, prot_native, &old_prot);
|
|
|
|
|
}
|
|
|
|
|