3 ms·
Use mprotect to change the access protection flags on a page of memory. Assuming it is initially allocated as write but no execute (PROT_READ|PROT_WRITE), write
by skissane 10y ago
Use mprotect to change the access protection flags on a page of memory. Assuming it is initially allocated as write but no execute (PROT_READ|PROT_WRITE), write your machine code to it, then change it to read-only and execute (PROT_READ|PROT_EXEC).
http://man7.org/linux/man-pages/man2/mprotect.2.html http://man7.org/linux/man-pages/man2/mprotect.2.html
mprotect is part of POSIX, so works on Linux, macOS, etc.
The Windows equivalent is VirtualProtect
https://msdn.microsoft.com/en-us/library/windows/desktop/aa366898(v=vs.85).aspx https://msdn.microsoft.com/en-us/library/windows/desktop/aa3...
- jheriko 10y agoAnnoyingly this doesn't apply on the most modern platforms... see windows phone/universal etc as well as mobile platforms, consoles and all sorts of embedded systems. (ps I did a significant chunk of this for https://code.google.com/archive/p/fridgescript/ https://code.google.com/archive/p/fridgescript/ back when this made real sense, I'm not just making hot air... this is quite a mediocre result imo ... bedroom stuff from years ago..,)
- my123 10y agoThere are AsApp variants on UWP, if you claim the JIT permission.