I am trying to use the mprotect API on MacOSX 10.4 (tiger), I tried in every possible way, I know it always returns -1, with errno 13, which means "permission denied" while I try to add write to some executable code.
The same code definitely works on MacOS X 10.5 (leopard).
the code is pretty simple
int ret = mprotect((void*)pFunc, 4096, PROT_WRITE | PROT_EXEC);
where pFunc is the address of any function loaded into the address space of the process. I tried to remove PROT_EXEC before adding the PROT_WRITE permission, but no luck. I also tried aligning pFunc with the page size of the memory, no luck either ...
Any idea how to do this?
Danial
source
share