How can I execute hex opcodes directly in Rust?

On most newer platforms, you have to explicitly signal to the OS to mark your pages of memory executable and writable in your page table. Otherwise, it will not work. Rust's standard library offers nothing to do that with, but you can always just use libc (or, I assume, winapi).

Here's an example of how that can be done under Linux, by using the mmap call to fetch an executable page. Rust Playground

5 Likes